Pārlūkot izejas kodu

销售退货 导入产品

chenrui 3 gadi atpakaļ
vecāks
revīzija
02cd8f8d75

+ 2 - 2
src/api/allocateBill.js

@@ -106,7 +106,7 @@ export const allocateBillDetailSave = params => {
 // 调拨管理 详情  打印
 export const allocateBillDetailPrint = params => {
   return axios.request({
-    url: `allocateBill/print/${params.sn}/${params.isPreview}`,
+    url: `/allocateBill/print/${params.sn}/${params.isPreview}`,
     method: 'get',
     responseType: 'blob'
   })
@@ -114,7 +114,7 @@ export const allocateBillDetailPrint = params => {
 // 调拨管理 下载模板
 export const allocateBillDownload = params => {
   return axios.request({
-    url: `allocateBill/detail/downloadExcel`,
+    url: `/allocateBill/detail/downloadExcel`,
     method: 'post',
     responseType: 'blob'
   })

+ 24 - 0
src/api/salesReturn.js

@@ -141,3 +141,27 @@ export const salesReturnFinancial = (params) => {
     method: 'post'
   })
 }
+// 退货确认 下载模板
+export const salesReturnDownload = params => {
+  return axios.request({
+    url: `/salesReturn/detail/downloadExcel/${params.grabFlag}`,
+    method: 'post',
+    responseType: 'blob'
+  })
+}
+// 退货确认  解析导入的文件
+export const salesReturnParseProducts = params => {
+  return axios({
+    url: '/salesReturn/detail/parseProducts',
+    data: params,
+    method: 'post'
+  })
+}
+// 退货确认  批量插入
+export const salesReturnBatchInsert = params => {
+  return axios({
+    url: '/salesReturn/detail/batchInsert',
+    data: params,
+    method: 'post'
+  })
+}

+ 207 - 0
src/views/salesManagement/salesReturn/chooseImportModal.vue

@@ -0,0 +1,207 @@
+<template>
+  <a-modal
+    centered
+    class="chooseImport-modal"
+    :footer="null"
+    :maskClosable="false"
+    title="导入"
+    v-model="isShow"
+    @cancle="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 }"
+        :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 }"
+        :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 60px;">确认导入</a-button>
+        <a-button
+          id="chooseImport-cancel"
+          size="large"
+          class="button-cancel"
+          @click="isShow=false"
+          style="padding: 0 60px;margin-left: 15px;">取消</a-button>
+      </div>
+    </div>
+  </a-modal>
+</template>
+
+<script>
+import { salesReturnParseProducts } from '@/api/salesReturn'
+export default {
+  name: 'ChooseImportModal',
+  props: {
+    openModal: { //  弹框显示状态
+      type: Boolean,
+      default: false
+    },
+    paramsData: {
+      type: Object,
+      default: () => {
+        return {}
+      }
+    }
+  },
+  data () {
+    return {
+      isShow: this.openModal, //  是否打开弹框
+      loadData: [],
+      unLoadData: [],
+      loading: false
+    }
+  },
+  computed: {
+    nowColumns () {
+      let arr = []
+      if (this.paramsData && this.paramsData.grabFlag == '0') {
+        arr = [
+          { title: '序号', dataIndex: 'no', width: 70, align: 'center' },
+          { title: '产品编码', dataIndex: 'productCode', align: 'center', customRender: function (text) { return text || '--' } },
+          { title: '产品名称', dataIndex: 'productName', align: 'center', customRender: function (text) { return text || '--' } },
+          { title: '数量', dataIndex: 'qtyText', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+          { title: '价格', dataIndex: 'priceText', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+          { title: '退货原因', dataIndex: 'errorDesc', width: 100, align: 'center', customRender: function (text) { return text || '--' } }
+        ]
+      } else if (this.paramsData && this.paramsData.grabFlag == '1') {
+        arr = [
+          { title: '序号', dataIndex: 'no', width: 70, align: 'center' },
+          { title: '销售单号', dataIndex: 'salesBillNo', align: 'center', customRender: function (text) { return text || '--' } },
+          { title: '产品编码', dataIndex: 'productCode', align: 'center', customRender: function (text) { return text || '--' } },
+          { title: '产品名称', dataIndex: 'productName', align: 'center', customRender: function (text) { return text || '--' } },
+          { title: '数量', dataIndex: 'qtyText', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+          { title: '价格', dataIndex: 'priceText', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+          { title: '退货原因', dataIndex: 'errorDesc', width: 100, align: 'center', customRender: function (text) { return text || '--' } }
+        ]
+      }
+      return arr
+    },
+    nowUnColumns () {
+      let arr = []
+      if (this.paramsData && this.paramsData.grabFlag == '0') {
+        arr = [
+          { title: '序号', dataIndex: 'no', width: 70, align: 'center' },
+          { title: '产品编码', dataIndex: 'productCode', align: 'center', customRender: function (text) { return text || '--' } },
+          { title: '产品名称', dataIndex: 'productName', align: 'center', customRender: function (text) { return text || '--' } },
+          { title: '数量', dataIndex: 'qtyText', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+          { title: '价格', dataIndex: 'priceText', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+          { title: '退货原因', dataIndex: 'errorDesc', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
+          { title: '备注', dataIndex: 'remark', width: 100, align: 'center', customRender: function (text) { return text || '--' } }
+        ]
+      } else if (this.paramsData && this.paramsData.grabFlag == '1') {
+        arr = [
+          { title: '序号', dataIndex: 'no', width: 70, align: 'center' },
+          { title: '销售单号', dataIndex: 'salesBillNo', align: 'center', customRender: function (text) { return text || '--' } },
+          { title: '产品编码', dataIndex: 'productCode', align: 'center', customRender: function (text) { return text || '--' } },
+          { title: '产品名称', dataIndex: 'productName', align: 'center', customRender: function (text) { return text || '--' } },
+          { title: '数量', dataIndex: 'qtyText', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+          { title: '价格', dataIndex: 'priceText', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
+          { title: '退货原因', dataIndex: 'errorDesc', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
+          { title: '备注', dataIndex: 'remark', width: 100, align: 'center', customRender: function (text) { return text || '--' } }
+        ]
+      }
+      return arr
+    }
+  },
+  methods: {
+    getData () {
+      const _this = this
+      this.loading = true
+      const params = {
+        salesReturnBillSn: this.paramsData.salesReturnBillSn,
+        path: this.paramsData.path
+      }
+      salesReturnParseProducts(params).then(res => {
+        this.loading = false
+        if (res.status == 200) {
+          if (res.data.okList && res.data.okList.length > 0) {
+            res.data.okList.map((item, index) => {
+              item.no = index + 1
+            })
+          }
+          if (res.data.failList && res.data.failList.length > 0) {
+            res.data.failList.map((item, index) => {
+              item.no = index + 1
+            })
+          }
+          _this.loadData = res.data.okList || []
+          _this.unLoadData = res.data.failList || []
+        }
+      })
+    },
+    // 确认导入
+    handleSubmit () {
+      if (this.loadData.length == 0) {
+        this.$message.warning('无可导入产品!')
+      } else {
+        this.$emit('ok', this.loadData)
+        this.isShow = 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{
+          font-size: 12px;
+        }
+      }
+    }
+  }
+</style>

+ 225 - 0
src/views/salesManagement/salesReturn/importGuideModal.vue

@@ -0,0 +1,225 @@
+<template>
+  <a-modal
+    centered
+    class="importGuide-modal"
+    :footer="null"
+    :maskClosable="false"
+    title="导入"
+    v-model="isShow"
+    @cancle="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) 导入的Excel文件中必须包含名为<span>{{ params.grabFlag=='0'?'':'“销售单号”、' }}</span>“产品编码”、“数量”、“价格”、“退货原因”的列,且名称必须相同</li>
+            <li>2) 除了<span>{{ params.grabFlag=='0'?'':'“销售单号”、' }}</span>“产品编码”、“数量”、“价格”、“退货原因”<span>{{ params.grabFlag=='0'?'四':'五' }}</span>列,其他列可自定义,不影响数据导入</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 ChooseImportModal from './chooseImportModal.vue'
+import { Upload } from '@/components'
+import { salesReturnDownload } from '@/api/salesReturn'
+export default {
+  name: 'ImportGuideModal',
+  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 = {
+          salesReturnBillSn: this.params.salesReturnBillSn || '',
+          grabFlag: this.params.grabFlag || '',
+          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 _this = this
+      _this.spinning = true
+      salesReturnDownload({ grabFlag: this.params.grabFlag }).then(res => {
+        _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
+      let fname
+      if (this.params.grabFlag == '0') {
+        fname = '销售退货单产品导入模板-不抓单'
+      } else if (this.params.grabFlag == '1') {
+        fname = '销售退货单产品导入模板-抓单'
+      }
+      link.setAttribute('download', fname + '.xlsx')
+      document.body.appendChild(link)
+      link.click()
+    }
+  },
+  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>

+ 24 - 8
src/views/salesManagement/salesReturn/salesReturnEdit.vue

@@ -21,11 +21,14 @@
         <!-- alert -->
         <a-alert style="margin-bottom: 10px;" type="info">
           <div slot="message" class="total-bar">
-            <div>
-              <span>退货总金额:{{ ordeDetail&&(ordeDetail.totalAmount || ordeDetail.totalAmount==0) ? ordeDetail.totalAmount : '--' }}元;</span>
-              <span>退货总数量:{{ ordeDetail&&(ordeDetail.totalQty || ordeDetail.totalQty==0) ? ordeDetail.totalQty : '--' }};</span>
-            </div>
-            <div>
+            <div style="position: relative;width: 100%;">
+              <div>
+                <span>退货总金额:{{ ordeDetail&&(ordeDetail.totalAmount || ordeDetail.totalAmount==0) ? ordeDetail.totalAmount : '--' }}元;</span>
+                <span>退货总数量:{{ ordeDetail&&(ordeDetail.totalQty || ordeDetail.totalQty==0) ? ordeDetail.totalQty : '--' }};</span>
+              </div>
+              <div style="position: absolute;right: 0;top: -2px;">
+                <a-button size="small" id="salesReturnEdit-import-btn" @click="openGuideModal=true">导入产品</a-button>
+              </div>
             </div>
           </div>
         </a-alert>
@@ -92,14 +95,17 @@
         @click="handleSubmit()"
         id="salesReturn-handleSubmit">提交</a-button>
     </div>
+    <!-- 导入产品 -->
+    <importGuideModal :openModal="openGuideModal" :params="{salesReturnBillSn: $route.params.sn, grabFlag: ordeDetail.grabFlag}" @close="openGuideModal=false" @ok="hanldeOk" />
   </div>
 </template>
 
 <script>
 import { STable, VSelect } from '@/components'
+import ImportGuideModal from './importGuideModal.vue'
 import queryPart from './queryPart.vue'
 import EditableCell from '@/views/common/editInput.js'
-import { salesReturnDetail, salesReturnSubmit } from '@/api/salesReturn'
+import { salesReturnDetail, salesReturnSubmit, salesReturnBatchInsert } from '@/api/salesReturn'
 import {
   salesReturnDetailList,
   salesReturnDetailDel,
@@ -113,7 +119,8 @@ export default {
     STable,
     VSelect,
     queryPart,
-    EditableCell
+    EditableCell,
+    ImportGuideModal
   },
   data () {
     return {
@@ -160,7 +167,8 @@ export default {
           this.chooseLoadData = data.list
           return data
         })
-      }
+      },
+      openGuideModal: false //  导入产品引导
     }
   },
   methods: {
@@ -289,6 +297,14 @@ export default {
         }
         this.spinning = false
       })
+    },
+    // 导入产品
+    hanldeOk (obj) {
+      salesReturnBatchInsert(obj).then(res => {
+        if (res.status == 200) {
+          this.$refs.table.refresh(true)
+        }
+      })
     }
   },
   mounted () {

+ 24 - 6
src/views/salesManagement/salesReturn/salesReturnGrabEdit.vue

@@ -21,9 +21,14 @@
         <!-- alert -->
         <a-alert style="margin-bottom: 10px;" type="info">
           <div slot="message" class="total-bar">
-            <div>
-              <span>退货总金额:{{ ordeDetail&&(ordeDetail.totalAmount || ordeDetail.totalAmount==0) ? ordeDetail.totalAmount : '--' }}元;</span>
-              <span>退货总数量:{{ ordeDetail&&(ordeDetail.totalQty || ordeDetail.totalQty==0) ? ordeDetail.totalQty : '--' }};</span>
+            <div style="position: relative;width: 100%;">
+              <div>
+                <span>退货总金额:{{ ordeDetail&&(ordeDetail.totalAmount || ordeDetail.totalAmount==0) ? ordeDetail.totalAmount : '--' }}元;</span>
+                <span>退货总数量:{{ ordeDetail&&(ordeDetail.totalQty || ordeDetail.totalQty==0) ? ordeDetail.totalQty : '--' }};</span>
+              </div>
+              <div style="position: absolute;right: 0;top: -2px;">
+                <a-button size="small" id="salesReturnEdit-import-btn" @click="openGuideModal=true">导入产品</a-button>
+              </div>
             </div>
           </div>
         </a-alert>
@@ -90,14 +95,17 @@
         @click="handleSubmit()"
         id="salesReturn-handleSubmit">提交</a-button>
     </div>
+    <!-- 导入产品 -->
+    <importGuideModal :openModal="openGuideModal" :params="{salesReturnBillSn: $route.params.sn, grabFlag: ordeDetail.grabFlag}" @close="openGuideModal=false" @ok="hanldeOk" />
   </div>
 </template>
 
 <script>
 import { STable, VSelect } from '@/components'
+import ImportGuideModal from './importGuideModal.vue'
 import queryPart from './queryPart.vue'
 import EditableCell from '@/views/common/editInput.js'
-import { salesReturnDetail, salesReturnSubmit } from '@/api/salesReturn'
+import { salesReturnDetail, salesReturnSubmit, salesReturnBatchInsert } from '@/api/salesReturn'
 import {
   salesReturnDetailList,
   salesReturnDetailDel,
@@ -111,7 +119,8 @@ export default {
     STable,
     VSelect,
     queryPart,
-    EditableCell
+    EditableCell,
+    ImportGuideModal
   },
   data () {
     return {
@@ -160,7 +169,8 @@ export default {
           this.chooseLoadData = data.list
           return data
         })
-      }
+      },
+      openGuideModal: false //  导入产品引导
     }
   },
   methods: {
@@ -302,6 +312,14 @@ export default {
         }
         this.spinning = false
       })
+    },
+    // 导入产品
+    hanldeOk (obj) {
+      salesReturnBatchInsert(obj).then(res => {
+        if (res.status == 200) {
+          this.$refs.table.refresh(true)
+        }
+      })
     }
   },
   mounted () {