index.vue 10.7 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">
        <div>
          合计:当前库存
          <span class="txt-blue">{{ totalInventory || '0' }}</span>
        </div>
        <div>
          <GLButton type="primary"
                    plain
                    size="small"
                    @click="handleStatementOfAccount"
                    fn="库存对账单">库存对账单</GLButton>
          <el-button size="small"
                     @click="exportExcel">导出</el-button>
        </div>
      </div>

      <!-- 表格区域 开始 -->
      <GLTable ref="stockRef"
               :getListApi="getListApi"
               :noDataImg="url"
               :searchForm="tableSearchForm"
               :tableParams="tableParams"
               :pageConf="pageConf"
               :beforeSearchFn="beforeSearchFn"
               @setTableFinishFun="setTableFinishFun">
        <div class="table-btns"
             slot="auth-button"
             slot-scope="scope">
          <el-button type="text"
                     @click="handleInventoryDetails(scope.scope)">库存明细</el-button>
          <el-button type="text"
                     @click="handleDetail(scope.scope)">统计</el-button>
        </div>
      </GLTable>
      <!-- 表格区域 end -->
    </div>
    <!-- 查看 -->
    <stock-month-dialog :stock-month-visible="stockMonthVisible"
                        :stockInfo="stockInfo"
                        v-if="stockMonthVisible"
                        @dialogClose="dialogClose" />
    <stockDetailDialog :visible.sync="stockDetailDialogVisible"
                       :recordInfo="stockInfo"
                       v-if="stockDetailDialogVisible" />
    <!-- 库存对账单 -->
    <statementOfAccountDialog :visible.sync="statementOfAccountDialogVisible"
                              v-if="statementOfAccountDialogVisible"
                              :yqMerchantList="baseData.yqMerchantList"
                              @handleRelateProConfirm="handleRelateProConfirm">
    </statementOfAccountDialog>
  </div>
</template>

<script>
import * as dayjs from 'dayjs'
import url from '@/assets/empty.png'
// import { membraneTypeList } from '@/utils/constants.js'
import stockMonthDialog from './stockMonthDialog'
import stockDetailDialog from './stockDetailDialog'
import statementOfAccountDialog from './statementOfAccountDialog'
export default {
  name: 'warehousing',
  components: {
    stockMonthDialog,
    stockDetailDialog,
    statementOfAccountDialog
  },
  data() {
    return {
      // membraneTypeList: membraneTypeList,
      size: 'small',
      totalInventory: '',
      url: url,
      searchForm: {
        upgradeGoodsName: '',
        yqMerchantId: '',
        goodsType: '',
        goodsSeries: '',
        productCode: ''
      },
      tableSearchForm: {},
      stockInfo: {},
      stockMonthVisible: false,
      stockDetailDialogVisible: false,
      statementOfAccountDialogVisible: 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: 'yqMerchantId',
          type: 'select',
          optionList: [],
          optionId: 'merchantNo',
          optionLabel: 'merchantName',
          optionsName: 'yqMerchantList'
        },
        {
          label: '所属分类',
          name: 'goodsType',
          type: 'select',
          optionList: [],
          optionId: 'categoryType',
          optionLabel: 'categoryName',
          optionsName: 'productTypeList'
        }
      ],
      // 表格
      getListApi: this.$apis.stockManage.getMerchantGoodsStockMonthReport,
      tableParams: {
        listName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: '商品名称',
            prop: 'upgradeGoodsName',
            width: 180,
            line: 1
          },
          {
            label: '规格',
            prop: 'specificationData',
            width: 180,
            line: 1
          },
          {
            label: '商品编码',
            prop: 'productCode',
            width: 180,
            line: 1
          },
          {
            label: '系列',
            prop: 'goodsSeries',
            width: 150,
            line: 1
          },
          {
            label: '所属分类',
            prop: 'goodsTypeName',
            minWidth: 120
          },

          {
            label: '上月结存库存',
            prop: 'lastMonthRemainStock',
            width: 120,
            formatter: cellValue => {
              return cellValue.lastMonthRemainStock || cellValue.lastMonthRemainStock == 0 ? parseFloat(cellValue.lastMonthRemainStock).toFixed(2) + (this.$membraneTypeList.includes(cellValue.goodsType) ? '米' : '件') : '-'
            }
          },
          {
            label: '上月结存金额',
            width: 120,
            prop: 'lastMonthRemainMoney',
            formatter: cellValue => {
              return cellValue.lastMonthRemainMoney || cellValue.lastMonthRemainMoney == 0 ? '¥' + cellValue.lastMonthRemainMoney.toFixed(2) : '-'
            }
          },
          {
            label: '当前库存',
            prop: 'stock',
            width: 100,
            formatter: cellValue => {
              return cellValue.stock || cellValue.stock == 0 ? parseFloat(cellValue.stock).toFixed(2) + (this.$membraneTypeList.includes(cellValue.goodsType) == 1 ? '米' : '件') : '-'
            }
          },
          {
            label: '所属仓库',
            prop: 'yqMerchantName',
            width: 200
          },
          {
            label: '所属商户',
            prop: 'partnerMerchantName',
            width: 200
          }
        ]
      },
      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({ mainPartnerMerchant: true }).then(res => {
      this.baseData.yqMerchantList = res || []
      this.getOptionsList('showFormData')
    })
    this.getMerchantGoodsStockMonthCount()
  },

  methods: {
    getMerchantGoodsStockMonthCount() {
      var params = this.$common.utils.deepClone(this.searchForm)
      params.dataMonth = dayjs(new Date()).format('YYYY-MM')
      this.$apis.stockManage.getMerchantGoodsStockMonthCount(params).then(res => {
        console.log(res, '???....')
        this.totalInventory = res
      })
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        this.tableSearchForm = this.$common.utils.deepClone(this.searchForm)
        this.tableSearchForm.dataMonth = dayjs(new Date()).format('YYYY-MM')
        resolve()
      })
    },
    handleInventoryDetails(row) {
      this.stockInfo = row
      console.log(this.stockInfo)
      this.stockDetailDialogVisible = true
    },
    // 库存对账单
    handleStatementOfAccount() {
      this.statementOfAccountDialogVisible = true
    },
    handleRelateProConfirm(data) {
      this.exportLoading = true
      var params = data
      this.$apis.stockManage.exportStatementOfAccount(params).then(res => {
        this.statementOfAccountDialogVisible = false
        window.location.href = res
      })
    },
    // 查看详情
    handleDetail(row) {
      this.stockInfo = row
      this.stockMonthVisible = true
    },
    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.stockRef.data.length ? (this.$refs.stockRef.tableHeightValues = '') : this.$refs.stockRef.setTableHeightFun()
    },
    exportExcel() {
      this.exportLoading = true
      var params = this.tableSearchForm
      this.$apis.stockManage.exportMerchantExcel(params).then(res => {
        window.location.href = res
      })
    },
    handleSearch() {
      this.$refs.stockRef.refreshTable()
      this.getMerchantGoodsStockMonthCount()
    },

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

  .txt-blue {
    color: #5850ff;
  }
}
</style>