mayf
2024-09-09 ba0c3e10b8bff315982438fc2aa0e33606179025
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<template>
  <div>
    <el-bus-crud
      ref="crud"
      v-bind="tableConfig"
      :extra-query="{ levelDown: checkedLevelDown }"
    >
      <template #header>
        <el-checkbox
          v-model="checkedLevelDown"
          true-label="1"
          false-label=""
          style="float: right"
          >未处理的质检异常订单</el-checkbox
        >
      </template>
    </el-bus-crud>
    <div id="print-container">
      <print-list ref="printList" :order-list="orderList" />
    </div>
  </div>
</template>
 
<script>
import printJS from 'print-js'
import { getPartnerListConfig } from '@/utils/form-item-config'
import { dateRangeOptions } from '@/utils/options'
import CustomDateRange from '@/components/custom-date-range.vue'
import PrintList from '@/components/order/print-list'
import GoodsTableItemList from '@/components/order/goods-table-item-list.vue'
export default {
  components: {
    PrintList,
  },
  data() {
    return {
      checkedLevelDown: '',
      orderList: [],
      tableConfig: {
        url: 'flower/api/order/list',
        hasNew: false,
        hasEdit: false,
        hasDelete: false,
        persistSelection: true,
        onResetView: (row) => {
          this.$router.push(`${this.$route.path}/${row.id}`)
        },
        operationAttrs: {
          width: 150,
          fixed: 'right',
        },
        beforeRequest: (params) => {
          const searchForm = this.$refs.crud?.$refs?.searchForm
          if (searchForm) {
            const statusComp = searchForm.getComponentById('statusBackend')
            if (statusComp) {
              // 组件内部不会修改这个prop直接修改可忽略警告
              statusComp.extraQuery = { ...params, statusBackend: '' }
              statusComp.getOtherOptions()
            }
          }
        },
        columns: [
          { label: '', type: 'selection', minWidth: 60, fixed: 'left' },
          { label: '订单号', prop: 'orderNo', minWidth: 150, fixed: 'left' },
          { label: '用户账号', prop: 'createName', minWidth: 120 },
          { label: '收货人', prop: 'customer', minWidth: 120 },
          { label: '收货人电话', prop: 'customerTel', minWidth: 120 },
          {
            label: '收货地址',
            formatter: (row) =>
              `${row.customerProvince || ''}${row.customerCity || ''}${
                row.customerRegion || ''
              }${row.customerAddress || ''}`,
            minWidth: 250,
          },
          { label: '订单金额(元)', prop: 'totalAmount', minWidth: 150 },
          { label: '底价(元)', prop: 'supplierAmount', minWidth: 150 },
          { label: '订单状态', prop: 'statusBackendStr', minWidth: 120 },
          { label: '下单时间', prop: 'createTime', minWidth: 180 },
          { label: '合伙人', prop: 'partnerName', minWidth: 120 },
        ],
        searchFormAttrs: {
          labelWidth: 'auto',
        },
        searchForm: [
          {
            type: 'row',
            id: 'row',
            items: [
              {
                label: '订单状态:',
                id: 'statusBackend',
                type: 'bus-radio',
                el: {
                  hasAll: true,
                  otherInterfaceUri: 'flower/api/order/status/count',
                  childType: 'el-radio-button',
                  filterOptions: (list) => {
                    return list.map((item) => {
                      return {
                        ...item,
                        label: `${item.label}(${item.orderCount})`,
                      }
                    })
                  },
                  // code: 'ORDER_STATUS_BACKEND',
                },
                default: '',
                span: 24,
                searchImmediately: true,
                on: {
                  optionsChange: (e, updateForm, { currentComp }) => {
                    if (Array.isArray(e[0]) && e[0].length > 0) {
                      const totalCount = e[0].reduce((total, current) => {
                        return (total += current.orderCount)
                      }, 0)
                      // 组件内部不会修改这个prop直接修改可忽略警告
                      currentComp.props = {
                        allLabel: `不限(${totalCount})`,
                      }
                    }
                  },
                },
              },
              {
                label: '下单日期:',
                id: 'dateType',
                component: CustomDateRange,
                el: {
                  options: dateRangeOptions,
                },
                searchImmediately: true,
                commonFormat: true,
                commonFormatProps: [
                  'dateType',
                  'createStartDateStr',
                  'createEndDateStr',
                ],
                span: 24,
              },
              { label: '订单号:', id: 'orderNo', type: 'input' },
              { ...getPartnerListConfig() },
              { label: '商品名称:', id: 'flowerName', type: 'input' },
              {
                label: '收货人:',
                id: 'customer',
                type: 'input',
                el: { placeholder: '收货人姓名/手机号' },
              },
            ],
          },
        ],
        headerButtons: [
          {
            text: '打印订单',
            type: 'primary',
            atClick: async (selected) => {
              const formValue = this.$refs.crud.$refs.searchForm.getFormValue()
              if (
                !formValue.createStartDateStr &&
                !formValue.createEndDateStr
              ) {
                this.$message.warning('请先选择需要打印订单的日期')
                return false
              }
              if (formValue.createStartDateStr !== formValue.createEndDateStr) {
                this.$message.warning('只能打印某一天的订单')
                return false
              }
              const ids = selected.map((i) => i.id)
              const { code, data } = await this.$elBusHttp.request(
                'flower/api/order/check/location/list',
                {
                  method: 'post',
                  data: {
                    ...formValue,
                    ids: ids?.length ? ids.join(',') : null,
                  },
                }
              )
              if (code === 0) {
                const orderList = data || []
                if (orderList.length !== 0) {
                  this.orderList = orderList
                  // 这边嵌套两个nextTick是因为重写el-table时在nextTick中进行了dom操作
                  this.$nextTick(() => {
                    this.$nextTick(() => {
                      const trs = document.querySelectorAll(
                        '.el-table__footer tr'
                      )
                      if (trs && trs.length > 0) {
                        for (const tr of trs) {
                          const tds = tr.querySelectorAll('td')
                          if (tds && tds.length > 0) {
                            tds[0].colSpan = 7
                            tds[0].style.textAlign = 'center'
                          }
                        }
                      }
                      this.$nextTick(async () => {
                        await printJS({
                          printable: 'print-container',
                          type: 'html',
                          header: '订单明细',
                          headerStyle:
                            'text-align:center;font-size:24px;color:#333;font-weight:bold;margin-bottom:15px',
                          style: `@media print { @page {size: auto; margin: 20mm 0 10mm 0; } body{margin:10mm} .el-table .el-table__header-wrapper{display: none} .el-table .el-table__body-wrapper thead{display: table-header-group} .break-page {page-break-after:always}}`,
                          css: [
                            `${this.$config.baseUrl}print/index.css`,
                            `${this.$config.baseUrl}print/custom.css`,
                          ],
                          scanStyles: false,
                        })
                      })
                    })
                  })
                } else {
                  this.$message.warning('没有相关订单')
                  return false
                }
              }
            },
          },
        ],
        extraButtons: [
          {
            text: '发货',
            show: (row) => !row.partnerName && row.statusBackend === 'SEND',
            atClick: (row) => {
              this.$refs.crud.$refs.extraDialog[0].show(row)
              return false
            },
          },
          {
            text: '退款',
            show: (row) => row.paymentTime && row.statusBackend !== 'REFUND',
            atClick: async (row) => {
              try {
                await this.$elBusUtil.confirm('确定要退款吗?')
                const { code } = await this.$elBusHttp.request(
                  'flower/api/order/refund',
                  {
                    params: {
                      id: row.id,
                    },
                  }
                )
                if (code === 0) {
                  this.$message.success('退款成功')
                }
              } catch (e) {
                return false
              }
            },
          },
        ],
        extraDialogs: [
          {
            title: '发货',
            hiddenReverseItems: [],
            form: [
              {
                label: '快递号:',
                id: 'deliveryNo',
                type: 'input',
                rules: {
                  required: true,
                  message: '请输入快递号',
                  trigger: 'blur',
                },
              },
            ],
            atConfirm: async (val) => {
              const { code } = await this.$elBusHttp.request(
                'flower/api/order/list/send',
                { method: 'post', data: val }
              )
              if (code === 0) {
                this.$message.success('发货成功')
              }
            },
          },
        ],
      },
    }
  },
  head() {
    return {
      title: '订单列表',
    }
  },
  watch: {
    checkedLevelDown() {
      this.$refs.crud.search()
    },
  },
}
</script>
 
<style lang="scss" scoped>
#print-container {
  width: 190mm;
  position: absolute;
  top: 9999px;
  left: 9999px;
}
</style>