index.vue 6.5 KB

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