<template>
  <a-modal
    centered
    class="purchaseOrder-basicInfo-modal"
    :footer="null"
    :maskClosable="false"
    title="新增采购单"
    v-model="isShow"
    @cancle="isShow=false"
    width="80%">
    <a-form-model
      id="purchaseOrder-basicInfo-form"
      ref="ruleForm"
      :model="form"
      :rules="rules"
      :label-col="formItemLayout.labelCol"
      :wrapper-col="formItemLayout.wrapperCol" >
      <a-form-model-item label="供应商" prop="state">
        <a-radio-group
          name="radioGroup"
          v-model="form.state"
          id="purchaseOrder-basicInfo-state" >
          <a-radio :value="1">箭冠营销中心</a-radio>
          <a-radio :value="0">支持省级</a-radio>
        </a-radio-group>
      </a-form-model-item>
      <a-form-model-item label="支付方式" prop="sort">
        <v-select
          v-model="form.billStatus"
          ref="billStatus"
          id="purchaseOrder-basicInfo-billStatus"
          code="PAYMENT_TYPE"
          placeholder="请选择支付方式"
          allowClear></v-select>
      </a-form-model-item>
      <a-form-model-item label="收货地址" prop="name">
        {{ chooseAddr }}
        <a-button type="link" id="purchaseOrder-basicInfo-chooseAddr" @click="handleChoose">{{ addressVal }} >></a-button>
      </a-form-model-item>
    </a-form-model>
    <div class="btn-cont">
      <a-button type="primary" id="purchaseOrder-basicInfo-modal-save" @click="handleSave">保存</a-button>
      <a-button id="purchaseOrder-basicInfo-modal-back" @click="isShow = false" style="margin-left: 15px;">取消</a-button>
    </div>
    <!-- 选择地址 -->
    <choose-address-modal :openModal="openAddrModal" @ok="handleOk" @close="openAddrModal=false" />
  </a-modal>
</template>

<script>
import { VSelect } from '@/components'
import chooseAddressModal from './receivingAddress/chooseAddressModal.vue'
export default {
  name: 'BasicInfoModal',
  components: { VSelect, chooseAddressModal },
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      isShow: this.openModal, //  是否打开弹框
      formItemLayout: {
        labelCol: { span: 6 },
        wrapperCol: { span: 16 }
      },
      form: {
        name: '', // 仓库名称
        sort: '' //  排序
      },
      rules: {
        name: [
          { required: true, message: '请输入仓库名称', trigger: 'blur' }
        ]
      },
      addressVal: '选择地址', //  选择地址/更换地址
      chooseAddr: '', //  当前已选地址信息
      openAddrModal: false // 选择地址弹框是否显示
    }
  },
  methods: {
    //  保存
    handleSave () {
      this.isShow = false
      this.$emit('ok')
    },
    //  选择地址
    handleChoose () {
      this.openAddrModal = true
    },
    //  地址保存
    handleOk (data) {
      this.chooseAddr = '张三（18800001111） 河南省 郑州市 中原区 大学科技园'
      this.addressVal = '更换地址'
      this.openAddrModal = false
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('close')
      }
    }
  }
}
</script>

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