<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :topList="topList"
      :moren="moren"
    ></topBar>
    <div class="main">
      <div class="main_title">
        <div class="bluekuai"></div>
        <div class="title_word">{{ '协议配置' }}</div>
      </div>
      <div class="main_content">
        <el-form ref="form" :rules="rules" :model="form" label-width="80px">
          <el-form-item :label="'标题'" prop="title" required>
            <el-input maxlength="150" clearable  v-model="form.title"></el-input>
          </el-form-item>
          <el-form-item :label="'内容'" prop="content" required>
            <quill-editor
              v-model="form.content"
              ref="myQuillEditor"
              style="height: 500px"
              :options="editorOption"
            >
            </quill-editor>
          </el-form-item>
          <el-form-item
            style="margin-top: 80px"
            :label="'生效日期'"
            prop="effectiveDate"
          >
            <el-date-picker
              v-model="form.effectiveDate"
              type="datetime"
              value-format="yyyy-MM-dd hh:mm:ss"
              placeholder="请选择日期"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="是否强读" prop="isForcedRead">
            <el-select clearable  v-model="form.isForcedRead">
              <el-option
                v-for="item in agreeList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item
            v-if="form.isForcedRead == 0"
            label="强读时间"
            prop="forcedReadTime"
          >
            <el-input clearable
              style="width: 220px"
              type="number"
              :placeholder="'请输入'"
              v-model="form.forcedReadTime"
            >
              <span slot="suffix">秒</span>
            </el-input>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div class="footer">
      <div style="margin: 0 auto">
        <el-button type="primary" class="thebtn" @click="saveDate('form')"
          > {{ '确认' }}</el-button
        >
      </div>
    </div>
  </div>
</template>

  <script>
import topBar from "@/components/topBar";
import {
  getAgreementDetail,
  saveAgreement,
  getEYesNoList,
  updateAgreement
} from "@/api/configManage";
import { quillEditor } from "vue-quill-editor";
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";
export default {
  name: "Xyxq",
  components: {
    topBar,
    quillEditor,
  },
  data() {
    return {
      moren: "protocol",
      topList: [
        {
          name: '协议配置',
          path: "protocol",
        },
      ],
      form: {
        title: "",
        content: "",
        effectiveDate: "",
        isForcedRead: "",
      },
      thepkId: "",
      rules: {},
      editorOption: {},
      agreeList: [],
    };
  },
  created() {
    this.getAgreementDetail();
    if (this.$route.query.id) {
      this.thepkId = this.$route.query.id;
    } else {
      this.thepkId = "";
    }
    this.getEYesNoList();
  },
  methods: {
    getEYesNoList() {
      getEYesNoList().then((res) => {
        this.agreeList = res.data;
      });
    },
    getAgreementDetail() {
      if (this.$route.query.id) {
        getAgreementDetail(this.$route.query.id).then((res) => {
          this.form = res.data;
        });
      }
    },
    saveDate(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.$route.query.id) {
            updateAgreement(this.form).then((res) => {
              if (res.code == 200) {
                this.$message({
                  message: res.msg,
                  type: "success",
                });
                this.$router.go(-1)
              } else {
                this.$message({
                  message: res.msg,
                  type: "warning",
                });
              }
            });
          } else {
            saveAgreement(this.form).then((res) => {
              if (res.code == 200) {
                this.$message({
                  message: res.msg,
                  type: "success",
                });
                this.$router.go(-1)
              } else {
                this.$message({
                  message: res.msg,
                  type: "warning",
                });
              }
            });
          }
        }
      });
    },
  },
};
</script>

  <style lang="scss" scoped>
  ::v-deep .el-select{
    width:220px
  }
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
  .main {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
    .main_title {
      display: flex;
      align-items: center;
      padding: 10px 0;
      border-bottom: 1px solid rgba(0, 0, 0, 0.1);
      .bluekuai {
        width: 5px;
        height: 19px;
        background: #C8161D;
        margin-right: 20px;
      }
      .title_word {
        font-size: 14px;
        font-family: MicrosoftYaHei-Bold, MicrosoftYaHei;
        font-weight: bold;
        color: #333333;
      }
    }
    .main_content {
      padding: 20px;
    }
  }
  .footer {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 15px 0;
    .thebtn {
      width: 120px;
      height: 38px;
    }
  }
}
</style>
