statementOfAccountDialog.vue 4.48 KB
<!-- 库存对账单弹窗 -->
<template>
  <d2-dialog title="库存对账单" :is-visible="dialogVisible" mode="mid" class="statementOfAccountDialog" width="720px" @closeDialog="handleClose" @confirmDialog="handleConfirm">
    <el-form ref="statementOfAccountForm" :model="dataForm" :rules="formRules" label-width="154px" size="small">
      <el-form-item label="时间:" prop="dataMonthStr">
        <el-date-picker
          v-model="dataForm.dataMonthStr"
          type="month"
          :clearable="false"
          value-format="yyyy-MM"
          :append-to-body="false"
          format="yyyy-MM"
          class="form-node"
          placeholder="选择时间"
          popper-class="statement-of-account-month-picker"
          :picker-options="beforeRangePickerOptions">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="仓库:" prop="yqMerchantId">
        <el-select v-model="dataForm.yqMerchantId" class="form-node" filterable @change="yqMerchantIdChange" placeholder="请选择仓库">
          <el-option v-for="(subItem, subIndex) in stockList" :key="subIndex" :value="subItem.merchantNo" :label="subItem.merchantName"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="门店:" prop="merchantId">
        <el-select v-model="dataForm.merchantId" class="form-node" filterable @focus="merchantSelectFocus" placeholder="请选择门店">
          <el-option v-for="(subItem, subIndex) in merchantList" :key="subIndex" :value="subItem.merchantId" :label="subItem.merchantName"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </d2-dialog>
</template>

<script>
import { deepClone } from '@/common/util'
import { getServicemerchantrefList } from '@api/stockManage'
export default {
  name: 'StatementOfAccountDialog',

  props: {
    visible: {
      type: Boolean,
      default: false
    },
    yqMerchantList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      beforeRangePickerOptions: {
        disabledDate(date) {
          if (date > new Date()) {
            return true
          }
          return false
        }
      },
      dataForm: {
        dataMonthStr: '',
        yqMerchantId: '',
        merchantId: ''
      },
      formRules: {
        dataMonthStr: [{ required: true, message: '请选择时间', trigger: 'change' }],
        yqMerchantId: [{ required: true, message: '请选择仓库', trigger: 'change' }],
        merchantId: [
          { required: true, message: '请选择门店', trigger: 'change' }
        ]
      },
      merchantList: []
    }
  },

  computed: {
    dialogVisible: {
      get() {
        return this.visible
      },
      set(val) {
        this.$emit('update:visible', val)
      }
    },
    stockList: {
      get() {
        const list = deepClone(this.yqMerchantList)
        if (list[0]?.merchantName == '全部') {
          list.shift()
        }
        return list
      }
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.$refs.statementOfAccountForm && this.$refs.statementOfAccountForm.resetFields()
    })
  },

  methods: {
    // 门店
    merchantSelectFocus() {
      if (!this.dataForm?.yqMerchantId) return this.$message.error('请先选择仓库')
    },
    // 仓库
    yqMerchantIdChange(e) {
      this.dataForm.merchantId = ''
      this.merchantList = []
      this.$nextTick(() => {
        this.$refs.statementOfAccountForm.clearValidate()
      })
      // 总店
      const _headOffice = this.stockList.find(item => item.merchantNo === e)
      _headOffice.merchantId = _headOffice.merchantNo
      // 获取仓库下的门店列表
      getServicemerchantrefList({
        yqMerchantId: e
      }).then(res => {
        this.merchantList = res || []
        this.merchantList.push(_headOffice) // 园区店可选择自己
      })
    },
    handleClose() {
      this.dialogVisible = false
    },
    handleConfirm() {
      this.$refs.statementOfAccountForm.validate(valid => {
        if (valid) {
          this.$emit('handleRelateProConfirm', this.dataForm)
        }
      })
    }
  }
}
</script>
<style scoped lang="scss">

.statementOfAccountDialog{
  .form-node{
    width: 432px;
  }
}
</style>
<style lang="scss">
.statement-of-account-month-picker {
  .el-picker-panel__body-wrapper .el-picker-panel__body .el-picker-panel__content .el-month-table td.current:not(.disabled) .cell {
    color: #fff;
    background: #2A58AD;
    border-radius: 18px;
  }
  .el-month-table td.today .cell{
    color: #2A58AD;
  }
}
</style>