<template>
  <div id="adviserList">
    <enterprisedg-detail
      :liebiaoList="liebiaoList"
      :dinggou1="dinggou1"
      :dinggou2="dinggou2"
      :dinggou3="dinggou3"
      @onsave="onsaveClick"
      :total1="total1"
      :total2="total2"
      :total3="total3"
      @handleCurrentChange="change1"
      @handleCurrentChange1="change2"
      @handleCurrentChange2="change3"
      @deletes="deleteData"
      :faqilist="faqilist"
      :totalfaqi="totalfaqi"
      @handleCurrentChangefaqi="handleCurrentChangefaqi"
      @jiaoyisuccess="jiaoyisuccess"
      @shibai="shibai"
      @success="success"
    ></enterprisedg-detail>
  </div>
</template>

<script>
import enterprisedgDetail from '@/components/enterprise/enterpisedg.vue';
import { createNamespacedHelpers, mapGetters, mapState } from 'vuex';
const { mapActions: transaction } = createNamespacedHelpers('transaction');
const { mapActions: expertsaudit } = createNamespacedHelpers('expertsaudit');
const { mapActions: login } = createNamespacedHelpers('login');
export default {
  name: 'adviserList',
  props: {},
  components: {
    enterprisedgDetail,
  },
  data: () => ({
    liebiaoList: [
      { name: '基本信息' },
      { name: '消息管理' },
      { name: '我的发布' },
      { name: '事项管理' },
      { name: '展会管理' },
      // { name: '返回首页' },
      { name: '修改密码' },
      { name: '注销账号' },
    ],
    total1: 0,
    total2: 0,
    total3: 0,
    totalfaqi: 0,
    faqilist: [],
    dinggou1: [],
    dinggou2: [],
    dinggou3: [],
    skip: '',
  }),
  created() {
    this.jiaoyi1();
    this.jiaoyi2();
    this.jiaoyi3();
    this.faqijiaoyi();
  },
  computed: {
    ...mapState(['user']),
  },
  methods: {
    ...transaction({ transactionList: 'query', transactiondtetle: 'delete', shenheupdate: 'update' }),
    ...expertsaudit({ expertsauditList: 'query', expertsauditdtetle: 'delete', expertsauditupdate: 'update' }),
    ...login({ logout: 'logout', transactiondtetlse: 'delete' }),
    // 查询
    async faqijiaoyi({ skip = 0, limit = 3, ...info } = {}) {
      let status = 0;
      let market_userid = this.user.uid;
      skip = this.skip;
      if (this.user.role == '2' || this.user.role == '3') {
        const res = await this.transactionList({ skip, limit, market_userid, status, ...info });
        if (this.$checkRes(res)) {
          this.$set(this, `faqilist`, res.data);
          this.$set(this, `totalfaqi`, res.total);
        }
      } else if (this.role == '6') {
        const res = await this.expertsauditList({ skip, limit, market_userid, status, ...info });
        if (this.$checkRes(res)) {
          this.$set(this, `faqilist`, res.data);
          this.$set(this, `totalfaqi`, res.total);
        }
      }
    },
    async jiaoyi1({ skip = 0, limit = 3, ...info } = {}) {
      let status = 1;
      let market_userid = this.user.uid;
      skip = this.skip;
      if (this.user.role == '2' || this.user.role == '3') {
        const res = await this.transactionList({ skip, limit, market_userid, status, ...info });
        if (this.$checkRes(res)) {
          this.$set(this, `dinggou1`, res.data);
          this.$set(this, `total1`, res.total);
        }
      } else if (this.role == '6') {
        const res = await this.expertsauditList({ skip, limit, market_userid, status, ...info });
        if (this.$checkRes(res)) {
          this.$set(this, `faqilist`, res.data);
          this.$set(this, `totalfaqi`, res.total);
        }
      }
    },
    async jiaoyi2({ skip = 0, limit = 3, ...info } = {}) {
      let status = 2;
      let market_userid = this.user.uid;
      skip = this.skip;
      if (this.user.role == '2' || this.user.role == '3') {
        const res = await this.transactionList({ skip, limit, market_userid, status, ...info });
        if (this.$checkRes(res)) {
          this.$set(this, `dinggou2`, res.data);
          this.$set(this, `total2`, res.total);
        }
      } else if (this.role == '6') {
        const res = await this.expertsauditList({ skip, limit, market_userid, status, ...info });
        if (this.$checkRes(res)) {
          this.$set(this, `faqilist`, res.data);
          this.$set(this, `totalfaqi`, res.total);
        }
      }
    },
    async jiaoyi3({ skip = 0, limit = 3, ...info } = {}) {
      skip = this.skip;
      if (this.user.role == '2' || this.user.role == '3') {
        const res = await this.transactionList({ skip, limit, ...info });
        if (this.$checkRes(res)) {
          this.$set(this, `dinggou3`, res.data);
          this.$set(this, `total3`, res.total);
        }
      } else if (this.role == '6') {
        const res = await this.expertsauditList({ skip, limit, market_userid, status, ...info });
        if (this.$checkRes(res)) {
          this.$set(this, `faqilist`, res.data);
          this.$set(this, `totalfaqi`, res.total);
        }
      }
    },

    //审核
    async jiaoyisuccess({ item }) {
      item.status = '1';
      let res = await this.shenheupdate(item);
      this.jiaoyi1();
      this.$checkRes(res, '同意成功', '审核失败');
    },
    async shibai({ item }) {
      item.status = '3';
      let res = await this.shenheupdate(item);
      this.$checkRes(res, '审核成功', '审核失败');
      this.jiaoyi3();
    },
    async success({ item }) {
      item.status = '2';
      let res = await this.shenheupdate(item);
      this.$checkRes(res, '审核成功', '审核失败');
      this.jiaoyi2();
    },
    //分页
    async handleCurrentChangefaqi({ skip, limit, currentPage }) {
      this.$set(this, `skip`, skip);
      this.faqijiaoyi();
    },
    async change1({ skip, limit, currentPage }) {
      this.$set(this, `skip`, skip);
      this.jiaoyi1();
    },
    async change2({ skip, limit, currentPage }) {
      this.$set(this, `skip`, skip);
      this.jiaoyi2();
    },
    async change3({ skip, limit, currentPage }) {
      this.$set(this, `skip`, skip);
      this.jiaoyi3();
    },
    async deleteData({ item }) {
      const res = await this.transactiondtetle(item.id);
      this.$checkRes(res, '删除成功', '删除失败');
    },
    async onsaveClick({ id }) {
      console.log(id);
      if (id === '基本信息') {
        this.$router.push({ path: '/enterprise/enterprisejb' });
      } else if (id === '消息管理') {
        this.$router.push({ path: '/enterprise/enterprisexx' });
      } else if (id === '我的发布') {
        this.$router.push({ path: '/enterprise/enterprisefabu' });
      } else if (id === '事项管理') {
        this.$router.push({ path: '/enterprise/enterprisedg' });
      } else if (id === '修改密码') {
        this.$router.push({ path: '/enterprise/xiugai' });
      } else if (id === '返回首页') {
        this.$router.push({ path: '/' });
      } else if (id === '注销账号') {
        this.logout();
        this.$message({
          message: '注销成功',
          type: 'success',
        });
        this.toLogin();
      } else if (id === '展会管理') {
        this.$router.push({ path: '/enterprise/appointment' });
      }
    },
    async toLogin() {
      this.$router.push({ path: '/platlive' });
    },
  },
};
</script>

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