<template>
  <div class="detail-base">
    <t-card title="会员信息修改" :bordered="false" class="info-block">
      <div style="padding: 20px">
        <div style="padding-bottom: 20px;font-weight: bold">登陆信息</div>
        <t-form
          layout="inline"
          labelAlign="top"
        >
          <t-form-item label="手机号" name="phone">
            <t-input v-model="formData.phone" placeholder="请输入手机号"></t-input>
          </t-form-item>
          <t-form-item label="密码" name="password">
            <t-input v-model="formData.password" placeholder="请输入密码"></t-input>
          </t-form-item>
          <t-form-item label="职位" name="position_id">
            <t-select v-model="formData.position_id" :style="{ width: '200px' }">
              <t-option v-for="(item,index) in plan_list" :label="item.position_name" :value="item.id"></t-option>
            </t-select>
          </t-form-item>
          <t-form-item label="行业" name="industry_id">
            <t-select v-model="formData.industry_id" :style="{ width: '200px' }">
              <t-option v-for="(item,index) in industry_list" :label="item.industry_name" :value="item.id"></t-option>
            </t-select>
          </t-form-item>
        </t-form>
      </div>
      <div style="padding: 20px">
        <div style="padding-bottom: 20px;font-weight: bold">人员信息</div>
        <t-form
          labelAlign="top"
          layout="inline"
        >
          <t-form-item label="真实姓名" name="nikename">
            <t-input v-model="formData.nikename" placeholder="请输入真实姓名"></t-input>
          </t-form-item>

          <t-form-item label="性别" name="gender">
            <t-select v-model="formData.gender" :style="{ width: '200px' }">
              <t-option key="0" label="女" value="0"></t-option>
              <t-option key="1" label="男" value="1"></t-option>
            </t-select>
          </t-form-item>
          <t-form-item label="民族" name="nation">
            <t-input v-model="formData.nation" placeholder="请输入民族"></t-input>
          </t-form-item>
          <t-form-item label="政治面貌" name="political">
            <t-input v-model="formData.political" placeholder="请输入政治面貌"></t-input>
          </t-form-item>
          <t-form-item label="出生日期" name="birth_time">
            <t-date-picker :style="{ width: '200px' }" v-model="formData.birth_time"/>
          </t-form-item>
          <t-form-item label="身份证号码" name="card_number">
            <t-input v-model="formData.card_number" placeholder="请输入身份证号码"></t-input>
          </t-form-item>
          <t-form-item label="籍贯" name="jiguan">
            <t-input v-model="formData.jiguan" placeholder="请输入籍贯"></t-input>
          </t-form-item>
          <t-form-item label="毕业院校" name="institution">
            <t-input v-model="formData.institution" placeholder="请输入毕业院校"></t-input>
          </t-form-item>
          <t-form-item label="学历" name="education">
            <t-input v-model="formData.education" placeholder="请输入学历"></t-input>
          </t-form-item>
          <t-form-item label="学位" name="academic_degree">
            <t-input v-model="formData.academic_degree" placeholder="请输入学位"></t-input>
          </t-form-item>
          <t-form-item label="工作单位" name="academic_degree">
            <t-input v-model="formData.work_unit" placeholder="请输入工作单位"></t-input>
          </t-form-item>
          <t-form-item label="单位职务" name="unit_position">
            <t-input v-model="formData.unit_position" placeholder="请输入单位职务"></t-input>
          </t-form-item>
          <t-form-item label="微信号" name="wx_number">
            <t-input v-model="formData.wx_number" placeholder="请输入微信号"></t-input>
          </t-form-item>
          <t-form-item label="邮箱" name="mailbox">
            <t-input v-model="formData.mailbox" placeholder="请输入邮箱"></t-input>
          </t-form-item>
          <t-form-item label="固定电话" name="fixed_telephone">
            <t-input v-model="formData.fixed_telephone" placeholder="请输入固定电话"></t-input>
          </t-form-item>
          <t-form-item label="其他社会职务" name="other_social_positions">
            <t-input v-model="formData.other_social_positions" placeholder="请输入其他社会职务"></t-input>
          </t-form-item>
          <t-form-item label="其他联系人" name="other_contacts">
            <t-input v-model="formData.other_contacts" placeholder="请输入其他联系人"></t-input>
          </t-form-item>
<!--          <t-form-item label="意向协会职务" name="position">-->
<!--            <t-input v-model="formData.position" placeholder="请输入意向协会职务"></t-input>-->
<!--          </t-form-item>-->
          <t-form-item label="主要成就以及获奖情况" name="achievement_award">
            <t-textarea placeholder="请输入主要成就以及获奖情况" :autosize="{ minRows: 3, maxRows: 5 }"
                        v-model="formData.achievement_award"/>
          </t-form-item>
        </t-form>
      </div>
      <div style="padding: 0px 20px">
        <t-form labelAlign="top"
                layout="inline">
          <t-form-item label="证件照">
            <t-upload
              :action="$store.state.user.apiUrl+'/api/common/upload'"
              v-model="formData.photo_image_show"
              theme="image"
              tips="请选择证件照"
              accept="image/*"
              :format-response="(response) => formatResponse(response, 0)"
            ></t-upload>
          </t-form-item>
          <t-form-item label="身份证正面照">
            <t-upload
              :action="$store.state.user.apiUrl+'/api/common/upload'"
              v-model="formData.cardz_image_show"
              theme="image"
              tips="请选择身份证正面照"
              accept="image/*"
              :format-response="(response) => formatResponse(response, 1)"
            ></t-upload>
          </t-form-item>
          <t-form-item label="身份证反面照">
            <t-upload
              :action="$store.state.user.apiUrl+'/api/common/upload'"
              v-model="formData.cardf_image_show"
              theme="image"
              tips="请选择身份证反面照"
              accept="image/*"
              :format-response="(response) => formatResponse(response, 2)"
            ></t-upload>
          </t-form-item>
        </t-form>
      </div>
      <div style="padding: 20px">
        <div style="padding: 20px 0px;font-weight: bold">企业信息</div>
        <t-form labelAlign="top"
                layout="inline">
          <t-form-item label="营业执照">
            <t-upload
              :action="$store.state.user.apiUrl+'/api/common/upload'"
              v-model="formData.business_license_image_show"
              theme="image"
              tips="请选择营业执照"
              accept="image/*"
              :format-response="(response) => formatResponse(response, 3)"
            ></t-upload>
          </t-form-item>
          <t-form-item label="统一社会信用代码" name="unified_code">
            <t-input v-model="formData.unified_code" placeholder="请输入统一社会信用代码"></t-input>
          </t-form-item>
          <t-form-item label="企业性质" name="enterprise_nature">
            <t-input v-model="formData.enterprise_nature" placeholder="请输入企业性质"></t-input>
          </t-form-item>
          <t-form-item label="企业网址" name="enterprise_website">
            <t-input v-model="formData.enterprise_website" placeholder="请输入企业网址"></t-input>
          </t-form-item>
          <t-form-item label="是否上市" name="if_list">
            <t-select v-model="formData.if_list" :style="{ width: '200px' }">
              <t-option key="0" label="是" value="0"></t-option>
              <t-option key="1" label="否" value="1"></t-option>
            </t-select>
          </t-form-item>
          <t-form-item label="员工人数" name="employee">
            <t-input v-model="formData.employee" placeholder="请输入员工人数"></t-input>
          </t-form-item>
          <t-form-item label="企业注册地" name="enterprise_location">
            <t-input v-model="formData.enterprise_location" placeholder="请输入企业注册地"></t-input>
          </t-form-item>
          <t-form-item label="上年度营业额" name="previous_revenue">
            <t-input v-model="formData.previous_revenue" placeholder="请输入上年度营业额"></t-input>
          </t-form-item>
          <t-form-item label="上年度纳税额" name="previous_tax">
            <t-input v-model="formData.previous_tax" placeholder="请输入上年度纳税额"></t-input>
          </t-form-item>
          <t-form-item label="上年度净利润" name="previous_profit">
            <t-input v-model="formData.previous_profit" placeholder="请输入上年度净利润"></t-input>
          </t-form-item>
          <t-form-item label="上年度公益性捐赠支出" name="previous_donation">
            <t-input v-model="formData.previous_donation" placeholder="上年度公益性捐赠支出"></t-input>
          </t-form-item>
          <t-form-item label="其他企业任职情况" name="qitaqiyerenzhiqingkuang">
            <t-input v-model="formData.qitaqiyerenzhiqingkuang" placeholder="其他企业任职情况"></t-input>
          </t-form-item>
          <t-form-item label="企业介绍" name="enterprise_Introduction">
            <t-textarea placeholder="请输入企业介绍" :autosize="{ minRows: 3, maxRows: 5 }"
                        v-model="formData.enterprise_Introduction"/>
          </t-form-item>
          <t-form-item label="业务介绍" name="introdiction">
            <t-textarea placeholder="请输入业务介绍" :autosize="{ minRows: 3, maxRows: 5 }"
                        v-model="formData.introdiction"/>
          </t-form-item>
          <t-form-item label="企业所获荣誉以及专利" name="enterprise_honor">
            <t-textarea placeholder="请输入企业所获荣誉以及专利" :autosize="{ minRows: 3, maxRows: 5 }"
                        v-model="formData.enterprise_honor"/>
          </t-form-item>
        </t-form>
        <t-form labelAlign="top"
                layout="inline">
          <t-form-item label="是否建立团组织" name="if_organization">
            <t-select v-model="formData.if_organization" :style="{ width: '200px' }">
              <t-option key="0" label="是" value="0"></t-option>
              <t-option key="1" label="否" value="1"></t-option>
            </t-select>
          </t-form-item>
        </t-form>
        <t-form v-if="formData.if_organization==0" labelAlign="top"
                layout="inline">
          <t-form-item label="团组织性质" name="nature">
            <t-input v-model="formData.nature" placeholder="团组织性质"></t-input>
          </t-form-item>
          <t-form-item label="建团时间" name="jiantuan_time">
            <t-date-picker :style="{ width: '200px' }" v-model="formData.jiantuan_time"/>
          </t-form-item>
          <t-form-item label="建团人数" name="jiantuan_number">
            <t-input v-model="formData.jiantuan_number" placeholder="建团人数"></t-input>
          </t-form-item>
          <t-form-item label="青年人数" name="youth_number">
            <t-input v-model="formData.youth_number" placeholder="青年人数"></t-input>
          </t-form-item>
          <t-form-item label="上级团组织" name="superior_nature">
            <t-input v-model="formData.superior_nature" placeholder="上级团组织"></t-input>
          </t-form-item>
          <t-form-item label="团委负责人信息" name="tuanweifuzerenxinxi">
            <t-input v-model="formData.tuanweifuzerenxinxi" placeholder="团委负责人信息"></t-input>
          </t-form-item>
          <t-form-item label="批复文件">
            <t-upload
              :action="$store.state.user.apiUrl+'/api/common/upload'"
              v-model="formData.documents_file_show"
              theme="image"
              tips="请选择批复文件(图片)"
              accept="image/*"
              :format-response="(response) => formatResponse(response, 4)"
            ></t-upload>
          </t-form-item>
        </t-form>
        <div style="text-align: center;margin-top: 40px">
          <t-space :style="{ width: '300px',margin:'0 auto',textAlign:'center' }">
            <t-button @click="submit">提交修改</t-button>
          </t-space>
        </div>
      </div>
    </t-card>

  </div>
</template>
<script lang="ts">
import {UserIcon, LockOnIcon} from 'tdesign-icons-vue';
import {CheckCircleIcon} from 'tdesign-icons-vue';
import store from '@/store'
export default {
  components: {
    CheckCircleIcon,
    UserIcon,
    LockOnIcon,
  },
  data() {
    return {
      formData: {
        phone: '',
        password: '',
        nikename: '',
        gender: null,
        birth_time: '',
        nation: '',
        political: '',
        jiguan: '',
        institution: '',
        education: '',
        academic_degree: '',
        card_number: '',
        work_unit: '',
        unit_position: '',
        wx_number: '',
        mailbox: '',
        fixed_telephone: '',
        achievement_award: '',
        other_contacts: '',
        other_social_positions: '',
        position: '',
        cardf_image_show: [],
        cardz_image_show: [],
        photo_image_show: [],
        cardf_image: '',
        cardz_image: '',
        photo_image: '',
        business_license_image_show: [],
        business_license_image: '',
        unified_code: '',
        enterprise_nature: '',
        enterprise_website: '',
        if_list: null,
        employee: '',
        previous_revenue: '',
        previous_tax: '',
        position_id:null,
        previous_profit: '',
        previous_donation: '',
        enterprise_location:'',
        industry_id:null,
        qitaqiyerenzhiqingkuang: '',
        enterprise_Introduction: '',
        introdiction: '',
        enterprise_honor: '',
        if_organization: null,
        nature: '',
        jiantuan_time: '',
        jiantuan_number: '',
        youth_number: '',
        superior_nature: '',
        tuanweifuzerenxinxi: '',
        documents_file: '',
        documents_file_show: []
      },
      id: 0,
      info: '',
      plan_list:[],
      industry_list:[]
    };
  },
  mounted() {
    this.id = this.$route.query.id;
    this.getInfo();
    this.getPlan();
    this.getIndustry();
  },
  methods: {
    formatResponse(res, type) {
      console.log(res);
      if (type == 0) {
        this.formData.photo_image = res.data.url;
      } else if (type == 1) {
        this.formData.cardz_image = res.data.url;
      } else if (type == 2) {
        this.formData.cardf_image = res.data.url;
      } else if (type == 3) {
        this.formData.business_license_image = res.data.url;
      } else {
        this.formData.documents_file = res.data.url;
      }

      return {url: res.data.fullurl};
    },
    getIndustry(){
      this.$request
        .post("/industry")
        .then( (res) => {
          console.log(res);
          if(res.code==1){
            this.industry_list=res.data;
          }
        })
        .catch((e) => {
          console.log(e);
        });
    },
    getPlan(){
      this.$request
        .post("/position")
        .then( (res) => {
            console.log(res);
            if(res.code==1){
              this.plan_list=res.data;
            }
        })
        .catch((e) => {
          console.log(e);
        });
    },
    getInfo() {
      this.$request
        .post("/member/find",{member_id:this.id})
        .then( (res) => {
          console.log(res);
          this.info=res.data;
          this.formData.phone=res.data.phone;
          this.formData.position_id=res.data.position_id;
          this.formData.industry_id=res.data.industry_id;
          this.formData.password=res.data.password;
            this.formData.nikename=res.data.nikename;
            this.formData.gender=res.data.gender;
            this.formData.birth_time=res.data.birth_time;
            this.formData.nation=res.data.nation;
            this.formData.political=res.data.political;
            this.formData.jiguan=res.data.jiguan;
            this.formData.institution=res.data.institution;
            this.formData.education=res.data.education;
            this.formData.academic_degree=res.data.academic_degree;
            this.formData.card_number=res.data.card_number;
            this.formData.work_unit=res.data.work_unit;
            this.formData.unit_position=res.data.unit_position;
            this.formData.wx_number=res.data.wx_number;
            this.formData.mailbox=res.data.mailbox;
            this.formData.fixed_telephone=res.data.fixed_telephone;
            this.formData.achievement_award=res.data.achievement_award;
            this.formData.other_contacts=res.data.other_contacts;
            this.formData.other_social_positions=res.data.other_social_positions;
            this.formData.position=res.data.position;
            this.formData.cardf_image_show=[{url: store.state.user.apiUrl+res.data.cardf_image}];
            this.formData.cardz_image_show=[{url: store.state.user.apiUrl+res.data.cardz_image}];
            this.formData.photo_image_show=[{url:store.state.user.apiUrl+ res.data.photo_image}];
            this.formData.cardf_image=res.data.cardf_image;
            this.formData.cardz_image=res.data.cardz_image;
            this.formData.photo_image=res.data.photo_image;
            this.formData.business_license_image_show=[{url:store.state.user.apiUrl+res.data.business_license_image}];
            this.formData.business_license_image=res.data.business_license_image;
            this.formData.unified_code=res.data.unified_code;
            this.formData.enterprise_nature=res.data.enterprise_nature;
            this.formData.enterprise_website=res.data.enterprise_website;
            this.formData.if_list=res.data.if_list;
            this.formData.employee=res.data.employee;
            this.formData.previous_revenue=res.data.previous_revenue;
            this.formData.previous_tax=res.data.previous_tax;
            this.formData.previous_profit=res.data.previous_profit;
            this.formData.previous_donation=res.data.previous_donation;
            this.formData.qitaqiyerenzhiqingkuang=res.data.qitaqiyerenzhiqingkuang;
            this.formData.enterprise_Introduction=res.data.enterprise_Introduction;
            this.formData.introdiction=res.data.introdiction;
            this.formData.enterprise_honor=res.data.enterprise_honor;
            this.formData.if_organization=res.data.if_organization;
            this.formData.nature=res.data.nature;
            this.formData.jiantuan_time=res.data.jiantuan_time;
            this.formData.jiantuan_number=res.data.jiantuan_number;
            this.formData.youth_number=res.data.youth_number;
            this.formData.superior_nature=res.data.superior_nature;
            this.formData.tuanweifuzerenxinxi=res.data.tuanweifuzerenxinxi;
            this.formData.documents_file=res.data.documents_file;
            this.formData.enterprise_location=res.data.enterprise_location;
            this.formData.documents_file_show= [{url:store.state.user.apiUrl+ res.data.documents_file}];
        })
        .catch((e) => {
          console.log(e);
        });
    },
    submit() {
      if (this.formData.business_license_image == '') {
        this.$message.error('请上传营业执照！');
        return;
      }
      if (this.formData.unified_code == '') {
        this.$message.error('请输入统一社会信用代码！');
        return;
      }
      if (this.formData.enterprise_nature == '') {
        this.$message.error('请输入企业性质！');
        return;
      }
      if (this.formData.enterprise_website == '') {
        this.$message.error('请输入企业网址！');
        return;
      }
      if (this.formData.if_list == null) {
        this.$message.error('请选择是否上市！');
        return;
      }
      if (this.formData.employee == '') {
        this.$message.error('请输入员工人数！');
        return;
      }
      if (this.formData.enterprise_location == '') {
        this.$message.error('请输入企业注册地！');
        return;
      }
      if (this.formData.previous_revenue == '') {
        this.$message.error('请输入上年度营业额！');
        return;
      }
      if (this.formData.previous_tax == '') {
        this.$message.error('请输入上年度纳税额！');
        return;
      }
      if (this.formData.education == '') {
        this.$message.error('请输入学历！');
        return;
      }
      if (this.formData.previous_profit == '') {
        this.$message.error('请输入上年度净利润！');
        return;
      }
      if (this.formData.previous_donation == '') {
        this.$message.error('请输入上年度公益性捐赠支出！');
        return;
      }
      if (this.formData.qitaqiyerenzhiqingkuang == '') {
        this.$message.error('请输入其他企业任职情况！');
        return;
      }
      if (this.formData.enterprise_Introduction == '') {
        this.$message.error('请输入企业介绍！');
        return;
      }
      if (this.formData.introdiction == '') {
        this.$message.error('请输入业务介绍！');
        return;
      }
      if (this.formData.enterprise_honor == '') {
        this.$message.error('请输入企业所获荣誉以及专利！');
        return;
      }
      if (this.formData.if_organization == null) {
        this.$message.error('是否建立团组织！');
        return;
      }
      if(this.formData.if_organization==0){
        if (this.formData.nature == '') {
          this.$message.error('请输主团组织性质！');
          return;
        }
        if (this.formData.jiantuan_time == '') {
          this.$message.error('请输入建团时间！');
          return;
        }
        if (this.formData.jiantuan_number == '') {
          this.$message.error('请输入建团人数！');
          return;
        }
        if (this.formData.youth_number == '') {
          this.$message.error('请输入青年人数！');
          return;
        }
        if (this.formData.superior_nature == '') {
          this.$message.error('请输入上级团组织！');
          return;
        }
        if (this.formData.tuanweifuzerenxinxi == '') {
          this.$message.error('请输入团委负责人信息！');
          return;
        }
        if (this.formData.documents_file == '') {
          this.$message.error('请上传批复文件！');
          return;
        }
      }
      this.formData.member_id = this.id;
      this.$request
        .post("/member/update", this.formData)
        .then((res) => {
          console.log(res);
          if (res.code==1){
            this.$message.success(res.msg);
          }else{
            this.$message.error(res.msg);
          }
          this.getInfo();
        })
        .catch((e) => {
          console.log(e);
        });
    },
  },

};
</script>
<style scoped lang="less">

</style>
