<template>
  <div id="assignReviewers">
    <div class="floatSty">
      <div class="headsty">资料审核管理</div>
      <div class="dis_sty">
        <div class="btnSty" @click="getInfo(1)">资料审核</div>
        <!-- <div class="btnSty" @click="getInfo(2)">盖章资料审核</div> -->
      </div>
    </div>
    <div class="floatSty">
      <div class="headsty">网课学习管理</div>
      <div class="dis_sty">
        <div class="btnSty" @click="getInfo(2)">学时审核</div>
      </div>
    </div>
    <div class="floatSty">
      <div class="headsty">订单管理</div>
      <div class="dis_sty">
        <div class="btnSty" @click="getInfo(3)">退款审核</div>
      </div>
    </div>
    <div style="clear: both"></div>
    <el-dialog
      :visible.sync="dialogVisible"
      width="610px"
      :show-close="false"
      :close-on-click-modal="false"
    >
      <div slot="title" class="hearders">
        <div class="leftTitle">{{ getName(statePop) }}</div>
        <div class="rightBoxs">
          <img
            src="@/assets/images/Close@2x.png"
            alt=""
            @click="dialogVisible = false"
          />
        </div>
      </div>
      <div>
        <el-row :gutter="20">
          <el-col :span="12" class="leftBox">
            <div
              v-for="(item, index) in educationType"
              :key="index"
              style="margin-bottom: 6px"
            >
              <div
                @click="getFist(item.id)"
                style="cursor: pointer; margin-bottom: 6px"
              >
                <i
                  :class="
                    item.id === activeFist
                      ? 'el-icon-caret-bottom'
                      : 'el-icon-caret-right'
                  "
                ></i>
                {{ item.onlyName }}
              </div>
              <ul
                v-if="item.id === activeFist"
                style="margin: 0px; padding-left: 18px"
              >
                <li
                  v-for="(items, indexs) in item.children"
                  :key="indexs"
                  style="margin-bottom: 4px; cursor: pointer"
                  :style="businessId === items.id ? 'color:red;' : ''"
                  @click="getapiUserList(items)"
                >
                  {{ items.onlyName }}
                </li>
                <li v-if="!item.children.length" style="color: blue">
                  暂无选项
                </li>
              </ul>
            </div>
          </el-col>
          <el-col :span="12" v-if="businessId">
            <el-select
              v-model="activeUserid"
              placeholder="请选择审核人"
              @change="editUserList"
            >
              <el-option
                v-for="(item, index) in options"
                :key="index"
                :label="item.nickName"
                :value="item.userId"
                :disabled="userList1.indexOf(item.userId) !== -1"
              >
              </el-option>
            </el-select>
            <ul style="max-height: 300px; overflow: auto">
              <li
                v-for="(item, index) in userList1"
                :key="index"
                class="userName"
              >
                {{ getuserName(item) }}
                <i
                  class="el-icon-error clearSty"
                  @click="userList1.splice(index, 1)"
                ></i>
                <div style="clear: both"></div>
              </li>
            </ul>
            <div v-if="statePop === 2 || statePop === 3">
              <el-select
                v-model="activeUserid"
                placeholder="请选择复审人"
                @change="editUserLists"
              >
                <el-option
                  v-for="(item, index) in options"
                  :key="index"
                  :label="item.nickName"
                  :value="item.userId"
                  :disabled="userList2.indexOf(item.userId) !== -1"
                >
                </el-option>
              </el-select>
              <ul style="max-height: 300px; overflow: auto">
                <li
                  v-for="(item, index) in userList2"
                  :key="index"
                  class="userName"
                >
                  {{ getuserName(item) }}
                  <i
                    class="el-icon-error clearSty"
                    @click="userList2.splice(index, 1)"
                  ></i>
                  <div style="clear: both"></div>
                </li>
              </ul>
            </div>
            <div style="text-align: center">
              <el-button size="mini" @click="submits">确定</el-button>
            </div>
          </el-col>
        </el-row>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dialogVisible: false,
      statePop: "",
      educationType: [],
      options: [], //审核人列表
      activeUserid: "", //select的v-model绑定值
      activeFist: "", //当前选中教育类型ID
      businessId: "",
      userList1: [],
      userList2: [],
    };
  },
  mounted() {
    this.getTypes();
  },
  methods: {
    /**
     *
     * @param {Number} int
     * @remards 点击教育类型触发
     */
    getFist(int) {
      if (this.activeFist === int) {
        this.activeFist = "";
      } else {
        this.activeFist = int;
      }
    },
    /**
     * 确定提交修改
     */
    submits() {
      if (!this.userList1.length) {
        this.$message.warning("请选择指派审核人");
        return;
      }

      if (this.statePop === 2 || this.statePop === 3) {
        if (!this.userList2.length) {
          this.$message.warning("请选择指派复审人");
          return;
        }
      }
      /**
       * 提交api
       */
      if (this.statePop === 1) {
        let ays = {
          id: this.businessId,
          profileTpUserIds: this.userList1.toString(),
          // userList2: this.userList2,
        };
        this.$api.editcourseBusinessProfileTpUserIds(ays).then((res) => {
          this.$message.success("指派成功");
        });
      }
      if (this.statePop === 2) {
        let ays = {
          id: this.businessId,
          periodUserIds: this.userList1.toString(),
          periodConfirmUserIds: this.userList2.toString(),
        };
        this.$api.editcourseBusinessPeriodUserIds(ays).then((res) => {
          this.$message.success("指派成功");
        });
      }
      if (this.statePop === 3) {
        let ays = {
          id: this.businessId,
          refundUserIds: this.userList1.toString(),
          refundConfirmUserIds: this.userList2.toString(),
        };
        this.$api.editRefundPeriodUserIdsCourseBusiness(ays).then((res) => {
          this.$message.success("指派成功");
        });
      }
    },
    /**
     *
     * @param {Number} int
     * @remards 新增审核人
     */
    editUserList(int) {
      this.userList1.push(int);
      this.activeUserid = "";
    },
    /**
     *
     * @param {Number} int
     * @remards 新增复审人
     */
    editUserLists(int) {
      this.userList2.push(int);
      this.activeUserid = "";
    },
    /**
     * 点击业务层次获取对应审核人
     */
    getapiUserList(item) {
      this.businessId = item.id;
      /**
       * 模拟数据
       */
      this.userList1 = [];
      this.userList2 = [];
      this.$api
        .inquiresystemUserbusinessPeopleList({ id: item.id })
        .then((res) => {
          this.options = res.rows;
          this.$api.obtainbusiness(item.id).then((result) => {
            if (this.statePop === 1) {
              if (result.data.profileTpUserIds) {
                this.userList1 = result.data.profileTpUserIds
                  .split(",")
                  .map(Number);
              }
            }
            if (this.statePop === 2) {
              if (result.data.periodUserIds) {
                this.userList1 = result.data.periodUserIds
                  .split(",")
                  .map(Number);
              }
              if (result.data.periodConfirmUserIds) {
                this.userList2 = result.data.periodConfirmUserIds
                  .split(",")
                  .map(Number);
              }
            }
            if (this.statePop === 3) {
              if (result.data.refundUserIds) {
                this.userList1 = result.data.refundUserIds
                  .split(",")
                  .map(Number);
              }
              if (result.data.refundConfirmUserIds) {
                this.userList2 = result.data.refundConfirmUserIds
                  .split(",")
                  .map(Number);
              }
            }
          });
        });
    },
    /**
     * 获取教育类型及业务层次
     */
    getTypes() {
      this.$api.inquireCourseEducationType({ status: 1 }).then((res) => {
        this.$api.inquirebusinessList({ status: 1 }).then((result) => {
          result.rows.forEach((items) => {
            items.onlyName = items.projectName + "-" + items.businessName;
            res.rows.forEach((ite, ide) => {
              ite.onlyName = ite.educationName;
              ite.checked = false;
              if (!ite.children) {
                ite.children = [];
              }
              if (items.educationId === ite.id) {
                ite.children.push(items);
              }
            });
          });
          this.educationType = res.rows;
        });
      });
    },
    /**
     * 获取标题
     */
    getName(int) {
      var ast = "";
      switch (int) {
        case 1:
          ast = "资料审核-指派审核人";
          break;
        case 2:
          ast = "学时审核-指派审核人";
          break;
        case 3:
          ast = "退款审核-指派审核人";
          break;
        default:
          break;
      }
      return ast;
    },
    /**
     * 转换审核人名字
     */
    getuserName(int) {
      var ast = "";
      for (let i = 0; i < this.options.length; i++) {
        if (this.options[i].userId === int) {
          return this.options[i].nickName;
        }
      }
    },
    /**
     *
     * @param {Number} int 1资料审核2学时审核
     * 初始化窗口数据
     */
    getInfo(int) {
      this.statePop = int;
      this.activeFist = "";
      this.activeUserid = "";
      this.businessId = "";
      this.userList1 = [];
      this.userList2 = [];
      this.dialogVisible = true;
    },
  },
};
</script>

<style lang="less" scoped>
.leftBox {
  border: 1px solid #999;
  border-radius: 4px;
  overflow-y: auto;
  max-height: 400px;
  padding: 10px;
}
.floatSty {
  float: left;
  margin-right: 20px;
  margin-bottom: 20px;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid #999;
  .headsty {
    height: 30px;
    line-height: 30px;
    background-color: #eee;
    color: #333;
    text-align: center;
    font-size: 14px;
  }
  .dis_sty {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    .btnSty {
      padding: 0px 10px;
      height: 28px;
      line-height: 28px;
      text-align: center;
      border-radius: 4px;
      border: 1px solid #999;
      font-size: 14px;
      margin-bottom: 10px;
      cursor: pointer;
      transition: all 0.2s;
      &:hover {
        background-color: #f4f4f4;
      }
    }
  }
}
/deep/.el-button {
  border-radius: 8px;
}
/deep/.el-dialog {
  border-radius: 8px;
  .el-dialog__header {
    padding: 0;
    .hearders {
      height: 40px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0px 18px 0px 20px;
      border-bottom: 1px solid #e2e2e2;
      .leftTitle {
        font-size: 14px;
        font-weight: bold;
        color: #2f4378;
      }
      .rightBoxs {
        display: flex;
        align-items: center;
        img {
          width: 14px;
          height: 14px;
          margin-left: 13px;
          cursor: pointer;
        }
      }
    }
  }
  .el-dialog__footer {
    padding: 0;
    .dialog-footer {
      padding: 0px 40px;
      height: 70px;
      border-top: 1px solid #e2e2e2;
      display: flex;
      align-items: center;
      justify-content: flex-end;
    }
  }
}
.imgBox {
  width: 100%;
  // height: 210px;
  border: 1px solid #e2e2e2;
  border-radius: 8px;
  padding: 8px 8px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  .imgLabel {
    flex: 1;
    width: 100%;
    border: 1px dotted #e2e2e2;
    color: #999;
    font-size: 14px;
    cursor: pointer;
    border-radius: 8px;
    .msPhoto {
      display: flex;
      justify-content: center;
      align-items: center;
      max-width: 100%;
      max-height: 270px;
      img {
        max-width: 100%;
        max-height: 270px;
      }
    }
    .imgbbx {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 100%;
      i {
        font-weight: bold;
        margin: 14px 0;
        font-size: 24px;
      }
    }
  }
  p {
    margin: 5px 0px;
  }
}
.userName {
  display: table;
  border-radius: 4px;
  border: 1px solid #999;
  margin: 0px 6px 6px 0px;
  padding: 0px 8px;
  height: 26px;
  line-height: 26px;
  font-size: 14px;
  .clearSty {
    color: red;
    cursor: pointer;
    font-size: 14px;
  }
}
</style>
