<!--
 * @Descripttion:
 * @version:
 * @Author: kBank
 * @Date: 2023-03-21 17:14:47
-->
<!--
 * @Descripttion:
 * @version:
 * @Author: kBank
 * @Date: 2022-10-24 10:45:39
-->
<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :topList="topList"
      :moren="moren"
      :waitApprovalNum="waitApprovalNum"
      :receiveApprovalNum="receiveApprovalNum"
    ></topBar>
    <div class="main">
      <div class="form_all">
        <el-form ref="select" :model="select" label-width="auto">
          <el-row :gutter="10">
            <el-col :span="4">
              <!-- <el-form-item :label="'来源'">
                <el-select clearable
                           v-model="select.signSource">
                  <el-option v-for="item in sourceList"
                             :key="item.value"
                             :label="item.label"
                             :value="item.value"></el-option>
                </el-select>
              </el-form-item> -->
              <el-form-item label="签呈编号">
                <el-input
                  clearable
                  v-model="select.approvalCode"
                  :placeholder="'请输入'"
                ></el-input>
              </el-form-item>
            </el-col>
            <!-- 一层 -->
            <el-col :span="4">
              <el-form-item :label="'业务类型'">
                <el-select
                  clearable
                  filterable
                  v-model="select.approvalBusiness"
                >
                  <el-option
                    v-for="item in ywsqList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="业务类型内容">
                <el-input
                  clearable
                  v-model="select.approvalBusinessVal"
                  :placeholder="'请输入'"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="情况说明">
                <el-input
                  clearable
                  v-model="select.remark"
                  :placeholder="'请输入'"
                ></el-input>
              </el-form-item>
            </el-col>
            <!-- <el-col :span="4">
              <el-form-item :label="'审核状态'">
                <el-select clearable
                           v-model="select.approvalOperation">
                  <el-option v-for="item in checkList"
                             :key="item.value"
                             :label="item.label"
                             :value="item.value"></el-option>
                </el-select>
              </el-form-item>
            </el-col> -->
            <el-col :span="4">
              <el-form-item :label="'签呈状态'">
                <el-select clearable v-model="select.approveStatus">
                  <el-option
                    v-for="item in approveStatusList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item :label="'创建日期'">
                <el-date-picker
                  v-model="select.creationTime"
                  value-format="yyyy-MM-dd"
                  type="daterange"
                  :range-separator="'至'"
                  :start-placeholder="'开始日期'"
                  :end-placeholder="'结束日期'"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item :label="'终审日期'">
                <el-date-picker
                  v-model="select.endTime"
                  value-format="yyyy-MM-dd"
                  type="daterange"
                  :range-separator="'至'"
                  :start-placeholder="'开始日期'"
                  :end-placeholder="'结束日期'"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-button type="primary" @click="getDataList1">
                {{ '搜索' }}</el-button
              >
              <el-button @click="reset"> {{ '重置' }}</el-button>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="main_a">
        <div class="mainbtn">
          <el-button size="small" @click="handleExport" class="exportBtn">
            {{ '导出' }}</el-button
          >
        </div>
      </div>
      <el-table
        :data="tableData1"
        style="width: 100%"
        height="100%"
        v-loading="loading"
        :header-cell-style="{ background: '#EEEEEE' }"
        :row-class-name="tableRowClassName"
      >
        <el-table-column align="center" prop="approvalCode" label="签呈编号">
        </el-table-column>
        <el-table-column
          align="center"
          prop="approvalBusinessVal"
          :label="'业务类型'"
        >
        </el-table-column>
        <el-table-column
          align="center"
          prop="parentClassifyName"
          :min-width="300"
          :label="'签呈进度'"
        >
          <!-- <template slot-scope="scope">
            <div class="bz_a">
              <div class="bz_i"
                   v-for="(item,index) in scope.row.detailList"
                   :key="item.deptName">
                <div :class="item.useTime == undefined?'qiu':'quan'"></div>
                <div :class="scope.row.detailList[index+1].useTime == undefined?'gun1':'gun'"
                     v-if="index!=scope.row.detailList.length-1"></div>
                <div class="time">{{ item.useTime }}</div>
                <div class="zhi">{{ item.deptName }}</div>
              </div>
            </div>
          </template> -->
          <template slot-scope="scope">
            <div class="bz_a">
              <div
                class="bz_i"
                v-for="(item, index) in scope.row.detailList"
                :key="index"
              >
                <div :class="item.useTime == undefined ? 'qiu' : 'quan'"></div>
                <div
                  :class="
                    scope.row.detailList[index + 1].useTime == undefined
                      ? 'gun1'
                      : 'gun'
                  "
                  v-if="index != scope.row.detailList.length - 1"
                ></div>
                <div class="time">{{ item.useTime }}</div>
                <div class="zhi">
                  <div>{{ item.nickName }}</div>
                  <div>({{ item.deptName }})</div>
                </div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="sendStr"
          :label="'抄送人'"
        >
          <template slot-scope="scope">
            <div
              :class="
                scope.row.receiveList.length > 0 &&
                scope.row.receiveList[0].receiveStatus == 1
                  ? 'act'
                  : 'act2'
              "
            >
              {{ scope.row.sendStr }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="useTime"
          :label="'总耗时'"
        >
        </el-table-column>
        <!-- <el-table-column align="center"
                         prop="approvalOperationVal"
                         :label="'审核状态'">
        </el-table-column> -->
        <el-table-column
          align="center"
          prop="approveStatusVal"
          :label="'签呈状态'"
        >
        </el-table-column>
        <!-- <el-table-column align="center"
                         prop="remark"
                         label="情况说明">
        </el-table-column> -->
        <el-table-column
          align="center"
          prop="creationTime"
          :label="'创建日期'"
        >
        </el-table-column>
        <el-table-column align="center" prop="endTime" :label="'终审日期'">
        </el-table-column>

        <el-table-column
          align="center"
          prop="time"
          :label="'操作'"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              @click="toFixed(scope.row.approvalCode, 1)"
              type="text"
              size="small"
            >
              {{ '查看签呈' }}
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getDataList1"
      />
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import * as api from "@/api/manage.js";
import topBar from "@/components/topBar";

export default {
  name: "Dashboard",
  components: {
    topBar,
  },
  computed: {
    ...mapGetters(["name"]),
  },
  data() {
    return {
      loading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 50,
      },
      total: 0,
      tableData: [],
      tableData1: [],
      tabActive: 0,
      select: {},
      moren: "hasIndex",
      topList: [
        {
          name: "代办",
          path: "dashboard",
        },
        {
          name: "已办",
          path: "hasIndex",
        },
        {
          name: "抄送查阅/操作",
          path: "receiveIndex",
        },
        // {
        //   name: '商品审核',
        //   path: 'goodsCheck',
        // },
        // {
        //   name: '产品审核',
        //   path: 'productCheck',
        // },
      ],
      ywsqList: [],
      checkList: [],
      sourceList: [],
      approveStatusList: [],
      waitApprovalNum: "",
      receiveApprovalNum: "",
    };
  },
  mounted() {
    // 获取列表
    this.getDataList1();
    this.getApprove();
    this.getSignType();
    this.getSource();
    this.getApprovalStatus();
  },
  methods: {
    reset() {
      this.select = {};
      this.getDataList1();
    },
    getApprove() {
      api.approvalBusiness().then((res) => {
        this.ywsqList = res.data;
      });
    },
    getSource() {
      api.signSource().then((res) => {
        this.sourceList = res.data;
      });
    },
    getSignType() {
      api.approvalOperation().then((res) => {
        this.checkList = res.data;
      });
    },
    getApprovalStatus() {
      api.approvalStatus().then((res) => {
        this.approveStatusList = res.data;
      });
      api.waitApprovalNum().then((res) => {
        this.waitApprovalNum = res.data;
      });
      api.receiveApprovalNum().then((res) => {
        this.receiveApprovalNum = res.data;
      });
    },
    // 切换tab
    handleLink(id) {
      this.tabActive = id;
      if (id == 0) {
        // 获取列表
        this.getDataList();
      } else {
        // 获取列表
        this.getDataList1();
      }
    },
    getDataList() {
      api.waitApproval().then((res) => {
        this.tableData = res.data;
      });
    },
    getDataList1() {
      this.loading = true;
      api
        .completeApproval(Object.assign({}, this.queryParams, this.select))
        .then((res) => {
          this.loading = false;
          this.tableData1 = res.rows;
          this.total = res.total;
        });
    },
    toFixed(id, index) {
      this.$router.push({
        path: "manageDetails",
        query: {
          id: id,
          index: index,
        },
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "warning",
      }).then((_) => {
        this.download(
          "/system/manage/index/export-approval",
          Object.assign({}, this.queryParams, this.select),
          `已办${new Date().getTime()}.xlsx`
        );
      });
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return "warning-row";
      } else if (rowIndex % 2 == 0) {
        return "success-row";
      }
      return "";
    },
  },
};
</script>

<style lang="scss" scoped>
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
}
.main {
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
}
.form_all {
  padding: 0px 20px 0 0px;
  // margin-bottom: 20px;
  background: #fff;
  border-radius: 8px;
}
.topbox {
  align-items: center;
  padding: 0px 0 3px 0;
  display: flex;
  //   background: skyblue;
  .levelList_i {
    margin-left: 20px;
    position: relative;
    cursor: pointer;
    padding: 0 5px;
    width: 88px;
    height: 34px;
    border-radius: 17px;
    border: 1px solid #cccccc;
    font-size: 14px;
    font-family: MicrosoftYaHei;
    text-align: center;
    line-height: 34px;
  }
  .act {
    color: #ffffff;
    background: #08143f;
  }
  .act1 {
    border-bottom: 3px solid #1890ff !important;
  }
  .cha {
    font-size: 16px;
    color: #606266;
    position: absolute;
    top: 10px;
  }
  .li {
    width: 40px;
    margin: 0 auto;
    border-bottom: 3px solid transparent;
  }
}
.main_a {
  display: flex;
  padding: 0px 20px 0px 0px;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  border-radius: 8px;
}
.bz_a {
  display: flex;
  // justify-content: center;
  // padding-left: 80px;
  // padding:0px 0 45px 80px;
  padding: 35px 0;
  // padding-left: 30px;
  display: flex;
  justify-content: center;
  .bz_i {
    display: flex;
    // flex-direction: column;
    align-items: center;
    position: relative;
    // padding: 20px 0;
    .quan {
      width: 14px;
      height: 14px;
      border: 2px solid #1678ff;
      border-radius: 50%;
    }
    .qiu {
      width: 14px;
      height: 14px;
      background: #ccc;
      border-radius: 50%;
    }
    .gun {
      width: 60px;
      height: 2px;
      background: #1678ff;
    }
    .gun1 {
      width: 60px;
      height: 2px;
      background: #ccc;
    }
    .time {
      position: absolute;
      top: -20px;
      left: -80px;
      // transform: translateX(-120%);
      font-size: 10px;
      font-family: PingFang SC-Regular, PingFang SC;
      font-weight: 400;
      color: #999999;
      width: 50px;
      white-space: nowrap;
    }
    .zhi {
      line-height: 14px;
      font-size: 8px;
      font-family: PingFang SC-Regular, PingFang SC;
      font-weight: 400;
      color: #999999;
      position: absolute;
      left: 3px;
      // right: 0;
      transform: translateX(-45%);
      bottom: -30px;
      white-space: nowrap;
    }
  }
  .bz_i:last-child {
    // width: 100px;
  }
}
::v-deep .el-date-editor--daterange {
  width: 100%;
}
.act {
  color: #e41b1b;
}
.act2 {
  color: rgb(83, 177, 30);
}
</style>
