<template>
  <div id="index">
    <el-row>
      <el-col :span="24">
        <!-- <el-col :span="24" class="add" style="text-align:right;padding: 10px 20px;">
          <el-button size="mini" type="primary" @click="toAdd" icon="el-icon-plus">添加{{ theme }}</el-button>
        </el-col> -->
        <!-- <el-col :span="24" class="main">
          <data-table :fields="fields" :opera="opera" @edit="toEdit" :data="list" :total="total" @delete="toDelete" @query="search"></data-table>
        </el-col> -->
        <el-col :span="24" class="main">
          <el-tabs v-model="activeName" type="card">
            <el-tab-pane label="待审核" name="first">
              <one :oneList="oneList" :total="onetotal" @handleDelete="handleDelete" @handleEdit="handleEdit1"></one>
            </el-tab-pane>
            <el-tab-pane label="审核成功" name="second">
              <two :oneList="twoList" :total="twototal" @handleDelete="handleDelete" @handleEdit="handleEdit1"></two>
            </el-tab-pane>
            <el-tab-pane label="审核失败" name="third">
              <three :oneList="threeList" :total="threetotal" @handleDelete="handleDelete" @handleEdit="handleEdit1"></three>
            </el-tab-pane>
          </el-tabs>
        </el-col>
        <el-dialog :title="theme" width="60%" :visible.sync="dialog" @closed="handleClose" :destroy-on-close="true">
          <el-form ref="form" :model="form" label-width="100px">
            <el-form-item label="用户状态" v-if="form.role !== '1'">
              <el-radio-group v-model="form.status">
                <el-radio label="0" disabled>已注册</el-radio>
                <el-radio label="1">审核成功</el-radio>
                <el-radio label="2">审核未通过</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="用户名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入用户名称"></el-input>
            </el-form-item>
            <el-form-item label="手机号" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入手机号" :minlength="11" :maxlength="11"></el-input>
            </el-form-item>
            <el-form-item label="用户类别" prop="role">
              <el-radio-group v-model="form.role">
                <el-radio label="4">个人</el-radio>
                <el-radio label="5">机构管理员</el-radio>
                <el-radio label="6">专家</el-radio>
              </el-radio-group>
            </el-form-item>
            <span v-if="form.role == '4' || form.role == '5'">
              <el-form-item label="电子邮箱" prop="email">
                <el-input v-model="form.email" placeholder="请输入电子邮箱"></el-input>
              </el-form-item>
              <el-form-item label="联系地址" prop="addr">
                <el-input v-model="form.addr" placeholder="请输入联系地址"></el-input>
              </el-form-item>
              <el-form-item label="办公电话" prop="office_phone">
                <el-input v-model="form.office_phone" placeholder="请输入办公电话"></el-input>
              </el-form-item>
              <el-form-item label="所属行业" prop="profession">
                <el-input v-model="form.profession" placeholder="请输入所属行业"></el-input>
              </el-form-item>
            </span>
            <span v-if="form.role == '4'">
              <el-form-item label="个人简历" v-if="form.role == '4'">
                <el-input type="textarea" v-model="form.resume" placeholder="请输入个人简介"></el-input>
              </el-form-item>
            </span>
            <span v-else-if="form.role == '5'">
              <el-form-item label="注册类型">
                <el-input v-model="form.companytype" placeholder="请输入注册类型"></el-input>
              </el-form-item>
              <el-form-item label="注册时间">
                <el-date-picker v-model="form.companydate" placeholder="请选择" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date"> </el-date-picker>
              </el-form-item>
              <el-form-item label="统一社会信用代码">
                <el-input v-model="form.institution_code" placeholder="请输入统一社会信用代码"></el-input>
              </el-form-item>
              <el-form-item label="注册资金">
                <el-input v-model="form.companycapital" placeholder="请输入注册资金"></el-input>
              </el-form-item>
              <el-form-item label="企业法人">
                <el-input v-model="form.companyperson" placeholder="请输入企业法人"></el-input>
              </el-form-item>
              <el-form-item label="上年度企业总收入">
                <el-input v-model="form.sndqyzsr" placeholder="请输入上年度企业总收入"></el-input>
              </el-form-item>
              <el-form-item label="上年度研发费用">
                <el-input v-model="form.sndyffy" placeholder="请输入上年度研发费用"></el-input>
              </el-form-item>
              <el-form-item label="企业总人数">
                <el-input v-model="form.companytotal" placeholder="请输入企业总人数"></el-input>
              </el-form-item>
              <el-form-item label="企业简介">
                <el-input
                  v-model="form.companybrief"
                  type="textarea"
                  maxlength="300"
                  show-word-limit
                  :autosize="{ minRows: 4, maxRows: 5 }"
                  placeholder="请输入企业简介"
                ></el-input>
              </el-form-item>
              <el-form-item label="主要产品">
                <el-input
                  v-model="form.mainproduct"
                  type="textarea"
                  maxlength="300"
                  show-word-limit
                  :autosize="{ minRows: 4, maxRows: 5 }"
                  placeholder="请输入主要产品"
                ></el-input>
              </el-form-item>
              <el-form-item label="企业资质/荣誉">
                <el-input
                  v-model="form.qualifications"
                  type="textarea"
                  maxlength="300"
                  show-word-limit
                  :autosize="{ minRows: 4, maxRows: 5 }"
                  placeholder="请输入企业资质/荣誉"
                ></el-input>
              </el-form-item>
            </span>
            <span v-else-if="form.role == '6'">
              <el-form-item label="头像">
                <upload :limit="1" :data="form.expertimage" type="expertimage" :url="'/files/imgpath/upload'" @upload="uploadSuccess"></upload>
              </el-form-item>
              <el-form-item label="最高学历">
                <el-input v-model="form.education" placeholder="请输入最高学历"></el-input>
              </el-form-item>
              <el-form-item label="毕业院校">
                <el-input v-model="form.school" placeholder="请输入毕业院校"></el-input>
              </el-form-item>
              <el-form-item label="出生日期">
                <el-date-picker v-model="form.birthDate" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"> </el-date-picker>
              </el-form-item>
              <el-form-item label="QQ/微信">
                <el-input v-model="form.qqwx" placeholder="请输入QQ/微信"></el-input>
              </el-form-item>
              <el-form-item label="电子邮箱">
                <el-input v-model="form.email" placeholder="请输入电子邮箱"></el-input>
              </el-form-item>
              <el-form-item label="工作单位">
                <el-input v-model="form.company" placeholder="请输入工作单位"></el-input>
              </el-form-item>
              <el-form-item label="职务职称">
                <el-input v-model="form.zwzc" placeholder="请输入职务职称"></el-input>
              </el-form-item>
              <el-form-item label="擅长领域">
                <el-input v-model="form.expertise" placeholder="请输入擅长领域"></el-input>
              </el-form-item>
              <el-form-item label="工作经历">
                <el-input
                  v-model="form.workexperience"
                  type="textarea"
                  maxlength="300"
                  show-word-limit
                  :autosize="{ minRows: 2, maxRows: 5 }"
                  placeholder="请输入工作经历"
                ></el-input>
              </el-form-item>
              <el-form-item label="科研综述">
                <el-input
                  v-model="form.scientific"
                  type="textarea"
                  maxlength="300"
                  show-word-limit
                  :autosize="{ minRows: 2, maxRows: 5 }"
                  placeholder="请输入科研综述"
                ></el-input>
              </el-form-item>
              <el-form-item label="承担项目">
                <el-input
                  v-model="form.undertakingproject"
                  type="textarea"
                  maxlength="300"
                  show-word-limit
                  :autosize="{ minRows: 2, maxRows: 5 }"
                  placeholder="请输入承担项目"
                ></el-input>
              </el-form-item>
              <el-form-item label="科技奖励">
                <el-input
                  v-model="form.scienceaward"
                  type="textarea"
                  maxlength="300"
                  show-word-limit
                  :autosize="{ minRows: 2, maxRows: 5 }"
                  placeholder="请输入科技奖励"
                ></el-input>
              </el-form-item>
              <el-form-item label="社会任职">
                <el-input
                  v-model="form.social"
                  type="textarea"
                  maxlength="300"
                  show-word-limit
                  :autosize="{ minRows: 2, maxRows: 5 }"
                  placeholder="请输入社会任职"
                ></el-input>
              </el-form-item>
            </span>
            <el-form-item>
              <el-button @click="handleClose">返回</el-button>
              <el-button type="primary" @click="handleSave()">提交</el-button>
            </el-form-item>
          </el-form>
        </el-dialog>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import one from './parts/one.vue';
import two from './parts/two.vue';
import three from './parts/three.vue';
import upload from '@/components/uploadone.vue';
import dataTable from '@/components/data-table.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: users } = createNamespacedHelpers('users');
const { mapActions: expertsuser } = createNamespacedHelpers('expertsuser');
export default {
  name: 'index',
  props: {},
  components: {
    // dataTable,
    upload,
    one,
    two,
    three,
  },
  data: function() {
    return {
      theme: '用戶',
      activeName: 'first',
      dialog: false,
      form: {},
      editData: {},
      oneList: [],
      onetotal: 0,
      twoList: [],
      twototal: 0,
      threeList: [],
      threetotal: 0,
    };
  },
  created() {
    this.search();
  },
  methods: {
    ...users(['fetch', 'create', 'query', 'update', 'delete', 'userquery']),
    ...expertsuser({ exportuserFetch: 'fetch', exportuserCreate: 'create', exportuserUpdate: 'update' }),
    async search({ skip = 0, limit = 10, pid = '', ...info } = {}) {
      if (this.user.code == 'JLCJGLY') {
        const res = await this.userquery({ skip, ...info });
        if (this.$checkRes(res)) {
          let one = res.data.filter(i => i.status == '0');
          if (one) {
            this.$set(this, `oneList`, one);
            this.$set(this, `onetotal`, one.length);
          }
          let two = res.data.filter(i => i.status == '1');
          if (two) {
            this.$set(this, `twototal`, two.length);
            this.$set(this, `twoList`, two);
          }
          let three = res.data.filter(i => i.status == '2');
          if (three) {
            this.$set(this, `threeList`, three);
            this.$set(this, `threetotal`, three.length);
          }
        }
      } else {
        const res = await this.userquery({ skip, limit, pid, code: this.user.code, ...info });
        if (this.$checkRes(res)) {
          let one = res.data.filter(i => i.status == '0');
          if (one) {
            this.$set(this, `oneList`, one);
            this.$set(this, `onetotal`, one.length);
          }
          let two = res.data.filter(i => i.status == '1');
          if (two) {
            this.$set(this, `twototal`, two.length);
            this.$set(this, `twoList`, two);
          }
          let three = res.data.filter(i => i.status == '2');
          if (three) {
            this.$set(this, `threeList`, three);
            this.$set(this, `threetotal`, three.length);
          }
        }
      }
    },
    // 添加
    toAdd() {
      console.log('添加');
    },
    // 修改handleEdit
    async toEdit({ data }) {
      if (data.role == '6') {
        const res = await this.exportuserFetch(data.uid);
        if (this.$checkRes(res)) {
          this.$set(this, `form`, res.data);
        }
      } else {
        const res = await this.fetch(data.uid);
        if (this.$checkRes(res)) {
          this.$set(this, `form`, res.data);
        }
      }
      this.$set(this, `editData`, data);
      this.dialog = true;
    },
    // 提交
    async handleSave() {
      // console.log(this.form);
      let data = this.form;
      if (data.role == '4' || data.role == '5') {
        data.id = data.uid;
        let res = await this.update(data);
        if (this.$checkRes(res)) {
          this.$message({
            message: '审核信息成功',
            type: 'success',
          });
          this.handleClose();
        }
      } else if (data.role == '6') {
        data.id = data.uid;
        let res = await this.exportuserUpdate(data);
        if (this.$checkRes(res)) {
          this.$message({
            message: '修改信息成功',
            type: 'success',
          });
          this.handleClose();
        }
      }
    },
    // 删除
    toDelete() {},
    // 取消
    handleClose() {
      this.dialog = false;
      this.form = {};
    },
    uploadSuccess({ type, data }) {
      this.$set(this.form, `${type}`, data.uri);
    },
    setIsQy(data) {
      let val = '0';
      data == '2' ? (val = '0') : (val = '1');
      this.$set(this.form, `is_qy`, val);
    },
    // 审核
    handleEdit1(data) {
      // console.log(data);
      this.$set(this, `form`, data);
      this.dialog = true;
    },
    async handleDelete(id) {
      this.$confirm('您确定要删除此信息吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(async () => {
          const res = await this.delete(id);
          if (this.$checkRes(res)) {
            this.$message({
              message: '删除信息成功',
              type: 'success',
            });
            this.search();
          }
        })
        .catch(() => {});
    },
  },
  computed: {
    ...mapState(['user']),
    pageTitle() {
      return `${this.$route.meta.title}`;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
};
</script>

<style lang="less" scoped></style>
