index.vue 6.97 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" size="small" @click="gotoReplenishment">去补货</el-button>
          <el-button type="primary" 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 * as dayjs from 'dayjs'
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: '',
        goodsType: '',
        goodsSeries: ''
      },
      tableSearchForm: {},
      stockInfo: {},
      stockMonthVisible: false,
      showFormData: [
        {
          label: '商品名称',
          name: 'upgradeGoodsName',
          type: 'input',
          maxlength: '20',
          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'
        }
      ],
      // 表格
      getListApi: this.$apis.stockManage.inventoryWarningList,
      tableParams: {
        listName: 'list',
        tableOption: false,
        tableColumns: [
          {
            label: '商品名称',
            prop: 'upgradeGoodsName'
          },
          {
            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: 'yqMerchantName'
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'currentPage', totalCount: 'total' },
      // 基本数据
      baseData: {
        productTypeList: [],
        yqMerchantList: []
      }
    }
  },

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

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

  methods: {
    beforeSearchFn() {
      return new Promise(resolve => {
        this.tableSearchForm = this.$common.utils.deepClone(this.searchForm)
        resolve()
      })
    },
    // 查看详情
    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() {
      this.exportLoading = true
      var params = this.getParams()
      this.$apis.stockManage.exportaInventExcel(params).then(res => {
        this.exportLoading = false
        window.location.href = res
      })
    },
     //去补货
    gotoReplenishment() {
      // this.close({ tagName: '/orderList' })
      this.$router.push({ name: 'purchasingMall' })
    },
    handleSearch() {
      this.$refs.earlyWarningRef.refreshTable()
    },

    handleReset() {
      this.searchForm = {
        upgradeGoodsName: '',
        yqMerchantId: '',
        goodsType: '',
        goodsSeries: ''
      }
      this.handleSearch()
    }
  }
}
</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>