index.vue 9.9 KB
<template>
  <div class="purchase">
    <div class="container">
      <GLCombiForm ref="showSearch"
                   :rowNumber="1"
                   :formObj="searchForm"
                   :formData="showFormData"
                   @handleOk="handleSearch"
                   @handleRest="handleReset"></GLCombiForm>
      <div class="table-header">
        <h2>预警列表</h2>
        <div>
          <el-button type="primary"
                     plain
                     size="small"
                     @click="gotoReplenishment">去补货</el-button>
          <el-button size="small"
                     @click="exportExcel">导出</el-button>
        </div>
      </div>

      <!-- 表格区域 开始 -->
      <GLTable ref="earlyWarningRef"
               :getListApi="getListApi"
               :noDataImg="url"
               :searchForm="tableSearchForm"
               :tableParams="tableParams"
               :pageConf="pageConf"
               :beforeSearchFn="beforeSearchFn"
               @setTableFinishFun="setTableFinishFun"></GLTable>
      <!-- 表格区域 end -->
    </div>
  </div>
</template>

<script>
import url from '@/assets/empty.png'
// import { membraneTypeList } from '@/utils/constants.js'
export default {
  name: 'earlyWarning',
  data() {
    return {
      // membraneTypeList: membraneTypeList,
      size: 'small',
      url: url,
      searchForm: {
        upgradeGoodsName: '',
        yqMerchantId: '',
        merchantId: '',
        goodsType: '',
        goodsSeries: '',
        productCode: ''
      },
      tableSearchForm: {},
      stockInfo: {},
      stockMonthVisible: false,
      showFormData: [
        {
          label: '商品名称',
          name: 'upgradeGoodsName',
          type: 'input',
          maxlength: '20',
          isClear: true
        },
        {
          label: '商品编码',
          name: 'productCode',
          type: 'input',
          isClear: true
        },
        {
          label: '系列',
          name: 'goodsSeries',
          type: 'input',
          maxlength: '20',
          isClear: true
        },
        {
          label: '所属分类',
          name: 'goodsType',
          type: 'select',
          optionList: [],
          optionId: 'categoryType',
          optionLabel: 'categoryName',
          optionsName: 'productTypeList'
        },
        {
          label: '所属仓库',
          name: 'yqMerchantId',
          type: 'select',
          optionList: [],
          optionId: 'merchantNo',
          optionLabel: 'merchantName',
          optionsName: 'yqMerchantList',
          changeAttr: (value, targetItem) => {
            value ? this.getServicemerchantrefList(value) : (this.baseData.merchantIdList = [])
            this.searchForm.merchantId = ''
            this.getOptionsList('showFormData')
          }
        },
        {
          label: '所属门店',
          name: 'merchantId',
          type: 'select',
          noDataText: '请先选择所属仓库',
          optionList: [],
          optionId: 'merchantId',
          optionLabel: 'merchantName',
          optionsName: 'merchantIdList'
        }
      ],
      // 表格
      getListApi: this.$apis.stockManage.inventoryWarningList,
      tableParams: {
        listName: 'list',
        tableOption: false,
        tableColumns: [
          {
            label: '商品名称',
            prop: 'upgradeGoodsName'
          },
          {
            label: '规格',
            prop: 'specificationData',
            width: 180,
            line: 1
          },
          {
            label: '商品编码',
            prop: 'productCode'
          },
          {
            label: '系列',
            prop: 'goodsSeries'
          },
          {
            label: '所属分类',
            prop: 'goodsTypeName'
          },
          {
            label: '库存',
            prop: 'stock',
            formatter: cellValue => {
              return cellValue.stock || cellValue.stock == 0 ? parseFloat(cellValue.stock).toFixed(2) + (this.$membraneTypeList.includes(cellValue.goodsType) ? '米' : '件') : '-'
            }
          },
          {
            label: '最低库存',
            prop: 'warningValue',
            formatter: cellValue => {
              return cellValue.warningValue || cellValue.warningValue == 0 ? parseFloat(cellValue.warningValue).toFixed(2) + (this.$membraneTypeList.includes(cellValue.goodsType) ? '米' : '件') : '-'
            }
          },
          {
            label: '最高库存',
            prop: 'warningValueMax',
            formatter: cellValue => {
              return cellValue.warningValueMax || cellValue.warningValueMax == 0 ? parseFloat(cellValue.warningValueMax).toFixed(2) + (this.$membraneTypeList.includes(cellValue.goodsType) ? '米' : '件') : '-'
            }
          },
          {
            label: '所属仓库',
            prop: 'yqMerchantName'
          },
          {
            label: '所属门店',
            prop: 'merchantName'
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'currentPage', totalCount: 'total' },
      // 基本数据
      baseData: {
        productTypeList: [],
        yqMerchantList: [],
        merchantIdList: []
      }
    }
  },

  mounted() {
    this.$apis.product.getProductTypeBySceneId({ sceneType: '' }).then(res => {
      this.baseData.productTypeList = res
      this.getOptionsList('showFormData')
    })

    // 获取当前登录账号可见的园区店列表
    this.$apis.stockManage.getyqMerchantList({ mainPartnerMerchant: true }).then(res => {
      this.baseData.yqMerchantList = res
      this.getOptionsList('showFormData')
    })
  },

  methods: {
    beforeSearchFn() {
      return new Promise(resolve => {
        this.tableSearchForm = this.$common.utils.deepClone(this.searchForm)
        resolve()
      })
    },
    // 获取仓库门店
    getServicemerchantrefList(merchantId) {
      this.$apis.stockManage
        .getServicemerchantrefList({
          yqMerchantId: merchantId
        })
        .then(res => {
          this.baseData.merchantIdList = res || []
          //总店
          let _headOffice = this.baseData.yqMerchantList.find(item => item.merchantNo === merchantId)
          _headOffice.merchantId = _headOffice.merchantNo
          //门店选项中加入总店
          this.baseData.merchantIdList.push(_headOffice)
          this.getOptionsList('showFormData')
        })
    },
    // 查看详情
    handleDetail(row) {
      this.stockInfo = row
      this.stockMonthVisible = true
    },
    //取消
    handleCancel(row) {
      this.secondConfirm('取消', '订单取消后即自动作废该订单,且无法撤回。是否确定取消?', 'purchaseShopping', 'purchaseOrderCancelOrCheck', { orderCode: row.orderCode, operateType: 2 })
    },

    getOptionsList(formName, hasAll = true, refreshSigle) {
      if (refreshSigle) {
        var item = this[formName].find(k => k.name == refreshSigle)
        var index = this[formName].findIndex(k => k.name == refreshSigle)
        this.$set(this[formName][index], 'optionList', this.$common.utils.deepClone(this.baseData[item.optionsName]))
        if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
          const temp = {}
          temp[this[formName][index].optionId] = ''
          temp[this[formName][index].optionLabel] = '全部'
          this[formName][index].optionList.unshift(temp)
        }
      } else {
        this[formName].forEach((item, index) => {
          if (item.type === 'select' && this.baseData[item.optionsName].length) {
            this.$set(this[formName][index], 'optionList', this.$common.utils.deepClone(this.baseData[item.optionsName]))
            if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
              const temp = {}
              temp[this[formName][index].optionId] = ''
              temp[this[formName][index].optionLabel] = '全部'
              this[formName][index].optionList.unshift(temp)
            }
          }
        })
      }
    },
    setTableFinishFun() {
      //接收到的数据为空
      this.$refs.earlyWarningRef.data.length ? (this.$refs.earlyWarningRef.tableHeightValues = '') : this.$refs.earlyWarningRef.setTableHeightFun()
    },
    exportExcel() {
      var params = this.searchForm
      this.$apis.stockManage.exportaInventExcel(params).then(res => {
        window.location.href = res
      })
    },
    //去补货
    gotoReplenishment() {
      this.$history.push(`/purchase/purchaseOrder/add`)
    },
    // async gotoReplenishment() {
    //   let result = await this.checkShipper()
    //   console.log(result)
    //   if (result) this.$history.push(`/purchase/purchaseOrder/add`)
    // },
    checkShipper() {
      return new Promise(resolve => {
        this.$apis.stockManage.checkShipper({}).then(res => {
          console.log(res)
          if (res.code == -1) {
            this.$message({
              type: 'error',
              message: res.message
            })
            resolve(false)
          } else {
            resolve(true)
          }
        })
      })
    },
    handleSearch() {
      this.$refs.earlyWarningRef.refreshTable()
    },

    handleReset() {
      this.searchForm = {
        upgradeGoodsName: '',
        yqMerchantId: '',
        merchantId: '',
        goodsType: '',
        goodsSeries: '',
        productCode: ''
      }
      this.showFormData[this.findFormIdx('merchantId')].optionList = []
      this.handleSearch()
    },

    findFormIdx(name) {
      return this.showFormData.findIndex(item => item.name === name)
    }
  }
}
</script>

<style scoped lang="scss">
@import '@/assets/css/mixin.scss';

.purchase {
  .table-header {
    @include space-between_center;
    margin-bottom: 10px;

    h2 {
      font-weight: 600;
      font-size: 16px;
      color: #333;
    }
  }
}
</style>