apply.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <template>
  2. <view :style="themeColor()">
  3. <swiper :indicator-dots="false" :autoplay="false" :disable-touch="true" :current="step" class="h-screen" :duration="300" v-if="detail">
  4. <swiper-item>
  5. <scroll-view scroll-y="true" class="bg-page h-screen">
  6. <view class="m-[24rpx] px-[24rpx] rounded-md bg-white">
  7. <view class="flex py-[30rpx] border-0 !border-b !border-[#f5f5f5] border-solid">
  8. <u--image width="120rpx" height="120rpx" :src="img(orderDetail.sku_image)" model="aspectFill">
  9. <template #error>
  10. <u-icon name="photo" color="#999" size="50"></u-icon>
  11. </template>
  12. </u--image>
  13. <view class="flex flex-1 w-0 flex-col justify-between ml-[20rpx]">
  14. <view>
  15. <view class="text-ellipsis text-[#303133] text-sm leading-normal">{{orderDetail.goods_name}}</view>
  16. <view class="mt-[10rpx] text-[26rpx] text-gray-subtitle">{{ orderDetail.sku_name }}</view>
  17. </view>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="m-[24rpx] px-[24rpx] rounded-md bg-white">
  22. <view class="py-[24rpx] flex items-center" @click="selectRefundType(1)">
  23. <view class="flex-1">
  24. <view class="text-sm">仅退款</view>
  25. <view class="text-xs mt-[10rpx] text-gray-subtitle" v-if="orderDetail.goods_type !='virtual'">未收到货,或与商家协商一致不用退货只退款</view>
  26. <view class="text-xs mt-[10rpx] text-gray-subtitle" v-else>与商家协商一致仅退款</view>
  27. </view>
  28. <text class="iconfont iconxiangyoujiantou text-[26rpx] text-gray-subtitle"></text>
  29. </view>
  30. <view class="py-[24rpx] flex items-center border-0 !border-t !border-[#f5f5f5] border-solid" v-if="orderDetail.goods_type == 'real' && (!orderDetail.delivery_status || orderDetail.delivery_status != 'wait_delivery')" @click="selectRefundType(2)">
  31. <view class="flex-1">
  32. <view class="text-sm">退货退款</view>
  33. <view class="text-xs mt-[10rpx] text-gray-subtitle">已收到货,需退还收到的货物</view>
  34. </view>
  35. <text class="iconfont iconxiangyoujiantou text-[26rpx] text-gray-subtitle"></text>
  36. </view>
  37. </view>
  38. </scroll-view>
  39. </swiper-item>
  40. <swiper-item>
  41. <scroll-view scroll-y="true" class="bg-page h-screen">
  42. <view class="m-[24rpx] px-[24rpx] rounded-md bg-white">
  43. <view class="py-[24rpx] flex justify-between items-center">
  44. <view class="text-sm">退款原因</view>
  45. <view class="flex items-center" @click="refundCausePopup = true">
  46. <view class="flex-1 text-right">
  47. <view class="text-xs text-gray-subtitle truncate w-[460rpx]">{{ formData.reason || '请选择' }}</view>
  48. </view>
  49. <text class="iconfont iconxiangyoujiantou text-[26rpx] text-gray-subtitle"></text>
  50. </view>
  51. </view>
  52. </view>
  53. <view class="m-[24rpx] px-[24rpx] rounded-md bg-white">
  54. <view class="py-[24rpx] flex items-center">
  55. <view class="text-sm">退款金额</view>
  56. <view class="flex-1 text-right">
  57. <view class="flex justify-end items-center">
  58. <text class="font-bold text-sm leading-none">¥</text>
  59. <input type="number" v-model.number="formData.apply_money" class="font-bold text-sm leading-none" :style="{ width: inputWidth(formData.apply_money) }" @blur="handleInput">
  60. </view>
  61. <view class="text-xs text-gray-subtitle mt-[10rpx]">
  62. <text>最多可输入金额¥{{ refundMoney.refund_money }}</text>
  63. <text v-if="refundMoney.is_refund_delivery === 1 && Number(refundMoney.refund_delivery_money) > 0" class="ml-[10rpx]">(包含运费¥{{ refundMoney.refund_delivery_money }})</text>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. <view class="m-[24rpx] px-[24rpx] rounded-md bg-white">
  69. <view class="py-[24rpx]">
  70. <view class="text-sm">上传凭证<text class="text-xs text-gray-subtitle ml-[10rpx]">选填</text></view>
  71. <view class="p-[20rpx] bg-[#f5f5f5] rounded mt-[20rpx]">
  72. <u-upload
  73. :fileList="voucherListPreview"
  74. @afterRead="afterRead"
  75. @delete="deletePic"
  76. multiple
  77. :maxCount="9"></u-upload>
  78. </view>
  79. </view>
  80. </view>
  81. <view class="m-[24rpx] px-[24rpx] rounded-md bg-white">
  82. <view class="py-[24rpx]">
  83. <view class="text-sm">补充描述<text class="text-xs text-gray-subtitle ml-[10rpx]">选填</text></view>
  84. <view class="p-[20rpx] bg-[#f5f5f5] rounded mt-[20rpx] h-[200rpx]">
  85. <textarea class="text-[28rpx] w-full h-full leading-[40rpx]" v-model="formData.remark" :maxlength="100" placeholder="补充描述,有助于更好的处理售后问题" placeholder-class="text-[28rpx]"></textarea>
  86. </view>
  87. </view>
  88. </view>
  89. <view class="mt-[40rpx] m-[24rpx]">
  90. <u-button type="primary" shape="circle" text="提交" @click="save" :loading="operateLoading"></u-button>
  91. </view>
  92. <!-- 退款原因 -->
  93. <u-popup :show="refundCausePopup" @close="close" @open="open">
  94. <view class="px-[30rpx] pb-[30rpx]" @touchmove.prevent.stop>
  95. <view class="flex items-center h-[90rpx] justify-between">
  96. <text>退款原因</text>
  97. <text class="iconfont iconguanbi" @click="refundCausePopup = false"></text>
  98. </view>
  99. <scroll-view scroll-y="true" class="h-[450rpx] mt-[20rpx]">
  100. <u-radio-group v-model="currReasonName" placement="column">
  101. <u-radio activeColor="var(--primary-color)" :customStyle="{marginBottom: '8px'}" v-for="(item, index) in reason" :key="index" :label="item" :name="item"></u-radio>
  102. </u-radio-group>
  103. </scroll-view>
  104. <u-button type="primary" class="mt-[40rpx]" shape="circle" @click="refundCausePopupFn">确定</u-button>
  105. </view>
  106. </u-popup>
  107. </scroll-view>
  108. </swiper-item>
  109. </swiper>
  110. <!-- #ifdef MP-WEIXIN -->
  111. <!-- 小程序隐私协议 -->
  112. <wx-privacy-popup ref="wxPrivacyPopupRef"></wx-privacy-popup>
  113. <!-- #endif -->
  114. </view>
  115. </template>
  116. <script setup lang="ts">
  117. import { ref, computed } from 'vue'
  118. import { onLoad } from '@dcloudio/uni-app'
  119. import { redirect, img, moneyFormat } from '@/utils/common'
  120. import { t } from '@/locale'
  121. import { getMallOrderDetail } from '@/addon/mall/api/order'
  122. import { getRefundReason, applyRefund,getRefundMoney } from '@/addon/mall/api/refund'
  123. import { uploadImage } from '@/app/api/system'
  124. import { useSubscribeMessage } from '@/hooks/useSubscribeMessage'
  125. const detail = ref(null)
  126. const orderDetail = ref({})
  127. const orderGoodsId = ref(0)
  128. const step = ref(0)
  129. let refundCausePopup = ref(false)
  130. const formData = ref({
  131. order_id: detail.value?.order_id,
  132. order_goods_id: orderGoodsId.value,
  133. refund_type: '',
  134. apply_money: '',
  135. reason: '',
  136. remark: '',
  137. voucher: []
  138. })
  139. let refundMoney = ref<any>({}) // 可退款金额
  140. const reason = ref<string[]>([])
  141. const currReasonName = ref('')
  142. getRefundReason().then(({ data }) => {
  143. reason.value = data
  144. if(reason.value && reason.value.length) currReasonName.value = reason.value[0];
  145. }).catch()
  146. onLoad((data) => {
  147. orderGoodsId.value = data.order_goods_id || 0
  148. formData.value.order_goods_id = orderGoodsId.value
  149. formData.value.order_id = data.order_id || 0
  150. getMallOrderDetail(data.order_id).then(({ data }) => {
  151. detail.value = data
  152. detail.value.order_goods.forEach((item,index)=>{
  153. if(orderGoodsId.value == item.order_goods_id){
  154. orderDetail.value = item;
  155. }
  156. })
  157. }).catch(() => {
  158. })
  159. // 获取可退款金额
  160. getRefundMoney({order_goods_id: data.order_goods_id}).then(res =>{
  161. refundMoney.value = res.data
  162. formData.value.apply_money = moneyFormat(refundMoney.value.refund_money)
  163. })
  164. })
  165. const inputWidth = computed((value) => {
  166. return function (value) {
  167. if (value == '' || value == 0) {
  168. return '60rpx';
  169. } else {
  170. return String(value).length * 17 + 'rpx';
  171. }
  172. };
  173. })
  174. const selectRefundType = (type : number) => {
  175. formData.value.refund_type = type
  176. step.value = 1
  177. }
  178. const voucherListPreview = computed(() => {
  179. return formData.value.voucher.map(item => {
  180. return {url: img(item)}
  181. })
  182. })
  183. const afterRead = (event) => {
  184. event.file.forEach(item => {
  185. uploadImage({
  186. filePath: item.url,
  187. name: 'file'
  188. }).then(res => {
  189. if (formData.value.voucher.length < 9 ) {
  190. formData.value.voucher.push(res.data.url)
  191. }
  192. }).catch(() => {
  193. })
  194. })
  195. }
  196. const deletePic = (event)=> {
  197. formData.value.voucher.splice(event.index, 1)
  198. }
  199. const operateLoading = ref(false)
  200. const save = ()=> {
  201. if(!formData.value.reason){
  202. uni.showToast({
  203. title: '请选择退款原因',
  204. icon: 'none'
  205. });
  206. return false;
  207. }
  208. if((Number(formData.value.apply_money).toFixed(2)) < 0 ){
  209. uni.showToast({
  210. title: '退款金额不能为0,保留两位小数',
  211. icon: 'none'
  212. });
  213. return false;
  214. }
  215. if(Number(formData.value.apply_money) > Number(refundMoney.value.refund_money)) {
  216. uni.showToast({
  217. title: '退款金额不能大于可退款总额',
  218. icon: 'none'
  219. });
  220. return false;
  221. }
  222. if (operateLoading.value) return
  223. operateLoading.value = true
  224. applyRefund(formData.value).then((res) => {
  225. operateLoading.value = false
  226. // 订阅消息
  227. useSubscribeMessage().request('mall_refund_agree,mall_refund_refuse')
  228. setTimeout(()=> {
  229. redirect({ url: '/addon/mall/pages/order/detail', param: { order_id: formData.value.order_id } })
  230. }, 1000)
  231. }).catch(() => {
  232. operateLoading.value = false
  233. })
  234. }
  235. const refundCausePopupFn = ()=>{
  236. formData.value.reason = currReasonName.value;
  237. refundCausePopup.value = false;
  238. }
  239. const handleInput = (event:any) =>{
  240. if(Number(event.detail.value) > Number(refundMoney.value.refund_money)){
  241. uni.showToast({
  242. title: '退款金额不能大于可退款总额',
  243. icon: 'none'
  244. });
  245. }
  246. }
  247. </script>
  248. <style lang="scss" scoped>
  249. :deep(.u-upload__button) {
  250. width: 70px!important;
  251. height: 70px!important;
  252. border: 1px dashed #ddd;
  253. }
  254. :deep(.u-upload__wrap__preview__image) {
  255. width: 70px!important;
  256. height: 70px!important;
  257. }
  258. </style>