<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :topList="topList"
      :moren="moren"
    ></topBar>
    <div class="thetopbox">
      <el-form label-width="100px">
        <el-row>
          <el-col :span="4">
            <!--          <div class="searchbox">-->
            <!--            <div class="searchtitle">业务类型</div>-->
            <!--            <div style="margin-right: 20px">-->
            <el-form-item :label="'业务类型'" prop="status">
              <el-select
                clearable
                v-model="queryParams.approvalBusiness"
                :placeholder="'请选择业务类型'"
              >
                <el-option
                  v-for="item in businesstypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <!--            </div>-->
            <!--          </div>-->
          </el-col>

          <el-col :span="4">
            <div class="searchbox">
              <el-button
                class="my_search"
                style="margin-left: 40px"
                @click="getApprovalList"
                > {{ '搜索' }}</el-button
              >
              <el-button class="my_reset" @click="reChongzhi"> {{ '重置' }}</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="main">
      <div class="maintop">
        <div class="mainbtn">
          <el-button size="mini" class="thebtn1" @click="adddate()"
            >{{'添加'}}</el-button
          >
          <el-button size="mini" class="thebtn2"> {{ '导出' }}</el-button>
        </div>
      </div>
      <div class="maintable">
        <el-table
          :data="tableData"
          v-loading="loading"
          height="700px"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          :row-class-name="tableRowClassName"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="45"> </el-table-column>

          <el-table-column
            align="center"
            prop="approvalBusinessVal"
            :label="'业务类型'"
            width="180"
          >
          </el-table-column>

          <el-table-column align="center" prop="process" label="审批流程">
          </el-table-column>
          <el-table-column align="center" prop="send" :label="'抄送人'">
          </el-table-column>
          <el-table-column
            align="center"
            prop="effectiveDate"
            :label="'生效日期'"
            width="400"
          >
          </el-table-column>

          <el-table-column
            align="center"
            prop="time"
            :label="'操作'"
            fixed="right"
            width="100"
          >
            <template slot-scope="scope">
              <el-button
                class="button-s"
                @click.native.prevent="find(scope.row, tableData)"
                type="text"
                size="small"
                style="color: #4391fd"
              >
                {{ '查看' }}
              </el-button>
              <el-button
                class="button-s"
                @click.native.prevent="deleteRow(scope.row, tableData)"
                type="text"
                size="small"
                style="color: #c73030"
              >
                {{'删除'}}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getApprovalList"
    />
    <el-dialog
      :title="'添加'"
      :visible.sync="updateShow"
      width="70%"
      center
      :before-close="handleClose"
    >
      <div>
        <el-form ref="formList">
          <el-row class="rowone">
            <el-col :span="4">{{ '业务类型' }}</el-col>
            <el-col :span="8"> {{'审批流程'}}</el-col>
            <el-col :span="8">{{'抄送人'}}</el-col>
            <el-col :span="6">{{'生效日期'}}</el-col>
          </el-row>

          <el-row v-for="(item, i) in formList" :key="i">
            <el-col :span="4">
              <el-select clearable v-model="formList[i].approvalBusiness">
                <el-option
                  v-for="item in businesstypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-col>
            <el-col :span="8">
              <div class="rowclass">
                <el-select
                  clearable
                  class="theselect"
                  v-for="(aitem, ai) in formList[i].userIdList"
                  :key="ai"
                  v-model="formList[i].userIdList[ai]"
                >
                  <el-option
                    v-for="item in optionList"
                    :key="item.userId"
                    :label="`${item.nickName + '(' + item.deptName + ')'}`"
                    :value="item.userId"
                  ></el-option>
                </el-select>

                <div style="margin-left: 10px">
                  <el-button
                    circle
                    icon="el-icon-plus"
                    size="small"
                    @click="addoptionList(i)"
                  ></el-button>
                  <el-button
                    circle
                    size="small"
                    icon="el-icon-minus"
                    @click="suboptionList(i)"
                  ></el-button>
                </div>
              </div>
            </el-col>
            <el-col :span="6">
              <div class="rowclass">
                <el-select
                  clearable
                  class="theselect"
                  v-for="(aitem, ai) in formList[i].sendIdList"
                  :key="ai"
                  v-model="formList[i].sendIdList[ai]"
                >
                  <el-option
                    v-for="item in userAllList"
                    :key="item.userId"
                    :label="`${item.nickName + '(' + item.deptName + ')'}`"
                    :value="item.userId"
                  ></el-option>
                </el-select>

                <div style="margin-left: 10px">
                  <el-button
                    circle
                    icon="el-icon-plus"
                    size="small"
                    @click="addoptionList2(i)"
                  ></el-button>
                  <el-button
                    circle
                    size="small"
                    icon="el-icon-minus"
                    @click="suboptionList2(i)"
                  ></el-button>
                </div>
              </div>
            </el-col>
            <el-col :span="6">
              <el-date-picker
                v-model="formList[i].effectiveDate"
                type="date"
                :placeholder="'请选择'"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker>
            </el-col>
          </el-row>
          <el-row>
            <el-col style="text-align: center">
              <el-button
                circle
                icon="el-icon-plus"
                @click="addList()"
              ></el-button>
              <el-button
                circle
                icon="el-icon-minus"
                @click="subList()"
              ></el-button>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="cancels" @click="handleClose">{{'取消'}}</el-button>
        <el-button class="submit" @click="onSubmit()">{{'确认'}}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import topBar from "@/components/topBar";
import {
  getbusinessTypeList,
  getApprovalList,
  deleteApproval,
  getoptionList,
  addApproval,
  getUserAll,
} from "@/api/signing";
export default {
  name: "Qcpz",
  components: {
    topBar,
  },

  data() {
    return {
      moren: "qcpz",
      topList: [
        {
          name: '签呈配置',
          path: "qcpz",
        },
      ],
      businesstypeList: [], //业务类型列表
      tableData: [],
      loading:false,
      multipleSelection: [],
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        approvalBusiness: "",
      },
      updateShow: false,
      optionList: [],
      userAllList: [],
      formList: [
        {
          approvalBusiness: "", //业务类型
          effectiveDate: "", //生效时间
          userIdList: [], //审批流程
          sendIdList: [],
        },
      ],
    };
  },
  created() {
    this.getApprovalList();
    this.getbusinessTypeList();
    this.getoptionList();
    this.getUserAll();
  },
  methods: {
    addList() {
      this.formList.push({
        lapprovalBusiness: "",
        effectiveDate: "",
        userIdList: [],
        sendIdList: [],
      });
    },
    subList() {
      this.formList.pop();
    },
    //添加-审批流程列表
    addoptionList(index) {
      this.formList.forEach((element, i) => {
        if (i == index) {
          this.formList[i].userIdList.push("");
        }
      });
    },
    suboptionList(index) {
      this.formList.forEach((element, i) => {
        if (i == index) {
          this.formList[i].userIdList.pop();
        }
      });
    },
    //添加-审批人列表
    addoptionList2(index) {
      this.formList.forEach((element, i) => {
        if (i == index) {
          this.formList[i].sendIdList.push("");
        }
      });
    },
    suboptionList2(index) {
      this.formList.forEach((element, i) => {
        if (i == index) {
          this.formList[i].sendIdList.pop();
        }
      });
    },
    //获取审批流程下拉选列表
    getoptionList() {
      getoptionList().then((res) => {
        this.optionList = res.data;
      });
    },
    getUserAll() {
      getUserAll().then((res) => {
        this.userAllList = res.data;
      });
    },
    //获取业务类型枚举列表
    getbusinessTypeList() {
      getbusinessTypeList().then((res) => {
        this.businesstypeList = res.data;
      });
    },
    //获取签呈配置列表
    getApprovalList() {
      this.loading = true
      getApprovalList(this.queryParams).then((res) => {
        this.tableData = res.rows;
        this.total = res.total;
        this.loading = false
      });
    },
    //重置
    reChongzhi() {
      this.queryParams.approvalBusiness = "";
    },

    //删除
    deleteRow(row) {
      this.$confirm('确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "warning",
      }).then(() => {
        deleteApproval(row.pkId).then((res) => {
          if (res.code == 200) {
            this.$message({
              message: res.msg,
              type: "success",
            });
            this.getApprovalList();
          } else {
            this.$message({
              message: res.msg,
              type: "warning",
            });
          }
        });
      });
    },
    //点击保存
    onSubmit() {
      addApproval(this.formList).then((res) => {
        if (res.code == 200) {
          this.updateShow = false;
          this.$message({
            message: res.msg,
            type: "success",
          });
          this.getApprovalList();
        } else {
          this.$message({
            message: res.msg,
            type: "warning",
          });
        }
      });
    },
    //查看
    find(row) {
      this.$router.push({
        path: "ckqc",
        query: row,
      });
    },
    //添加
    adddate() {
      this.updateShow = true;
      this.formList = [
        {
          approvalBusiness: "", //业务类型
          effectiveDate: "", //生效时间
          userIdList: [], //审批流程
          sendIdList: [],
        },
      ];
    },
    handleClose() {
      this.updateShow = false;
      this.formList = [
        {
          approvalBusiness: "", //业务类型
          effectiveDate: "", //生效时间
          userIdList: [], //审批流程
          sendIdList: [],
        },
      ];
    },

    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return "warning-row";
      } else if (rowIndex % 2 == 0) {
        return "success-row";
      }
      return "";
    },
  },
};
</script>

  <style lang="scss" scoped>
::v-deep .el-select .el-input .el-select__caret {
  margin-top: 5px;
}
::v-deep .el-input__icon {
  margin-top: -4px;
}
.button-s {
  padding: 0 3px;
}
.submit {
  width: 209px;
  height: 48px;
  background: #c8161d;
  border-radius: 5px;
  color: #fff;
  font-size: 18px;
  border-color: #c8161d;
  margin-left: 20px;
}
.cancels {
  width: 209px;
  height: 48px;
  background: #cccccc;
  border-radius: 5px;
  color: #fff;
  font-size: 18px;
  border-color: #ccc;
}
::v-deep .el-dialog--center .el-dialog__body {
  text-align: center;
  padding: 0 25px 30px 30px;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-row {
  margin-top: 15px;
}
.rowclass {
  display: flex;
  justify-content: center;
  margin-right: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.theselect {
  width: 140px;
}
.rowone {
  font-weight: bold;
  background: #eeeeee;
  height: 50px;
  display: flex;
  align-items: center;
}
.tem {
  display: flex;
  justify-content: center;
  img {
    width: 44px;
    height: 44px;
    border-radius: 8px;
  }
}
.redcolor {
  color: #ed1d25;
}
.greencolor {
  color: #37bf46;
}
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
  .thetopbox {
    padding: 0 20px 0 0;
    background: #ffffff;
    border-radius: 8px;

    .searchbox {
      display: flex;
      align-items: center;
      .searchtitle {
        margin-right: 10px;
      }
      .searchbtn {
        background: #08143f;
        color: #ffffff;
      }
    }
  }
  .main {
    //margin-top: 20px;
    background: #f9f9f9;
    //border-radius: 8px;
    //box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);

    .maintop {
      display: flex;
      // padding: 10px 0;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn1 {
          background: #3181e5;
          color: #ffffff;
        }
        .thebtn2 {
          background: #ffad41;
          color: #ffffff;
        }
      }
    }
  }
}
</style>
