<template>
  <div id="AccountTag">
    <el-dialog
      :visible.sync="dialogVisible"
      width="460px"
      :show-close="false"
      :close-on-click-modal="false"
    >
      <div slot="title" class="hearders">
        <div class="leftTitle">
          {{
            stice == 1
              ? "学习完成状态标记"
              : stice == 4
              ? "学习账号开通状态标记"
              : stice == 3
              ? "移除学员"
              : ""
          }}
        </div>
        <div class="rightBoxs">
          <img
            src="@/assets/images/Close@2x.png"
            alt=""
            @click="dialogVisible = false"
          />
        </div>
      </div>
      <div>
        <ul>
          <li
            v-for="(item, index) in allCheckList"
            :key="index"
            class="btnLists"
          >
            {{ item.realname }}
            <i
              class="el-icon-close btnIcon"
              v-if="allCheckList.length > 1"
              @click="clearStudent(index)"
            ></i>
          </li>
          <div style="clear: both"></div>
          <p>
            {{
              stice == 1
                ? "请对以上所选学员进行学习完成状态标记："
                : stice == 3
                ? "是否移除所选中的学员？"
                : stice == 4
                ? "请对以上所选学员进行账号开通状态标记："
                : ""
            }}
          </p>
          <div style="text-align: center">
            <el-radio-group v-model="finishStatusOS" v-if="stice == 1">
              <el-radio :label="1">已学完</el-radio>
              <el-radio :label="0">未学完</el-radio>
            </el-radio-group>
            <el-radio-group
              v-model="finishStatusOS"
              v-if="stice == 4"
              @change="failReason = ''"
            >
              <el-radio :label="1">已开通</el-radio>
              <el-radio :label="0">未开通</el-radio>
              <el-radio :label="2">标记失败</el-radio>
            </el-radio-group>
          </div>
          <div v-if="stice == 4 && finishStatusOS === 2">
            <p>失败原因：</p>
            <el-input type="textarea" v-model="failReason"></el-input>
          </div>
        </ul>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dialogVisible: false,
      stice: "",
      allCheckList: [],
      finishStatusOS: "",
      failReason: "",
    };
  },
  methods: {
    clearStudent(index) {
      this.allCheckList.splice(index, 1);
    },
    openBox(int, array, status) {
      this.stice = int;
      this.allCheckList = JSON.parse(JSON.stringify(array));
      this.finishStatusOS = "";
      if (status) {
        this.initData();
      }
      this.dialogVisible = true;
    },
    /**
     * 修改回填
     */
    initData() {
      if (this.stice === 1) {
        this.finishStatusOS = this.allCheckList[0].finishStatus;
      }
      if (this.stice === 4) {
        this.finishStatusOS = this.allCheckList[0].learnStatus;
        if (this.finishStatusOS === 2) {
          this.failReason = this.allCheckList[0].reason;
        }
      }
    },
    submit() {
      if (!this.allCheckList.length) {
        this.dialogVisible = false;
        return;
      }
      let ars = [];
      this.allCheckList.map((item) => {
        ars.push(item.id);
      });
      let data = {
        id: ars,
      };
      if (this.stice === 1 || this.stice === 4) {
        if (this.stice === 1) {
          if (this.finishStatusOS !== 0 && this.finishStatusOS !== 1) {
            this.$message.warning("请进行学习完成状态标记");
            return;
          }
        }
        if (this.stice === 4) {
          if (
            this.finishStatusOS !== 0 &&
            this.finishStatusOS !== 1 &&
            this.finishStatusOS !== 2
          ) {
            this.$message.warning("请选择账号开通状态标记");
            return;
          }
        }
        if (this.stice === 1) {
          data.finishStatus = this.finishStatusOS;
        }
        if (this.stice === 4) {
          data.learnStatus = this.finishStatusOS;
          if (this.finishStatusOS === 2) {
            if (!this.failReason) {
              this.$message.error("请填写失败原因");
              return;
            }
            data.reason = this.failReason;
          }
        }
      }
      if (this.stice === 3) {
        data.status = 0;
      }
      this.$api.editGradeUserGradegrade(data).then((res) => {
        this.$message.success("成功");
        this.$emit("successFuncBack");
        this.dialogVisible = false;
      });
    },
  },
};
</script>

<style lang="less" scoped>
.dis__s {
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.btnLists {
  float: left;
  border: 1px solid #333;
  padding: 0px 10px;
  margin-right: 10px;
  margin-bottom: 10px;
  border-radius: 4px;
  height: 30px;
  line-height: 30px;
  .btnIcon {
    cursor: pointer;
    transition: all 0.2s;
    &:hover {
      color: blue;
    }
  }
}
/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;
  }
}
/deep/.radioTables > .el-radio__label {
  display: none;
}
</style>
