<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-row>
              <a-col :span="2">
              </a-col>
              <a-col :span="9">
                <a-form-model-item label="用地单位编码" :labelCol="labelColNew" :wrapperCol="wrapperCol" prop="qybm">
                  <a-input   v-model="model.qybm" placeholder="用地单位编码" disabled ></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="10">
                <a-form-model-item label="用地单位名称" :labelCol="labelColNew" :wrapperCol="wrapperCol" prop="qymc">
                  <a-input   v-model="model.qymc" placeholder="请输入企业名称" disabled ></a-input>
                  <!--              <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"
                                />-->
                </a-form-model-item>
              </a-col>
            </a-row>


          </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="orgType">
              <a-input   v-model="model.orgType" 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="orgCode">
              <a-input  v-model="model.orgCode" 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" v-show='isQy'>
            <a-form-model-item label="企业控股类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qylx">
              <j-dict-select-tag type="list" v-model="model.qylx" dictCode="qylx" placeholder="请选择企业类型" @change='change' />
            </a-form-model-item>
          </a-col>
          <a-col :span="24" v-show='isQy'>
            <a-form-model-item label="国有资产持股比例(%)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gyzccgbl">
              <a-input-number v-model="model.gyzccgbl" placeholder="请输入国有资产持股比例" style="width: 98%;margin-right: 3px" :max='100' :min='0' :disabled='blDisable'/>
              <a-icon class='info' type='question-circle-o' @click='info("gyzccgbl")'></a-icon>
            </a-form-model-item>
          </a-col>
          <a-col :span="24" v-show='isQy'>
            <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>
             <!-- <a-icon class='info' type='question-circle-o' @click='info("sfsjtdzc")'></a-icon>-->
          </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:{
              orgType:'',
              orgCode:''
          },
        isQy:false,
        blDisable:false,
        model:{
          gyzccgbl:0,
            qybm:''
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        labelColNew: {
          xs: { span: 24 },
          sm: { span: 8 },
        },
        confirmLoading: false,
        validatorRules: {
           qymc: [
              { required: true, message: '请输入用地单位名称!'},
           ],
            sjdw: [
                { required: true, message: '请输入上级单位名称!'},
            ],
           tyshxybm: [
              { required: true, message: '请输入统一社会信用编码!'},
           ],
           qylx: [
              { required: true, message: '请输入企业类型!'},
           ],
           gyzccgbl: [
              { required: true, message: '请输入国有资产持股比例!'},

           ],
          tyshxydmzs: [
            { required: true, message: '请输入统一社会信用代码证书!'},
          ],
            sfsjtdzc: [
                { required: true, message: '请输入是否涉及省内土地资产!'},
            ],
            fgld: [
                { required: true, message: '请输入分管领导姓名!'},
            ],
            fgldsjh: [
                { required: true, message: '请输入分管领导手机号!'},
            ],
            tbr: [
                { required: true, message: '请输入联络人姓名!'},
            ],
            sjh: [
                { required: true, message: '请输入手机号!'},
            ],
            tyshxydmzs: [
                { 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() {
            debugger
            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)
                  debugger
                  this.model= res.result
                  this.model.orgCode=res.result.orgCode
                  this.model.orgType=res.result.orgType
                  this.param.orgType=parseInt(res.result.orgType)-1
                  let org_code=""
                  if(this.param.orgType==1){
                      this.param.orgCode=res.result.orgCode.substring(0,3)
                      org_code = res.result.orgCode.substring(0, 3)
                  }else {
                      this.param.org_code = res.result.orgCode.substring(0, 6)
                      org_code = res.result.orgCode.substring(0, 3)
                  }
                  debugger
                  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){
        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>
<style scoped>
.info {
  /*position: absolute;
  right: -10%;
  top: 40%;*/
  color: red;
  margin-left: 5px;
}
</style>