index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <template>
  2. <view class="refund">
  3. <view class="money-section">
  4. <view class="acea-row row-middle item">
  5. <view class="">退款金额</view>
  6. <input v-model="refundMoney" class="input" type="text" />
  7. <text class="iconfont icon-ic_edit"></text>
  8. </view>
  9. <view class="acea-row row-middle item">
  10. <view class="">退款类型</view>
  11. <view class="acea-row row-right radio-group">
  12. <view class="acea-row row-middle radio-item" :class="{ on: !isSplit}" @click="refundTypeChange(0)">
  13. <text class="iconfont" :class="isSplit?'icon-ic_unselect':'icon-ic_Selected'"></text>整单退款
  14. </view>
  15. <view class="acea-row row-middle radio-item" :class="{ on: isSplit}" @click="refundTypeChange(1)">
  16. <text class="iconfont" :class="isSplit?'icon-ic_Selected':'icon-ic_unselect'"></text>分单退款
  17. </view>
  18. </view>
  19. </view>
  20. </view>
  21. <splitOrder v-if="isSplit" :splitGoods="splitGoods" :select_all="false" @getList="getList"></splitOrder>
  22. <view class="footer acea-row row-middle">
  23. <view class="all acea-row row-middle" v-if="isSplit" @click="allChange">
  24. <text class="iconfont" :class="isAll?'icon-a-ic_CompleteSelect':'icon-ic_unselect'"></text>
  25. 全选
  26. </view>
  27. <view class="btn-box">
  28. <view class="btn" :style="{ width: isSplit?'auto':'100%'}" @click="openRefund">
  29. 确认
  30. <text v-if="isSplit">({{ numTotal }})</text>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. import {
  38. getAdminOrderDetail,
  39. orderSplitInfo,
  40. openRefund,
  41. } from '@/api/admin.js';
  42. import splitOrder from '@/components/splitOrder/index.vue';
  43. export default {
  44. components: {
  45. splitOrder,
  46. },
  47. data() {
  48. return {
  49. refundMoney: 0,
  50. isSplit: 0,
  51. isAll: false,
  52. splitGoods: [],
  53. goodsChecked: [],
  54. cart_ids: [],
  55. }
  56. },
  57. computed: {
  58. total() {
  59. return this.goodsChecked.reduce((total, item) => {
  60. return this.$util.$h.Add(total, this.$util.$h.Mul(item.refundPrice, item.surplus_num));
  61. }, 0);
  62. },
  63. numTotal() {
  64. return this.goodsChecked.reduce((total, {
  65. surplus_num,
  66. }) => {
  67. return this.$util.$h.Add(total, surplus_num);
  68. }, 0);
  69. },
  70. },
  71. watch: {
  72. total(newValue, oldValue) {
  73. this.refundMoney = newValue
  74. },
  75. },
  76. onLoad(option) {
  77. this.order_id = option.id;
  78. this.listId = option.listId;
  79. this.getIndex();
  80. // this.splitList();
  81. },
  82. methods: {
  83. allChange() {
  84. this.isAll = !this.isAll;
  85. this.cart_ids = [];
  86. this.goodsChecked = [];
  87. for (let i = 0; i < this.splitGoods.length; i++) {
  88. this.splitGoods[i].checked = this.isAll;
  89. if (this.splitGoods[i].checked) {
  90. this.goodsChecked.push(this.splitGoods[i]);
  91. this.cart_ids.push(this.splitGoods[i].id);
  92. }
  93. }
  94. },
  95. refundTypeChange(value) {
  96. this.isSplit = value;
  97. if (value) {
  98. this.goodsChecked = []
  99. } else {
  100. this.goodsChecked = this.splitGoods
  101. }
  102. },
  103. splitList() {
  104. orderSplitInfo(this.listId).then(res => {
  105. let list = res.data;
  106. list.forEach((item) => {
  107. item.checked = false
  108. item.numShow = item.surplus_num
  109. })
  110. // this.splitGoods = list;
  111. }).catch(err => {
  112. return this.$util.Tips({
  113. title: err
  114. });
  115. })
  116. },
  117. getIndex() {
  118. let that = this;
  119. let obj = '';
  120. getAdminOrderDetail(that.order_id).then(res => {
  121. const {
  122. cartInfo
  123. } = res.data;
  124. let list = cartInfo.map(item => {
  125. return {
  126. id: item.id,
  127. checked: false,
  128. numShow: item.cart_num - item.refund_num,
  129. surplus_num: item.cart_num - item.refund_num,
  130. cart_info: item,
  131. refundPrice: this.$util.$h.Div(item.refund_price, item.cart_num),
  132. };
  133. });
  134. this.splitGoods = list;
  135. this.goodsChecked = list;
  136. }).catch(err => {
  137. that.$util.Tips({
  138. title: err.msg
  139. });
  140. })
  141. },
  142. getList(val) {
  143. let that = this;
  144. let goodsChecked = [];
  145. let cart_ids = [];
  146. for (let i = 0; i < val.length; i++) {
  147. if (val[i].checked) {
  148. goodsChecked.push(val[i]);
  149. cart_ids.push(val[i].id);
  150. }
  151. }
  152. this.goodsChecked = goodsChecked;
  153. this.cart_ids = cart_ids;
  154. this.isAll = this.goodsChecked.length == this.splitGoods.length;
  155. },
  156. openRefund() {
  157. let cart_ids = [];
  158. let data = {
  159. refund_price: this.refundMoney,
  160. type: 1,
  161. is_split_order: this.isSplit,
  162. };
  163. cart_ids = this.goodsChecked.map(({
  164. id,
  165. surplus_num
  166. }) => {
  167. return {
  168. cart_id: id,
  169. cart_num: surplus_num
  170. }
  171. });
  172. data.cart_ids = cart_ids;
  173. openRefund(this.listId, data).then(res => {
  174. if (res.data.order_id) {
  175. // const pages = getCurrentPages();
  176. // pages.splice(pages.length - 2, 2)
  177. this.$util.Tips({
  178. title: res.msg
  179. }, {
  180. tab: 5,
  181. url: '/pages/admin/orderDetail/index?id=' + res.data.order_id + '&types=',
  182. });
  183. } else {
  184. this.$util.Tips({
  185. title: res.msg
  186. }, {
  187. tab: 3,
  188. url: 1,
  189. });
  190. }
  191. }).catch(err => {
  192. this.$util.Tips({
  193. title: err
  194. });
  195. })
  196. },
  197. },
  198. }
  199. </script>
  200. <style lang="scss" scoped>
  201. .refund {
  202. padding: 22rpx 20rpx;
  203. }
  204. .money-section {
  205. padding: 12rpx 0;
  206. border-radius: 24rpx;
  207. background: #FFFFFF;
  208. .item {
  209. height: 80rpx;
  210. padding: 0 24rpx;
  211. font-size: 28rpx;
  212. color: #333333;
  213. }
  214. .input {
  215. flex: 1;
  216. height: 80rpx;
  217. text-align: right;
  218. font-family: Regular;
  219. font-size: 36rpx;
  220. color: #FF7E00;
  221. }
  222. .icon-ic_edit {
  223. margin-left: 8rpx;
  224. font-size: 32rpx;
  225. color: #999999;
  226. }
  227. .radio-group {
  228. flex: 1;
  229. }
  230. .radio-item {
  231. font-size: 28rpx;
  232. color: #999999;
  233. +.radio-item {
  234. margin-left: 48rpx;
  235. }
  236. .iconfont {
  237. margin-right: 12rpx;
  238. font-size: 32rpx;
  239. }
  240. &.on {
  241. color: #333333;
  242. .iconfont {
  243. color: #2A7EFB;
  244. }
  245. }
  246. }
  247. }
  248. .footer {
  249. position: fixed;
  250. bottom: 0;
  251. left: 0;
  252. width: 100%;
  253. padding: 16rpx 20rpx 16rpx 32rpx;
  254. padding-bottom: calc(16rpx + constant(safe-area-inset-bottom));
  255. padding-bottom: calc(16rpx + env(safe-area-inset-bottom));
  256. background: #FFFFFF;
  257. .btn {
  258. display: inline-block;
  259. height: 64rpx;
  260. padding: 0 40rpx;
  261. border-radius: 32rpx;
  262. background: #2A7EFB;
  263. font-weight: 500;
  264. font-size: 26rpx;
  265. line-height: 64rpx;
  266. color: #FFFFFF;
  267. }
  268. .all {
  269. font-size: 26rpx;
  270. color: #333333;
  271. .iconfont {
  272. margin-right: 12rpx;
  273. font-size: 40rpx;
  274. color: #CCCCCC;
  275. &.icon-a-ic_CompleteSelect {
  276. color: #2A7EFB;
  277. }
  278. }
  279. }
  280. .btn-box {
  281. flex: 1;
  282. text-align: right;
  283. .btn {
  284. text-align: center;
  285. }
  286. }
  287. }
  288. </style>