<template>
  <div class="app-container">
    <el-tabs tab-position="left" v-model="taskState" @tab-click="handleSelectState">
      <el-tab-pane label="我的任务" name="0"></el-tab-pane>
      <el-tab-pane label="历史任务" name="1"></el-tab-pane>

      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
               label-width="80px">
        <!--        <el-form-item label="任务类型">-->
        <!--          <el-select v-model="queryParams.receiveType" style="width: 100%" @change="getList"-->
        <!--                     placeholder="请选择任务类型">-->
        <!--            <el-option-->
        <!--              v-for="dict in dict.type.official_reciver"-->
        <!--              :key="dict.value"-->
        <!--              :label="dict.label"-->
        <!--              :value="dict.value">-->
        <!--            </el-option>-->
        <!--          </el-select>-->
        <!--        </el-form-item>-->
        <el-form-item label="发文字号" prop="issuedNum">
          <el-input
            v-model="queryParams.issuedNum"
            placeholder="请输入发文字号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="标题" prop="issuedName">
          <el-input
            v-model="queryParams.issuedName"
            placeholder="请输入发文标题"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="officialList">
        <el-table-column type="index" width="55" label="序号" align="center"/>
        <el-table-column label="发文字号" align="center" prop="issuedNum"/>
        <el-table-column label="标题" align="center" prop="issuedName"/>
<!--        <el-table-column label="密级" align="center" prop="issuedLevel">-->
<!--          <template slot-scope="scope">-->
<!--            <dict-tag :options="dict.type.secret_level" :value="scope.row.issuedLevel"/>-->
<!--          </template>-->
<!--        </el-table-column>-->
        <el-table-column label="紧急程度" align="center" prop="urgency">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.urgency" :value="scope.row.urgency"/>
          </template>
        </el-table-column>
        <el-table-column label="收文时间" align="center" prop="receiveDate" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.receiveDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="办理期限" align="center" prop="deadline" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.deadline, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="简介" align="center" prop="remarks"/>
        <el-table-column label="状态" align="center" prop="state">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.official_state" :value="scope.row.state"/>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">

            <el-button v-if="taskState==0 && scope.row.receiveType==0" size="mini" icon="el-icon-document-checked"
                       type="text"
                       @click="handle(scope.row)">发起
            </el-button>
            <el-button v-if="taskState==0 && scope.row.receiveType==1" size="mini" icon="el-icon-document-checked"
                       type="text"
                       @click="handle(scope.row)">批阅
            </el-button>
            <el-button v-if="taskState==0 && scope.row.receiveType==2" size="mini" icon="el-icon-document-checked"
                       type="text"
                       @click="handle(scope.row)">传阅
            </el-button>
            <el-button v-if="taskState==1" size="mini" icon="el-icon-view" type="text"
                       @click="view(scope.row)">查看
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

    </el-tabs>

  </div>

</template>

<script>
import {getDocumentFlowList} from "@/api/smartSchool/indexMould/myTask/documentFlow/index.js";

export default {
  name: "Official",
// , 'official_reciver', 'receiver_state'
  dicts: ['secret_level', 'urgency', 'official_state', 'official_reciver'],

  data() {
    return {
      //我的任务--历史人物
      taskState: "0",
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      officialList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        receiveType: undefined,
        issuedNum: undefined,
        issuedName: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        delFlag: [
          {required: true, message: "$comment不能为空", trigger: "blur"}
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 列表 */
    /** 获取列表数据 */
    async getList() {
      let response = null; // 返回结果
      try {
        this.loading = true; // 加载效果
        switch (this.taskState) {
          case '0':
            response = await getDocumentFlowList(0, this.queryParams);
            break;
          case '1':
            response = await getDocumentFlowList(1, this.queryParams);
            break;
        }
        this.loading = false;
        this.officialList = response.rows;
        this.total = response.total;
      } catch (exception) {
        this.loading = false;
      }
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        issuedNum: null,
        issuedName: null,
        issuedLevel: null,
        receiveDate: null,
        deadline: null,
        urgency: null,
        remarks: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        state: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 选中状态改变 */
    handleSelectState({name}) {
      this.taskState = name;
      this.resetQuery();
    },
    // 重置按钮
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        receiveType: null,
        issuedNum: null,
        issuedName: null,
      }
      this.handleQuery(); // 重新发一次请求
    },
    // 搜索按钮
    handleQuery() {
      this.throttle(() => {
        this.queryParams.pageNum = 1;
        this.getList();
      })
    },
    handle(row) {
      console.log(row.receiveType, 223)
      if (row.receiveType == 0) {
        console.log(224)
        this.$router.push({
          path: "/index/myTask/initiator",
          query: {
            id: row.id
          }
        })
      } else if (row.receiveType == 2) {
        console.log(231)
        this.$router.push({
          path: "/index/myTask/reviewer",
          query: {
            id: row.id
          }
        })
      } else if (row.receiveType == 1) {
        console.log(240)
        this.$router.push({
          path: "/index/myTask/circulator",
          query: {
            id: row.id
          }
        })
      }


    },

    view(row) {
      this.$router.push({
        path: '/indexMould/myTask/documentFlow/reviewer',
        query: {
          id: row.id,
          back:'indexMould',
          isRead:1//1表示从历史任务点进来的，0代表第一次进人
        }
      })
    }


  }
};
</script>

<style scoped>

</style>
