index.vue 8.3 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>
        <el-button type="primary" size="small" @click="exportExcel">导出</el-button>
      </div>

      <!-- 表格区域 开始 -->
      <GLTable ref="outboundRef" :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: 'warehousing',
  data() {
    return {
      membraneTypeList: membraneTypeList,
      size: 'small',
      url: url,
      searchForm: {
        reduceDate: '',
        eventType: '',
        upgradeGoodsName: '',
        yqMerchantId: '',
        goodsType: '',
        businessCode: '',
        goodsSeries: ''
      },
      tableSearchForm: {},
      paramsObj: {},
      // 查看门店
      detailVisible: false,
      showFormData: [
        {
          label: '出库时间',
          name: 'reduceDate',
          type: 'datePicker',
          isClear: true,
          pickerOptions: 'beforeRangePickerOptions'
        },
        {
          label: '出库类型',
          name: 'eventType',
          type: 'select',
          optionList: [],
          optionId: 'confId',
          optionLabel: 'confLabel',
          optionsName: 'eventTypeList'
        },
        {
          label: '商品名称',
          name: 'upgradeGoodsName',
          type: 'input',
          maxlength: '20',
          isClear: true
        },
        {
          label: '出库门店',
          name: 'yqMerchantId',
          type: 'select',
          optionList: [],
          optionId: 'merchantNo',
          optionLabel: 'merchantName',
          optionsName: 'yqMerchantList'
        },
        {
          label: '所属分类',
          name: 'goodsType',
          type: 'select',
          optionList: [],
          optionId: 'categoryType',
          optionLabel: 'categoryName',
          optionsName: 'productTypeList'
        },
        {
          label: '业务单号',
          name: 'businessCode',
          type: 'input',
          maxlength: '20',
          isClear: true
        },
        {
          label: '系列',
          name: 'goodsSeries',
          type: 'input',
          maxlength: '20',
          isClear: true
        }
      ],
      // 表格
      getListApi: this.$apis.stockManage.getMerchantGoodsStockReduceRecord,
      tableParams: {
        listName: 'list',
        tableOption: false,
        tableColumns: [
          {
            label: '出库时间',
            prop: 'reduceDate',
            formatter: cellValue => {
              return dayjs(cellValue.reduceDate).format('YYYY-MM-DD HH:mm:ss')
            },
            width: 180
          },
          {
            label: '商品名称',
            prop: 'upgradeGoodsName',
            width: 180,
            line: 1
          },
          {
            label: '系列',
            prop: 'goodsSeries'
          },
          {
            label: '所属分类',
            prop: 'goodsTypeName',
            minWidth: 120
          },

          {
            label: '出库数量',
            prop: 'reduceStockNum',
            formatter: cellValue => {
              return cellValue.reduceStockNum || cellValue.reduceStockNum == 0 ? parseFloat(cellValue.reduceStockNum).toFixed(2) + (this.membraneTypeList.includes(cellValue.goodsType) ? '米' : '件') : '-'
            }
          },
          {
            label: '出库金额',
            prop: 'reduceStockMoney',
            formatter: cellValue => {
              return cellValue.reduceStockMoney ? '¥' + cellValue.reduceStockMoney.toFixed(2) : '-'
            }
          },
          {
            label: '出库类型',
            prop: 'eventType',
            width: 100,
            formatter: cellValue => {
              return this.baseData.eventTypeList.find(item => item.confId === cellValue.eventType?.toString())?.confLabel
            }
          },
          {
            label: '关联业务单号',
            prop: 'businessCode'
          },
          {
            label: '出库门店',
            prop: 'yqMerchantName',
            width: 200
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'currentPage', totalCount: 'total' },
      // 基本数据
      baseData: {
        eventTypeList: [
          {
            confId: '1',
            confLabel: '订单出库'
          },
          {
            confId: '2',
            confLabel: '盘点出库'
          },
          {
            confId: '3',
            confLabel: '调拨出库'
          }
        ],
        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: {
    getParams() {
      var params = JSON.parse(JSON.stringify(this.searchForm))
      if (this.searchForm.reduceDate) {
        params.reduceStartDateStr = dayjs(this.searchForm.reduceDate[0]).format('YYYY-MM-DD HH:mm:ss')
        params.reduceEndDateStr = dayjs(this.searchForm.reduceDate[0]).format('YYYY-MM-DD') + ' 23:59:59'
      }
      delete params.reduceDate
      return params
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        this.tableSearchForm = this.getParams()
        resolve()
      })
    },
    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.outboundRef.data.length ? (this.$refs.outboundRef.tableHeightValues = '') : this.$refs.outboundRef.setTableHeightFun()
    },
    exportExcel() {
      var params = this.getParams()
      this.$apis.stockManage.exportReduceExcel(params).then(res => {
        window.location.href = res
      })
    },
    handleSearch() {
      this.$refs.outboundRef.refreshTable()
    },

    handleReset() {
      this.searchForm = {
        reduceDate: '',
        eventType: '',
        upgradeGoodsName: '',
        yqMerchantId: '',
        goodsType: '',
        businessCode: '',
        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>