index.vue 9.75 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="warehousingRef" :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: {
        increaseTime: '',
        increaseStockType: '',
        upgradeGoodsName: '',
        yqMerchantId: '',
        goodsType: '',
        businessCode: '',
        goodsSeries: ''
      },
      tableSearchForm: {},
      paramsObj: {},
      // 查看门店
      detailVisible: false,
      showFormData: [
        {
          label: '入库时间',
          name: 'increaseTime',
          type: 'datePicker',
          isClear: true,
          pickerOptions: 'beforeRangePickerOptions'
        },
        {
          label: '入库类型',
          name: 'increaseStockType',
          type: 'select',
          optionList: [],
          optionId: 'confId',
          optionLabel: 'confLabel',
          optionsName: 'storageTypeList'
        },
        {
          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.getGoodsWarehousingList,
      tableParams: {
        listName: 'list',
        tableOption: false,
        tableColumns: [
          {
            label: '入库时间',
            prop: 'increaseTime',
            formatter: cellValue => {
              return dayjs(cellValue.increaseTime).format('YYYY-MM-DD HH:mm:ss')
            },
            width: 180
          },
          {
            label: '商品名称',
            prop: 'upgradeGoodsName',
            width: 160
          },
          {
            label: '系列',
            prop: 'goodsSeries'
          },
          {
            label: '所属分类',
            prop: 'goodsTypeName',
            minWidth: 120
          },

          {
            label: '入库数量',
            prop: 'increaseStockNum',
            formatter: cellValue => {
              return cellValue.increaseStockNum || cellValue.increaseStockNum == 0 ? parseFloat(cellValue.increaseStockNum).toFixed(2) + (this.membraneTypeList.includes(cellValue.goodsType) ? '米' : '件') : '-'
            },
            width: 120
          },
          {
            label: '入库金额',
            prop: 'increaseStockMoney',
            formatter: cellValue => {
              return cellValue.increaseStockMoney || cellValue.increaseStockMoney == 0 ? '¥' + cellValue.increaseStockMoney.toFixed(2) : '-'
            },
            width: 120
          },
          {
            label: '入库类型',
            prop: 'increaseStockType',
            width: '100px',
            formatter: cellValue => {
              return this.baseData.storageTypeList.find(item => item.confId === cellValue.increaseStockType?.toString())?.confLabel
            }
          },
          {
            label: '关联业务单号',
            prop: 'businessCode',
            minWidth: 150
          },
          {
            label: '入库门店',
            prop: 'yqMerchantName',
            width: 200
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'currentPage', totalCount: 'total' },
      // 基本数据
      baseData: {
        storageTypeList: [
          {
            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.increaseTime) {
        params.startDate = new Date(this.searchForm.increaseTime[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
        params.endDate = new Date(this.searchForm.increaseTime[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59'
      }
      delete params.increaseTime
      return params
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        this.tableSearchForm = this.getParams()
        resolve()
      })
    },

    secondConfirm(title, txt, apiModule, apiName, apiParams, fn) {
      this.$confirm(txt, title, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        callback: action => {
          if (action == 'confirm') {
            this.$apis[apiModule][apiName](apiParams).then(res => {
              this.$message({
                message: res.code == '0' ? '操作成功' : res.message,
                type: res.code == '0' ? 'success' : 'error'
              })
              if (res.code == '0') {
                fn && fn()
                this.handleSearch()
              }
            })
          }
        }
      })
    },
    // 查看详情
    handleDetail(row) {
      this.paramsObj = {
        orderCode: row.orderCode,
        merchantName: row.merchantName
      }
      this.detailVisible = 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.warehousingRef.data.length ? (this.$refs.warehousingRef.tableHeightValues = '') : this.$refs.warehousingRef.setTableHeightFun()
    },
    // 创建采购
    handleCreatePurchase() {
      this.$router.push('/purchaseOrder/add')
    },
    exportExcel() {
      this.exportLoading = true
      var params = this.getParams()
      this.$apis.stockManage.exportExcel(params).then(res => {

        // window.location.href = res
      })
      
    },
    handleSearch() {
      this.$refs.warehousingRef.refreshTable()
    },

    handleReset() {
      this.searchForm = {
        increaseTime: '',
        increaseStockType: '',
        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>