<!--
 * @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="40">
            <!-- 一层 -->
            <el-col :span="4">
              <el-form-item :label="$t('MN_F_9')">
                <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="$t('MN_F_T_520')">
                <el-input
                  clearable
                  v-model="select.userName"
                  :placeholder="$t('S_C_70')"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="$t('MN_F_T_529')">
                <el-select clearable v-model="select.receiveStatus">
                  <el-option
                    v-for="item in readStateList"
                    :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="$t('PER_DA_9')">
                <el-date-picker
                  v-model="select.creationTime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  type="daterange"
                  :range-separator="$t('w_0139')"
                  :start-placeholder="$t('CK_KS_4')"
                  :end-placeholder="$t('CK_KS_5')"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item :label="$t('MN_F_Y_3')">
                <el-date-picker
                  v-model="select.sendTime"
                  value-format="yyyy-MM-dd"
                  type="daterange"
                  :range-separator="$t('w_0139')"
                  :start-placeholder="$t('CK_KS_4')"
                  :end-placeholder="$t('CK_KS_5')"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-button type="primary" @click="getDataList1">
                {{ $t("MN_T_2") }}</el-button
              >
              <el-button @click="reset"> {{ $t("MN_T_3") }}</el-button>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="main_a">
        <div class="mainbtn">
          <el-button
            size="small"
            :disabled="pkIdList.length == 0"
            @click="toReceive(0)"
            type="success"
            >{{ $t("MN_F_T_3") }}</el-button
          >
          <el-button size="small" @click="handleExport" class="exportBtn">
            {{ $t("MN_T_8") }}</el-button
          >
        </div>
      </div>
      <el-table
        :data="tableData1"
        style="width: 100%"
        height="100%"
        v-loading="loading"
        @selection-change="handleSelectionChange"
        :header-cell-style="{ background: '#EEEEEE' }"
        :row-class-name="tableRowClassName"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column
          align="center"
          prop="userName"
          :label="$t('MN_F_T_520')"
        >
        </el-table-column>
        <el-table-column
          align="center"
          prop="approvalBusinessVal"
          :label="$t('MN_F_9')"
        >
        </el-table-column>

        <el-table-column
          align="center"
          prop="receiveStatusVal"
          :label="$t('MN_F_T_529')"
        >
          <template slot-scope="scope">
            <div :class="scope.row.receiveStatus == 1 ? 'act' : 'act2'">
              {{ scope.row.receiveStatusVal }}
            </div>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="creationTime"
          :label="$t('PER_DA_9')"
        >
        </el-table-column>
        <el-table-column align="center" prop="sendTime" :label="$t('MN_F_Y_3')">
        </el-table-column>

        <el-table-column
          align="center"
          prop="time"
          :label="$t('MY_ORD_14')"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              style="color: #48b2fd"
              @click="toFixed(scope.row.approvalCode, 2, scope.row.pkId)"
              type="text"
              size="small"
            >
              {{ $t("MN_F_15") }}
            </el-button>
            <el-button
              style="color: #53b11e"
              v-show="scope.row.receiveStatus == 1"
              @click="toReceive(1, scope.row.pkId)"
              type="text"
              size="small"
            >
              {{ $t("MN_F_T_3") }}
            </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: "receiveIndex",
      topList: [
        {
          name: "代办",
          path: "dashboard",
        },
        {
          name: "已办",
          path: "hasIndex",
        },
        {
          name: "抄送查阅/操作",
          path: "receiveIndex",
        },
        // {
        //   name: this.$t('MN_F_T_4'),
        //   path: 'goodsCheck',
        // },
        // {
        //   name: this.$t('MN_F_T_5'),
        //   path: 'productCheck',
        // },
      ],
      ywsqList: [],
      checkList: [],
      sourceList: [],
      approveStatusList: [],
      pkIdList: [],
      readStateList: [],
      waitApprovalNum: "",
      receiveApprovalNum: "",
    };
  },
  mounted() {
    // 获取列表
    this.getDataList1();
    this.getApprove();
    this.getSignType();
    this.getSource();
    this.getreadState();
    this.getApprovalStatus();
  },
  methods: {
    reset() {
      this.select = {};
      this.getDataList1();
    },
    getApprove() {
      api.approvalBusiness().then((res) => {
        this.ywsqList = res.data;
      });
    },
    getreadState() {
      api.readState().then((res) => {
        this.readStateList = 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;
      });
    },
    getDataList1() {
      this.loading = true;
      api
        .receiveApprovalList(Object.assign({}, this.queryParams, this.select))
        .then((res) => {
          this.loading = false;
          this.tableData1 = res.rows;
          this.total = res.total;
        });
    },
    handleSelectionChange(val) {
      if (val.length > 0) {
        let pkIdList = val.map((item) => {
          return item.pkId;
        });
        this.pkIdList = pkIdList;
        console.log(
          "%c [ this.pkIdList ]-274",
          "font-size:13px; background:#69b38c; color:#adf7d0;",
          this.pkIdList
        );
      } else {
        this.pkIdList = [];
      }
    },
    toReceive(index, id) {
      if (index) {
        this.pkIdList = [id];
      }
      api
        .receiveApproval({
          pkIdList: this.pkIdList,
        })
        .then((res) => {
          if (res.code == 200) {
            this.$message({
              type: "success",
              message: res.msg,
            });
            this.getDataList1();
            this.getApprovalStatus();
          }
        });
    },
    toFixed(id, index, pkId) {
      this.$router.push({
        path: "manageDetails",
        query: {
          id: id,
          index: index,
          pkId: pkId,
        },
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.$confirm(this.$t("MN_F_T_407"), this.$t("MN_F_T_304"), {
        confirmButtonText: this.$t("w_0035"),
        cancelButtonText: this.$t("ENU_P_TYPE0"),
        type: "warning",
      }).then((_) => {
        this.download(
          "/system/manage/index/receive-approval-export",
          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 20px;
  // 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 20px;
  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>
