浏览代码

销售退货导入产品新增导出错误项功能

chenrui 3 年之前
父节点
当前提交
6874e7701f
共有 3 个文件被更改,包括 80 次插入4 次删除
  1. 11 0
      src/api/salesReturn.js
  2. 41 0
      src/libs/exportExcel.js
  3. 28 4
      src/views/salesManagement/salesReturn/chooseImportModal.vue

+ 11 - 0
src/api/salesReturn.js

@@ -165,3 +165,14 @@ export const salesReturnBatchInsert = params => {
     method: 'post'
   })
 }
+//  销售退货 导入产品 导出错误项
+export const salesReturnFailExcel = (params) => {
+  const url = `/salesReturn/detail/downloadFailExcel/${params.grabFlag}`
+  delete params.grabFlag
+  return axios.request({
+    url: url,
+    method: 'post',
+    data: params.list,
+    responseType: 'blob'
+  })
+}

+ 41 - 0
src/libs/exportExcel.js

@@ -0,0 +1,41 @@
+import notification from 'ant-design-vue/es/notification'
+import moment from 'moment'
+
+// 导出excel
+/*
+  *url: 数据请求接口
+  *params: 请求参数
+  *fileName: 导出文件名称
+  *callback: 回调函数
+*/
+export const hdExportExcel = function (url, params, fileName, callback) {
+  url(params).then(res => {
+    if (res.type == 'application/json') {
+      var reader = new FileReader()
+      reader.addEventListener('loadend', function () {
+        const obj = JSON.parse(reader.result)
+        notification.error({
+          message: '提示',
+          description: obj.message
+        })
+      })
+      reader.readAsText(res)
+    } else {
+      downloadExcel(res, fileName)
+    }
+    callback()
+  })
+}
+// 导出下载excel
+export const downloadExcel = function (data, fileName) {
+  if (!data) { return }
+  const url = window.URL.createObjectURL(new Blob([data]))
+  const link = document.createElement('a')
+  link.style.display = 'none'
+  link.href = url
+  const a = moment().format('YYYYMMDDHHmmss')
+  const fname = fileName + a
+  link.setAttribute('download', fname + '.xlsx')
+  document.body.appendChild(link)
+  link.click()
+}

+ 28 - 4
src/views/salesManagement/salesReturn/chooseImportModal.vue

@@ -46,20 +46,28 @@
           size="large"
           :class="loadData.length==0?'button-grey':'button-primary'"
           @click="handleSubmit"
-          style="padding: 0 60px;">确认导入</a-button>
+          style="padding: 0 40px;">确认导入</a-button>
         <a-button
           id="chooseImport-cancel"
           size="large"
           class="button-cancel"
           @click="isShow=false"
-          style="padding: 0 60px;margin-left: 15px;">取消</a-button>
+          style="padding: 0 40px;margin-left: 15px;">取消</a-button>
+        <a-button
+          type="primary"
+          id="chooseImport-error"
+          size="large"
+          class="button-error"
+          @click="handleError"
+          style="padding: 0 40px;margin-left: 15px;">导出错误项</a-button>
       </div>
     </div>
   </a-modal>
 </template>
 
 <script>
-import { salesReturnParseProducts } from '@/api/salesReturn'
+import { hdExportExcel } from '@/libs/exportExcel'
+import { salesReturnParseProducts, salesReturnFailExcel } from '@/api/salesReturn'
 export default {
   name: 'ChooseImportModal',
   props: {
@@ -168,6 +176,22 @@ export default {
         this.$emit('ok', this.loadData)
         this.isShow = false
       }
+    },
+    // 导出
+    handleError () {
+      const _this = this
+      if (_this.unLoadData.length < 1) {
+        _this.$message.info('暂无可导出错误项~')
+        return
+      }
+      _this.spinning = true
+      const params = {
+        grabFlag: _this.paramsData.grabFlag,
+        list: _this.unLoadData
+      }
+      hdExportExcel(salesReturnFailExcel, params, '产品导入错误项', function () {
+        _this.spinning = false
+      })
     }
   },
   watch: {
@@ -198,7 +222,7 @@ export default {
       .btn-con{
         text-align: center;
         margin: 30px 0 20px;
-        .button-cancel{
+        .button-cancel,.button-error{
           font-size: 12px;
         }
       }