Prechádzať zdrojové kódy

库存查询 导出

chenrui 3 rokov pred
rodič
commit
d1b26f52a6

+ 107 - 0
src/views/inventoryManagement/inventoryQuery/exportExcelModal.vue

@@ -0,0 +1,107 @@
+<template>
+  <a-modal
+    centered
+    :footer="null"
+    :maskClosable="false"
+    class="export-excel-modal"
+    title="选择导出方式"
+    v-model="isShow"
+    @cancle="isShow=false"
+    :width="600">
+    <a-spin :spinning="spinning" tip="Loading...">
+      <a-form-model
+        id="export-excel-form"
+        ref="ruleForm"
+        :model="form"
+        :rules="rules"
+        :label-col="formItemLayout.labelCol"
+        :wrapper-col="formItemLayout.wrapperCol"
+      >
+        <a-form-model-item label="导出库存" prop="exportType">
+          <a-radio-group v-model="form.exportType">
+            <a-radio value="all">所有</a-radio>
+            <a-radio value="type">分类汇总导出</a-radio>
+          </a-radio-group>
+        </a-form-model-item>
+      </a-form-model>
+      <div class="btn-cont">
+        <a-button type="primary" id="export-excel-save" @click="handleSave()">导出</a-button>
+        <a-button id="export-excel-back" @click="handleCancel" style="margin-left: 15px;">取消</a-button>
+      </div>
+    </a-spin>
+  </a-modal>
+</template>
+
+<script>
+export default {
+  props: {
+    openModal: { //  弹框显示状态
+      type: Boolean,
+      default: false
+    },
+    itemData: {
+      type: Object,
+      default: () => {
+        return null
+      }
+    }
+  },
+  data () {
+    return {
+      isShow: this.openModal, //  是否打开弹框
+      form: {
+        exportType: 'all'
+      },
+      rules: {
+        exportType: [{ required: true, message: '请选择导出方式', trigger: 'change' }]
+      },
+      formItemLayout: {
+        labelCol: { span: 6 },
+        wrapperCol: { span: 18 }
+      },
+      spinning: false
+    }
+  },
+  methods: {
+    // 确认
+    handleSave (isPrint) {
+      const _this = this
+      this.$refs.ruleForm.validate(valid => {
+        if (valid) {
+          _this.$emit('ok', _this.form.exportType)
+          _this.isShow = false
+        } else {
+          console.log('error submit!!')
+          return false
+        }
+      })
+    },
+    // 取消选择分类
+    handleCancel () {
+      this.isShow = false
+    }
+  },
+  watch: {
+    //  父页面传过来的弹框状态
+    openModal (newValue, oldValue) {
+      this.isShow = newValue
+    },
+    //  重定义的弹框状态
+    isShow (newValue, oldValue) {
+      if (!newValue) {
+        this.$emit('close')
+        this.$refs.ruleForm.resetFields()
+      }
+    }
+  }
+}
+</script>
+
+<style lang="less">
+  .export-excel-modal{
+    .btn-cont {
+      text-align: center;
+      margin: 35px 0 10px;
+    }
+  }
+</style>

+ 14 - 50
src/views/inventoryManagement/inventoryQuery/list.vue

@@ -63,7 +63,7 @@
                 type="primary"
                 style="margin-left: 5px"
                 class="button-warning"
-                @click="handleExport"
+                @click="openExcelModal=true"
                 :disabled="disabled"
                 :loading="exportLoading"
                 id="inventoryQueryList-export">导出</a-button>
@@ -116,6 +116,8 @@
     </a-spin>
     <!-- 库存详情 -->
     <inventory-query-detail-modal :openModal="openModal" :itemId="itemId" @close="closeModal" />
+    <!-- 导出Excel -->
+    <export-excel-modal :openModal="openExcelModal" @ok="handleExcelOk" @close="openExcelModal=false" />
   </a-card>
 </template>
 
@@ -123,11 +125,13 @@
 import moment from 'moment'
 import { STable, VSelect } from '@/components'
 import inventoryQueryDetailModal from './detailModal.vue'
+import exportExcelModal from './exportExcelModal.vue'
 import { productBrandQuery } from '@/api/productBrand'
 import { productTypeQuery } from '@/api/productType'
+import { hdExportExcel } from '@/libs/exportExcel'
 import { stockList, stockCount, stockExport } from '@/api/stock'
 export default {
-  components: { STable, VSelect, inventoryQueryDetailModal },
+  components: { STable, VSelect, inventoryQueryDetailModal, exportExcelModal },
   data () {
     return {
       spinning: false,
@@ -194,7 +198,8 @@ export default {
       },
       openModal: false, //  查看库存详情  弹框
       itemId: '', //  当前库存记录id
-      currentStock: null
+      currentStock: null,
+      openExcelModal: false
     }
   },
   computed: {
@@ -253,59 +258,18 @@ export default {
     goWarehouseDetail (row) {
       this.$router.push({ path: `/inventoryManagement/inventoryQuery/warehouseDetail/${row.productSn}` })
     },
-    //  导出
-    handleExport () {
+    // 导出Excel
+    handleExcelOk (exportType) {
       const _this = this
       const params = JSON.parse(JSON.stringify(this.queryParam))
-      if (params.zeroQtyFlag) {
-        params.zeroQtyFlag = '0'
-      } else {
-        params.zeroQtyFlag = ''
-      }
+      params.exportType = exportType
       this.exportLoading = true
-      _this.spinning = true
-      stockExport(params).then(res => {
-        this.exportLoading = false
+      this.spinning = true
+      hdExportExcel(stockExport, params, '库存查询', function () {
+        _this.exportLoading = false
         _this.spinning = false
-        if (res.type == 'application/json') {
-          var reader = new FileReader()
-          reader.addEventListener('loadend', function () {
-            const obj = JSON.parse(reader.result)
-            _this.$notification.error({
-              message: '提示',
-              description: obj.message
-            })
-          })
-          reader.readAsText(res)
-        } else {
-          this.download(res)
-        }
       })
     },
-    download (data) {
-      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 = '库存查询' + a
-      link.setAttribute('download', fname + '.xlsx')
-      document.body.appendChild(link)
-      link.click()
-    },
-    //  递归函数
-    recursionFun (data) {
-      if (data) {
-        data.map((item, index) => {
-          if (item.children && item.children.length == 0) {
-            delete item.children
-          } else {
-            this.recursionFun(item.children)
-          }
-        })
-      }
-    },
     //  产品分类  change
     changeProductType (val, opt) {
       this.queryParam.productTypeSn1 = val[0] ? val[0] : ''