<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="top">
        <topInfo :topTitle="topTitle" :display="display" @add="add"></topInfo>
      </el-col>
      <el-col :span="24" class="main">
        <el-col :span="24" class="list">
          <seeList :tableData="tableData" :total="total" @deleteRow="deleteRow" @select="select" @updateState="updateState" @handle="handle"></seeList>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import topInfo from '@/layout/custom/topInfo.vue';
import seeList from '@/layout/financingTUrgeHandle/seeList.vue';
import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
const { mapActions: tUrgeHandle } = createNamespacedHelpers('tUrgeHandle');
const { mapActions: dictionary } = createNamespacedHelpers('dictionary');

export default {
  name: 'index',
  props: {},
  components: {
    topInfo, //头部导航
    seeList, //列表
  },
  data: () => ({
    topTitle: '我要融资催办处理',
    display: '',
    tableData: [],
    total: 0,
  }),
  created() {
    this.select();
  },
  computed: {
    ...mapState(['user']),
  },
  methods: {
    ...tUrgeHandle(['create', 'delete', 'update', 'fetch', 'query', 'originalQuery']),
    ...dictionary({ dictQuery: 'query' }),
    async select({ skip = 0, limit = 10, ...info } = {}) {
      console.log(this.user);
      const res = await this.originalQuery({ skip, limit, jg_id: this.user.userid, type: '2', ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `tableData`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    async handle({ id, skip, limit, ...info }) {
      console.log(id);

      let data = {};
      data.id = id;
      data.status = '2';
      data.handle_time = new Date().getTime();

      const res = await this.update(data);
      this.$checkRes(res, '处理成功', '处理失败');

      this.select({ skip, limit, ...info });
    },
    add() {
      this.$router.push({ path: '/tDeclarationApproval/detail' });
    },
    async deleteRow({ id, skip = 0, limit = 10, ...info } = {}) {
      const res = await this.delete(id);
      this.$checkRes(res, '删除成功', '删除失败');
      this.select({ skip, limit, ...info });
    },
    async publish({ row, skip = 0, limit = 10, ...info } = {}) {
      let res = await this.update({ id: row.id, publish_state: 1, publish_state_description: '已发布', publish_time: new Date().getTime() });
      this.$checkRes(res, '发布成功', '发布失败');
      this.select({ skip, limit, ...info });
    },
    async updateState({ id, state, result, skip = 0, limit = 10, ...info } = {}) {
      let res = null;
      switch (state) {
        case '0':
          break;
        case '1':
          res = await this.state({ id: id, current_approval_id: this.user.uid, state: state, state_description: '', result_description: result });
          this.$checkRes(res, '审核成功', '审核失败');
          break;
        case '2':
          res = await this.state({ id: id, current_approval_id: this.user.uid, state: state, state_description: '', result_description: result });
          this.$checkRes(res, '审核成功', '审核失败');
          break;
        case '3':
          res = await this.state({ id: id, current_approval_id: this.user.uid, state: state, state_description: '', result_description: result });
          this.$checkRes(res, '停用成功', '停用失败');
          break;
        case '9':
          res = await this.state({ id: id, current_approval_id: this.user.uid, state: state, state_description: '', result_description: result });
          this.$checkRes(res, '完成成功', '完成失败');
          break;
      }
      this.select({ skip, limit, ...info });
    },
  },
};
</script>

<style lang="less" scoped>
.top {
  height: 50px;
  margin: 0 0 10px 0;
}
.main {
  min-height: 765px;
  background: #ffffff;
}
.search {
  width: 97%;
  height: 35px;
  margin: 20px;
}
.list {
  padding: 0 20px;
}
</style>
