<template>
  <div id="index">
    <el-row>
      <el-col :span="24">
        <el-col :span="24" class="leftTop">
          <span>|</span>
          <span>基本信息</span>
          <el-button type="primary" size="mini" @click="bindWx" style="margin:0 10px;">绑定微信</el-button>
        </el-col>
        <el-col :span="24" class="info">
          <el-form ref="form" :model="form" :rules="rules" label-width="150px">
            <el-col :span="24">
              <el-form-item prop="name">
                <el-col :span="21" slot="label">
                  用户名称
                </el-col>
                <el-col :span="24">
                  <el-input v-model="form.name" placeholder="请输入用户名称"></el-input>
                </el-col>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item prop="phone">
                <el-col :span="21" slot="label">
                  手机号
                </el-col>
                <el-col :span="24">
                  <el-input v-model="form.phone" placeholder="请输入手机号" :minlength="11" :maxlength="11"></el-input>
                </el-col>
              </el-form-item>
            </el-col>
            <el-col :span="24" v-if="user.role == '4'">
              <el-form-item prop="role">
                <el-col :span="21" slot="label">
                  用户类别
                </el-col>
                <el-col :span="24">
                  <el-radio-group v-model="form.role">
                    <el-radio label="4">个人</el-radio>
                    <el-radio label="6">专家</el-radio>
                  </el-radio-group>
                </el-col>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item prop="code">
                <el-col :span="21" slot="label">
                  所属机构
                </el-col>
                <el-col :span="24">
                  <el-input v-model="form.code" placeholder="请输入机构代码"></el-input>
                </el-col>
              </el-form-item>
            </el-col>
            <span v-if="form.role == '4' || form.role == '5'">
              <el-col :span="12">
                <el-form-item prop="email">
                  <el-col :span="21" slot="label">
                    电子邮箱
                  </el-col>
                  <el-col :span="24">
                    <el-input v-model="form.email" placeholder="请输入电子邮箱"></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="addr">
                  <el-col :span="21" slot="label">
                    联系地址
                  </el-col>
                  <el-col :span="24">
                    <el-input v-model="form.addr" placeholder="请输入联系地址"></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="office_phone">
                  <el-col :span="21" slot="label">
                    办公电话
                  </el-col>
                  <el-col :span="24">
                    <el-input v-model="form.office_phone" placeholder="请输入办公电话"></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="profession">
                  <el-col :span="21" slot="label">
                    所属行业
                  </el-col>
                  <el-col :span="24">
                    <el-input v-model="form.profession" placeholder="请输入所属行业"></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
            </span>
            <span v-if="form.role == '4'">
              <el-col :span="24" class="langInfo">
                <el-form-item prop="resume">
                  <el-col :span="21" slot="label">
                    个人简历
                  </el-col>
                  <el-col :span="24">
                    <el-input
                      v-model="form.resume"
                      type="textarea"
                      maxlength="300"
                      show-word-limit
                      :autosize="{ minRows: 4, maxRows: 5 }"
                      placeholder="请输入个人简介"
                    ></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
            </span>
            <span v-else-if="form.role == '5'">
              <el-col :span="12">
                <el-form-item prop="companytype">
                  <el-col :span="21" slot="label">
                    注册类型
                  </el-col>
                  <el-col :span="24">
                    <el-input v-model="form.companytype" placeholder="请输入注册类型"></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="companydate">
                  <el-col :span="21" slot="label">
                    注册时间
                  </el-col>
                  <el-col :span="24">
                    <el-date-picker
                      v-model="form.companydate"
                      placeholder="请选择"
                      value-format="yyyy-MM-dd"
                      format="yyyy-MM-dd"
                      type="date"
                      style="width: 100%;"
                    >
                    </el-date-picker>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="institution_code">
                  <el-col :span="21" slot="label">
                    组织机构代码
                  </el-col>
                  <el-col :span="24">
                    <el-input v-model="form.institution_code" placeholder="请输入组织机构代码"></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="companycapital">
                  <el-col :span="21" slot="label">
                    注册资金
                  </el-col>
                  <el-col :span="24">
                    <el-input v-model="form.companytype" placeholder="请输入注册类型"></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="companyperson">
                  <el-col :span="21" slot="label">
                    企业法人
                  </el-col>
                  <el-col :span="24">
                    <el-input v-model="form.companyperson" placeholder="请输入企业法人"></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="sndqyzsr">
                  <el-col :span="21" slot="label">
                    上年度企业总收入
                  </el-col>
                  <el-col :span="24">
                    <el-input v-model="form.sndqyzsr" placeholder="请输入上年度企业总收入"></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="sndyffy">
                  <el-col :span="21" slot="label">
                    上年度研发费用
                  </el-col>
                  <el-col :span="24">
                    <el-input v-model="form.sndyffy" placeholder="请输入上年度研发费用"></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="companytotal">
                  <el-col :span="21" slot="label">
                    企业总人数
                  </el-col>
                  <el-col :span="24">
                    <el-input v-model="form.companytotal" placeholder="请输入企业总人数"></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="24" class="langInfo">
                <el-form-item prop="companybrief">
                  <el-col :span="21" slot="label">
                    企业简介
                  </el-col>
                  <el-col :span="24">
                    <el-input
                      v-model="form.companybrief"
                      type="textarea"
                      maxlength="300"
                      show-word-limit
                      :autosize="{ minRows: 4, maxRows: 5 }"
                      placeholder="请输入企业简介"
                    ></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="24" class="langInfo">
                <el-form-item prop="mainproduct">
                  <el-col :span="21" slot="label">
                    主要产品
                  </el-col>
                  <el-col :span="24">
                    <el-input
                      v-model="form.mainproduct"
                      type="textarea"
                      maxlength="300"
                      show-word-limit
                      :autosize="{ minRows: 4, maxRows: 5 }"
                      placeholder="请输入主要产品"
                    ></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="24" class="langInfo">
                <el-form-item prop="qualifications">
                  <el-col :span="21" slot="label">
                    企业资质/荣誉
                  </el-col>
                  <el-col :span="24">
                    <el-input
                      v-model="form.qualifications"
                      type="textarea"
                      maxlength="300"
                      show-word-limit
                      :autosize="{ minRows: 4, maxRows: 5 }"
                      placeholder="请输入企业资质/荣誉"
                    ></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
            </span>
            <span v-else-if="form.role == '6'">
              <el-col :span="24">
                <el-form-item prop="company">
                  <el-col :span="21" slot="label">
                    工作单位
                  </el-col>
                  <el-col :span="24">
                    <el-input v-model="form.company" placeholder="请输入工作单位"></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="school">
                  <el-col :span="21" slot="label">
                    毕业院校
                  </el-col>
                  <el-col :span="24">
                    <el-input v-model="form.school" placeholder="请输入毕业院校"></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="education">
                  <el-col :span="21" slot="label">
                    最高学历
                  </el-col>
                  <el-col :span="24">
                    <el-input v-model="form.education" placeholder="请输入最高学历"></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="birthDate">
                  <el-col :span="21" slot="label">
                    出生日期
                  </el-col>
                  <el-col :span="24">
                    <el-date-picker v-model="form.birthDate" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"> </el-date-picker>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="qqwx">
                  <el-col :span="21" slot="label">
                    QQ/微信
                  </el-col>
                  <el-col :span="24">
                    <el-input v-model="form.qqwx" placeholder="请输入QQ/微信"></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="email">
                  <el-col :span="21" slot="label">
                    电子邮箱
                  </el-col>
                  <el-col :span="24">
                    <el-input v-model="form.email" placeholder="请输入电子邮箱"></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="zwzc">
                  <el-col :span="21" slot="label">
                    职务职称
                  </el-col>
                  <el-col :span="24">
                    <el-input v-model="form.zwzc" placeholder="请输入职务职称"></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item prop="expertise">
                  <el-col :span="21" slot="label">
                    请输入擅长领域
                  </el-col>
                  <el-col :span="24">
                    <el-input v-model="form.expertise" placeholder="请输入擅长领域"></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="24" class="langInfoImage">
                <el-form-item prop="expertimage">
                  <el-col :span="21" slot="label">
                    头像
                  </el-col>
                  <el-col :span="24">
                    <upload :limit="1" :data="form.expertimage" type="expertimage" :url="'/files/imgpath/upload'" @upload="uploadSuccess"></upload>
                  </el-col>
                </el-form-item>
              </el-col>

              <el-col :span="24" class="langInfo">
                <el-form-item prop="workexperience">
                  <el-col :span="21" slot="label">
                    工作经历
                  </el-col>
                  <el-col :span="24">
                    <el-input
                      v-model="form.workexperience"
                      type="textarea"
                      maxlength="300"
                      show-word-limit
                      :autosize="{ minRows: 4, maxRows: 5 }"
                      placeholder="请输入工作经历"
                    ></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="24" class="langInfo">
                <el-form-item prop="scientific">
                  <el-col :span="21" slot="label">
                    科研综述
                  </el-col>
                  <el-col :span="24">
                    <el-input
                      v-model="form.scientific"
                      type="textarea"
                      maxlength="300"
                      show-word-limit
                      :autosize="{ minRows: 4, maxRows: 5 }"
                      placeholder="请输入科研综述"
                    ></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="24" class="langInfo">
                <el-form-item prop="undertakingproject">
                  <el-col :span="21" slot="label">
                    承担项目
                  </el-col>
                  <el-col :span="24">
                    <el-input
                      v-model="form.undertakingproject"
                      type="textarea"
                      maxlength="300"
                      show-word-limit
                      :autosize="{ minRows: 4, maxRows: 5 }"
                      placeholder="请输入承担项目"
                    ></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="24" class="langInfo">
                <el-form-item prop="scienceaward">
                  <el-col :span="21" slot="label">
                    科技奖励
                  </el-col>
                  <el-col :span="24">
                    <el-input
                      v-model="form.scienceaward"
                      type="textarea"
                      maxlength="300"
                      show-word-limit
                      :autosize="{ minRows: 4, maxRows: 5 }"
                      placeholder="请输入科技奖励"
                    ></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
              <el-col :span="24" class="langInfo">
                <el-form-item prop="social">
                  <el-col :span="21" slot="label">
                    社会任职
                  </el-col>
                  <el-col :span="24">
                    <el-input
                      v-model="form.social"
                      type="textarea"
                      maxlength="300"
                      show-word-limit
                      :autosize="{ minRows: 4, maxRows: 5 }"
                      placeholder="请输入社会任职"
                    ></el-input>
                  </el-col>
                </el-form-item>
              </el-col>
            </span>
            <span v-if="form.status == '3'">
              <el-col :span="24">
                <el-form-item prop="status">
                  <el-col :span="21" slot="label">
                    用户审核状态
                  </el-col>
                  <el-col :span="24">
                    <el-radio-group v-model="form.status">
                      <el-radio label="0">待审核</el-radio>
                      <el-radio label="3">待认证</el-radio>
                    </el-radio-group>
                  </el-col>
                </el-form-item>
              </el-col>
            </span>
            <el-col :span="24" class="btn">
              <el-button type="primary" @click="authSubmit" v-if="form.status == '0' || form.status == '3'">提交认证</el-button>
              <el-button type="primary" @click="upgradeSubmit" v-if="user.role == '4'">升级用户</el-button>
              <el-button type="primary" @click="onSubmit">提交修改</el-button>
            </el-col>
          </el-form>
        </el-col>
      </el-col>
    </el-row>
    <el-dialog title="绑定微信" :visible.sync="dialogVisible" width="50%" :before-close="handleClose">
      <div style="text-align:center">
        <img :src="qc" />
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
import upload from '@/components/uploadone.vue';
const { mapActions: login } = createNamespacedHelpers('login');
const { mapActions: market } = createNamespacedHelpers('market');
const { mapActions: expertsuser } = createNamespacedHelpers('expertsuser');
import QRCode from 'qrcode';
export default {
  name: 'index',
  props: {},
  components: {
    upload,
  },
  data: function() {
    return {
      rules: {
        name: [{ required: true, message: '请输入用户名称', trigger: 'blur' }],
        phone: [{ required: true, message: '请输入手机号', trigger: 'blur' }],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
        role: [{ required: true, message: '请输入用户类型', trigger: 'blur' }],
      },
      form: {},
      qc: '',
      // 绑定微信
      dialogVisible: false,
    };
  },
  created() {
    this.searchInfo();
  },
  methods: {
    ...login({ logout: 'logout', transactiondtetle: 'delete' }),
    ...market(['fetch', 'update']),
    ...expertsuser({ expertsuserFetch: 'fetch', expertsuserUpdate: 'update', expertsuserUpgrade: 'upgrade' }),
    async searchInfo() {
      if (this.user.role == '4' || this.user.role == '5') {
        let res = await this.fetch(this.user.userid);
        if (res.errcode === 0) {
          this.$set(this, `form`, res.data);
        }
      } else if (this.user.role == '6') {
        let res = await this.expertsuserFetch(this.user.userid);
        if (res.errcode === 0) {
          console.log(res);
          this.$set(this, `form`, res.data);
        }
      }
    },
    async onSubmit() {
      if (this.form.role == '4' || this.form.role == '5' || this.form.role == '7') {
        let res;
        let msg;
        res = await this.update(this.form);
      } else if (this.form.role == '6') {
        let res;
        let msg;
        res = await this.expertsuserUpdate(this.form);
      }
      this.$message({
        message: '修改信息成功',
        type: 'success',
      });
      this.searchInfo();
    },
    async authSubmit() {
      let res;
      let msg;
      res = await this.update(this.form);
      this.$message({
        message: '提交认证信息成功，等待管理员认证',
        type: 'success',
      });
      this.searchInfo();
    },
    async upgradeSubmit() {
      this.form.status = '0';
      this.form.uid = this.user.uid;
      let res = await this.expertsuserUpgrade(this.form);
      if (this.$checkRes(res)) {
        this.$message({
          message: '用戶升級成功，等待管理员审核',
          type: 'success',
        });
        this.logout();
        this.$router.push({ path: '/webLogin' });
      } else {
        this.$message({
          message: '用戶升級失敗',
          type: 'error',
        });
      }
    },
    uploadSuccess({ type, data }) {
      this.$set(this.form, `${type}`, data.uri);
    },
    async creatQrCode() {
      let url = `http://free.liaoningdoupo.com/api/auth/wxchat?redirect_uri=http://free.liaoningdoupo.com/platmobile/bind/&type=1&uid=${this.user.uid}`; // 需要转换为二维码的内容
      let el = document.getElementById('qrCodeUrl');
      this.qc = await QRCode.toDataURL(url, { height: 200, width: 200 });
    },
    // 绑定微信打开
    bindWx() {
      this.dialogVisible = true;
    },
    // 绑定微信关闭
    handleClose() {
      this.dialogVisible = false;
    },
  },
  mounted() {
    this.creatQrCode();
  },
  computed: {
    ...mapState(['user']),
    pageTitle() {
      return `${this.$route.meta.title}`;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
};
</script>

<style lang="less" scoped>
.leftTop {
  font-size: 18px;
  width: 96%;
  height: 41px;
  line-height: 35px;
  border-bottom: 1px solid #e5e5e5;
  position: relative;
  bottom: 1px;
  margin: 10px;
  font-weight: 600;
  color: #22529a;
}
.info {
  margin: 0 40px 15px 10px;
  border: 1px dashed #ccc;
  width: 96%;
  padding: 10px;
  /deep/.el-form-item {
    margin-bottom: 0px;
  }
  /deep/.el-form-item__label {
    border: 1px solid #dcdfe6;
  }
  /deep/.el-radio-group {
    border: 1px solid #ccc;
    padding: 12px 20px;
    width: 943px;
  }
  /deep/.el-input__inner {
    border-radius: 0;
    height: 42px;
    line-height: 42px;
  }
  /deep/.el-textarea__inner {
    border-radius: 0;
  }
  /deep/.langInfo .el-form-item__label {
    padding: 27px 0;
  }
  /deep/.langInfoImage .el-form-item__label {
    padding: 53px 0;
  }
  .btn {
    text-align: center;
    margin: 10px 0;
  }
}
.qrcode {
  padding: 10px 45px;
  span {
    float: left;
    width: 85px;
    font-size: 16px;
    color: #606266;
    padding: 50px 0;
  }
  img {
    border: 1px solid #ccc;
  }
}
</style>
