index.vue 10.9 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>
          <GLButton type="primary" plain size="small" @click="handleAdd" fn="创建调拨">创建调拨</GLButton>
          <!-- <el-button type="primary" size="small" @click="handleAdd">创建调拨</el-button> -->
          <el-button  size="small" @click="exportExcel">导出</el-button>
        </div>
      </div>

      <!-- 表格区域 开始 -->
      <GLTable ref="allocationRef" :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="handleDetail(scope.scope)">查看</el-button>
        </div>
      </GLTable>
      <!-- 表格区域 end -->
    </div>
    <!-- 查看 -->
    <allocation-detail-dialog :allocation-detail-visible="allocationDetailVisible" :allocationInfo="allocationInfo" v-if="allocationDetailVisible" @dialogClose="dialogClose" />
  </div>
</template>

<script>
import * as dayjs from 'dayjs'
import url from '@/assets/empty.png'
import allocationDetailDialog from './allocationDetailDialog'
export default {
  name: 'warehousing',
  components: {
    allocationDetailDialog
  },
  data() {
    return {
      size: 'small',
      url: url,
      searchForm: {
        allocateTime: '',
        allocateCode: '',
        callOutYqMerchantId: '',
        callInYqMerchantId: '',
        callOutMerchantId: '',
        callInMerchantId: ''
      },
      tableSearchForm: {},
      allocationInfo: {},
      allocationDetailVisible: false,
      showFormData: [
        {
          label: '调拨单号',
          name: 'allocateCode',
          type: 'input',
          maxlength: '20',
          isClear: true
        },
        {
          label: '调拨时间',
          name: 'allocateTime',
          type: 'datePicker',
          isClear: true,
          pickerOptions: 'beforeRangePickerOptions'
        },
        {
          label: '调出仓库',
          name: 'callOutYqMerchantId',
          type: 'select',
          optionList: [],
          optionId: 'merchantNo',
          optionLabel: 'merchantName',
          optionsName: 'yqRelatedMerchantList',
          changeAttr: (value, targetItem) => {
            value ? this.getServicemerchantrefList(value, 'out') : (this.baseData.outMerchantList = [])
            this.searchForm.callOutMerchantId = ''
            this.getOptionsList('showFormData')
          }
        },
        {
          label: '调出门店',
          name: 'callOutMerchantId',
          type: 'select',
          noDataText: '请先选择调出仓库',
          optionList: [],
          optionId: 'merchantId',
          optionLabel: 'merchantName',
          optionsName: 'outMerchantList'
        },
        {
          label: '调入仓库',
          name: 'callInYqMerchantId',
          type: 'select',
          optionList: [],
          optionId: 'merchantNo',
          optionLabel: 'merchantName',
          optionsName: 'yqRelatedMerchantList',
          changeAttr: (value, targetItem) => {
            value ? this.getServicemerchantrefList(value, 'in') : (this.baseData.inMerchantList = [])
            this.searchForm.callInMerchantId = ''
            this.getOptionsList('showFormData')
          }
        },
        {
          label: '调入门店',
          name: 'callInMerchantId',
          type: 'select',
          noDataText: '请先选择调入仓库',
          optionList: [],
          optionId: 'merchantId',
          optionLabel: 'merchantName',
          optionsName: 'inMerchantList'
        }
      ],
      // 表格
      getListApi: this.$apis.stockManage.stockAllocatePage,
      tableParams: {
        listName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: '调拨单号',
            prop: 'allocateCode',
            width: 200
          },
          {
            label: '调拨时间',
            prop: 'allocateTime',
            width: 170,
            formatter: cellValue => {
              return dayjs(cellValue.allocateTime).format('YYYY-MM-DD HH:mm:ss')
            }
          },
          {
            label: '调拨人',
            prop: 'operator',
            width: 100
          },
          {
            label: '调出仓库',
            prop: 'callOutYqMerchantName',
            width: 150
          },
          {
            label: '调出门店',
            prop: 'callOutMerchantName',
            width: 150
          },
          {
            label: '调入仓库',
            prop: 'callInYqMerchantName',
            width: 150
          },
          {
            label: '调入门店',
            prop: 'callInMerchantName',
            width: 150
          },
          {
            label: '承运单号',
            prop: 'deliveryNumber',
            width: 150
          },
          {
            label: '承运公司',
            prop: 'deliveryCompany',
            width: 150
          },
          {
            label: '备注',
            prop: 'remark',
            width: 200,
            line: 1
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'currentPage', totalCount: 'total' },
      // 基本数据
      baseData: {
        yqRelatedMerchantList: [],
        outMerchantList: [], //调出门店
        inMerchantList: [] //调入门店
      },
      imgVisible: false,
      previewImgUrl: ''
    }
  },

  mounted() {
    //调入门店
    // this.$apis.stockManage.yqRelatedList({}).then(res => {
    //   this.baseData.yqRelatedMerchantList = res
    //   this.getOptionsList('showFormData')
    // })
    this.$apis.stockManage.getyqMerchantList({ mainPartnerMerchant: true }).then(res => {
      this.baseData.yqRelatedMerchantList = res
      this.getOptionsList('showFormData')
    })
  },

  methods: {
    getParams() {
      var params = JSON.parse(JSON.stringify(this.searchForm))
      if (this.searchForm.allocateTime) {
        params.allocateTimeStart = new Date(this.searchForm.allocateTime[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
        params.allocateTimeEnd = new Date(this.searchForm.allocateTime[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59'
      }
      delete params.allocateTime
      return params
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        this.tableSearchForm = this.getParams()
        resolve()
      })
    },

    // 获取仓库门店
    getServicemerchantrefList(merchantId, type) {
      this.$apis.stockManage
        .getServicemerchantrefList({
          yqMerchantId: merchantId
        })
        .then(res => {
          let _headOffice = {}
          if (type == 'out') {
            //调出门店
            this.baseData.outMerchantList = res || []
            //总店
            _headOffice = this.baseData.yqRelatedMerchantList.find(item => item.merchantNo === merchantId)
            _headOffice.merchantId = _headOffice.merchantNo
            //门店选项中加入总店
            this.baseData.outMerchantList.push(_headOffice)
          } else if (type == 'in') {
            //调入门店
            this.baseData.inMerchantList = res || []
            //总店
            _headOffice = this.baseData.yqRelatedMerchantList.find(item => item.merchantNo === merchantId)
            _headOffice.merchantId = _headOffice.merchantNo
            //门店选项中加入总店
            this.baseData.inMerchantList.push(_headOffice)
          }
          this.getOptionsList('showFormData')
        })
    },

    // 查看详情
    handleDetail(row) {
      this.allocationInfo = row
      this.allocationDetailVisible = true
      console.log(this.allocationDetailVisible)
    },
    handleAdd() {
      this.$router.push({ path: '/allocation/add' })
    },
    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.allocationRef.data.length ? (this.$refs.allocationRef.tableHeightValues = '') : this.$refs.allocationRef.setTableHeightFun()
    },
    exportExcel() {
      var params = this.getParams()
      this.$apis.stockManage.exportaAllocateExcel(params).then(res => {
        window.location.href = res
      })
    },
    handleSearch() {
      this.$refs.allocationRef.refreshTable()
    },

    handleReset() {
      this.searchForm = {
        allocateTime: '',
        allocateCode: '',
        callOutYqMerchantId: '',
        callInYqMerchantId: '',
        callOutMerchantId: '',
        callInMerchantId: ''
      }
      this.showFormData[this.findFormIdx('callOutMerchantId')].optionList = []
      this.showFormData[this.findFormIdx('callInMerchantId')].optionList = []
      this.handleSearch()
    },

    findFormIdx(name) {
      return this.showFormData.findIndex(item => item.name === name)
    },

    handleEnlargeImg(url) {
      if (url) {
        this.previewImgUrl = url
        this.imgVisible = !this.imgVisible
      }
    },
    handleCloseImg() {
      this.imgVisible = !this.imgVisible
    },
    dialogClose() {
      this.allocationDetailVisible = !this.allocationDetailVisible
    }
  }
}
</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>