<template>
  <a-modal
    centered
    class="shelfSet-basicInfo-modal"
    :footer="null"
    :maskClosable="false"
    title="新增调回单"
    v-model="isShow"
    @cancel="isShow = false"
    :width="600">
    <a-spin :spinning="spinning" tip="Loading...">
      <a-form-model
        id="shelfSet-basicInfo-form"
        ref="ruleForm"
        :model="form"
        :rules="rules"
        :label-col="formItemLayout.labelCol"
        :wrapper-col="formItemLayout.wrapperCol">
        <a-form-model-item label="货架名称" prop="shelfSn">
          <shelfSList v-model="form.shelfSn" @change="shelfChange"></shelfSList>
        </a-form-model-item>
      </a-form-model>
      <div class="btn-cont">
        <a-button size="large" type="primary" id="importGuide-nextStep" @click="handlerNextStep">下一步</a-button>
        <a-button size="large" id="shelfSet-basicInfo-modal-back" @click="isShow = false" style="margin-left: 15px;">取消</a-button>
      </div>
    </a-spin>
    <!-- 新增回调单（实现新增） -->
    <add-recall-bill-modal :recallBillInfo="detailObj" :openModal="showRecallBill" @ok="handleInfoOk" @close="showRecallBill=false"></add-recall-bill-modal>
  </a-modal>
</template>

<script>
import { commonMixin } from '@/utils/mixin'
import { VSelect } from '@/components'
import custList from '@/views/common/custList.vue'
import shelfSList from '@/views/common/shelfList'
import addRecallBillModal from './addRecallBillModal.vue'
export default {
  name: 'ShelfSetBasicInfoModal',
  components: { VSelect, custList, shelfSList, addRecallBillModal },
  mixins: [commonMixin],
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    },
    nowData: {
      type: Object,
      default: () => {
        return {}
      }
    },
    type: {
      type: [String, Number],
      default: '1'
    }
  },
  data () {
    return {
      spinning: false,
      isShow: this.openModal, //  是否打开弹框
      formItemLayout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 17 }
      },
      form: {
        shelfSn: undefined
      },
      rules: {
        shelfSn: [{ required: true, message: '请选择需要调回产品货架', trigger: 'change' }]
      },
      showRecallBill: false, // 显示选择货架弹窗
      detailObj: {
        shelfName: '',
        shelfSn: ''
      }
    }
  },
  methods: {
    shelfChange (v, row) {
      this.detailObj.shelfName = row ? row.shelfName : ''
    },
    // 下一步 保存货架信息
    handlerNextStep () {
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          this.detailObj.shelfSn = this.form.shelfSn
          this.showRecallBill = true
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    // 新增调货单成功
    handleInfoOk () {
      this.$emit('ok')
      this.isShow = false
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('close')
        this.$refs.ruleForm.resetFields()
      }
    }
  }
}
</script>

<style lang="less">
.shelfSet-basicInfo-modal {
	.ant-modal-body {
		padding: 40px 40px 24px;
	}
  .ant-form-item{
    margin-bottom: 15px;
  }
	.btn-cont {
		text-align: center;
		margin: 35px 0 10px;
	}
}
</style>
