earlyWarningList.vue 8.31 KB
<!-- 库存预警 -->
<template>
  <div>
    <d2-container>
      <div class="header"
           slot="header"
           style="padding: 10px 20px;">
        <d2-search ref="showSearch"
                   class="show-search"
                   :search-form="searchForm"
                   :form-data="showFormData" />
        <div class="up-btns">
          <el-button :id="tableParams.btnId"
                     size="small"
                     type="primary">
            查询
          </el-button>
          <el-button size="small"
                     @click="handleReset">
            重置
          </el-button>
        </div>
      </div>
      <div class="d2-container-content">
        <d2-table-header>
          <auth-button category="Button" />
        </d2-table-header>
        <d2-table ref="recordTable"
                  :get-list-api="getListApi"
                  :search-form="searchFormSearch"
                  :table-params="tableParams"
                  :before-search-fn="beforeSearchFn">
          <auth-button slot="auth-button"
                       slot-scope="scope"
                       :data="scope.scope" />
        </d2-table>
      </div>
    </d2-container>
  </div>
</template>

<script>
import { Util, deepClone } from '@/common/util'
import { mapActions, mapState } from 'vuex'
import { getProductTypeBySceneId } from '@api/product'
import { getyqMerchantList, inventoryWarningList, getServicemerchantrefList } from '@api/stockManage'
import { baseConfig } from '@/main'
export default {
  name: 'EarlyWarningList',
  components: {

  },
  data() {
    return {
      userInfo: this.$store.state.d2admin.user.info,
      membraneTypeList: baseConfig.membraneTypeList,
      searchForm: {
        upgradeGoodsName: '',
        yqMerchantId: '',
        merchantId: '',
        goodsType: '',
        goodsSeries: ''
      },
      searchFormSearch: {},
      searchSelectObj: {
        orderOrTrade: {
          attr: 'inputtedOrderCode',
          value: ''
        }
      },
      showFormData: [{
        label: '商品名称',
        name: 'upgradeGoodsName',
        type: 'input',
        maxlength: '20',
        isClear: true
      }, {
        label: '商品编号',
        name: 'productCode',
        type: 'input',
        maxlength: '40',
        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()
        }
      }, {
        label: '所属门店',
        name: 'merchantId',
        type: 'select',
        noDataText: '请先选择所属仓库',
        optionList: [],
        optionId: 'merchantId',
        optionLabel: 'merchantName',
        optionsName: 'merchantIdList'
      }],
      getListApi: inventoryWarningList,
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: false,
        tableColumns: [{
          label: '商品名称',
          prop: 'upgradeGoodsName',
          width: '160px'
        }, {
          label: '商品编码',
          prop: 'productCode',
          width: '250px'
        }, {
          label: '系列',
          prop: 'goodsSeries',
          width: '250px'
        }, {
          label: '所属分类',
          prop: 'goodsTypeName',
          width: '250px'
        }, {
          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',
          width: '200px'
        }, {
          label: '所属门店',
          prop: 'merchantName',
          width: '200px'
        }
        ]
      },
      baseData: {
        productTypeList: [],
        yqMerchantList: [],
        merchantIdList: []
      }
    }
  },
  computed: {
    ...mapState({
      dowloadList: (state) => state.d2admin.user.dowloadList
    })
  },
  mounted() {
    // this.getBaseData()
    // 获取全部类目
    getProductTypeBySceneId({ sceneType: '' }).then(res => {
      this.baseData.productTypeList = res
      this.getOptionsList()
    })

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

  methods: {
    ...mapActions({
      get: 'd2admin/base/get',
      close: 'd2admin/page/close'
    }),
    ...mapActions('d2admin/user', ['actionSetDownloadList']),

    // async getBaseData() {
    //   this.getOptionsList()
    // },

    // 获取仓库门店
    getServicemerchantrefList(merchantId) {
      getServicemerchantrefList({
        yqMerchantId: merchantId
      }).then(res => {
        this.baseData.merchantIdList = res || []
        // 总店
        const _headOffice = this.baseData.yqMerchantList.find(item => item.merchantNo === merchantId)
        _headOffice.merchantId = _headOffice.merchantNo
        // 门店选项中加入总店
        this.baseData.merchantIdList.push(_headOffice)
        this.getOptionsList()
      })
    },

    beforeSearchFn() {
      return new Promise(resolve => {
        this.searchFormSearch = deepClone(this.searchForm)
        resolve()
      })
    },

    getOptionsList() {
      this.showFormData.forEach((item, index) => {
        if (item.type === 'select') {
          if (this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this.showFormData[index].optionLabel] !== '全部') {
            const temp = {}
            temp[this.showFormData[index].optionId] = ''
            temp[this.showFormData[index].optionLabel] = '全部'
            this.baseData[item.optionsName].unshift(temp)
          }
          this.$set(this.showFormData[index], 'optionList', this.baseData[item.optionsName])
        }
      })
    },

    // handleSearch() {
    //   this.$refs.recordTable.refreshTable()
    // },
    handleReset() {
      this.searchForm = {
        upgradeGoodsName: '',
        yqMerchantId: '',
        merchantId: '',
        goodsType: '',
        goodsSeries: ''
      }
      this.$refs.recordTable.refreshTable()
    },

    // 去补货
    gotoReplenishment() {
      // this.close({ tagName: '/orderList' })
      this.$router.push({ name: 'purchasingMall' })
    },

    handleExport() {
      var params = this.searchFormSearch
      params.method = 'dj.api.life.InventoryWarningInfo.exportExcel.async'
      const list = [
        ...this.dowloadList,
        {
          name: '库存预警列表',
          exportParam: JSON.stringify(params),
          status: 'waiting',
          timeid: new Date().getTime()
        }
      ]
      this.actionSetDownloadList({ list, type: 'dowloadList' })
    }

  }
}

</script>
<style scoped>
.count-txt {
  font-weight: 700;
  color: #2a58ad;
  margin: 0 2px;
}

.leftSpan {
  display: inline-block;
  box-sizing: border-box;
  margin-right: 10px;
}
</style>