deliver.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <div id="form-1">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight">
  5. <el-col class="top_btn"><el-button type="primary" size="mini" @click="toBack()">返回</el-button></el-col>
  6. <el-col :span="24" class="one"> <span>发货清单</span> </el-col>
  7. <el-col class="top_btn"> <el-button type="primary" @click="toFile()">导出清单</el-button></el-col>
  8. <el-col :span="24" class="two">
  9. <el-col :span="15" v-for="(item, index) in list" :key="index">
  10. <el-card class="box-card">
  11. <el-col class="clearfix">
  12. <el-col>收货人:{{ item.address.name }},{{ item.address.phone }}</el-col>
  13. <el-col>收货人地址:{{ item.address.province }},{{ item.address.city }},{{ item.address.area }},{{ item.address.address }}</el-col>
  14. </el-col>
  15. <el-col class="two_1">
  16. <data-table
  17. :select="true"
  18. :selected="selected"
  19. @handleSelect="(e) => handleSelect(e, item.address)"
  20. rowKey="index"
  21. :usePage="false"
  22. :fields="fields"
  23. :data="item.goodsList"
  24. >
  25. </data-table>
  26. </el-col>
  27. </el-card>
  28. </el-col>
  29. </el-col>
  30. </el-col>
  31. </el-row>
  32. </div>
  33. </template>
  34. <script>
  35. const _ = require('lodash');
  36. import { mapState, mapGetters, createNamespacedHelpers } from 'vuex';
  37. const { mapActions } = createNamespacedHelpers('order');
  38. export default {
  39. name: 'form-1',
  40. props: {},
  41. components: {},
  42. data: function () {
  43. return {
  44. list: [],
  45. fields: [
  46. // { label: '订单id', model: 'order_id' },
  47. { label: '订单编号', model: 'order_no' },
  48. { label: '商品名称', model: 'goods.name' },
  49. { label: '商品规格', model: 'name' },
  50. { label: '商品数量', model: 'buy_num' },
  51. ],
  52. selected: [],
  53. fileList: [],
  54. };
  55. },
  56. async created() {
  57. await this.search();
  58. },
  59. methods: {
  60. ...mapActions(['query', 'fetch', 'create', 'update']),
  61. // 查询
  62. async search() {
  63. let data = this.data;
  64. let test = _(data).groupBy('address._id').values().value();
  65. let list = [];
  66. for (const p1 of test) {
  67. let goodsList = [];
  68. for (const p2 of p1) {
  69. for (const p3 of p2.goods) {
  70. // p3 = (({ goods, name, buy_num }) => ({ goods, name, buy_num }))(p3);
  71. delete p3.flow_money;
  72. delete p3.freight;
  73. delete p3.id;
  74. delete p3.status;
  75. delete p3._id;
  76. delete p3.meta;
  77. delete p3.num;
  78. delete p3.sell_money;
  79. delete p3.__v;
  80. delete p3.tags;
  81. delete p3.cart_id;
  82. let good = (({ name }) => ({ name }))(p3.goods);
  83. p3.goods = good;
  84. p3.order_no = p2.no;
  85. }
  86. goodsList.push(...p2.goods);
  87. let i = 0;
  88. for (const p4 of goodsList) {
  89. p4.index = i;
  90. i++;
  91. }
  92. }
  93. let address = (({ name, phone, province, city, area, address }) => ({ name, phone, province, city, area, address }))(p1[0].address);
  94. list.push({ goodsList, address });
  95. }
  96. console.log(list);
  97. this.$set(this, 'list', list);
  98. },
  99. handleSelect(goodsList, address) {
  100. let fileList = [];
  101. if (this.fileList.length == 0) {
  102. fileList.push({ goodsList, address });
  103. this.$set(this, 'fileList', fileList);
  104. } else {
  105. for (const val of this.fileList) {
  106. // 判断this.fileList里是否有和选中的地址id相同的
  107. if (val.address._id == address._id) {
  108. // 判断是否有选中的商品,没有就过滤掉
  109. if (goodsList.length == 0) {
  110. let p2 = this.fileList.filter((f) => f.address._id != address._id);
  111. this.fileList = p2;
  112. } else {
  113. val.goodsList = goodsList;
  114. }
  115. } else {
  116. this.fileList.push({ goodsList, address });
  117. }
  118. }
  119. }
  120. console.log(this.fileList);
  121. },
  122. toFile() {
  123. console.log(this.fileList);
  124. this.$message({ message: '导出成功', type: 'success' });
  125. },
  126. // 返回
  127. toBack() {
  128. window.history.go('-1');
  129. },
  130. },
  131. computed: {
  132. data() {
  133. return this.$route.query.data;
  134. },
  135. },
  136. metaInfo() {
  137. return { title: this.$route.meta.title };
  138. },
  139. watch: {
  140. test: {
  141. deep: true,
  142. immediate: true,
  143. handler(val) {},
  144. },
  145. },
  146. };
  147. </script>
  148. <style lang="less" scoped>
  149. .main {
  150. .top_btn {
  151. margin: 0 0 10px 0;
  152. }
  153. .one {
  154. margin: 0 0 10px 0;
  155. span:nth-child(1) {
  156. font-size: 20px;
  157. font-weight: 700;
  158. margin-right: 10px;
  159. }
  160. }
  161. .two {
  162. margin: 5px 10%;
  163. .data-table {
  164. margin: 5px 0;
  165. }
  166. .clearfix {
  167. margin: 4px 0;
  168. .el-col {
  169. margin: 4px 0;
  170. }
  171. }
  172. .box-card {
  173. margin: 5px;
  174. padding: 5px 0 20px 0;
  175. }
  176. .shop {
  177. text-align: center;
  178. font-size: 18px;
  179. }
  180. .item {
  181. margin-bottom: 18px;
  182. }
  183. }
  184. }
  185. </style>