<template>
  <a-modal
    centered
    class="checkingTypeEdit-modal"
    :footer="null"
    :maskClosable="false"
    title="选择盘点类型"
    v-model="isShow"
    @cancle="isShow=false"
    :width="800">
    <!-- 表单 -->
    <div>
      <a-form-model
        id="checkingTypeEdit-form"
        ref="ruleForm"
        :model="form"
        :rules="rules"
        :label-col="formItemLayout.labelCol"
        :wrapper-col="formItemLayout.wrapperCol"
      >
        <a-form-model-item label="" prop="type">
          <a-radio-group v-model="form.type" size="large" class="radio-group">
            <a-radio-button value="a" class="radio-button">
              全盘<a-icon class="radio-button-icon" type="check" v-show="form.type=='a'" />
            </a-radio-button>
            <a-radio-button value="b" class="radio-button">
              自选盘点<a-icon class="radio-button-icon" type="check" v-show="form.type=='b'" />
            </a-radio-button>
          </a-radio-group>
        </a-form-model-item>
      </a-form-model>
      <div class="btn-cont">
        <a-button type="primary" id="checkingType-edit-modal-save" @click="handleSubmit">确定</a-button>
        <a-button id="checkingType-edit-modal-back" @click="isShow = false" style="margin-left: 15px;">取消</a-button>
      </div>
    </div>
  </a-modal>
</template>

<script>
// import { checkingTypeSave } from '@/api/checkingType'
export default {
  name: 'checkingTypeEditModal',
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    },
    itemId: {
      type: [Number, String],
      default: ''
    },
    nowData: {
      type: Object,
      default: null
    }
  },
  data () {
    return {
      isShow: this.openModal, //  是否打开弹框
      formItemLayout: {
        labelCol: { span: 0 },
        wrapperCol: { span: 24 }
      },
      form: {
        type: '', // 盘点类型
      },
      rules: {
        type: [
          { required: true, message: '请先选择盘点类型', trigger: 'change' }
        ],
      }
    }
  },
  methods: {
    //  确定
    handleSubmit(){
      const _this = this
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          _this.$emit('ok', _this.form.type)
          _this.isShow = false
          // const params = {
          //   id: this.itemId ? this.itemId : undefined,
          //   name: this.form.name,  //  仓库名称
          //   sort: this.form.sort,  //  排序
          //   isDefault: 0  //  是否为默认仓库   0为非默认，1为默认
          // }
          // checkingTipsSave(params).then(res => {
          //   if(res.status == 200){
          //     _this.$message.success(res.message)
          //     _this.$emit('ok')
          //     setTimeout(function () {
          //       _this.isShow = false
          //       _this.$refs.ruleForm.resetFields()
          //     }, 300)
          //   }else{
              
          //   }
          // })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('close')
      }else{
        this.form = {
          name: '',
          sort: ''
        }
      }
    }
  }
}
</script>

<style lang="less">
  .checkingTypeEdit-modal{
    .ant-modal-body {
    	padding: 40px 40px 24px;
    }
    .radio-group{
      display: block;
      margin: 30px auto;
      width: 80%;
      .radio-button{
        width: 50%;
        height: 100px;
        line-height: 100px;
        text-align: center;
        position: relative;
        &-icon{
          position: absolute;
          right: 30px;
          top: 42px;
        }
      }
    }
    .btn-cont {
    	text-align: center;
    	margin: 35px 0 10px;
    }
  }
</style>
