fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
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
309
310
<template>
  <div>
    <list-condition-template ref="table" v-loading="isLoading" :form="listQuery" :formLabel="formLabel"
                             :tableData="tableData" :total="total"
                             @page-info-change="handlePageInfoChange">
      <template slot="otherElement">
        <el-col :span="6" :offset="0">
          <el-form-item>
            <el-button size="mini" type="primary" @click="queryData">查询</el-button>
            <el-button size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </template>
      <template slot="operationSection">
        <el-button size="mini" type="success" @click="addItem">新增</el-button>
        <el-button size="mini" type="warning" @click="importMemberInfo">导入</el-button>
        <el-button size="mini" @click="downTemplate">下载模板</el-button>
        <el-button size="mini" icon="el-icon-download" type="primary" @click="exportData">导出
        </el-button>
      </template>
      <template slot="columns">
        <el-table-column label="商品主编码" prop="spuNum" show-overflow-tooltip width="250px">
        </el-table-column>
        <el-table-column label="存货辅助核算编码" prop="auxiliaryCode" show-overflow-tooltip width="250px">
        </el-table-column>
        <el-table-column label="商品名称" prop="spuName" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="规格型号" prop="model" width="150px" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="单位" prop="unit" width="150px">
        </el-table-column>
        <el-table-column label="操作" :width="`${2 * $store.getters.colSize}px`">
          <template slot-scope="scope">
            <wly-btn type="primary" @click="editInfo(scope.row)">编辑</wly-btn>
            <wly-btn type="danger" @click="deleteItem(scope.row)">删除</wly-btn>
          </template>
        </el-table-column>
      </template>
    </list-condition-template>
    <prod-account-info :show.sync="show" :row="row" :title="title"></prod-account-info>
    <el-dialog :visible.sync="importDialogVisible" title="导入" :close-on-click-modal="false"
               :modal-append-to-body="false" width="450px">
      <el-form ref="form" size="mini">
        <el-upload class="upload-demo" action="api" ref="upload" :limit="1" :accept="'.xlsx, .xls'"
                   :http-request="handleRequrst" :auto-upload="false" :on-change="handleChange"
                   :file-list="fileList" drag>
          <i class="el-icon-upload"></i>
          <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
          <div class="el-upload__tip" slot="tip">只能上传一个文件,且文件格式只支持.xlsx, .xls文件</div>
        </el-upload>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" size="mini" :loading="loading" @click="submitImport">确定
        </el-button>
        <el-button size="mini" @click="importDialogVisible=false">取消</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="tipDialogVisible" title="导入提示" :close-on-click-modal="false"
               :modal-append-to-body="false">
      <h4 style="margin-bottom:20px;">导入{{successNum+tipTableData.length}}条核算编码,成功 {{successNum}}
        条,失败{{tipTableData.length}}条</h4>
      <tablePagination :tableData="tipTableData" :showOperatBtn="false">
        <el-table-column label="商品主编码" prop="spuNum" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="存货辅助核算编码" prop="auxiliaryCode" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="商品名称" prop="spuName" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="规格型号" prop="model">
        </el-table-column>
        <el-table-column label="单位" prop="unit">
        </el-table-column>
        <el-table-column label="失败原因" prop="failReason">
        </el-table-column>
      </tablePagination>
      <div slot="footer" class="buttonPosition dialog-footer">
        <el-button size="mini" @click="closeTip()">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import invoiceProdInfoApi from '@/api/invoiceProdInfo'
import prodAccountInfo from '@/views/invoiceProdInfo/info.vue'
import { objectCopy } from '@/utils/objectCopyHelper'
import { downloadFile } from '@/utils/downloadFile'
import tablePagination from '@/views/blindBoxActivity/components/tablePagination.vue'
 
export default {
  components: { prodAccountInfo, tablePagination },
  data() {
    return {
      formLabel: [
        {
          model: 'spuNum',
          label: '商品主编码',
          type: 'input',
          labelWidth: '100px',
          rule: /[^\w]/g // 可输入数字字母
        },
        {
          model: 'auxiliaryCode',
          label: '核算编码',
          type: 'input',
          rule: /[^\w]/g // 可输入数字字母
        },
        {
          model: 'spuName',
          label: '商品名称',
          type: 'input'
        }
      ],
      listQuery: {
        spuNum: null,
        auxiliaryCode: null,
        spuName: null
      },
      tableData: [],
      show: false,
      title: null,
      row: {},
      dialogVisible: false,
      form: {},
      total: 0,
      importDialogVisible: false,
      fileList: [],
      loading: false,
      percentage: 0, // 进度条数值
      isLoading: false, // 是否展示进度条遮罩
      tipDialogVisible: false,
      tipTableData: [],
      successNum: 0, // 导入成功数量
      exportQuery: null // 导出参数
    }
  },
  /**
   * 数据变化后刷新列表
   */
  activated() {
    this.queryList(this.$refs.table.getPageInfo())
  },
  methods: {
    // 导出
    async exportData() {
      this.isLoading = true
      const config = {
        url: 'awl-order-service/invoiceProdInfo/download/exportData',
        data: this.exportQuery,
        fileName: '商品核算信息',
        type: '.xlsx'
      }
      await downloadFile(config)
      this.isLoading = false
    },
    // 下载模板
    async downTemplate() {
      const config = {
        onUploadProgress: ProgressEvent => {
          const progressPercent = Math.round(ProgressEvent.loaded / ProgressEvent.total * 100 | 0)
          this.percentage = progressPercent === 100 ? 99 : progressPercent
          this.isLoading = true
        },
        onDownloadProgress: ProgressEvent => {
        },
        url: 'awl-order-service/invoiceProdInfo/download/demoExcel',
        data: null,
        fileName: '商品核算信息模板',
        Method: 'get',
        type: '.xlsx'
      }
      const res = await downloadFile(config)
      if (res) {
        this.percentage = 100
        this.isLoading = false
      } else {
        this.percentage = 100
        this.isLoading = false
      }
    },
    // 导入
    importMemberInfo() {
      this.importDialogVisible = true
    },
    // 导入三方系统会员信息
    submitImport() {
      this.$refs.upload.submit()
    },
    closeTip() {
      this.tipDialogVisible = false
      this.importDialogVisible = false
      if (this.successNum) {
        this.$refs.table.reloadCurrent()
      }
    },
    // 当文件改变时获取选中的文件
    handleChange(file, fileList) {
      const acceptFile = '.xlsx, .xls'
      var nameType = file.name.substring(file.name.lastIndexOf('.') + 1)
      var fileType = acceptFile.indexOf(nameType) !== -1
      if (!fileType) {
        this.$message.error(`上传失败!仅支持${acceptFile}格式,请重新上传`)
        this.fileList = []
        return false
      }
      return true
    },
    // 手动上传文件
    async handleRequrst(param) {
      this.loading = true
      const formData = new FormData()
      formData.append('file', param.file)
      try {
        const res = await invoiceProdInfoApi.importData(formData)
        if (res.code === '0') {
          this.loading = false
          this.fileList = []
          if (res.data.failNum) {
            this.tipTableData = res.data.omsInvoiceProdInfoExcelVoList
            this.tipDialogVisible = true
          } else {
            this.$message.success('导入成功!')
            this.importDialogVisible = false
            this.$refs.table.reloadCurrent()
          }
          this.successNum = res.data.successNum
        } else {
          this.loading = false
          this.fileList = []
        }
      } catch (error) {
        this.fileList = []
        this.$message.error('上传文件失败!请重新上传')
        this.loading = false
      }
    },
    /**
     * 删除
     */
    deleteItem(row) {
      this.$confirm('确认删除该数据?', '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        invoiceProdInfoApi.deleteItem({ id: row.id }).then(res => {
          if (res.code === '0') {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
            this.queryData()
          }
        })
      }).catch(() => { })
    },
    /**
       * '分页信息改变时查询列表
       */
    handlePageInfoChange(pageInfo) {
      this.queryList(pageInfo)
    },
    /**
     * 重置
     */
    resetQuery() {
      this.$refs.table.reloadCurrent()
    },
    /**
     * 点击查询按钮
     */
    queryData() {
      this.$refs.table.changeCondition()
    },
    /**
     * 查看详情
     */
    lookInfo(row) {
      this.dialogVisible = true
      this.form = row
    },
    /**
     * 编辑
     */
    editInfo(row) {
      this.show = true
      this.title = '编辑商品核算信息'
      this.row = objectCopy(row)
    },
    /**
     * 查询列表
     */
    queryList(pageInfo = { pageNum: 1, pageSize: 10 }) {
      invoiceProdInfoApi.getList({ ...this.listQuery, ...pageInfo }).then(res => {
        if (res.data) {
          this.tableData = res.data.list
          this.total = res.data.total
          this.exportQuery = JSON.parse(JSON.stringify(this.listQuery))
        }
      })
    },
    /**
       * 跳转到新增页面
       */
    addItem() {
      this.show = true
      this.title = '添加商品核算信息'
    }
  }
}
</script>