<!--
 * @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"
      :top-list="topList"
      :moren="defaultTabItem"
      :wait-approval-num="waitApprovalNum"
      :receive-approval-num="receiveApprovalNum"
    />
    <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="'业务类型'">
                <el-select
                  v-model="select.approvalBusiness"
                  clearable
                  filterable
                >
                  <el-option
                    v-for="item in ywsqList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="'发起人'">
                <el-input
                  v-model="select.userName"
                  clearable
                  :placeholder="'请输入'"
                />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="'签呈状态'">
                <el-select v-model="select.receiveStatus" clearable>
                  <el-option
                    v-for="item in readStateList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </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 HH:mm:ss"
                  type="daterange"
                  :range-separator="'至'"
                  :start-placeholder="'开始日期'"
                  :end-placeholder="'结束日期'"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item :label="'终审日期'">
                <el-date-picker
                  v-model="select.sendTime"
                  value-format="yyyy-MM-dd"
                  type="daterange"
                  :range-separator="'至'"
                  :start-placeholder="'开始日期'"
                  :end-placeholder="'结束日期'"
                />
              </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"
            :disabled="pkIdList.length == 0"
            type="success"
            @click="toReceive(0)"
          >{{ '接收' }}</el-button>
          <el-button size="small" class="exportBtn" @click="handleExport">
            {{ '导出' }}</el-button>
        </div>
      </div>
      <el-table
        v-loading="loading"
        :data="tableData1"
        style="width: 100%"
        height="100%"
        :header-cell-style="{ background: '#EEEEEE' }"
        :row-class-name="tableRowClassName"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column
          align="center"
          prop="userName"
          :label="'发起人'"
        />
        <el-table-column
          align="center"
          prop="approvalBusinessVal"
          :label="'业务类型'"
        />

        <el-table-column
          align="center"
          prop="receiveStatusVal"
          :label="'签呈状态'"
        >
          <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="'创建日期'"
        />
        <el-table-column align="center" prop="sendTime" :label="'终审日期'" />

        <el-table-column
          align="center"
          prop="time"
          :label="'操作'"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              style="color: #48b2fd"
              type="text"
              size="small"
              @click="toFixed(scope.row.approvalCode, 2, scope.row.pkId)"
            >
              {{ '查看签呈' }}
            </el-button>
            <el-button
              v-show="scope.row.receiveStatus == 1"
              style="color: #53b11e"
              type="text"
              size="small"
              @click="toReceive(1, scope.row.pkId)"
            >
              {{ '接收' }}
            </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'
import topBarMixin from './mixins/top-bar-mixin'
export default {
  name: 'Dashboard',
  components: {
    topBar
  },
  mixins: [topBarMixin],
  computed: {
    ...mapGetters(['name'])
  },
  data() {
    return {
      loading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 50
      },
      total: 0,
      tableData: [],
      tableData1: [],
      tabActive: 0,
      select: {},
      defaultTabItem: 'receiveIndex',
      ywsqList: [],
      checkList: [],
      sourceList: [],
      pkIdList: [],
      readStateList: []

    }
  },
  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
      })
    },

    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) {
        const 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('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        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>
