<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :bodyStyle="bodyStyle"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    :maskClosable="false"
    @cancel="handleCancel"
    cancelText="关闭"
    :footer="null">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">


        <a-form-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'userName', validatorRules.userName]" placeholder="请输入姓名" :disabled="readonlytype"></a-input>
        </a-form-item>
          
        <a-form-item label="手机号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'phone', validatorRules.phone]" placeholder="请输入手机号"></a-input>
        </a-form-item>



        <a-form-item label="身份证号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'idcardNumber', validatorRules.idcardNumber]" :disabled="readonlytype" placeholder="请输入身份证号"></a-input>
        </a-form-item>


        <!--<a-form-item label="身份证照片" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
          <!--<template v-if="model.idcardFront">-->
          <!--<a-input-group>-->
            <!--<a-row :gutter="24">-->
              <!--<a-col :span="7">-->
                  <!--<img :src="getAvatarView()" :preview="getAvatarView()" alt="身份证正面" style="height:124px;max-width:124px"/>-->
              <!--</a-col>-->
              <!--<a-col :span="7">-->
                  <!--<img :src="getAvatarView1()" :preview="getAvatarView1()" alt="身份证反面" style="height:124px;max-width:124px"/>-->
              <!--</a-col>-->
            <!--</a-row>-->
          <!--</a-input-group>-->
          <!--</template>-->
          <!--<template v-else>-->
            <!--未上传-->
          <!--</template>-->
        <!--</a-form-item>-->

      </a-form>
    </a-spin>

  </a-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'
  import Vue from 'vue'
  import { ACCESS_TOKEN } from '@/store/mutation-types'
  
  export default {
    name: "hlwUserInfoModal",
    components: {
      JDate,
    },
    data () {
      return {
        picUrl: '',
        picUrl1: '',
        readonlytype:false,
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        bodyStyle: {
          paddingTop: '20px',
          paddingBottom:'20px',
          maxHeight: (window.innerHeight * 0.62) + 'px',
          'overflow-y': 'auto'
        },
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        headers: {},
        uploadLoading: false,
        confirmLoading: false,
        validatorRules:{
          userName:{rules: [{ required: true, message: '请输入姓名!' }]},
        phone:{rules: [{ required: true, message: '请输入电话!' }]},
        idcardNumber:{rules: [{ required: true, message: '请输入身份证号!' }]},
        gender:{},
          cardNumber:{},
        type:{},


        },
        url: {
          add: "/hwuser/hwUser/add",
          edit: "/hwuser/hwUser/edit",
          fileUpload: window._CONFIG['domianURL'] + '/hpSys/common/ossUpload',
          imgerver: window._CONFIG['imgDomainOssURL']
        }
     
      }
    },
    props: {
      /*这个属性用于控制文件上传的业务路径*/
      bizPath: {
        type: String,
        required: false,
        default: '/hpwork/hwcompany'
      }
    },
    created () {
      const token = Vue.ls.get(ACCESS_TOKEN)
      this.headers = { 'X-Access-Token': token }
    },
    computed: {
      uploadAction: function() {
        return this.url.fileUpload
      }
    },
    methods: {
      add () {
        this.picUrl = ''
        this.picUrl1 = ''
        this.edit({});
      },
      edit (record) {
        this.readonlytype=false
        if(record.id && record.authenticationStatus==1){
          this.readonlytype=true
        }
        this.form.resetFields();
        this.model = Object.assign({}, record);
        console.log(11111111,this.model)
        // this.picUrl = '';
        // this.picUrl1 = '';
        // if (record.hasOwnProperty('id') && record.idcardFront) {
        //   this.picUrl = 'Has no pic url yet'
        // }
        // if (record.hasOwnProperty('id') && record.idcardBack) {
        //   this.picUrl1 = 'Has no pic url yet'
        // }
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'userName','phone','idcardNumber','idcardFront','idcardBack'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'platformCompanyId','name','phone','idcardNumber','gender','type','authenticationStatus','sysOrgCode','registerTime','registerFrom','cardNumber','bnkflg','eacbnk','rcveaa','authenticationPhone','idcardFront','idcardBack'))
      },

      selectSubcontractType(e){
        if(e!=null && e!=''){
          this.form.setFieldsValue({ bnkflg:e})
          this.model.bnkflg=e
          if(e=='N'){
            this.form.setFieldsValue({ eacbnk:this.model.eacbnk})
            this.form.setFieldsValue({ rcveaa:this.model.rcveaa})
          }
        }
      },
      //监听身份证输入事件
      changeCardNumber(e){
        this.model.cardNumber=e.target.value;
        //输入框清空时同步清空招行选择radio
        if(!e.target.value){
          this.model.bnkflg = '';
        }
      },


      // getAvatarView() {
      //   if(this.model.idcardFront){
      //     if( this.model.idcardFront.indexOf("http")!=-1){
      //       return this.model.idcardFront
      //     }else{
      //       return this.url.imgerver + this.model.idcardFront
      //     }
      //   }
      // },
      //
      // getAvatarView1() {
      //   if( this.model.idcardBack){
      //     if( this.model.idcardBack.indexOf("http")!=-1){
      //       return this.model.idcardBack
      //     }else{
      //       return this.url.imgerver + this.model.idcardBack
      //     }
      //   }
      // },

    }
  }
</script>
<style lang="less" scoped>
  .avatar-uploader > .ant-upload {
    width: 104px;
    height: 104px;
  }

  .ant-upload-select-picture-card i {
    font-size: 49px;
    color: #999;
  }

  .ant-upload-select-picture-card .ant-upload-text {
    margin-top: 8px;
    color: #666;
  }
</style>