cloudroam
2024-09-23 692be76f2ca0011750095ae59188467cbcf2322a
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
<template>
  <div>
    <el-bus-crud ref="crud" v-bind="tableConfig"></el-bus-crud>
    <div id="print-container">
      <print-list ref="printList" :order-list="orderList" />
    </div>
  </div>
</template>
 
<script>
import printJS from 'print-js'
import { dateRangeOptions } from '@/utils/options'
import CustomDateRange from '@/components/custom-date-range.vue'
import PrintList from '@/components/order/print-list'
export default {
  components: {
    PrintList,
  },
  data() {
    return {
      orderList: [],
      tableConfig: {
        url: 'flower/api/partner/order/list',
        hasNew: false,
        hasEdit: false,
        hasDelete: false,
        onResetView: (row) => {
          this.$router.push(`${this.$route.path}/${row.id}`)
        },
        operationAttrs: {
          width: 180,
          fixed: 'right',
        },
        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: 'statusBackendStr', minWidth: 120 },
          { label: '下单时间', prop: 'createTime', minWidth: 180 },
          { label: '库位', id: 'warehouseLocationCode', type: 'input' },
        ],
        searchFormAttrs: {
          labelWidth: 'auto',
        },
        searchForm: [
          {
            type: 'row',
            items: [
              {
                label: '订单状态:',
                id: 'statusBackend',
                type: 'bus-radio',
                el: {
                  hasAll: true,
                  childType: 'el-radio-button',
                  code: 'ORDER_STATUS_BACKEND',
                },
                default: '',
                span: 24,
                searchImmediately: true,
              },
              {
                label: '下单日期:',
                id: 'dateType',
                component: CustomDateRange,
                el: {
                  options: dateRangeOptions,
                },
                searchImmediately: true,
                commonFormat: true,
                commonFormatProps: [
                  'dateType',
                  'createStartDateStr',
                  'createEndDateStr',
                ],
                span: 24,
              },
              { label: '订单号:', id: 'orderNo', type: 'input' },
              { label: '库位:', id: 'warehouseLocationCode', type: 'input' },
            ],
          },
        ],
        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/partner/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
                }
              }
            },
          },
        ],
      },
    }
  },
  head() {
    return {
      title: '订单列表',
    }
  },
}
</script>
 
<style lang="scss" scoped>
#print-container {
  width: 190mm;
  position: absolute;
  top: 9999px;
  left: 9999px;
}
</style>