Przeglądaj źródła

批量导入产品

lilei 2 lat temu
rodzic
commit
cfb5ef578d

+ 27 - 0
src/api/product.js

@@ -402,4 +402,31 @@ export const stackPlaceSave = (params) => {
     data: params,
     method: 'post'
   })
+}
+
+// 批量导入产品
+export const batchImportProduct = (params) => {
+  return axios({
+    url: '/product/importProduct',
+    data: params,
+    method: 'post'
+  })
+}
+// 导出错误项产品
+export const exportErrorProduct = (params) => {
+  return axios({
+    url: '/product/exportErrorProduct',
+    data: params,
+    method: 'post',
+    responseType: 'blob'
+  })
+}
+
+// 批量保存产品
+export const saveBatchImportProduct = (params) => {
+  return axios({
+    url: '/product/saveBatchImportProduct',
+    data: params,
+    method: 'post'
+  })
 }

+ 221 - 0
src/views/productManagement/productInfo/chooseImportModal.vue

@@ -0,0 +1,221 @@
+<template>
+  <a-modal
+    centered
+    class="chooseImport-modal"
+    :footer="null"
+    :maskClosable="false"
+    title="导入"
+    v-model="isShow"
+    @cancel="isShow=false"
+    :width="900">
+    <div class="chooseImport-con">
+      <!-- 可导入数据 -->
+      <p class="">可导入数据{{ loadData.length }}条</p>
+      <a-table
+        class="sTable"
+        ref="table"
+        size="small"
+        :rowKey="(record) => record.allocateSn"
+        :columns="nowColumns"
+        :dataSource="loadData"
+        :loading="loading"
+        :scroll="{ y: 200, x: 2000 }"
+        :pagination="false"
+        bordered>
+      </a-table>
+      <a-divider />
+      <!-- 不可导入数据 -->
+      <p class="red">不可导入数据{{ unLoadData.length }}条</p>
+      <a-table
+        class="unTable"
+        ref="unTable"
+        size="small"
+        :rowKey="(record) => record.errorDesc"
+        :columns="nowUnColumns"
+        :dataSource="unLoadData"
+        :loading="loading"
+        :scroll="{ y: 200, x: 2000 }"
+        :pagination="false"
+        bordered>
+      </a-table>
+      <!-- 按钮 -->
+      <div class="btn-con">
+        <a-button
+          type="primary"
+          id="chooseImport-submit"
+          size="large"
+          :class="loadData.length==0?'button-grey':'button-primary'"
+          @click="handleSubmit"
+          style="padding: 0 40px;">确认导入</a-button>
+        <a-button
+          id="chooseImport-cancel"
+          size="large"
+          class="button-cancel"
+          @click="isShow=false"
+          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 { commonMixin } from '@/utils/mixin'
+import { hdExportExcel } from '@/libs/exportExcel'
+import { batchImportProduct, exportErrorProduct } from '@/api/product'
+export default {
+  name: 'SalesChooseImportModal',
+  mixins: [commonMixin],
+  props: {
+    openModal: { //  弹框显示状态
+      type: Boolean,
+      default: false
+    },
+    paramsData: {
+      type: Object,
+      default: () => {
+        return {}
+      }
+    }
+  },
+  data () {
+    return {
+      isShow: this.openModal, //  是否打开弹框
+      nowColumns: [
+        { title: '序号', dataIndex: 'no', width: '50px', align: 'center' },
+        { title: '产品名称', dataIndex: 'name', width: '150px', align: 'center', customRender: function (text) { return text || '--' } },
+        { title: '产品编码', dataIndex: 'code', width: '100px', align: 'center', customRender: function (text) { return text || '--' } },
+        { title: '原厂编码', dataIndex: 'origCode', width: '100px', align: 'center', customRender: function (text) { return text || '--' } },
+        { title: '其它编码', dataIndex: 'otherCode', width: '100px', align: 'center', customRender: function (text) { return text || '--' } },
+        { title: '产品品牌', dataIndex: 'productBrandName', width: '100px', align: 'center', customRender: function (text) { return text || '--' } },
+        { title: '一级分类', dataIndex: 'productTypeName1', width: '100px', align: 'center', customRender: function (text) { return text || '--' } },
+        { title: '二级分类', dataIndex: 'productTypeName2', width: '100px', align: 'center', customRender: function (text) { return text || '--' } },
+        { title: '三级分类', dataIndex: 'productTypeName3', width: '100px', align: 'center', customRender: function (text) { return text || '--' } },
+        { title: '单位', dataIndex: 'unit', width: '80px', align: 'center', customRender: function (text) { return text || '--' } },
+        { title: '包装数', dataIndex: 'packQty', width: '80px', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+        { title: '包装数单位', dataIndex: 'packQtyUnit', width: '80px', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+        { title: '是否箭冠产品', dataIndex: 'arrowFalgDictValue', width: '80px', align: 'center', customRender: function (text) { return text || '--' } },
+        { title: '条形码', dataIndex: 'qrCode', width: '120px', align: 'center', customRender: function (text) { return text || '--' } },
+        { title: '产品尺寸', dataIndex: 'size', width: '100px', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+        { title: '产品重量', dataIndex: 'weight', width: '100px', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+        { title: '颜色', dataIndex: 'color', width: '100px', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+        { title: '产品内盒尺寸', dataIndex: 'boxSize', width: '100px', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+        { title: '产品说明', dataIndex: 'description', width: '100px', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+        { title: '其他说明', dataIndex: 'otherDesc', width: '100px', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } }
+      ],
+      loadData: [],
+      nowUnColumns: [
+        { title: '序号', dataIndex: 'no', width: '50px', align: 'center' },
+        { title: '产品名称', dataIndex: 'name', width: '150px', align: 'center', customRender: function (text) { return text || '--' } },
+        { title: '产品编码', dataIndex: 'code', width: '100px', align: 'center', customRender: function (text) { return text || '--' } },
+        { title: '原厂编码', dataIndex: 'origCode', width: '100px', align: 'center', customRender: function (text) { return text || '--' } },
+        { title: '其它编码', dataIndex: 'otherCode', width: '100px', align: 'center', customRender: function (text) { return text || '--' } },
+        { title: '产品品牌', dataIndex: 'productBrandName', width: '100px', align: 'center', customRender: function (text) { return text || '--' } },
+        { title: '一级分类', dataIndex: 'productTypeName1', width: '100px', align: 'center', customRender: function (text) { return text || '--' } },
+        { title: '二级分类', dataIndex: 'productTypeName2', width: '100px', align: 'center', customRender: function (text) { return text || '--' } },
+        { title: '三级分类', dataIndex: 'productTypeName3', width: '100px', align: 'center', customRender: function (text) { return text || '--' } },
+        { title: '单位', dataIndex: 'unit', width: '80px', align: 'center', customRender: function (text) { return text || '--' } },
+        { title: '包装数', dataIndex: 'packQty', width: '80px', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+        { title: '包装数单位', dataIndex: 'packQtyUnit', width: '80px', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+        { title: '是否箭冠产品', dataIndex: 'arrowFalgDictValue', width: '80px', align: 'center', customRender: function (text) { return text || '--' } },
+        { title: '条形码', dataIndex: 'qrCode', width: '120px', align: 'center', customRender: function (text) { return text || '--' } },
+        { title: '产品尺寸', dataIndex: 'size', width: '100px', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+        { title: '产品重量', dataIndex: 'weight', width: '100px', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+        { title: '颜色', dataIndex: 'color', width: '100px', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+        { title: '产品内盒尺寸', dataIndex: 'boxSize', width: '100px', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+        { title: '产品说明', dataIndex: 'description', width: '100px', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+        { title: '其他说明', dataIndex: 'otherDesc', width: '100px', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+        { title: '备注', dataIndex: 'errorDesc', width: '100px', align: 'center', customRender: function (text) { return text || '--' } }
+      ],
+      unLoadData: [],
+      loading: false
+    }
+  },
+  methods: {
+    getData () {
+      const _this = this
+      this.loading = true
+      const params = {
+        path: this.paramsData.path
+      }
+      batchImportProduct(params).then(res => {
+        this.loading = false
+        if (res.status == 200) {
+          if (res.data.rightList && res.data.rightList.length > 0) {
+            res.data.rightList.map((item, index) => {
+              item.no = index + 1
+            })
+          }
+          if (res.data.errorList && res.data.errorList.length > 0) {
+            res.data.errorList.map((item, index) => {
+              item.no = index + 1
+            })
+          }
+          _this.loadData = res.data.rightList || []
+          _this.unLoadData = res.data.errorList || []
+        }
+      })
+    },
+    // 确认导入
+    handleSubmit () {
+      if (this.loadData.length == 0) {
+        this.$message.warning('无可导入产品!')
+      } else {
+        this.$emit('ok', this.loadData)
+        this.isShow = false
+      }
+    },
+    // 导出
+    handleError () {
+      const _this = this
+      if (_this.unLoadData.length < 1) {
+        _this.$message.info('暂无可导出的错误项~')
+        return
+      }
+      _this.spinning = true
+      hdExportExcel(exportErrorProduct, _this.unLoadData, '导出产品错误项', function () {
+        _this.spinning = false
+      })
+    }
+  },
+  watch: {
+    //  父页面传过来的弹框状态
+    openModal (newValue, oldValue) {
+      this.isShow = newValue
+    },
+    //  重定义的弹框状态
+    isShow (newValue, oldValue) {
+      if (!newValue) {
+        this.$emit('close')
+        this.loadData = []
+        this.unLoadData = []
+      } else {
+        this.getData()
+      }
+    }
+  }
+}
+</script>
+
+<style lang="less" scoped>
+  .chooseImport-modal{
+    .chooseImport-con{
+      .red{
+        color: #f30;
+      }
+      .btn-con{
+        text-align: center;
+        margin: 30px 0 20px;
+        .button-cancel,.button-error{
+          font-size: 12px;
+        }
+      }
+    }
+  }
+</style>

+ 197 - 0
src/views/productManagement/productInfo/importGuideModal.vue

@@ -0,0 +1,197 @@
+<template>
+  <a-modal
+    centered
+    class="importGuide-modal"
+    :footer="null"
+    :maskClosable="false"
+    title="导入"
+    v-model="isShow"
+    @cancel="isShow=false"
+    :width="750">
+    <div class="importGuide-con">
+      <div class="explain-con">
+        <div class="explain-item">
+          <div class="explain-tit">
+            <span>1</span>准备导入
+          </div>
+          <ul>
+            <li>1) 请先下载导入模板,模板中已标示出必填项</li>
+            <li>2) 产品编码具有唯一性,系统中已存在的无法导入</li>
+            <li>3) 产品品牌、产品分类、单位、包装数单位,必须是系统中已经存在的值,否则无法导入</li>
+          </ul>
+          <a-button type="link" icon="download" style="padding: 0 0 0 23px;" @click="handleExport">下载导入模板</a-button>
+        </div>
+        <div class="explain-item">
+          <div class="explain-tit">
+            <span>2</span>上传数据文件
+          </div>
+          <p>目前支持的文件类型*.xls,*.xlsx.</p>
+          <div style="overflow: hidden;padding-left: 23px;">
+            <Upload
+              id="importGuide-attachList"
+              ref="importUpload"
+              :maxNums="1"
+              fileType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
+              uploadType="import"
+              :action="attachAction"
+              :uploadParams="uploadParams"
+              upText="添加文件"
+              @change="changeImport"></Upload>
+          </div>
+        </div>
+      </div>
+      <!-- 按钮 -->
+      <div class="btn-con">
+        <a-button
+          type="primary"
+          id="importGuide-nextStep"
+          size="large"
+          class="button-primary"
+          @click="handlerNextStep"
+          style="padding: 0 60px;">下一步</a-button>
+        <a-button
+          id="importGuide-cancel"
+          size="large"
+          class="button-cancel"
+          @click="isShow=false"
+          style="padding: 0 60px;margin-left: 15px;">取消</a-button>
+      </div>
+    </div>
+    <!-- 导入 -->
+    <chooseImportModal :openModal="openImportModal" :paramsData="paramsData" @close="handleClose" @ok="hanldeOk" />
+  </a-modal>
+</template>
+
+<script>
+import { commonMixin } from '@/utils/mixin'
+import ChooseImportModal from './chooseImportModal.vue'
+import { Upload } from '@/components'
+export default {
+  name: 'SalesImportGuideModal',
+  mixins: [commonMixin],
+  components: { ChooseImportModal, Upload },
+  props: {
+    openModal: { //  弹框显示状态
+      type: Boolean,
+      default: false
+    },
+    params: {
+      type: Object,
+      default: null
+    }
+  },
+  data () {
+    return {
+      isShow: this.openModal, //  是否打开弹框
+      openImportModal: false, //  导入
+      attachAction: process.env.VUE_APP_API_BASE_URL + '/upload',
+      paramsData: null,
+      uploadParams: {
+        savePathType: 'local'
+      }
+    }
+  },
+  methods: {
+    // 下一步
+    handlerNextStep () {
+      if (this.paramsData) {
+        this.openImportModal = true
+      } else {
+        this.$message.warning('添加文件后再进行下一步操作!')
+      }
+    },
+    // 上传文件  change
+    changeImport (file) {
+      if (file) {
+        this.paramsData = {
+          path: file
+        }
+      }
+    },
+    // 导入
+    hanldeOk (obj) {
+      if (obj && obj.length > 0) {
+        this.$emit('ok', obj)
+        this.isShow = false
+      }
+    },
+    // 关闭
+    handleClose () {
+      this.openImportModal = false
+      this.isShow = false
+    },
+    // 下载模板
+    handleExport () {
+      const link = document.createElement('a')
+      link.style.display = 'none'
+      link.href = 'https://jg-ocs.oss-cn-beijing.aliyuncs.com/templ/promo/expenseAccountDetailImport.xlsx?t=' + new Date().getTime()
+      link.setAttribute('download', '产品批量导入模板' + '.xlsx')
+      document.body.appendChild(link)
+      link.click()
+      document.body.removeChild(link)
+    }
+  },
+  watch: {
+    //  父页面传过来的弹框状态
+    openModal (newValue, oldValue) {
+      this.isShow = newValue
+    },
+    //  重定义的弹框状态
+    isShow (newValue, oldValue) {
+      if (!newValue) {
+        this.$emit('close')
+        this.paramsData = null
+        this.$refs.importUpload.setFileList('')
+      }
+    }
+  }
+}
+</script>
+
+<style lang="less" scoped>
+  .importGuide-modal{
+    .importGuide-con{
+      .explain-con{
+        .explain-item{
+          margin-bottom: 10px;
+          .explain-tit{
+            font-weight: bold;
+            span{
+              display: inline-block;
+              width: 18px;
+              height: 18px;
+              line-height: 16px;
+              text-align: center;
+              margin-right: 5px;
+              border-radius: 50%;
+              border: 1px solid rgba(0, 0, 0, 0.3);
+            }
+          }
+          p{
+            margin: 8px 0;
+            padding-left: 23px;
+          }
+          ul{
+            list-style: none;
+            padding: 0;
+            padding-left: 23px;
+            margin: 0;
+            li{
+              line-height: 26px;
+            }
+          }
+        }
+        #importGuide-attachList{
+          width: 100%;
+        }
+      }
+      .btn-con{
+        margin: 10px 0 20px;
+        text-align: center;
+        .button-cancel{
+          font-size: 12px;
+        }
+      }
+    }
+  }
+</style>

+ 25 - 5
src/views/productManagement/productInfo/list.vue

@@ -93,7 +93,7 @@
           class="button-warning"
           :loading="loadingAudit"
           @click="handleBatchAudit"
-          style="margin: 0 15px;">批量审核</a-button>
+          style="margin: 0 10px;">批量审核</a-button>
         <a-button
           id="productInfoList-batchLaunch"
           type="primary"
@@ -101,7 +101,7 @@
           class="button-primary"
           :loading="loadingLaunch"
           @click="handleBatchLaunch"
-          style="margin: 0 15px;">批量上线</a-button>
+          style="margin: 0 10px;">批量上线</a-button>
         <a-button
           id="productInfoList-batchDownline"
           type="primary"
@@ -109,7 +109,13 @@
           class="button-grey"
           :loading="loadingDownline"
           @click="handleBatchDownline"
-          style="margin: 0 15px;">批量下线</a-button>
+          style="margin: 0 10px;">批量下线</a-button>
+        <a-button
+          id="productInfoList-batchLaunch"
+          type="primary"
+          class="button-error"
+          @click="openGuideModal=true"
+          style="margin: 0 10px;">批量导入</a-button>
         <span style="margin-left: 8px" v-if="$hasPermissions('B_productInfo_batchAudit') || $hasPermissions('B_productInfo_batchLaunch') || $hasPermissions('B_productInfo_batchDownline')">
           <template v-if="rowSelectionInfo && rowSelectionInfo.selectedRowKeys.length>0">{{ `已选 ${rowSelectionInfo.selectedRowKeys.length} 项` }}</template>
         </span>
@@ -204,6 +210,8 @@
     <product-info-detail-modal v-drag :openModal="openModal" :itemSn="itemSn" @close="closeModal" />
     <!-- 产品下线 -->
     <product-info-offline-modal v-drag :openModal="openOfflineModal" :offlineProductList="offlineProductList" @close="closeOfflineModal" @ok="$refs.table.refresh()" />
+    <!-- 导入产品 -->
+    <importGuideModal :openModal="openGuideModal" @close="openGuideModal=false" @ok="hanldeOk" />
   </a-card>
 </template>
 
@@ -217,11 +225,12 @@ import { productTypeQueryAll } from '@/api/productType'
 import ProductBrand from '@/views/common/productBrand.js'
 import { exportExcel } from '@/libs/JGPrint.js'
 import rangeDate from '@/views/common/rangeDate.vue'
-import { productList, productAudit, productBatchAudit, productDel, productOnline, productBatchOnline, productExport } from '@/api/product'
+import importGuideModal from './importGuideModal.vue'
+import { productList, productAudit, productBatchAudit, productDel, productOnline, productBatchOnline, productExport, saveBatchImportProduct } from '@/api/product'
 export default {
   name: 'ProductInfoList',
   mixins: [commonMixin],
-  components: { STable, VSelect, productInfoDetailModal, productInfoOfflineModal, ProductBrand, rangeDate },
+  components: { STable, VSelect, productInfoDetailModal, productInfoOfflineModal, ProductBrand, rangeDate, importGuideModal },
   data () {
     return {
       spinning: false,
@@ -243,6 +252,7 @@ export default {
       productType: [],
       disabled: false, //  查询、重置按钮是否可操作
       exportLoading: false,
+      openGuideModal: false,
       columns: [
         { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
         { title: '创建时间', dataIndex: 'createDate', width: '8%', align: 'center', customRender: function (text) { return text || '--' } },
@@ -305,6 +315,16 @@ export default {
     rowSelectionFun (obj) {
       this.rowSelectionInfo = obj || null
     },
+    // 批量导入产品
+    hanldeOk (obj) {
+      this.spinning = true
+      saveBatchImportProduct(obj).then(res => {
+        if (res.status == 200) {
+          this.resetSearchForm()
+        }
+        this.spinning = false
+      })
+    },
     // 审核
     handleAudit (row) {
       const _this = this

+ 2 - 2
vue.config.js

@@ -107,9 +107,9 @@ const vueConfig = {
     // If you want to turn on the proxy, please remove the mockjs /src/main.jsL11
     proxy: {
       '/api': {
-        // target: 'http://160f12de.nat123.fun:53612/ocs-admin',
+        target: 'http://192.168.0.183:8602/ocs-admin',
         // target: 'https://t.ocs.360arrow.com/ocs-admin', //  Á·Ï°
-        target: 'http://p.ocs.360arrow.com/ocs-admin', //  Ô¤·¢²¼
+        // target: 'http://p.ocs.360arrow.com/ocs-admin', //  Ô¤·¢²¼
         ws: false,
         changeOrigin: true,
         pathRewrite: {