<template>
  <div class="disFlex">
    <NavLeft navIf="topicParameters projectManagement" />

    <div class="topicParametersCon projectManagement">
      <div class="title">项目管理</div>
      <div class="topicParametersConLsit">
        <div class="topicParametersNav">
          <p
            @click="topicParametersNavIfFun(1)"
            :class="topicParametersNavIf == 1 ? 'topicParametersNavIf' : ''"
          >
            题型一
          </p>
          <p
            @click="topicParametersNavIfFun(2)"
            :class="topicParametersNavIf == 2 ? 'topicParametersNavIf' : ''"
          >
            题型二
          </p>
          <p
            @click="topicParametersNavIfFun(3)"
            :class="topicParametersNavIf == 3 ? 'topicParametersNavIf' : ''"
          >
            题型三
          </p>
          <p
            @click="topicParametersNavIfFun(4)"
            :class="topicParametersNavIf == 4 ? 'topicParametersNavIf' : ''"
          >
            题型四
          </p>
        </div>
        <div class="topicParametersData">
          <div class="topicParametersDataNav">
            <div
              v-for="(item, index) in topicParametersDataNavDataList"
              :key="item"
            >
              <p
                :class="
                  topicParametersDataNavIf == index + 1
                    ? 'topicParametersDataNavIf'
                    : ''
                "
                @click="topicParametersDataNavDataFun(index + 1)"
              >
                {{ item }}
              </p>
            </div>
          </div>
          <div class="topicParametersDataCon">
            <p class="addtopicParameters">
              <button @click="topicParametersIfFun()">新增</button>
            </p>

            <div class="topicParametersConment">
              <div v-for="item in topicParametersDataList" :key="item">
                <div class="topicParametersConmentTit">
                  <p>{{ item.key }}</p>
                  <button @click="updata(item)">编辑</button
                  ><button @click="open(item)">删除</button>
                </div>

                <div class="topicParametersConmentData">
                  {{ item.value }}
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <el-drawer
      v-model="topicParametersIf"
      title="编辑问题"
      :direction="direction"
      :before-close="handleClose"
    >
      <el-form-item label="key">
        <el-input v-model="topicParametersData.key"></el-input>
      </el-form-item>

      <div>
        <p class="tit">value</p>
        <el-input
          v-model="topicParametersData.value"
          :autosize="{ minRows: 6, maxRows: 4 }"
          type="textarea"
          placeholder="请输入测试说明"
        >
        </el-input>
      </div>
      <el-form-item class="topicParametersButton">
        <el-button
          type="primary"
          v-if="updataIf"
          @click="addtopicParametersData()"
          >新建项目</el-button
        >
        <el-button type="primary" v-else @click="updLibraryTypeParam()"
          >修改项目</el-button
        >
        <el-button @click="resetForm(ruleFormRef)">取消新建</el-button>
      </el-form-item>
    </el-drawer>
  </div>
</template>

<script>
import NavLeft from "../components/nav.vue";
import "@vueup/vue-quill/dist/vue-quill.snow.css";
import { ElMessageBox, ElMessage } from "element-plus";
export default {
  components: {
    NavLeft,
  },
  props: {
    msg: String,
  },
  data() {
    return {
      topicParametersNavIf: 1,
      text: "",
      keyText: "",
      navData: "",

      topicParametersIf: false,
      topicParametersDataNavIf: 1,
      topicParametersDataList: [],
      updataIf: true,
      topicParametersData: {
        key: "",
        libraryType: "topic_type_1",
        topicType: "1",
        value: "",
      },
      topicParametersDataNavData: [
        ["支配/老板型", "影响/互动型", "谨慎/修正型", "稳健/支配型"],
        ["老虎型", "考拉型", "孔雀型", "猫头鹰", "变色龙"],
        ["s1命令", "s2教练", "s3支持", "s4授权"],
        ["支配/老板型", "影响/互动型", "谨慎/修正型", "稳健/支配型"],
      ],
      topicParametersDataNavDataList: [
        "支配/老板型",
        "影响/互动型",
        "谨慎/修正型",
        "稳健/支配型",
      ],
    };
  },
  mounted() {
    this.getTopicParametersData();
  },
  methods: {
    // A导航
    topicParametersNavIfFun(num) {
      this.topicParametersNavIf = num;
      this.topicParametersDataNavDataList =
        this.topicParametersDataNavData[num - 1];
    },
    topicParametersIfFun() {
      (this.topicParametersData = {
        key: "",
        libraryType: "topic_type_1",
        topicType: "1",
        value: "",
      }),
        (this.topicParametersIf = true);
    },
    topicParametersDataNavDataFun(num) {
      this.topicParametersDataNavIf = num;
      this.updataIf = true;
      this.topicParametersDataNavData = { ...this.topicParametersDataNavData };
    },
    updata(data) {
      this.topicParametersData = { ...data };
      this.topicParametersIf = true;
      this.updataIf = false;
    },
    updLibraryTypeParam() {
      let that = this;
      console.log();
      this.axios
        .post("/hysc/library/updLibraryTypeParam", this.topicParametersData)
        .then(function (data) {
          console.log(data.data);
          that.getTopicParametersData();
        })
        .catch(function (error) {
          console.log(error);
        });
    },
    delLibraryTypeParam(obj) {
      console.log(obj);
      let that = this;
      this.axios
        .post("/hysc/library/delLibraryTypeParam", obj)
        .then(function (data) {
          console.log(data.data);
          that.getTopicParametersData();
        })
        .catch(function (error) {
          console.log(error);
        });
    },
    addtopicParametersData() {
      if (this.topicParametersNavIf == 1) {
        this.topicParametersData.libraryType = "topic_type_1";
      } else if (this.topicParametersNavIf == 2) {
        this.topicParametersData.libraryType = "topic_type_2";
      } else if (this.topicParametersNavIf == 3) {
        this.topicParametersData.libraryType = "topic_type_3";
      } else if (this.topicParametersNavIf == 4) {
        this.topicParametersData.libraryType = "topic_type_4";
      }
      let that = this;
      this.topicParametersData.topicType = this.topicParametersDataNavIf;
      this.axios
        .post("/hysc/library/addLibraryTypeParam", this.topicParametersData)
        .then(function (data) {
          console.log(data.data);
          that.getTopicParametersData();
        })
        .catch(function (error) {
          console.log(error);
        });
    },
    getTopicParametersData() {
      let param = new URLSearchParams();
      let that = this;

      param.append("libraryType", this.topicParametersData.libraryType);
      param.append("topicType", this.topicParametersData.topicType);
      this.axios
        .get("/hysc/library/getLibraryTypeParam", { params: param })
        .then(function (data) {
          console.log(data.data);
          that.topicParametersDataList = data.data.data;
        })
        .catch(function (error) {
          console.log(error);
        });
    },

    open(obj) {
      let that = this;

      ElMessageBox.confirm("是否确定删除", {
        confirmButtonText: "取消",
        cancelButtonText: "确定",
        type: "提示",
      })
        .then(() => {
          ElMessage({
            type: "delet",
            message: "已取消",
          });
        })
        .catch(() => {
          that.delLibraryTypeParam(obj);
        });
    },
  },
};
</script>


<style scoped>
.topicParametersConmentData {
  font-size: 14px;
  background-color: #ddd;
  width: 94%;
  color: #fff;
  margin-left: 20px;
  padding: 20px;
  box-sizing: border-box;
  min-height: 150px;
  margin-top: 20px;
}
.topicParametersButton {
  margin-top: 30px;
}
.topicParametersConmentTit > p {
  margin-right: 60px;
  font-size: 16px;
  padding-left: 20px;
}
.topicParametersConmentTit > button {
  width: 60px;
  height: 25px;
  cursor: pointer;
  background: #0544a4;
  box-shadow: 0px 2px 7px 0px rgb(120 137 149 / 25%);
  border-radius: 3px;
  margin-left: 20px;
  border: none;
  font-size: 15px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #ffffff;
}
.topicParametersConmentTit {
  display: flex;
}
.topicParametersCon {
  flex: 1;
  box-sizing: border-box;
  height: 100vh;
}
.topicParametersConLsit {
  padding: 40px 60px;
  background: #f8fafb;
  padding-bottom: 0px;
  display: flex;
  height: 86%;
  box-sizing: border-box;
}
.topicParametersNav p {
  font-size: 20px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #1b2125;
  line-height: 22px;
  margin-bottom: 60px;
}
.topicParametersData {
  margin-left: 120px;
  flex: 1;
}
.topicParametersDataNav {
  display: flex;
  font-size: 16px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #1b2125;
  padding-bottom: 30px;
  line-height: 22px;
}
.topicParametersDataNav > div > p {
  margin-right: 60px;
}

.topicParametersDataCon {
  border: 1px solid #ddd;
  width: 100%;
  height: 90%;
  overflow-x: auto;
}
.addtopicParameters {
  text-align: right;
  padding-right: 20px;
  padding-top: 20px;
}
.addtopicParameters button {
  width: 90px;
  height: 36px;
  cursor: pointer;
  background: #0544a4;
  box-shadow: 0px 2px 7px 0px rgb(120 137 149 / 25%);
  border-radius: 3px;
  margin-left: 20px;
  border: none;
  font-size: 15px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #ffffff;
}
.topicParametersNav .topicParametersNavIf {
  color: #0544a4;
}
.topicParametersDataNav .topicParametersDataNavIf {
  color: #0544a4;
}
.topicParametersConment > div {
  margin-bottom: 30px;
}
</style>
