<template>
  <a-modal
    centered
    :footer="null"
    :maskClosable="false"
    class="export-excel-modal"
    title="选择导出方式"
    v-model="isShow"
    @cancel="isShow=false"
    :width="600">
    <a-spin :spinning="spinning" tip="Loading...">
      <a-form-model
        id="export-excel-form"
        ref="ruleForm"
        :model="form"
        :rules="rules"
        :label-col="formItemLayout.labelCol"
        :wrapper-col="formItemLayout.wrapperCol"
      >
        <a-form-model-item label="导出库存" prop="exportType">
          <a-radio-group v-model="form.exportType" id="export-excel-radio">
            <a-radio value="all" id="export-excel-radio-all">所有</a-radio>
            <a-radio value="type" id="export-excel-radio-type">分类汇总导出</a-radio>
          </a-radio-group>
        </a-form-model-item>
      </a-form-model>
      <div class="btn-cont">
        <a-button type="primary" id="export-excel-save" @click="handleSave()">导出</a-button>
        <a-button id="export-excel-back" @click="handleCancel" style="margin-left: 15px;">取消</a-button>
      </div>
    </a-spin>
  </a-modal>
</template>

<script>
export default {
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    },
    itemData: {
      type: Object,
      default: () => {
        return null
      }
    }
  },
  data () {
    return {
      isShow: this.openModal, //  是否打开弹框
      form: {
        exportType: 'all' // 导出方式
      },
      rules: {
        exportType: [{ required: true, message: '请选择导出方式', trigger: 'change' }]
      },
      formItemLayout: {
        labelCol: { span: 6 },
        wrapperCol: { span: 18 }
      },
      spinning: false
    }
  },
  methods: {
    // 确认
    handleSave (isPrint) {
      const _this = this
      this.$store.state.app.curActionPermission = 'B_inventoryQuery_export'
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          _this.$emit('ok', _this.form.exportType)
          _this.isShow = false
        } else {
          return false
        }
      })
    },
    // 取消选择分类
    handleCancel () {
      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">
  .export-excel-modal{
    .btn-cont {
      text-align: center;
      margin: 35px 0 10px;
    }
  }
</style>
