<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <div style="text-align: center;font-size: larger;margin-bottom: 10px">用地单位信息填报</div>
          </a-col>
              <a-col :span="24">
                <a-form-model-item label='单位名称' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='qymc'>
                  <a-col :span="22">
                    <a-input v-model='model.qymc' placeholder='请输入单位名称' disabled></a-input>
                  </a-col>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="主管部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sjdw">
                  <a-col :span="22">
                    <j-popup
                      v-model="model.sjdw"
                      field="sjdw"
                      org-fields="depart_name,id"
                      dest-fields="sjdw,sjdwdm"
                      code="sjdw"
                      :multi="false"
                      :param="param"
                      @input="popupCallback"
                    />
                  </a-col>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item  v-show="false" label="单位级别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="org_type">
                  <a-col :span="22">
                    <a-input   v-model="model.org_type" placeholder="请输入上级单位代码"  ></a-input>
                  </a-col>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item v-show="false" label="单位编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="org_code">
                  <a-col :span="22">
                    <a-input  v-model="model.org_code" placeholder="请输入上级单位代码"  ></a-input>
                  </a-col>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label='统一社会信用代码' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='tyshxybm'>
                  <a-col :span="22">
                    <a-input v-model='model.tyshxybm' placeholder='请输入统一社会信用代码'></a-input>
                  </a-col>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label='单位基本性质' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='qylx'>
                  <a-col :span="22">
                    <j-dict-select-tag type="list" v-model="model.qylx" dictCode="dwjbxz" placeholder="请选择单位基本性质" />
                  </a-col>
                </a-form-model-item>
              </a-col>
              <a-col :span="24" >
                <a-form-model-item label="是否涉及省内土地资产" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sfsjtdzc">
                  <a-col :span="22">
                    <j-dict-select-tag type="list" v-model="model.sfsjtdzc" dictCode="sfsjtdzc" placeholder="请选择是否涉及省内土地资产" />
                  </a-col>
                </a-form-model-item>
                <!--  <a-icon class='info' type='question-circle-o' @click='info("sfsjtdzc")'></a-icon>-->
              </a-col>
              <a-col :span="24">

              </a-col>
              <a-col :span="24">
                <a-form-model-item label="分管领导" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fgld">
                  <a-col :span="22">
                    <a-input v-model="model.fgld" placeholder="请输入分管领导姓名"  ></a-input>
                  </a-col>
                </a-form-model-item>
              </a-col>
<!--              <a-col :span="24">
                <a-form-model-item label="分管领导手机" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fgldsjh">
                  <a-col :span="22">
                    <a-input v-model="model.fgldsjh" placeholder="请输入分管领导手机号码"  ></a-input>
                  </a-col>
                </a-form-model-item>
              </a-col>-->
              <a-col :span="24">
                <a-form-model-item label="联络人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tbr">
                  <a-col :span="22">
                    <a-input v-model="model.tbr" placeholder="请输入联络人姓名"  ></a-input>
                  </a-col>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="手机号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sjh">
                  <a-col :span="22">
                    <a-input v-model="model.sjh" placeholder="请输入手机号"  ></a-input>
                  </a-col>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="邮箱号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zjh">
                  <a-col :span="22">
                    <a-input v-model="model.zjh" placeholder="请输入邮箱号"  ></a-input>
                  </a-col>
                </a-form-model-item>
              </a-col>

<!-- <a-col :span="8">-->
<!--                <a-form-model-item label="用地单位编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qybm">-->
<!--                  <a-input   v-model="model.qybm" placeholder="用地单位编码" disabled ></a-input>-->
<!--                </a-form-model-item>-->
<!--              </a-col>-->
<!--              <a-col :span="24">
                <a-form-model-item label="单位名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qymc">
                  <a-input   v-model="model.qymc" placeholder="请输入企业名称" disabled ></a-input>
                  &lt;!&ndash;              <j-popup
                                  v-model="model.qymc"
                                  field="qymc"
                                  org-fields="depart_name,org_type,org_code"
                                  dest-fields="qymc,org_type,org_code"
                                  code="qymc"
                                  :multi="false"
                                  @input="popupCallback"
                                />&ndash;&gt;
                </a-form-model-item>
              </a-col>
            </a-row>


          </a-col>
          <a-col :span="24">
            <a-form-model-item label='单位级别' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='orgType'>
              <j-dict-select-tag type="list" v-model="model.orgType" dictCode="dwjb" placeholder="请选择单位级别" @change='change' />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="上级单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sjdw">
                 <j-popup
                   v-model="model.sjdw"
                   field="sjdw"
                   org-fields="depart_name,id"
                   dest-fields="sjdw,sjdwdm"
                   code="sjdw"
                   :multi="false"
                   :param="param"
                   @input="popupCallback"
                 />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item  v-show="false" label="单位级别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="org_type">
              <a-input   v-model="model.org_type" placeholder="请输入上级单位代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item v-show="false" label="单位编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="org_code">
              <a-input  v-model="model.org_code" placeholder="请输入上级单位代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="统一社会信用编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tyshxybm">
              <a-input v-model="model.tyshxybm" placeholder="请输入统一社会信用编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label='机构类型' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='jglx'>
              <a-input type="list" v-model="model.qylx"  placeholder="请选择机构类型" @change='change' />
            </a-form-model-item>
          </a-col>
&lt;!&ndash;          <a-col :span="24" v-show='isQy'>&ndash;&gt;
&lt;!&ndash;            <a-form-model-item label="企业类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qylx">&ndash;&gt;
&lt;!&ndash;              <j-dict-select-tag type="list" v-model="model.qylx" dictCode="qylx" placeholder="请选择企业类型" @change='change' />&ndash;&gt;
&lt;!&ndash;            </a-form-model-item>&ndash;&gt;
&lt;!&ndash;          </a-col>&ndash;&gt;
&lt;!&ndash;          <a-col :span="24" v-show='isQy'>&ndash;&gt;
&lt;!&ndash;            <a-form-model-item label="国有资产持股比例(%)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gyzccgbl">&ndash;&gt;
&lt;!&ndash;              <a-input-number v-model="model.gyzccgbl" placeholder="请输入国有资产持股比例" style="width: 100%" :max='100' :min='0' :disabled='blDisable'/>&ndash;&gt;
&lt;!&ndash;              <a-icon class='info' type='question-circle-o' @click='info("gyzccgbl")'></a-icon>&ndash;&gt;
&lt;!&ndash;            </a-form-model-item>&ndash;&gt;
&lt;!&ndash;          </a-col>&ndash;&gt;
          <a-col :span="24" >
            <a-form-model-item label="是否涉及省内土地资产" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sfsjtdzc">
              <j-dict-select-tag type="list" v-model="model.sfsjtdzc" dictCode="sfsjtdzc" placeholder="请选择是否涉及省内土地资产" />
            </a-form-model-item>
            &lt;!&ndash;  <a-icon class='info' type='question-circle-o' @click='info("sfsjtdzc")'></a-icon>&ndash;&gt;
          </a-col>
          <a-col :span="24">
            <div style="text-align: center;font-size: larger;margin-bottom: 10px">联络人报名表</div>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="分管领导" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fgld">
              <a-input v-model="model.fgld" placeholder="请输入分管领导姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="分管领导手机" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fgldsjh">
              <a-input v-model="model.fgldsjh" placeholder="请输入分管领导手机号码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联络人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tbr">
              <a-input v-model="model.tbr" placeholder="请输入联络人姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="手机号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sjh">
              <a-input v-model="model.sjh" placeholder="请输入手机号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="座机号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lxdh">
              <a-input v-model="model.lxdh" placeholder="请输入座机号"  ></a-input>
            </a-form-model-item>
          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="统一社会信用代码证书" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tyshxydmzs">
              <j-upload v-model='model.tyshxydmzs'></j-upload>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction,putAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  const ruleBaseURL = '/sys/fillRule/executeRuleByCode/'
  export default {
    name: 'QcQyxxForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
          param:{
              org_type:'',
              org_code:''
          },
        isQy:false,
        blDisable:false,
        model:{
          gyzccgbl:0,
            qybm:''
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           qymc: [
              { required: true, message: '请输入用地单位名称!'},
           ],
            sjdw: [
                { required: true, message: '请输入上级单位名称!'},
            ],
           tyshxybm: [
              { required: true, message: '请输入统一社会信用编码!'},
           ],
           qylx: [
              { required: true, message: '请输入企业类型!'},
           ],
            jglx: [
                { required: true, message: '请选择机构类型!'},
            ],
           gyzccgbl: [
              { required: true, message: '请输入国有资产持股比例!'},

           ],
          tyshxydmzs: [
            { required: true, message: '请输入统一社会信用代码证书!'},
          ],
          tyshxydm:[
            { required: true, message: '请输入统一社会信用代码!'},
          ],
            sfsjtdzc: [
                { required: true, message: '请输入是否涉及省内土地资产!'},
            ],
            fgld: [
                { required: true, message: '请输入分管领导姓名!'},
            ],
            fgldsjh: [
                { required: true, message: '请输入分管领导手机号!'},
            ],
            tbr: [
                { required: true, message: '请输入联络人姓名!'},
            ],
            sjh: [
                { required: true, message: '请输入手机号!'},
            ],
        },
          formInfo: {
              gyzccgbl:"请填写1~100之间的数值。"
          },
        url: {
              rule:{
                qybm: ruleBaseURL+'qybm'
              },
          add: "/qcsb.qyxx/qcQyxx/add",
          edit: "/qcsb.qyxx/qcQyxx/edit",
          queryById: "/qcsb.qyxx/qcQyxx/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
      mounted(){
        this.getQybm();
      },
    methods: {
        getQybm() {

            putAction(this.url.rule.qybm, this.model).then(res => {
                // 执行成功，获取返回的值，并赋到页面上
                if (res.success) {
                    this.model.qybm = res.result
                }
            })
        },
        /**
         *点击提示
         */
        info(name) {
            this.$info({
                title: '说明',
                content: (<div><p>{this.formInfo[name]}</p></div>),
                onOk() {
            }
        })
        },
      add () {
          getAction("/qcsb.qyxx/qcQyxx/queryQyjbxx").then(res=>{
              if(res.code==200){

                  this.model= res.result
                  this.model.org_code=res.result.org_code
                  this.model.org_type=res.result.org_type
                  this.param.org_type=parseInt(res.result.org_type)-1
                  let org_code=""
                  if(this.param.org_type==1){
                      this.param.org_code=res.result.org_code.substring(0,3)
                      org_code = res.result.org_code.substring(0, 3)
                  }else {
                      this.param.org_code = res.result.org_code.substring(0, 6)
                      org_code = res.result.org_code.substring(0, 3)
                  }

                  if(org_code==='A04'){
                      this.isQy=true;
                  }else {
                      this.isQy=false;
                  }
              }
          })
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
        let org_code=this.model.sysOrgCode.substring(0,3)
        if(org_code==='A04'){
          this.isQy=true;
        }else {
          this.isQy=false;
        }
        if(this.model.qylx==='国有全资公司'){
          this.model.gyzccgbl=100;
          this.blDisable=true;
        }else {
          //this.model.gyzccgbl=0;
          this.blDisable=false;
        }
      },
      change(val){
        if(val==='国有全资公司'){
          this.model.gyzccgbl=100;
          this.blDisable=true;
        }else {
          this.model.gyzccgbl=0;
          this.blDisable=false;
        }
      },
      popupCallback(value,row){
          debugger
        this.model = Object.assign(this.model, row);
      },
      submitForm () {
        const that = this;

        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            if(this.param.org_code==='A04'){
              if(this.model.qylx==''||this.model.gyzccgbl=='') {
                this.$message.error('请选择企业类型且输入国有持资比例！')
                return
              }
            }
            that.confirmLoading = true;
            this.model.gyzccgbl=this.model.gyzccgbl;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>