<template>
  <div class="app-container">
    <el-descriptions title="编辑触发条件" style="height: 25px; width: 99px" />

    <div class="title">
      <!-- <div >触发条件</div> -->
      <div class="nodes">
        <!-- 一级 -->
        <div class="node" v-if="updata">
          <!-- {{ updata.length }} -->
          <el-select
            v-model="updata.triggerConditionName"
            style="width: 120px"
            disabled
            @change="changetriggerConditionName($event, index)"
          >
            <el-option
              v-for="item in optionsname"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>
          <el-select
            disabled
            v-model="updata.triggerConditionOperatorName"
            style="width: 100px"
            @change="changetriggerLogic($event, index)"
          >
            <el-option
              v-for="item in optionstriggerConditionOperator"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>

          <el-input
            disabled
            v-if="updata.triggerConditionCode != 'DRESSING_CHANGE_DATE'"
            v-model="updata.triggerConditionValue"
            style="width: 300px"
          ></el-input>
          <el-date-picker
            disabled
            v-if="updata.triggerConditionCode == 'DRESSING_CHANGE_DATE'"
            v-model="updata.triggerConditionValue"
            style="width: 300px"
            type="date"
            placeholder="选择日期时间"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </div>
        <!-- 二级 -->
        <div v-show="show3 == true">
          <div class="node" v-for="(item, index) in updatalist" :key="index">
            <div
              style="width: 60px; position: absolute; top: 8%"
              v-if="updatalist.length == 2"
            >
              <img src="@/assets/images/images.png" class="login-code-img" />
              <div class="selectname">
                <el-select
                  disabled
                  v-model="item.triggerLogic"
                  style="width: 60px"
                  @change="changetriggerLogicsname($event, index)"
                >
                  <el-option
                    v-for="item in optionslistS"
                    :key="item.dictValue"
                    :label="item.dictLabel"
                    :value="item.dictValue"
                  >
                  </el-option>
                </el-select>
              </div>
            </div>
            <div>
              <el-select
                v-model="item.triggerConditionName"
                style="width: 120px"
                disabled
                @change="changetriggerConditionName($event, index)"
              >
                <el-option
                  v-for="item in optionsname"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
              <el-select
                disabled
                v-model="item.triggerConditionOperatorName"
                style="width: 100px"
                @change="changetriggerLogic($event, index)"
              >
                <el-option
                  v-for="item in optionstriggerConditionOperator"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>

              <el-input
                v-if="item.triggerConditionCode != 'DRESSING_CHANGE_DATE'"
                v-model="item.triggerConditionValue"
                style="width: 300px"
                disabled
              ></el-input>
              <el-date-picker
                disabled
                v-if="item.triggerConditionCode == 'DRESSING_CHANGE_DATE'"
                v-model="item.triggerConditionValue"
                style="width: 300px"
                type="date"
                placeholder="选择日期时间"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker>
            </div>
          </div>
        </div>
      </div>

      <div class="select">
        <span> 适用范围 </span>
        <el-select v-model="updata.suitRange" placeholder="请选择" disabled>
          <el-option
            v-for="item in options"
            :key="item.dictValue"
            :label="item.dictLabel"
            :value="item.dictValue"
          >
          </el-option>
        </el-select>
      </div>
      <div class="addlistname">
        <i @click="edit()" class="el-icon-edit">编辑</i>
        <span v-if="updatalist.length > 0">
          <i
            @click="addlistname()"
            class="el-icon-arrow-down"
            v-if="show3 == false"
            >展开</i
          >
          <i @click="addlistname()" class="el-icon-arrow-up" v-else>关闭</i>
        </span>
      </div>
    </div>
    <div class="list">
      <div class="timelist">
        <div class="timetitle">
          管理路径节点({{ lists.length }})
          <i class="el-icon-circle-plus-outline" @click="addlist"></i>
        </div>
        <el-timeline>
          <el-timeline-item
            v-for="(item, index) in lists"
            :key="index"
            :color="listindex == index ? '#409EFF' : ''"
          >
            <div class="top">
              <div class="toptop">
                <el-select v-model="item.routeNodeName" style="width: 100px" @change="changetoday">
                  <el-option
                    v-for="item in parentDictCodelist"
                    :key="item.dictValue"
                    :label="item.dictLabel"
                    :value="item.dictValue"
                  >
                  </el-option>
                </el-select>
                <el-input
                  v-model="item.routeNodeDay"
                  style="width: 70px"
                  type="number"
                  :min="0"
                ></el-input>
                <span>天</span>
              </div>
              <div>
                <i class="el-icon-delete" @click="delitemh(item, index)"></i>
                <i
                  class="el-icon-circle-plus-outline"
                  @click="additem(item)"
                ></i>
              </div>
            </div>
            <el-card
              v-for="(uitem, uindex) in item.list"
              :key="uitem.id"
              @click.native="bottomclickevent(uitem, index, uindex)"
              :class="listindex == index && itemindex == uindex ? 'cards' : ''"
            >
              <h3 style="height: 20px">{{ uitem.taskTypeName }}</h3>
              <el-tag
                v-if="uitem.routeCheckStatus == 'AGREE'"
                class="routeCheckStatus"
                >已审核</el-tag
              >
              <el-tag
                v-else-if="uitem.routeCheckStatus == 'DISAGREE'"
                type="danger"
                class="routeCheckStatus"
                >不同意</el-tag
              >
              <el-tag v-else type="warning" class="routeCheckStatus"
                >未审核</el-tag
              >
              <p style="height: 16px">{{ uitem.taskSubdivisionName }}</p>
            </el-card>
          </el-timeline-item>
        </el-timeline>
      </div>
      <div class="texts">
        <div class="topform">
          <el-form ref="form" :inline="true" :model="form" class="form">
            <el-form-item label="任务类型" prop="">
              <el-select
                v-model="form.taskType"
                style="width: 110px"
                @change="changeTaskType"
              >
                <el-option
                  v-for="item in selectTaskTypeList"
                  :key="item.taskTypeCode"
                  :label="item.taskTypeName"
                  :value="item.taskTypeCode"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="任务细分" prop="">
              <el-select
                v-model="form.taskSubdivision"
                style="width: 110px"
                @change="changetaskSubdivision"
              >
                <el-option
                  v-for="item in taskPartitionList"
                  :key="item.taskPartitionCode"
                  :label="item.taskPartitionName"
                  :value="item.taskPartitionCode"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="任务状态" prop="">
              <el-select v-model="form.taskStatus" style="width: 100px">
                <el-option
                  v-for="item in taskStatusDictList"
                  :key="item.id"
                  :label="item.taskStatusName"
                  :value="item.taskStatusCode"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="二级分类描述" prop="">
              <el-input
                v-model="form.secondClassifyDescribe"
                style="width: 110px"
                disabled
              ></el-input>
            </el-form-item>
            <el-form-item label="执行时间" prop="">
              <el-time-select
                v-model="form.executionTime"
                style="width: 120px"
                placeholder="选择时间"
                disabled
              >
              </el-time-select>
            </el-form-item>
            <el-form-item
              label="问卷库模板选择"
              prop=""
              v-if="form.taskSubdivisiontemplateType == 'QUESTIONNAIRE'"
            >
              <question
                @on-template="questionontemplate"
                :templateId="form.templateId"
                :templateName="form.templateName"
              ></question>
            </el-form-item>
            <el-form-item
              label="宣教库模板选择"
              prop=""
              v-if="form.taskSubdivisiontemplateType == 'PROPAGANDA'"
            >
              <propaganda
                @on-template="propagandaontemplate"
                :templateId="form.templateId"
                :templateName="form.templateName"
              ></propaganda>
            </el-form-item>
          </el-form>
        </div>
        <div class="bottomform">
          <wangeditor
            style="width: 100%"
            :nodeContent="form.nodeContent"
            @on-nodeContent="onNodeContent"
            v-show="
              form.taskSubdivisiontemplateType != 'QUESTIONNAIRE' &&
              form.taskSubdivisiontemplateType != 'PROPAGANDA' &&
              form.taskSubdivisiontemplateType != 'SCRIPT'
            "
            ref="wangeditor"
          />
          <div
            class="card"
            v-show="form.taskSubdivisiontemplateType != 'SCRIPT'"
          >
            <div class="flex">
              <div class="pushMethod">
                推送方式：
                <span> 短信 </span>
              </div>
              <div class="pushMethod">
                模板：
                <message
                  @on-template="messageontemplate"
                  :templateId="form.messageTemplateId"
                  :templateName="form.messageTemplateName"
                ></message>
              </div>
              <div class="pushMethod">
                <el-switch
                  v-model="form.messagePushSign"
                  active-color="#13ce66"
                  active-value="1"
                  inactive-value="0"
                >
                </el-switch>
              </div>
            </div>
          </div>
          <div
            class="card"
            v-show="form.taskSubdivisiontemplateType != 'SCRIPT'"
          >
            <div class="flex">
              <div class="pushMethod">
                推送方式：
                <span> 公众号 </span>
              </div>
              <div class="pushMethod">
                模板：
                <span>
                  <officialAccount
                    @on-template="officialAccountontemplate"
                    :templateId="form.officialTemplateId"
                    :templateName="form.officialTemplateName"
                  >
                  </officialAccount>
                </span>
              </div>
              <div class="pushMethod">
                <el-switch
                  v-model="form.officialPushSign"
                  active-color="#13ce66"
                  active-value="1"
                  inactive-value="0"
                >
                </el-switch>
              </div>
            </div>
          </div>
          <div
            class="card"
            v-show="form.taskSubdivisiontemplateType != 'SCRIPT'"
          >
            <div class="flex">
              <div class="pushMethod">
                推送方式：
                <span> 小程序 </span>
              </div>
              <div class="pushMethod">
                模板：
                <span>
                  <miniProgram
                    @on-template="miniProgramtemplate"
                    :templateId="form.appletTemplateId"
                    :templateName="form.appletTemplateName"
                  >
                  </miniProgram>
                </span>
              </div>
              <div class="pushMethod">
                <el-switch
                  v-model="form.appletPushSign"
                  active-color="#13ce66"
                  active-value="1"
                  inactive-value="0"
                >
                </el-switch>
              </div>
            </div>
          </div>
          <div
            class="card"
            style="height: 250px"
            v-show="form.taskSubdivisiontemplateType == 'SCRIPT'"
          >
            <div class="flex">
              <div class="pushMethod">
                推送方式：
                <span> 人工电话 </span>
              </div>
              <div class="pushMethod">
                模板：
                <scripts
                  @on-template="messageontemplateword"
                  :templateId="form.phoneTemplateId"
                  :templateName="form.phoneTemplateName"
                ></scripts>
              </div>
              <div class="pushMethod">
                <el-switch
                  v-model="form.phonePushSign"
                  active-color="#13ce66"
                  active-value="1"
                  inactive-value="0"
                >
                </el-switch>
              </div>
            </div>
            <div class="flex">
              <div class="pushMethod">
                重播次数：
                <span>
                  <el-select
                    v-model="form.phoneRedialTimes"
                    style="width: 100px"
                  >
                    <el-option
                      v-for="item in optionslistSname"
                      :key="item.dictValue"
                      :label="item.dictLabel"
                      :value="item.dictValue"
                    >
                    </el-option>
                  </el-select>
                </span>
              </div>
              <div class="pushMethod">
                时间间隔:
                <span>
                  <el-input
                    v-model.number="form.phoneTimeInterval"
                    oninput="value=value.replace(/[^\d]/g,'')"
                    style="width: 100px"
                  >
                  </el-input>
                </span>
              </div>
              <div class="pushMethod">
                短信提醒：
                <el-select
                  v-model="form.phoneMessageRemind"
                  style="width: 150px"
                >
                  <el-option
                    v-for="item in optionslist"
                    :key="item.dictValue"
                    :label="item.dictLabel"
                    :value="item.dictValue"
                  >
                  </el-option>
                </el-select>
              </div>
              <div class="pushMethod">
                短信模板：
                <span
                  class="spanname"
                  v-if="form.phoneMessageRemind == 'NOT_SEND_MESSAGE'"
                >
                  <message
                    style="width: 200px"
                    @on-template="messageontemplateMESSAGE"
                    :templateId="form.phoneMessageTemplateId"
                    :templateName="form.phoneMessageTemplateName"
                  ></message>
                </span>
                <span v-else>
                  <message
                    style="width: 200px"
                    @on-template="messageontemplateMESSAGE"
                    :templateId="form.phoneMessageTemplateId"
                    :templateName="form.phoneMessageTemplateName"
                  ></message>
                </span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 编辑触发条件 -->
    <el-dialog
      title="添加触发条件"
      :visible.sync="open"
      width="800px"
      append-to-body
    >
      <el-form
        ref="openlist"
        :model="openlist"
        :rules="rules"
        label-width="80px"
      >
        <el-form-item label="适用范围:">
          <el-select
            v-model="openlist.suitRange"
            @change="changeoptions"
            style="width: 200px"
          >
            <el-option
              v-for="item in options"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-descriptions title="触发条件"> </el-descriptions>
        <div class="nodesname">
          <div
            class="node"
            v-for="(item, index) in openlist.triggerConditionList"
            :key="index"
          >
            <!-- 且或 -->
            <div
              style="width: 60px; position: absolute; left: 2%; top: 57%"
              v-if="openlist.triggerConditionList.length === 3"
            >
              <img src="@/assets/images/images.png" class="login-code" />
              <div class="selectnamelist">
                <el-select
                  v-model="item.triggerLogic"
                  style="width: 60px"
                  placeholder=""
                  @change="changetriggerLogicsname($event, index)"
                >
                  <el-option
                    v-for="item in optionslistS"
                    :key="item.dictValue"
                    :label="item.dictLabel"
                    :value="item.dictValue"
                  >
                  </el-option>
                </el-select>
              </div>
            </div>
            <!-- 诊断 -->
            <el-select
              v-model="item.triggerConditionCode"
              style="width: 120px"
              @change="changetriggerConditionName($event, index)"
            >
              <el-option
                v-for="item in optionsname"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
              >
              </el-option>
            </el-select>
            <!-- 包含 -->
            <el-select
              v-model="item.triggerConditionOperator"
              style="width: 100px"
              @change="changetriggerLogic($event, index)"
            >
              <el-option
                v-for="item in optionstriggerConditionOperator"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
              >
              </el-option>
            </el-select>

            <el-input
              v-if="item.dictDataType == 'STRING'"
              v-model="item.triggerConditionValue"
              style="width: 300px"
              placeholder="请输入触发条件"
              maxlength="100"
            ></el-input>
            <el-date-picker
              v-if="item.dictDataType == 'DATE'"
              v-model="item.triggerConditionValue"
              style="width: 300px"
              type="date"
              placeholder="选择日期时间"
              value-format="yyyy-MM-dd"
            >
            </el-date-picker>
            <!-- {{ item }} -->
            <el-input
              v-if="item.dictDataType == 'DECIMAL'"
              style="width: 300px"
              v-model="item.triggerConditionValue"
              type="number"
              :min="0"
            ></el-input>
            <span class="icon">
              <el-button
                type="danger"
                class="el-icon-remove-outline"
                plain
                @click="delitemlistname(index)"
                v-if="index != 0"
              ></el-button>

              <el-button
                type="primary"
                plain
                class="el-icon-circle-plus-outline"
                @click="addtriggerCondition(index)"
                v-if="index == 0"
                >添加属性</el-button
              >
            </span>
          </div>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="upload">确 定</el-button>
        <el-button @click="openfalse">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 提交审核 -->
    <el-dialog
      title="提交审核完成"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <el-form
        ref="routeform"
        :model="routeform"
        label-width="120px"
        :rules="rules"
      >
        <el-form-item label="节点审核状态" prop="routeCheckStatus">
          <el-radio v-model="routeform.routeCheckStatus" label="AGREE"
            >同意</el-radio
          >
          <el-radio v-model="routeform.routeCheckStatus" label="DISAGREE"
            >不同意</el-radio
          >
        </el-form-item>
        <el-form-item label="节点审核备注">
          <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入节点审核备注"
            v-model="routeform.routeCheckRemark"
          >
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="auditing">确 定</el-button>
        <el-button @click="handleClose">取 消</el-button>
      </div>
    </el-dialog>
    <div slot="footer" class="dialog-footer">
      <el-button @click="TemporaryStorage">暂 存</el-button>
      <el-button
        type="primary"
        @click="dialogVisible = true"
        v-if="form.specialDiseaseNodeId"
        >审核完成 {{ agreeNumber ? agreeNumber : "0" }} /
        {{ totalNumber ? totalNumber : "0" }}</el-button
      >
    </div>
  </div>
</template>

<script>
import wangeditor from "../components/wangEditor.vue";
import question from "../components/question.vue";
import message from "../components/message.vue";
import scripts from "../components/script.vue";
import propaganda from "../components/propaganda.vue";
import officialAccount from "../components/officialAccount.vue";
import miniProgram from "../components/miniProgram.vue";
import { getAgencytype } from "@/api/system/agency";
import {
  selectTaskTypeList,
  taskPartitionList,
  taskStatusDictList,
  specialDiseaseNode,
  triggerCondition,
  selectSpecialDisease,
  updateRouteCheckStatus,
  list,
  triggerConditionList,
  getList,
} from "@/api/system/specialDiseaseNode";
import Cookies from "js-cookie";

export default {
  components: {
    wangeditor,
    question,
    propaganda,
    message,
    scripts,
    officialAccount,
    miniProgram,
  },
  name: "specialDiseaseNode",
  data() {
    return {
      dictDataType: "",
      openlist: {
        suitRange: "",
        routeId: "",
        triggerConditionList: [],
      },
      open: false,
      show3: false,
      activeNames: ["1"],
      routeform: {
        routeCheckStatus: null,
        routeCheckRemark: "",
      },
      optionslist: [],
      // 包含
      optionstriggerConditionOperator: [],
      optionslistS: [],
      optionslistSname: [],
      // 诊断
      optionsname: [],
      routeName: "",
      updata: [],
      updatalists: [],
      updatalist: [],
      // triggerConditionList: [{}],
      form: {
        specialDiseaseNodeId: "",
        nodeContent: "",
        templateId: "",
        templateName: "",
        taskType: "",
        taskTypeName: "",
        taskSubdivision: "",
        taskSubdivisionName: "",
        taskStatus: "",
        secondClassifyDescribe: "",
        executionTime: "",
        appletPushSign: "0",
        officialPushSign: "0",
        messagePushSign: "0",
        taskSubdivisiontemplateType: "",
      },
      itemindex: 0,
      listindex: 0,
      totalNumber: 0,
      agreeNumber: 0,
      value: "",
      input: "",
      //任务类型
      selectTaskTypeList: [],
      //任务状态
      taskStatusDictList: [],
      //任务细分
      taskPartitionList: [],
      routeId: "",
      options: [],
      lists: [],
      dialogVisible: false,
      parentDictCodelist: [],
      parentDictCode: "",
      itemlist: {
        specialDiseaseRouteId: "",
        // suitRange: "",
        routeName: "",
        specialDiseaseNodeList: [],
      },
      updataname: "",
      rules: {
        routeCheckStatus: [
          { required: true, message: "请选择节点审核状态", trigger: "change" },
        ],
      },
    };
  },
  created() {
    if (this.$route.query) {
      this.$set(this.form, "specialDiseaseNodeId", this.$route.query.id);
      this.$set(this.openlist, "suitRange", this.$route.query.suitRange);
      this.openlist.routeId = this.$route.query.id;
    }
    this.taskinfo();
    this.infolistname();

    this.infolists();
    this.infolistoptionslistS();
    this.infolistMESSAGE();
    this.infolistword();
    this.optiononditionOperator();
    this.optiononditionOperators();
  },
  beforeDestroy() {},
  watch: {
    "form.phoneMessageRemind": {
      handler(newValue, oldValue) {
        if (newValue == "NOT_SEND_MESSAGE") {
          this.form.phoneMessageTemplateId = "";
          this.form.phoneMessageTemplateName = "";
        }
      },
      deep: true,
    },
  },
  mounted() {
    // this.form = this.lists[0].list[0];
  },
  methods: {
    // 短信提醒
    infolistword() {
      var dictType = "text_message_remind";
      getAgencytype(dictType).then((res) => {
        this.optionslist = res.data;
        // this.taskinfo();
      });
    },
    // 重播次数
    infolistMESSAGE() {
      var dictType = "redial_times";
      getAgencytype(dictType).then((res) => {
        this.optionslistSname = res.data;
        this.taskinfo();
      });
    },
    // 弹框确定
    upload() {
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      this.openlist.triggerConditionList.forEach((e) => {
        e.routeId = this.$route.query.id;
        e.routeName = this.$route.query.routeName;
      });
      console.log(
        this.openlist.triggerConditionList,
        "  this.openlist.triggerConditionList"
      );
      loading.close();

      triggerCondition(this.openlist).then((res) => {

        if (res.code == 200) {

          this.$notify({
            type: "success",
            title: "提示",
            message: "修改触发条件成功",
          });
          this.routeName = res.data;
          Cookies.remove("routeName");

          Cookies.set("routeName", this.routeName);
        }
        this.infolist();
        this.handlelist();

        this.openfalse();
      });
    },
    // 关闭弹框
    openfalse() {
      this.openlist.triggerConditionList = [
        {
          routeId: "",
          routeName: "",
          triggerConditionName: "",
          triggerConditionOperator: "",
          triggerConditionValue: "",
          triggerConditionName: "",
          triggerConditionOperatorName: "",
          dictDataType: "STRING",

          triggerLogic: "AND",
          triggerLogicName: "",
        },
      ];
      this.open = false;
      this.resetForm("openlist");
    },
    // 批量新增添加属性
    addtriggerCondition() {
      this.idd++;
      var obj = {
        routeId: "",
        routeName: "",
        triggerConditionName: "",
        triggerConditionOperator: "",
        triggerConditionValue: "",
        triggerConditionName: "",
        triggerConditionOperatorName: "",
        dictDataType: "STRING",
        triggerLogic: "AND",
        triggerLogicName: "",
      };

      if (this.openlist.triggerConditionList.length == 3) {
        this.$message.error("至多仅支持两种属性");
      } else {
        this.openlist.triggerConditionList.push(obj);
      }
    },
    // 删除属性
    delitemlistname(index, item) {
      this.openlist.triggerConditionList.splice(index, 1);
    },
    //取消
    handleClose() {
      this.dialogVisible = false;
      this.routeform = {
        routeCheckStatus: "",
        routeCheckRemark: "",
      };
      this.resetForm("routeform");
    },
    //审核
    auditing() {
      this.$refs["routeform"].validate((valid) => {
        if (valid) {
          const loading = this.$loading({
            lock: true,
            text: "审核中",
            spinner: "el-icon-loading",
            background: "rgba(0, 0, 0, 0.7)",
          });
          if (!this.form.routeNodeDay) {
            this.$message.error("请输入节点时间段天数");
            return loading.close();
          }
          if (!this.form.routeNodeName) {
            this.$message.error("请选择节点时间段");
            return loading.close();
          }
          if (!this.form.taskType) {
            this.$message.error("请选择任务类型");
            return loading.close();
          }
          if (!this.form.taskSubdivision) {
            this.$message.error("请选择任务细分");
            return loading.close();
          }
          if (!this.form.taskStatus) {
            this.$message.error("请选择任务状态");
            return loading.close();
          }
          updateRouteCheckStatus({
            routeCheckStatus: this.routeform.routeCheckStatus,
            id: this.form.specialDiseaseNodeId,
            routeCheckRemark: this.routeform.routeCheckRemark,
            routeCheckPerson: JSON.parse(localStorage.getItem("user")).nickName,
          }).then((res) => {
            loading.close();
            if (res.data == 1) {
              this.info();
              this.handleClose();
              this.$modal.msgSuccess("审核成功!");
            }
          });
        }
      });
    },
    // 保存触发条件
    addlistname() {
      this.show3 = !this.show3;
    },
    // 适用范围
    changeoptions(e) {
      this.parentDictCode = this.options.find(
        (el) => el.dictValue == e
      )?.dictCode;
      this.changelisy();
    },
    changelisy() {
      list(this.parentDictCode).then((res) => {
        this.parentDictCodelist = res.rows;
      });
    },
    changetoday(e){
      console.log(e,'eeeeeeeeeeeeeooooooooooooo')
    },
    // 回显
    info() {
      const loading = this.$loading({
        lock: true,
        text: "数据加载中",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      this.lists = [];
      if (this.$route.query) {
        this.$set(this.updata, "suitRange", this.$route.query.suitRange);
        this.parentDictCode = this.options.find(
          (el) => el.dictValue == this.updata.suitRange
        )?.dictCode;
        setTimeout(() => {
          this.changelisy();
        }, 1000);
        this.itemlist.specialDiseaseRouteId = this.$route.query.id;
        this.itemlist.routeName = Cookies.get("routeName");
        selectSpecialDisease(this.$route.query.id).then((res) => {
          loading.close();
          this.agreeNumber = res.data.agreeNumber;
          this.totalNumber = res.data.totalNumber;
          res.data.specialDiseaseNodeList.forEach((e) => {
            if (e.messagePushSign) {
              e.messagePushSign = "" + e.messagePushSign;
            }
            if (e.officialPushSign) {
              e.officialPushSign = "" + e.officialPushSign;
            }
            if (e.appletPushSign) {
              e.appletPushSign = "" + e.appletPushSign;
            }
            if (e.phonePushSign) {
              e.phonePushSign = "" + e.phonePushSign;
            }
          });
          this.lists = this.handleData(
            res.data.specialDiseaseNodeList,
            "routeNodeDay",
            "routeNodeName"
          );
          this.form = this.lists[0].list[0];
          if (this.form.taskType) {
            this.changeTaskType(this.form.taskType, this.form.taskSubdivision);
          }
        });
      } else {
        loading.close();
        this.lists.push({
          routeNodeName: "",
          routeNodeDay: "",
          list: [
            {
              nodeContent: "<p></p>",
              templateId: "",
              templateName: "",
              taskType: "",
              taskSubdivision: "",
              taskSubdivisionName: "",
              taskStatus: "",
              secondClassifyDescribe: "",
              executionTime: "",
              appletPushSign: "0",
              officialPushSign: "0",
              messagePushSign: "0",
              messagePreview: "",
              officialRemindContent: "",
              taskSubdivisiontemplateType: "",
              appletRemindContent: "",
              appletPromptDescription: "",
            },
          ],
        });
        this.form = this.lists[0].list[0];
      }
    },
    handleData(list, key, keytwo) {
      //得到数据的主键列表
      let keysArr = list.map((item) => {
        return {
          routeNodeDay: item[key],
          routeNodeName: item[keytwo],
        };
      });
      let array = keysArr.filter(
        (item, index, arr) =>
          index ===
          arr.findIndex(
            (ite) =>
              ite.routeNodeDay == item.routeNodeDay &&
              ite.routeNodeName == item.routeNodeName
          )
      );

      let keys = [...new Set(array)];
      let newList = keys.map((item) => {
        return {
          //这里写新的 数据结构 如下是整体复制
          routeNodeDay: item[key],
          routeNodeName: item[keytwo],
          list: list.filter(
            (i) => i[key] == item[key] && i[keytwo] == item[keytwo]
          ),
        };
      });
      return newList;
    },

    // 且或
    infolistoptionslistS() {
      var dictType = "trigger_logic";
      getAgencytype(dictType).then((res) => {
        this.optionslistS = res.data;
      });
    },
    // 诊断
    optiononditionOperators() {
      var dictType = "trigger_condition_name";
      getAgencytype(dictType).then((res) => {
        this.optionsname = res.data;
      });
    },
    // 包含
    optiononditionOperator() {
      var dictType = "trigger_condition_operator";
      getAgencytype(dictType).then((res) => {
        this.optionstriggerConditionOperator = res.data;
      });
    },
    // 包含或等号接口
    handlelist() {
      var dictType = "trigger_condition_operator";

      getList(dictType, this.dictDataType).then((res) => {
        console.log(res, "res");
        this.optionstriggerConditionOperator = res.data;
      });
    },

    // 包含
    changetriggerLogic(e, index) {
      console.log(e, index, "e包含,index");

      this.openlist.triggerConditionList[index].triggerConditionOperatorName =
        this.optionstriggerConditionOperator.find(
          (el) => el.dictValue == e
        ).dictLabel;
      this.openlist.triggerConditionList[index].triggerConditionValue = null;
    },
    // 数值=s
    // changetriggerLogics(e,index){
    //   console.log(e,index,'e,index')
    //   this.openlist.triggerConditionList[index].triggerConditionOperator =
    //     this.optionstriggerConditionOperator.find(
    //       (el) => el.dictValue == e
    //     ).dictLabel;
    //   this.openlist.triggerConditionList[index].triggerConditionValue = null;
    // },
    // 诊断
    changetriggerConditionName(e, index) {
      console.log(e, index, "e诊断, index");
      // this.dictDataType = e;
      this.openlist.triggerConditionList[index].triggerConditionName =
        this.optionsname.find((el) => el.dictValue == e).dictLabel;
      this.openlist.triggerConditionList[index].triggerConditionOperator = null;
      this.openlist.triggerConditionList[index].triggerConditionValue = null;
      this.dictDataType = this.optionsname.find(
        (el) => el.dictValue == e
      ).dictDataType;
      this.openlist.triggerConditionList[index].dictDataType =
        this.optionsname.find((el) => el.dictValue == e).dictDataType;
      console.log(
        this.openlist.triggerConditionList[index].dictDataType,
        "this.dictDataType"
      );
      this.handlelist();
    },
    // 且或
    changetriggerLogicsname(e, index) {
      console.log(e,'qie')
      this.openlist.triggerConditionList[index].triggerLogic = e;
      this.openlist.triggerConditionList[index].triggerLogicName =
        this.optionslistS.find((el) => el.dictValue == e).dictLabel;
    },
    // 适用范围
    infolists() {
      var dictType = "suit_range";
      getAgencytype(dictType).then((res) => {
        this.options = res.data;
      });
      this.infolist();
    },
    // 展示触发条件
    infolist() {
      this.routeId = this.$route.query.id;
      triggerConditionList(this.routeId).then((res) => {
        this.openlist.triggerConditionList = res.data;
          this.handlelist();

        // this.openlist.triggerConditionList.forEach((o) => {
        //   // this.triggerConditionCode=o.triggerConditionCode
        //   this.handlelist();
        //   // o.dictDataType = this.optionstriggerConditionOperator.find(
        //   //   (el) => el.dictValue == o.triggerConditionOperator
        //   // )?.dictDataType;
        // });
        // console.log(
        //   this.openlist.triggerConditionList,
        //   " this.openlist.triggerConditionList"
        // );

        if (res.data.length == 1) {
          // 新增一条时
          this.updata = res.data[0];

          this.updata.triggerConditionOperatorName =
            this.optionstriggerConditionOperator.find(
              (el) => el.dictValue == this.updata.triggerConditionOperator
            )?.dictLabel;
          console.log(
            this.updata.triggerConditionOperatorName,
            "updata.triggerConditionOperatorName"
          );

          this.updatalist = [];
        } else {
          // 新增两条或者三条
          this.updata = res.data[0];
          // this.handlelist();
          this.updata.triggerConditionOperatorName =
            this.optionstriggerConditionOperator.find(
              (el) => el.dictValue == this.updata.triggerConditionOperator
            )?.dictLabel;
          console.log(
            this.updata.triggerConditionOperatorName,
            "updata.triggerConditionOperatorName"
          );
          res.data.splice(0, 1);
          this.updatalist = res.data;
          this.updatalist.forEach((e) => {
            e.triggerConditionOperatorName =
              this.optionstriggerConditionOperator.find(
                (el) => el.dictValue == e.triggerConditionOperator
              )?.dictLabel;
          });
          //   this.updatalist.triggerConditionOperatorName = this.optionstriggerConditionOperator.find(
          //   (el) => el.dictValue == this.updatalist.triggerConditionOperator
          // )?.dictLabel;
        }
        if (this.open == true) {
          this.$set(this.openlist, "suitRange", this.$route.query.suitRange);
        } else {
          this.$set(this.updata, "suitRange", this.openlist.suitRange);
        }
      });
    },
    // 编辑接口
    infolistname() {
      this.routeId = this.$route.query.id;
      triggerConditionList(this.routeId).then((res) => {
        this.openlist.triggerConditionList = res.data;
        this.openlist.triggerConditionList.forEach((o) => {
          this.optiononditionOperators();
          o.dictDataType = this.optionsname.find(
            (el) => el.dictValue == o.triggerConditionCode
          )?.dictDataType;
          console.log(o.dictDataType, "dict");
        });
        console.log(
          this.openlist.triggerConditionList,
          " this.openlist.triggerConditionList11111111111"
        );

        this.$set(this.updata, "suitRange", this.openlist.suitRange);
      });
    },
    // 编辑
    edit() {
      this.open = true;
      this.infolistname();
      // this.infolist()
    },
    //wangeditor传值
    onNodeContent(item) {
      this.form.nodeContent = item.nodeContent;
      var abc = new RegExp("<br>", "g");
      var bbb = this.form.nodeContent.replace(abc, "");
      this.form.nodeContent = bbb;
    },
    //小程序传值
    miniProgramtemplate(item) {
      this.form.appletTemplateId = item.templateId;
      this.form.appletTemplateName = item.templateName;
      this.form.appletRemindContent = item.templateContent;
    },
    // 话术
    messageontemplateword(item) {
      this.form.phoneTemplateId = item.templateId;
      this.form.phoneTemplateName = item.templateName;
      // this.form.messagePreview = item.templateContent;
    },
    //短信传值
    messageontemplate(item) {
      this.form.messageTemplateId = item.templateId;
      this.form.messageTemplateName = item.templateName;
      this.form.messagePreview = item.templateContent;
    },
    // 短信
    messageontemplateMESSAGE(item) {
      this.form.phoneMessageTemplateId = item.templateId;
      this.form.phoneMessageTemplateName = item.templateName;
      this.form.messagePreview = item.templateContent;
    },
    //公众号传值
    officialAccountontemplate(item) {
      this.form.officialTemplateId = item.templateId;
      this.form.officialTemplateName = item.templateName;
      this.form.officialRemindContent = item.templateContent;
    },
    // 暂存
    TemporaryStorage() {
      if (
        this.form.taskSubdivisiontemplateType != "QUESTIONNAIRE" &&
        this.form.taskSubdivisiontemplateType != "PROPAGANDA"
      ) {
        this.$refs.wangeditor.emit();
      }
      this.$confirm(
        "确认暂存时将过滤掉部分内容未填写完成的子节点,是否确认暂存？",
        "提示",
        {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
        }
      ).then(() => {
        const loading = this.$loading({
          lock: true,
          text: "暂存中",
          spinner: "el-icon-loading",
          background: "rgba(0, 0, 0, 0.7)",
        });
        this.itemlist.specialDiseaseNodeList = [];
        this.lists.forEach((e) => {
          e.list.length > 0
            ? e.list.forEach((el) => {
                el.routeNodeDay = e.routeNodeDay;
                el.routeNodeName = e.routeNodeName;
                this.itemlist.specialDiseaseNodeList.push(el);
              })
            : "";
        });
        // this.updata.specialDiseaseNodeList =
        //   this.updata.specialDiseaseNodeList.filter(
        //     (e) =>
        //       !e.routeNodeDay &&
        //       !e.routeNodeName &&
        //       !e.taskType &&
        //       !e.taskSubdivision &&
        //       !e.taskStatus
        //   );
        // if (this.routeName) {
        //   this.itemlist.routeName = this.routeName;
        // } else {
        //   this.itemlist.routeName = this.$route.query.routeName;
        // }
        this.itemlist.routeName = Cookies.get("routeName");
        specialDiseaseNode(this.itemlist).then((res) => {
          this.info();
          loading.close();
          this.$modal.msgSuccess("暂存成功!");
        });
        setTimeout(() => {
          loading.close();
        }, 3000);
      });
    },
    //问卷传值
    questionontemplate(item) {
      this.form.templateId = item.templateId;
      this.form.templateName = item.templateName;
    },
    //宣教传值
    propagandaontemplate(item) {
      this.form.templateId = item.templateId;
      this.form.templateName = item.templateName;
    },

    bottomclickevent(uitem, index, uindex) {
      if (
        this.form.taskSubdivisiontemplateType != "QUESTIONNAIRE" &&
        this.form.taskSubdivisiontemplateType != "PROPAGANDA"
      ) {
        this.$refs.wangeditor.emit();
      }
      setTimeout(() => {
        this.form = uitem;
        this.taskPartitionList = [];
        if (this.form.taskType) {
          this.changeTaskType(this.form.taskType, this.form.taskSubdivision);
        }
        this.listindex = index;
        this.itemindex = uindex;
      }, 150);
    },
    handleStep() {
      this.active = 2;
    },
    //任务类型 任务状态
    taskinfo() {
      selectTaskTypeList().then((res) => {
        this.selectTaskTypeList = res.data;
        this.info();
      });
    },
    //任务类型
    changeTaskType(code, taskSubdivision) {
      let id = this.selectTaskTypeList?.find((e) => e.taskTypeCode == code)?.id;
      this.form.taskTypeName = this.selectTaskTypeList?.find(
        (e) => e.taskTypeCode == code
      )?.taskTypeName;
      taskPartitionList(id).then((res) => {
        this.taskPartitionList = res.data;
        this.form.taskSubdivision = "";
        this.form.taskSubdivisionName = "";
        this.form.taskSubdivisiontemplateType = "";
        this.taskStatusDictList = [];
        if (taskSubdivision) {
          this.form.taskSubdivision = taskSubdivision;
          this.changetaskSubdivision(taskSubdivision, 1);
        }
      });
    },
    //点击任务细分
    changetaskSubdivision(code, type) {
      this.form.taskSubdivisionName = this.taskPartitionList?.find(
        (e) => e.taskPartitionCode == code
      )?.taskPartitionName;
      let id = this.taskPartitionList?.find(
        (e) => e.taskPartitionCode == code
      )?.id;

      this.form.secondClassifyDescribe = this.taskPartitionList?.find(
        (e) => e.taskPartitionCode == code
      )?.secondClassifyDescribe;
      this.form.executionTime = this.taskPartitionList?.find(
        (e) => e.taskPartitionCode == code
      )?.executionTime;
      taskStatusDictList(id).then((res) => {
        this.taskStatusDictList = res.data;
      });
      this.taskPartitionList.forEach((el) => {
        if (code == el.taskPartitionCode) {
          this.form.executionTime = el.executionTime;
          this.form.taskSubdivisiontemplateType = el.templateType;
          if (
            this.form.taskSubdivisiontemplateType == "SCRIPT" ||
            this.form.taskSubdivisiontemplateType == "PROPAGANDA" ||
            this.form.taskSubdivisiontemplateType == "QUESTIONNAIRE"
          ) {
            this.form.nodeContent = `<p></p>`;
          }
          if (!type) {
            this.form.templateId = "";
            this.form.templateName = "";
          }
        }
      });
    },
    // 添加管理路径节点
    addlist() {
      list(this.parentDictCode).then((res) => {
        // this.parentDictCodelist = res.rows;
        res.rows.forEach((e) => {
          this.lists.forEach((el) => {
            el.routeNodeName = e.dictLabel;
          });
        });
      });
      this.lists.push({
        routeNodeName: "",
        routeNodeDay: "",
        list: [
          {
            nodeContent: "<p></p>",
            templateId: "",
            templateName: "",
            taskType: "",
            officialRemindContent: "",
            taskSubdivision: "",
            taskSubdivisionName: "",
            appletRemindContent: "",
            appletPromptDescription: "",
            taskStatus: "",
            secondClassifyDescribe: "",
            executionTime: "",
            appletPushSign: "0",
            officialPushSign: "0",
            messagePushSign: "0",
            messagePreview: "",
            taskSubdivisiontemplateType: "",
          },
        ],
      });
      // },
    },
    // 添加节点
    additem(item) {
      item.list.push({
        nodeContent: "<p></p>",
        templateId: "",
        templateName: "",
        taskType: "",
        officialRemindContent: "",
        taskSubdivision: "",
        taskSubdivisionName: "",
        appletRemindContent: "",
        appletPromptDescription: "",
        taskStatus: "",
        secondClassifyDescribe: "",
        executionTime: "",
        appletPushSign: "0",
        officialPushSign: "0",
        messagePushSign: "0",
        messagePreview: "",
        taskSubdivisiontemplateType: "",
      });
    },
    // 删除节点
    delitemh(item, index) {
      item.list.splice(this.itemindex, 1);
      if (item.list.length == 0) {
        this.lists.splice(index, 1);
      }
    },
  },
};
</script>
<style scoped lang="scss">
::v-deep .el-input.is-disabled .el-input__inner {
  background-color: #fff !important;
  color: #606266 !important;
}

.el-icon-arrow-down {
  margin-left: 50px;
}

.el-icon-arrow-up {
  margin-left: 50px;
}

.addlistname {
  color: #409eff;
  font-size: 12px;
  margin-left: 20px;
  margin-top: 10px;
}

.login-code {
  width: 62px;
  height: 81px;
  position: relative;
  z-index: 0;
  top: -30px;
  right: 56px;
}

.login-code-img {
  width: 62px;
  height: 81px;
  position: absolute;
  z-index: -1;
  top: 32px;
  right: 61px;
}

.selectnamelist {
  position: absolute;
  right: 54px;
  top: -8px;
}

.selectname {
  position: absolute;
  right: 70px;
  top: 55px;
}

.dialog-footer {
  padding: 0px 30px;
  text-align: right;
}

.nodesname {
  margin-left: 6%;
  width: 660px;
  display: flex;
  flex-wrap: wrap;
  position: relative;
  padding-left: 20px;

  .node {
    margin-bottom: 10px;
  }
}

.nodes {
  width: 660px;
  display: flex;
  flex-wrap: wrap;
  position: relative;
  padding-left: 20px;

  .node {
    margin-bottom: 10px;
  }
}

.bottomform {
  background-color: #f2f4f5;
  margin-top: 10px;

  .card {
    background-color: #fff;
    width: 100%;
    height: 200px;
    margin: 20px 0 0;
    padding: 20px 50px 0px 20px;

    .flextwo {
      // display: flex;
      // align-items: center;
      margin-top: 20px;

      .text {
        font-size: 13px;
        color: #64666a;
      }

      .textarea {
        width: 90%;
        padding: 0 10px;
        height: 50px;
        line-height: 50px;
        // border: 1px solid #dcdfe6;
        border-radius: 5px;
        display: flex;
        align-items: center;

        ::v-deep .el-input {
          padding: 0 10px;
          width: 50%;
          color: black;
          font-size: 13px;
          height: 40px;
          line-height: 40px;
        }

        ::v-deep .el-input__inner {
          color: black;
          font-size: 13px;
          cursor: default !important;
        }
      }
    }

    .flex {
      display: flex;
      width: 100%;
      align-items: center;
      // background: red;
      justify-content: space-between;

      .pushMethod {
        height: 30px;
        margin-top: 30px;
        line-height: 30px;
        font-size: 13px;
        color: #64666a;

        .spanname {
          pointer-events: none;
        }

        ::v-deep .el-input__inner {
          color: black;
          font-size: 13px;
        }

        span {
          color: black;
          font-size: 13px;
        }
      }
    }
  }
}

.routeCheckStatus {
  position: absolute;
  right: 10px;
  top: 30px;
}

.topform {
  padding: 15px 0 0 15px;
  height: 200px;

  .form {
    ::v-deep .el-input__inner {
      height: 30px !important;
      line-height: 30px !important;
    }

    ::v-deep .el-form-item__label {
      font-size: 12px !important;
    }
  }
}

.title {
  display: flex;
  margin-left: 100px;

  .select {
    font-weight: 550;
    // margin-left: 10%;
    position: relative;
    right: 20px;
    // width: 300px;
    font-size: 12px;

    .el-input {
      width: 200px;
      height: 30px !important;
      line-height: 30px !important;
    }
  }
}

.container {
  padding: 20px;
}

.list {
  margin: 12px auto;
  width: 100%;
  // height: calc(100% - 80px);
  background-color: #f2f4f5;
  display: flex;
  padding-top: 15px;
  justify-content: space-evenly;

  .timelist {
    width: 25%;
    background-color: #fff;
    padding: 0 20px 20px;
    height: calc(100vh - 350px);

    overflow: scroll;

    .timetitle {
      height: 60px;
      display: flex;
      align-items: center;
      justify-content: space-between;
    }

    ::v-deep .el-timeline {
      width: 100%;
      padding: 15px 0 0 !important;
    }
  }

  .texts {
    width: 75%;
    height: calc(100vh - 350px);

    overflow: scroll;
    background-color: #fff;
  }
}

.cards {
  border: 1px solid #409eff;
  border-left: 5px solid #409eff;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;

  .toptop {
    display: flex;
    align-items: center;
  }

  span {
    padding: 0 4px;
  }

  i {
    font-size: 17px;
  }

  i:nth-child(2) {
    padding-left: 12px;
  }
}

::v-deep .el-timeline-item__timestamp {
  margin: 0 !important;
  padding: 0 !important;
}

::v-deep .el-timeline-item__wrapper {
  padding-left: 14px !important;
}

::v-deep .el-timeline-item__content {
  transform: translateY(-2%);
}

::v-deep .el-card {
  position: relative !important;
  margin-top: 20px !important;
}
</style>