<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">
          <tUrgeHandleList :tableData="tableData" :total="total" @deleteRow="deleteRow" @select="select" @updateState="updateState"></tUrgeHandleList>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>
<script>
  import topInfo from '@/layout/custom/topInfo.vue';
  import tUrgeHandleList from '@/layout/tUrgeHandle/tUrgeHandleList.vue';
  import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
  const { mapActions: tUrgeHandle } = createNamespacedHelpers('tUrgeHandle');
  const { mapActions: dictionary } = createNamespacedHelpers('dictionary');

  export default {
    name: 'index',
    props: {},
    components: {
      topInfo, //头部导航
      tUrgeHandleList, //列表
    },
    data: () => ({
      topTitle: '催办操作',
      display: '',
      tableData: [],
      total: 0,
    }),
    created() {
      this.select();
    },
    computed: {
      ...mapState(['user']),
    },
    methods: {
      ...tUrgeHandle(['create', 'delete', 'update', 'fetch', 'query']),
      ...dictionary({dictQuery:'query'}),
      async select({ skip = 0, limit = 10, ...info } = {}) {
        const res = await this.query({ skip, limit, ...info });
        if (this.$checkRes(res)) {
          this.$set(this, `tableData`, res.data);
          this.$set(this, `total`, res.total);
        }
      },
      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>
