refund.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <view class="app-content">
  3. <view class="flex refund-item">
  4. <view class="refund-label">退款方式:</view>
  5. <view class="flex list">
  6. <view class="flex" @tap="refundType=1" >
  7. <view class="flex-center radioBtn" :class="refundType==1?'active':''">
  8. </view>退货并退款</view>
  9. <view style="margin-left: 30upx" class="flex" @tap="refundType=2">
  10. <view class="flex-center radioBtn" :class="refundType==1?'':'active'">
  11. </view>仅退款</view>
  12. </view>
  13. </view>
  14. <view class="refund-item-list" v-if="refundType==1">
  15. <view class="refund-label"><text></text>选择商品:</view>
  16. <view>
  17. <template v-if="!$util.isEmpty(goodsInfoList)">
  18. <view class="list" v-for="(res,i) in goodsInfoList" :key="i">
  19. <view class="flex list-title" >
  20. <text class="product-name">{{res.name}}</text>
  21. <text class="product-num">{{ `${parseFloat(res.num)}` }}份</text>
  22. <text class="product-price">{{`${parseFloat(res.unitPrice)}`}}元/份</text>
  23. </view>
  24. <view class="flex list-val" style="font-size:26upx;font-weight:bold;">
  25. <input type="number" placeholder="退货数" v-model="res.refundCount" placeholder-style="color:#CCCCCC" />
  26. <text style="margin-left:10upx;">份</text>
  27. <text style="color:green;margin-left:20upx;">可退{{Number(res.num)-Number(res.refundNum)}}份</text>
  28. </view>
  29. </view>
  30. </template>
  31. <template v-if="!$util.isEmpty(itemInfoList)">
  32. <view class="list" v-for="(res,i) in itemInfoList" :key="i">
  33. <view class="flex list-title" >
  34. <text class="product-name">{{res.name}}</text>
  35. <text class="product-num">{{ `${parseFloat(res.num)}` }}{{res.unitName}}</text>
  36. <text class="product-price">{{`${parseFloat(res.unitPrice)}`}}元/{{res.unitName}}</text>
  37. </view>
  38. <view class="flex list-val" style="font-size:26upx;font-weight:bold;">
  39. <input type="number" placeholder="退货数" v-model="res.refundCount" placeholder-style="color:#CCCCCC" />
  40. <text style="margin-left:10upx;">{{res.unitName}}</text>
  41. <text style="color:green;margin-left:20upx;">可退{{Number(res.num)-Number(res.refundNum)}}{{res.unitName}}</text>
  42. </view>
  43. </view>
  44. </template>
  45. </view>
  46. </view>
  47. <view class="flex refund-item">
  48. <view class="refund-label">订单金额:</view>
  49. <view class="list">
  50. ¥{{parseFloat(orderInfo.orderPrice)||0}}
  51. <text style="margin-left:25upx;font-size:25upx;color:green;" v-if="Number(orderInfo.tkPrice)>0">已退¥{{orderInfo.tkPrice ? parseFloat(orderInfo.tkPrice) : 0}}</text>
  52. </view>
  53. </view>
  54. <view class="flex refund-item">
  55. <view class="refund-label">可退金额:</view>
  56. <view class="list">¥{{coundRefundPrice}}</view>
  57. </view>
  58. <view class="flex refund-item">
  59. <view class="refund-label"><text></text>退款金额:</view>
  60. <input type="digit" v-model="refundMoney" @focus="refundMoney=''">
  61. </view>
  62. <view class="refund-item">
  63. <view class="refund-label">备注:</view>
  64. <textarea v-model="remark" />
  65. </view>
  66. <view class="flex-center btn-box" style="margin-bottom:50upx;margin-top:20upx;">
  67. <view class="flex-center btn" @tap="cancelRefund">取消</view>
  68. <view class="flex-center btn active" @tap="confirmRefund" style="margin-left: 80upx">确定</view>
  69. </view>
  70. </view>
  71. </template>
  72. <script>
  73. import { getDetail,refund } from "@/api/order/index";
  74. export default {
  75. name: "orderDetail",
  76. components: {},
  77. data() {
  78. return {
  79. product:[],
  80. goodsInfoList:[],
  81. itemInfoList:[],
  82. refundMoney:0,
  83. refundType:1,
  84. remark:'',
  85. orderInfo:{},
  86. coundRefundPrice:0
  87. };
  88. },
  89. onShow() {
  90. },
  91. computed:{
  92. refundPrice(){
  93. let price = 0
  94. if(!this.$util.isEmpty(this.goodsInfoList)){
  95. for (const item of this.goodsInfoList) {
  96. if(Number(item.refundCount)>0){
  97. let currentPrice = Number(item.refundCount)*Number(item.unitPrice)
  98. currentPrice.toFixed(2)
  99. price = Number(price) + Number(currentPrice)
  100. price.toFixed(2)
  101. }
  102. }
  103. }
  104. if(!this.$util.isEmpty(this.itemInfoList)){
  105. for (const item of this.itemInfoList) {
  106. if(Number(item.refundCount)>0){
  107. let currentPrice = Number(item.refundCount)*Number(item.unitPrice)
  108. currentPrice.toFixed(2)
  109. price = Number(price) + Number(currentPrice)
  110. price.toFixed(2)
  111. }
  112. }
  113. }
  114. this.refundMoney = parseFloat(price.toFixed(2))
  115. return price
  116. }
  117. },
  118. watch:{
  119. },
  120. methods: {
  121. cancelRefund(){
  122. uni.navigateBack({delta: 1});
  123. },
  124. confirmRefund(){
  125. let hasError = false
  126. let selectProduct = []
  127. let that = this
  128. if(!this.$util.isEmpty(this.goodsInfoList)){
  129. this.goodsInfoList.forEach(ele=>{
  130. let currentRefundCont = ele.refundCount ? Number(ele.refundCount) :0
  131. let currentNum = ele.num ? Number(ele.num) : 0
  132. let hasRefundNum = ele.refundNum ? Number(ele.refundNum) : 0
  133. let couldRefundNum = Number(currentNum) - Number(hasRefundNum)
  134. if(Number(currentRefundCont) > Number(couldRefundNum)){
  135. uni.showToast({title:ele.name+'超过可退数量',icon:'none'})
  136. hasError = true;
  137. return false
  138. }
  139. if(Number(ele.refundCount)>0){
  140. selectProduct.push({"productId":ele.goodsId,"num":ele.refundCount,"unitType":ele.unitType,unitName:ele.unitName,unitPrice:ele.unitPrice,property:0})
  141. }
  142. })
  143. }
  144. if(!this.$util.isEmpty(this.itemInfoList)){
  145. this.itemInfoList.forEach(ele=>{
  146. let currentRefundCont = ele.refundCount ? Number(ele.refundCount) :0
  147. let currentNum = ele.num ? Number(ele.num) : 0
  148. let hasRefundNum = ele.refundNum ? Number(ele.refundNum) : 0
  149. let couldRefundNum = Number(currentNum) - Number(hasRefundNum)
  150. if(Number(currentRefundCont) > Number(couldRefundNum)){
  151. uni.showToast({title:ele.name+'超过可退数量',icon:'none'})
  152. hasError = true;
  153. return false
  154. }
  155. if(Number(ele.refundCount)>0){
  156. selectProduct.push({"productId":ele.itemId,"num":ele.refundCount,"unitType":ele.unitType,unitName:ele.unitName,unitPrice:ele.unitPrice,property:1})
  157. }
  158. })
  159. }
  160. if(hasError){
  161. return
  162. }
  163. if(this.$util.isEmpty(selectProduct)&&this.refundType==1){
  164. uni.showToast({title:'请选择商品',icon:'none'})
  165. return;
  166. }
  167. let refundParams = {product:JSON.stringify(selectProduct),id: this.option.id,price:this.refundMoney,remark:this.remark,refundType:this.refundType,getOriginalItem:1}
  168. that.$util.confirmModal({content:'确认退款?'},() => {
  169. uni.showLoading({mask:true})
  170. refund(refundParams).then(res => {
  171. uni.hideLoading()
  172. if(res.code == 1){
  173. this.$util.pageTo({url:'/common/success',query:{titleType:1},type:2})
  174. }
  175. })
  176. })
  177. },
  178. async init() {
  179. const res = await getDetail({ id: this.option.id})
  180. this.orderInfo = res.data
  181. this.coundRefundPrice = Number(res.data.orderPrice) - Number(res.data.tkPrice)
  182. this.coundRefundPrice = this.coundRefundPrice.toFixed(2)
  183. this.coundRefundPrice = parseFloat(this.coundRefundPrice)
  184. this.goodsInfoList = res.data.goodsInfoList.map(ele=>{
  185. return {...ele,refundCount:null}
  186. })
  187. this.itemInfoList = res.data.itemInfoList.map(ele=>{
  188. return {...ele,refundCount:null}
  189. })
  190. }
  191. }
  192. };
  193. </script>
  194. <style lang="scss" scoped>
  195. .app-content{
  196. height: calc(100vh - 30upx * 2);
  197. padding: 30upx;
  198. background: #FFFFFF;
  199. font-size: 30upx;
  200. .radioBtn{
  201. width: 30upx;
  202. height: 30upx;
  203. margin-right: 10upx;
  204. border: 1upx solid #ddd;
  205. border-radius: 50%;
  206. &.active{
  207. position: relative;
  208. border: 1upx solid #3385ff;
  209. &:after{
  210. content: '';
  211. position: absolute;
  212. width: 18upx;
  213. height: 18upx;
  214. background: #3385ff;
  215. border-radius: 50%;
  216. }
  217. }
  218. }
  219. .refund-item-list{
  220. display: flex;
  221. padding-bottom: 30upx;
  222. padding-top: 30upx;
  223. border-top: 1upx solid #e6e4e4;
  224. border-bottom: 1upx solid #e6e4e4;
  225. .refund-label{
  226. width: 200upx;
  227. color:#666666;
  228. font-size:26upx;
  229. text{color: red;}
  230. }
  231. .list{
  232. margin-bottom: 10upx;
  233. .list-title{
  234. height: 60upx;
  235. padding-bottom: 20upx;
  236. font-size:26upx;
  237. font-weight:bold;
  238. .product-name{
  239. overflow: hidden;
  240. text-overflow:ellipsis;
  241. white-space: nowrap;
  242. width:190upx;
  243. }
  244. .product-price{
  245. overflow: hidden;
  246. text-overflow:ellipsis;
  247. white-space: nowrap;
  248. width:130upx;
  249. margin-left:10upx;
  250. }
  251. .product-num{
  252. width:90upx;
  253. overflow: hidden;
  254. text-overflow:ellipsis;
  255. white-space: nowrap;
  256. margin-left:10upx;
  257. }
  258. }
  259. .list-val{
  260. input{
  261. width: 200upx;
  262. border: 1upx solid #ddd;
  263. text-align: center;
  264. font-weight: normal;
  265. }
  266. }
  267. }
  268. }
  269. .refund-item{
  270. display: flex;
  271. padding: 18upx 0;
  272. .refund-label{
  273. width: 200upx;
  274. color:#666666;
  275. font-size:26upx;
  276. text{
  277. color: red;
  278. }
  279. }
  280. input{
  281. border: 1upx solid #ddd;
  282. }
  283. textarea{
  284. width: calc(100% - 210upx);
  285. height:150upx;
  286. border: 1upx solid #ddd;
  287. }
  288. }
  289. .btn-box{
  290. .btn{
  291. width: 220upx;
  292. height: 90upx;
  293. border: 1upx solid #666666;
  294. border-radius: 10upx;
  295. color:#666666;
  296. &.active{
  297. background: #3385ff;
  298. color: #fff;
  299. border: 1upx solid #3385ff;
  300. }
  301. }
  302. }
  303. }
  304. </style>