<template>
  <a-modal
    centered
    class="quotation-basicInfo-modal"
    :footer="null"
    :maskClosable="false"
    title="选择客户"
    v-model="isShow"
    @cancle="isShow=false"
    width="80%">
    <a-form-model
      id="quotation-basicInfo-form"
      ref="ruleForm"
      :model="form"
      :rules="rules"
      :label-col="formItemLayout.labelCol"
      :wrapper-col="formItemLayout.wrapperCol" >
      <a-form-model-item label="客户名称" prop="name" extra="(未搜索到客户时可直接录入,但客户信息不保存于客户资料)">
        <a-auto-complete id="quotation-basicInfo-bundleName" allowClear v-model="form.name" placeholder="请输入客户名称">
          <template slot="dataSource">
            <a-select-option v-for="item in optData" :key="item">{{ item }}</a-select-option>
          </template>
        </a-auto-complete>
      </a-form-model-item>
      <a-form-model-item label="价格类型" prop="priceType">
      	<v-select code="PRICE_TYPE" id="quotation-basicInfo-priceType" v-model="form.priceType" allowClear placeholder="请选择价格类型" ></v-select>
      </a-form-model-item>
      <a-form-model-item label="电话" prop="phone">
        <a-input id="quotation-basicInfo-bundleName" v-model="form.bundleName" allowClear :maxLength="30" placeholder="请输入电话(最多30个字符)"/>
      </a-form-model-item>
      <a-form-model-item label="联系人" prop="phone">
        <a-input id="quotation-basicInfo-bundleName" v-model="form.bundleName" allowClear :maxLength="30" placeholder="请输入联系人(最多30个字符)"/>
      </a-form-model-item>
      <a-form-model-item label="备注" prop="phone">
        <a-textarea id="quotation-basicInfo-bundleName" v-model="form.bundleName" allowClear :maxLength="120" placeholder="请输入备注(最多120个字符)"/>
      </a-form-model-item>
    </a-form-model>
    <div class="btn-cont">
      <a-button type="primary" id="quotation-basicInfo-modal-submit" @click="handleSubmit">提交</a-button>
      <a-button id="quotation-basicInfo-modal-back" @click="isShow = false" style="margin-left: 15px;">取消</a-button>
    </div>
  </a-modal>
</template>

<script>
  import { VSelect } from '@/components'
  export default{
    name: 'BasicInfoModal',
    components: { VSelect },
    props: {
      openModal: { //  弹框显示状态
        type: Boolean,
        default: false
      }
    },
    data(){
      return{
        isShow: this.openModal, //  是否打开弹框
        formItemLayout: {
          labelCol: { span: 6 },
          wrapperCol: { span: 16 }
        },
        form: {
          name: '', // 仓库名称
          priceType: undefined,  //  价格类型
        },
        rules: {
          name: [
            { required: true, message: '请输入客户名称', trigger: 'blur' }
          ],
          priceType: [
            { required: true, message: '请选择价格类型', trigger: 'change' },
          ],
        },
        optData: ['aa', 'bb', 'cc'],
        dataSource: [
          {name: '111', id:1},
          {name: '222', id:2},
          {name: '333', id:3},
        ],
      }
    },
    methods: {
      //  提交
      handleSubmit(){
        const _this = this
        // this.$refs.ruleForm.validate(valid => {
        //   if (valid) {
            _this.$emit('ok')
            _this.isShow = false
        //   } else {
        //     console.log('error submit!!')
        //     return false
        //   }
        // })
      },
      filterOption(input, option) {
        console.log(input, option)
      	return (
      		option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
      	)
      },
    },
    watch: {
      //  父页面传过来的弹框状态
      openModal (newValue, oldValue) {
        this.isShow = newValue
      },
      //  重定义的弹框状态
      isShow (newValue, oldValue) {
        if (!newValue) {
          this.$emit('close')
        }
      }
    }
  }
</script>

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