allocationList.vue 10.3 KB
<!-- 调拨管理 -->
<template>
  <div>
    <d2-container>
      <div class="header"
           slot="header"
           style="padding: 10px 20px;">
        <d2-search ref="showSearch"
                   class="show-search"
                   :search-form="searchForm"
                   :form-data="showFormData" />
        <div class="up-btns">
          <el-button :id="tableParams.btnId"
                     size="small"
                     type="primary">
            查询
          </el-button>
          <el-button size="small"
                     @click="handleReset">
            重置
          </el-button>
        </div>
      </div>
      <div class="d2-container-content">
        <d2-table-header>
          <!-- <span slot="left"
                v-if="!userInfo.beSuper && userInfo.beYQMerchant">
            <auth-button category="Button"
                         :show-btn-ids="['9080501']" />
          </span> -->
          <auth-button category="Button"
                       :show-btn-ids="['9080502']" />
        </d2-table-header>
        <d2-table ref="recordTable"
                  :get-list-api="getListApi"
                  :search-form="searchFormSearch"
                  :table-params="tableParams"
                  :before-search-fn="beforeSearchFn">
          <auth-button slot="auth-button"
                       slot-scope="scope"
                       :data="scope.scope" />
        </d2-table>
      </div>
    </d2-container>
    <!-- 查看 -->
    <allocation-detail-dialog :allocation-detail-visible="allocationDetailVisible"
                              :record-info="recordInfo"
                              v-if="allocationDetailVisible"
                              @dialogClose="dialogClose" />
  </div>
</template>

<script>
import { Util, deepClone } from '@/common/util'
import { mapActions, mapState } from 'vuex'
import { getProductTypeBySceneId } from '@api/product'
import { getyqMerchantList, stockAllocatePage, yqRelatedList, getServicemerchantrefList } from '@api/stockManage'
import allocationDetailDialog from './allocationDetailDialog'
export default {
  name: 'AllocationList',
  components: {
    allocationDetailDialog
  },
  data() {
    return {
      userInfo: this.$store.state.d2admin.user.info,
      searchForm: {
        allocateTime: '',
        allocateCode: '',
        callOutYqMerchantId: '',
        callInYqMerchantId: '',
        callOutMerchantId: '',
        callInMerchantId: ''
      },
      searchFormSearch: {},
      searchSelectObj: {
        orderOrTrade: {
          attr: 'inputtedOrderCode',
          value: ''
        }
      },
      showFormData: [{
        label: '调拨单号',
        name: 'allocateCode',
        type: 'input',
        maxlength: '20',
        isClear: true
      }, {
        label: '调拨时间',
        name: 'allocateTime',
        type: 'datePicker',
        isClear: true,
        pickerOptions: 'rangePickerOptions'
      }, {
        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()
        }
      }, {
        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()
        }
      }, {
        label: '调入门店',
        name: 'callInMerchantId',
        type: 'select',
        noDataText: '请先选择调入仓库',
        optionList: [],
        optionId: 'merchantId',
        optionLabel: 'merchantName',
        optionsName: 'inMerchantList'
      }],
      getListApi: stockAllocatePage,
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: true,
        tableColumns: [{
          label: '调拨单号',
          prop: 'allocateCode',
          width: '200px'
        }, {
          label: '调拨时间',
          prop: 'allocateTime',
          width: '150px',
          formatter: (cellValue) => {
            return cellValue.allocateTime ? Util.dateFormate(cellValue.allocateTime, 'YYYY-MM-DD HH:mm:ss') : ''
          }
        }, {
          label: '调拨人',
          prop: 'operator',
          width: '150px'
        }, {
          label: '调出仓库',
          prop: 'callOutYqMerchantName'
        }, {
          label: '调出门店',
          prop: 'callOutMerchantName'
        }, {
          label: '调入仓库',
          prop: 'callInYqMerchantName'
        }, {
          label: '调入门店',
          prop: 'callInMerchantName'
        }, {
          label: '承运单号',
          prop: 'deliveryNumber'
        }, {
          label: '承运公司',
          prop: 'deliveryCompany'
        }, {
          label: '备注',
          prop: 'remark'
        }
        ]
      },
      baseData: {
        productTypeList: [],
        yqRelatedMerchantList: [],
        outMerchantList: [], // 调出门店
        inMerchantList: []// 调入门店
      },

      allocationDetailVisible: false,
      recordInfo: null
    }
  },
  computed: {
    ...mapState({
      dowloadList: (state) => state.d2admin.user.dowloadList
    })
  },
  mounted() {
    // this.getBaseData()
    // 获取全部类目
    getProductTypeBySceneId({ sceneType: '' }).then(res => {
      this.baseData.productTypeList = res
      this.getOptionsList()
    })

    // 获取当前登录账号可见的园区店列表
    getyqMerchantList({ mainPartnerMerchant: true }).then(res => {
      this.baseData.yqRelatedMerchantList = res
      this.getOptionsList()
    })

    // //调入门店
    // yqRelatedList({}).then(res => {
    //   this.baseData.yqRelatedMerchantList = res
    //   this.getOptionsList()
    // })
  },

  methods: {
    ...mapActions({
      get: 'd2admin/base/get',
      close: 'd2admin/page/close'
    }),
    ...mapActions('d2admin/user', ['actionSetDownloadList']),

    // async getBaseData() {
    //   this.getOptionsList()
    // },

    beforeSearchFn() {
      return new Promise(resolve => {
        this.searchFormSearch = deepClone(this.searchForm)
        if (this.searchFormSearch.allocateTime) {
          this.searchFormSearch.allocateTimeStart = Util.dateFormate(this.searchFormSearch.allocateTime[0], 'YYYY-MM-DD HH:mm:ss')
          this.searchFormSearch.allocateTimeEnd = Util.dateFormate(this.searchFormSearch.allocateTime[1], 'YYYY-MM-DD') + ' 23:59:59'
        }
        delete this.searchFormSearch.allocateTime
        resolve()
      })
    },

    getOptionsList() {
      this.showFormData.forEach((item, index) => {
        if (item.type === 'select') {
          if (this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this.showFormData[index].optionLabel] !== '全部') {
            const temp = {}
            temp[this.showFormData[index].optionId] = ''
            temp[this.showFormData[index].optionLabel] = '全部'
            this.baseData[item.optionsName].unshift(temp)
          }
          this.$set(this.showFormData[index], 'optionList', this.baseData[item.optionsName])
        }
      })
    },

    // 获取仓库门店
    getServicemerchantrefList(merchantId, type) {
      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()
      })
    },

    // handleSearch() {
    //   this.$refs.recordTable.refreshTable()
    // },
    handleReset() {
      this.searchForm = {
        allocateTime: '',
        allocateCode: '',
        callOutYqMerchantId: '',
        callInYqMerchantId: '',
        callOutMerchantId: '',
        callInMerchantId: ''
      }
      this.baseData.outMerchantList = []// 调出门店
      this.baseData.inMerchantList = []// 调入门店
      this.getOptionsList()
      this.$refs.recordTable.refreshTable()
    },

    handleExport() {
      var params = this.searchFormSearch
      params.method = 'dj.smartcarlife.api.stock.allocate.export.async'
      const list = [
        ...this.dowloadList,
        {
          name: '调拨列表',
          exportParam: JSON.stringify(params),
          status: 'waiting',
          timeid: new Date().getTime()
        }
      ]
      this.actionSetDownloadList({ list, type: 'dowloadList' })
    },

    // 查看
    look(row) {
      this.recordInfo = row
      this.allocationDetailVisible = true
    },

    gotoAdd() {
      this.$router.push({ name: 'addAllocation' })
    },

    dialogClose(flag) {
      this.allocationDetailVisible = !this.allocationDetailVisible
    }

  }
}

</script>
<style scoped>
.count-txt {
  font-weight: 700;
  color: #2a58ad;
  margin: 0 2px;
}
.leftSpan {
  display: inline-block;
  box-sizing: border-box;
  margin-right: 10px;
}
</style>