AddReturn.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <template>
  2. <view class="detail-view">
  3. <u-form label-width="140" :model="add_form" ref="uForm">
  4. <view class="form-model-view">
  5. <u-form-item required label="选择订单" prop="originNo">
  6. <u-input @click="goPage('/pagesT/order/selOrder')" class="dis-input" disabled v-model="add_form.originNo" placeholder="请选择" />
  7. <u-icon name="arrow-right" size="24" color="#6c6c6c"></u-icon>
  8. </u-form-item>
  9. <u-form-item v-if="add_form.originNo" label="退货商铺"><u-input class="dis-input" disabled v-model="add_form.shopName" placeholder="请选择" /></u-form-item>
  10. <u-form-item required label="商品清单" label-position="top">
  11. <view class="goods-view">
  12. <view class="desc">
  13. 共{{ goods_list.length }}种商品,{{ numTotal }}个
  14. <!-- <u-icon name="arrow-right" size="24" color="#6c6c6c"></u-icon> -->
  15. </view>
  16. <block v-for="(item, index) in goods_list" :key="index">
  17. <image v-if="index <= 4" :src="item.images ? item.images[0] : '../../static/img/goods.png'" mode="aspectFill"></image>
  18. </block>
  19. <view class="more-goods" @click="openSelect('sel_pop')"><u-icon name="more-dot-fill" size="36" color="#6c6c6c"></u-icon></view>
  20. </view>
  21. </u-form-item>
  22. </view>
  23. <view class="form-model-view">
  24. <u-form-item label="订单备注" label-position="top"><u-input type="textarea" v-model="add_form.remark" /></u-form-item>
  25. </view>
  26. </u-form>
  27. <u-popup v-model="sel_pop" mode="bottom">
  28. <view class="sel-goods-pop">
  29. <view class="pop-tit clearfix">
  30. <view class="float_left">本次已选商品</view>
  31. <!-- <view class="float_right" @click="clearGoods">
  32. <text class="custom-icon custom-icon-shanchu"></text>
  33. <text>清空</text>
  34. </view> -->
  35. </view>
  36. <scroll-view class="goods-ul" scroll-y>
  37. <view class="goods-li" v-for="(item, index) in goods_list" :key="index">
  38. <view class="goods-name">{{ item.goodsName }}</view>
  39. <view class="goods-code clearfix">
  40. <view class="float_left">{{ item.goodsCode }}</view>
  41. <view class="float_right">
  42. <view style="width:200rpx;display: inline-block;border: 1px solid #eeeeee; vertical-align: middle;border-radius: 8rpx;text-align: right;padding: 0 10rpx;">
  43. <input style="height: 40rpx;line-height: 40rpx;" type="digit" v-model="item.returnUnitPrice" />
  44. </view>
  45. 元/{{ item.unitName }}
  46. </view>
  47. </view>
  48. <view class="goods-code clearfix">
  49. <view class="float_left">
  50. {{ item.unitName }};
  51. <text v-for="(sku, skuI) in sku.specGroup" :key="skuI">{{ sku.specValueName }};</text>
  52. </view>
  53. <view class="float_right"><u-number-box :min="0" :index="index" :value="item.num"></u-number-box></view>
  54. </view>
  55. <text class="custom-icon custom-icon-shanchu" @click="delGoods(index, item)"></text>
  56. </view>
  57. <view style="padding-top: 100rpx;" v-if="!goods_list.length"><u-empty text="未选择商品" mode="data"></u-empty></view>
  58. </scroll-view>
  59. </view>
  60. </u-popup>
  61. <view class="detail-bottom"><view class="handel-btn" @click="submit">提交订单</view></view>
  62. <u-modal :show-cancel-button="true" @confirm="topConfirm" v-model="tip_show" :content="tip_content"></u-modal>
  63. </view>
  64. </template>
  65. <script>
  66. export default {
  67. data() {
  68. return {
  69. orderout_id: '',
  70. sel_pop: false,
  71. tip_show: false,
  72. tip_content: '',
  73. goods_list: [],
  74. delete_array: [],
  75. orderData: '',
  76. add_form: {
  77. originId: '', //销售订单id
  78. originNo: '', //销售订单no
  79. shopId: '',
  80. shopName: '',
  81. operatorName: '', //制单人
  82. remark: '', //备注
  83. details: []
  84. },
  85. rules: {
  86. originNo: [
  87. {
  88. required: true,
  89. message: '请选择订单',
  90. // 可以单个或者同时写两个触发验证方式
  91. trigger: 'change'
  92. }
  93. ]
  94. }
  95. };
  96. },
  97. watch: {
  98. orderData(val) {
  99. if (val) {
  100. const allowReturn = val.allowReturn;
  101. const allowReturnDay = val.allowReturnDay;
  102. if (allowReturn === 4) {
  103. this.tip_content = `已经超过${allowReturnDay}天,建议不能退货, 是否确定强制退货?`;
  104. this.tip_show = true;
  105. return;
  106. }
  107. this.getOrderInfoById(val.userCenterId, val.id);
  108. }
  109. }
  110. },
  111. computed: {
  112. userName() {
  113. return this.$store.state.userInfo.name;
  114. },
  115. numTotal() {
  116. if (!this.goods_list.length) {
  117. return 0;
  118. } else if (this.goods_list.length === 1) {
  119. return Number(this.goods_list[0].num);
  120. } else {
  121. let sum = 0;
  122. this.goods_list.forEach(item => {
  123. sum = sum + Number(item.num);
  124. });
  125. return sum;
  126. }
  127. }
  128. },
  129. onLoad(options) {
  130. if (options.id) {
  131. this.orderout_id = options.id;
  132. uni.setNavigationBarTitle({
  133. title: '编辑退货单'
  134. });
  135. this.getOrderOut();
  136. }
  137. },
  138. methods: {
  139. openSelect(key) {
  140. this[key] = true;
  141. },
  142. topConfirm() {
  143. this.$u.toast('您已确定强制退货!');
  144. this.getOrderInfoById(val.userCenterId, val.id);
  145. },
  146. // 退货单详情接口
  147. async getOrderOut() {
  148. this.$u.api.getOrderOut(this.orderout_id).then(res => {
  149. this.add_form = {
  150. originId: res.data.originId, //销售订单id
  151. originNo: res.data.no, //销售订单no
  152. shopId: res.data.shopId,
  153. shopName: res.data.shopName,
  154. operatorName: res.data.operatorName, //制单人
  155. remark: res.data.remark, //备注
  156. details: []
  157. };
  158. this.goods_list = res.data.details.map(item => {
  159. return {
  160. ...item,
  161. saleNum: item.extend.saleNum
  162. };
  163. });
  164. });
  165. },
  166. // 获取订单详情
  167. getOrderInfoById() {
  168. this.$u.api
  169. .getOrderInfoById(this.orderData.userCenterId, {
  170. orderId: this.orderData.id
  171. })
  172. .then(res => {
  173. this.orderSelResult(res.data);
  174. });
  175. },
  176. submit() {
  177. const details = this.goods_list.map(item => {
  178. const skuName = this.orderout_id
  179. ? item.skuName
  180. : item.specGroup
  181. .map(itemM => {
  182. return itemM.specValueName;
  183. })
  184. .join('_');
  185. return {
  186. id: item.id,
  187. goodsId: item.goodsId,
  188. goodsCode: item.goodsCode,
  189. goodsName: item.goodsName,
  190. goodsBasicId: item.goodsBasicId,
  191. skuId: item.skuId,
  192. skuName: skuName,
  193. unitName: item.unitName,
  194. num: item.num,
  195. saleNum: item.saleNum,
  196. saleUnitPrice: item.saleUnitPrice, // 销售单价
  197. returnUnitPrice: item.returnUnitPrice, // 退货单价
  198. returnTotalPrice: item.returnUnitPrice * item.num, // 退货总价
  199. saleTotalPrice: item.saleUnitPrice * item.saleNum // 销售总价
  200. };
  201. });
  202. const params = {
  203. ...this.add_form,
  204. deleteArray: this.delete_array,
  205. operatorName: this.userName,
  206. details: details
  207. };
  208. this.$refs.uForm.validate(valid => {
  209. if (!details.length) {
  210. this.$u.toast('无退货商品');
  211. return;
  212. }
  213. if (valid) {
  214. if (this.orderout_id) {
  215. this.$u.api.updateOrderReturn(this.orderout_id, params).then(res => {
  216. this.$u.toast('操作成功');
  217. setTimeout(() => {
  218. uni.navigateBack();
  219. }, 1500);
  220. });
  221. } else {
  222. this.$u.api.addOrderOut(params).then(res => {
  223. this.$u.toast('操作成功');
  224. setTimeout(() => {
  225. uni.navigateBack();
  226. }, 1500);
  227. });
  228. }
  229. }
  230. });
  231. },
  232. delGoods(index, row) {
  233. if (this.goods_list.length === 1) {
  234. this.$u.toast('至少保留一条');
  235. return;
  236. }
  237. if (this.delete_array.indexOf(row.id) === -1) {
  238. this.delete_array.push(row.id);
  239. }
  240. this.goods_list.splice(index, 1);
  241. },
  242. orderSelResult(row) {
  243. this.add_form.originId = row.id;
  244. this.add_form.originNo = row.no;
  245. this.userCenterId = row.userCenterId;
  246. // 订单状态 orderStatus
  247. this.orderStatus = row.orderStatus;
  248. this.add_form.shopId = row.shopId;
  249. this.add_form.shopName = row.shopName;
  250. this.goods_list = row.goodsData.map(item => {
  251. return {
  252. images: item.images,
  253. id: item.id,
  254. goodsId: item.goodsId,
  255. goodsName: item.goodsName,
  256. goodsCode: item.goodsCode,
  257. goodsBasicId: item.goodsBasicId,
  258. skuId: item.skuId,
  259. unitName: item.unitName,
  260. specGroup: item.specGroup,
  261. num: item.buyNum,
  262. saleNum: item.buyNum,
  263. saleUnitPrice: item.price, // 销售单价
  264. returnUnitPrice: item.returnPrice, // 退货单价
  265. returnTotalPrice: item.price * item.buyNum, // 退货总价
  266. saleTotalPrice: item.price * item.buyNum // 销售总价
  267. };
  268. });
  269. }
  270. },
  271. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  272. onReady() {
  273. this.$refs.uForm.setRules(this.rules);
  274. }
  275. };
  276. </script>
  277. <style lang="scss" scoped>
  278. .form-model-view {
  279. background-color: #ffffff;
  280. margin-bottom: 20rpx;
  281. padding: 0 20rpx;
  282. text-align: right;
  283. .goods-view {
  284. text-align: left;
  285. position: relative;
  286. .desc {
  287. font-size: 24rpx;
  288. color: #6c6c6c;
  289. position: absolute;
  290. right: 0;
  291. top: -80rpx;
  292. }
  293. image {
  294. width: 102rpx;
  295. height: 102rpx;
  296. border-radius: 8rpx;
  297. margin: 0 6rpx;
  298. vertical-align: middle;
  299. }
  300. .more-goods {
  301. width: 102rpx;
  302. height: 102rpx;
  303. border-radius: 8rpx;
  304. margin: 0 6rpx;
  305. display: inline-block;
  306. background-color: #eeeeee;
  307. line-height: 102rpx;
  308. text-align: center;
  309. vertical-align: middle;
  310. }
  311. }
  312. .sel-goods-view {
  313. text-align: center;
  314. display: flex;
  315. .sel-li {
  316. line-height: 32rpx;
  317. flex: 2;
  318. .icon {
  319. margin-bottom: 16rpx;
  320. .custom-icon {
  321. font-size: 46rpx;
  322. color: $uni-color-primary;
  323. }
  324. }
  325. }
  326. }
  327. }
  328. .sel-goods-pop {
  329. padding-bottom: 1px;
  330. .pop-tit {
  331. line-height: 70rpx;
  332. background-color: #f5f5f5;
  333. padding: 0 24rpx;
  334. .float_right {
  335. font-size: 24rpx;
  336. color: #666666;
  337. .custom-icon-shanchu {
  338. font-size: 26rpx;
  339. margin-right: 10rpx;
  340. }
  341. }
  342. }
  343. .goods-ul {
  344. min-height: 400rpx;
  345. max-height: 600rpx;
  346. .goods-li {
  347. padding: 24rpx;
  348. position: relative;
  349. border-bottom: 1px solid #f5f5f5;
  350. .goods-name {
  351. width: 660rpx;
  352. }
  353. .goods-code {
  354. padding-top: 10rpx;
  355. font-size: 24rpx;
  356. color: #999999;
  357. }
  358. .custom-icon-shanchu {
  359. position: absolute;
  360. right: 24rpx;
  361. top: 24rpx;
  362. width: 40rpx;
  363. height: 40rpx;
  364. color: $uni-color-error;
  365. }
  366. }
  367. }
  368. .btn-view {
  369. width: 680rpx;
  370. height: 70rpx;
  371. line-height: 70rpx;
  372. border-radius: 10rpx;
  373. background-color: $uni-color-primary;
  374. color: #ffffff;
  375. text-align: center;
  376. margin: 20rpx auto;
  377. }
  378. }
  379. </style>