<template>
  <div style="background-color: #f1f3f5; padding-top: 10px">
    <div class="titlemengt" ref="layout">
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="upload">保存</el-button>
      </div>
      <el-descriptions title="手动创建任务"> </el-descriptions>
      <el-form
        :inline="true"
        :model="updata"
        class="demo-form-inline"
        ref="updata"
      >
        <el-form-item label="任务名称">
          <el-input v-model="updata.routeName"></el-input>
        </el-form-item>
        <el-form-item label="适用范围">
          <el-select v-model="updata.suitRange" @change="changeoptions">
            <el-option
              v-for="item in options"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <!-- <el-form ref="updata" :model="updata" label-width="80px">
        <div class="chufatitle">
          <span>触发条件</span>
        </div>
        <div class="nodesname">
          <div class="node" v-for="(item, index) in updata.triggerConditionList" :key="index">
            <div style="
                width: 60px;
                position: absolute;
                left: 3%;
                top: 195px;
              " v-if="updata.triggerConditionList.length === 3">
              <img src="@/assets/images/images.png" class="login-code-img" />
              <el-select v-model="item.triggerLogic" style="width: 60px" placeholder=""
                @change="changetriggerLogicsname($event, index)">
                <el-option v-for="itemh in optionslistS" :key="itemh.dictValue" :label="itemh.dictLabel"
                  :value="itemh.dictValue">
                </el-option>
              </el-select>
            </div>
            <el-select v-model="item.triggerConditionCode" style="width: 120px;z-index: 10;"
              @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 item.optionstriggerConditionOperator" :key="item.dictValue"
                :label="item.dictLabel" :value="item.dictValue">
              </el-option>
            </el-select>
            <el-input v-if="item.dictDataType == 'STRING' || !dictDataType" v-model="item.triggerConditionValue"
              style="width: 300px" placeholder="请输入触发条件" maxlength="100"></el-input>
            <el-select v-if="item.dictDataType == 'SELECT'" v-model="item.triggerConditionValue" style="width: 300px">
              <el-option v-for="item in ConditionValue" :key="item.dictValue" :label="item.dictLabel"
                :value="item.dictValue">
              </el-option>
            </el-select>
            <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>
            <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
          class="node"
          v-for="(item, index) in updata.triggerConditionList"
          :key="index"
          :style="updata.triggerConditionList.length > 1 ? '' : 'margin:0'"
        >
          <el-select v-model="item.triggerConditionName" style="width: 120px">
            <el-option label="诊断" value="DIAGNOSIS" />
            <el-option label="换药日期" value="DRESSING_CHANGE_DATE" />
            <el-option label="治疗方式" value="TREATMENT_METHOD" />
            <el-option label="手术名称" value="SURGICAL_NAME" />
            <el-option label="药品名称" value="DRUG_NAME" />
          </el-select>
          <el-select
            v-model="item.triggerConditionOperator"
            style="width: 100px"
          >
            <el-option label="包含" value="CONTAIN" />
            <el-option label="不包含" value="NOT_CONTAIN" />
            <el-option label="等于" value="EQUAL_TO" />
            <el-option label="不等于" value="NOT_EQUAL_TO" />
          </el-select>
          <el-input
            v-model="item.triggerConditionValue"
            style="width: 300px"
            placeholder="请输入触发条件"
          ></el-input>
          <i
            class="el-icon-delete"
            @click="delitem(item, index, updata.triggerConditionList)"
          ></i>
        </div> -->
      <!-- <el-button @click="submit" style="float:right">保存触发条件</el-button> -->
    </div>
    <div class="nodes" :style="{ height: heightLine + 'px' }">
      <div class="nodenames">
        <div class="timetitle">
          管理路径节点({{ list.length }})
          <i class="el-icon-circle-plus-outline" @click="additem"></i>
        </div>
        <el-timeline>
          <el-timeline-item
            v-for="(item, index) in list"
            :key="index"
            :color="listindex == index ? '#13CE66' : ''"
            @click.native="clicktimelineitem(item, index)"
          >
            <div class="top">
              <div class="toptop">
                <el-radio
                  v-model="item.checked1"
                  :label="1"
                  @change="handleCheckAllChange1($event, item)"
                >
                  <el-select
                    style="width: 123px"
                    v-model="item.routeNodeName"
                    @focus="handleFocusone(item)"
                  >
                    <el-option
                      v-for="item in parentDictCodelist"
                      :key="item.dictValue"
                      :label="item.dictLabel"
                      :value="item.dictValue"
                    >
                    </el-option>
                  </el-select>
                  <el-input
                    style="width: 90px"
                    v-model="item.routeNodeDay"
                    type="number"
                    @focus="handleFocus(item)"
                  ></el-input>
                  <span>天</span>
                </el-radio>
              </div>
              <div>
                <i
                  class="el-icon-delete"
                  @click="delitem(item, index, list)"
                ></i>
              </div>
            </div>
            <div class="top">
              <div class="toptop">
                <el-radio  v-model="item.checked2" :label="2" @change="handleCheckAllChange2($event, item, index)">
                  <span style="width: 78px">指定时间：</span>
                <el-date-picker
                   format="yyyy-MM-dd HH:mm:ss"
                   value-format="yyyy-MM-dd HH:mm:ss"
                  v-model="item.nodePlanTime"
                  type="datetime"
                  placeholder="选择日期时间"
                  :picker-options="pickerOptions"
                  @input="input(item,index)"
                  @focus="setCurrentTime(item,index)"
                  :default-time="currentDate"
                  ref="datePicker"
                >
                  <span style="width: 78px">指定时间：</span>
                  <el-date-picker
                    format="yyyy-MM-dd HH:mm:ss"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    v-model="item.nodePlanTime"
                    type="datetime"
                    placeholder="选择日期时间"
                    :picker-options="pickerOptions"
                    @input="input(item, index)"
                    @focus="setCurrentTime(item, index)"
                    ref="datePicker"
                  >
                  </el-date-picker>
                </el-radio>
              </div>
            </div>
            <div class="top">
              <div class="toptop">
                <!-- <el-checkbox
                  v-model="item.checked3"
                  style="margin-right: 5px"
                  @change="handleCheckAllChange3($event, item)"
                ></el-checkbox> -->
                <el-radio
                  v-model="item.checked3"
                  :label="3"
                  @change="handleCheckAllChange3($event, item)"
                >
                  <span>立即执行</span>
                </el-radio>
              </div>
            </div>
            <el-card :class="listindex == index ? 'cards' : ''">
              <h3 style="height: 20px">
                {{ item.taskNodeType == "PHONE_OUTBOUND" ? "电话外呼" : "" }}
                {{
                  item.taskNodeType == "QUESTIONNAIRE_SCALE" ? "问卷量表" : ""
                }}
                {{
                  item.taskNodeType == "PROPAGANDA_ARTICLE" ? "宣教文案" : ""
                }}
                {{ item.taskNodeType == "TEXT_REMIND" ? "文字提醒" : "" }}
                {{
                  item.taskNodeType == "ARTIFICIAL_FOLLOW_UP" ? "人工随访" : ""
                }}
              </h3>
            </el-card>
          </el-timeline-item>
        </el-timeline>
      </div>
      <div class="nodetexts">
        <div
          style="background-color: #fff; border-radius: 10px; padding: 20px"
          :style="
            formInline.taskNodeType
              ? formInline.taskNodeType != 'PHONE_OUTBOUND'
                ? formInline.taskNodeType == 'TEXT_REMIND'
                  ? 'height:260px'
                  : 'height:160px'
                : 'height:80px'
              : 'height:80px'
          "
        >
          <el-form :model="formInline" class="demo-form-inline">
            <el-form-item label="任务节点类型">
              <el-radio-group
                v-model="formInline.taskNodeType"
                @change="taskNodeTypechange"
              >
                <el-radio label="PHONE_OUTBOUND">电话外呼</el-radio>
                <el-radio label="QUESTIONNAIRE_SCALE">问卷量表</el-radio>
                <el-radio label="PROPAGANDA_ARTICLE">宣教文案</el-radio>
                <el-radio label="TEXT_REMIND">文字提醒</el-radio>
                <!-- <el-radio label="ARTIFICIAL_FOLLOW_UP">人工随访</el-radio> -->
              </el-radio-group>
            </el-form-item>
            <!-- <el-form-itemlabel="电话模板"  v-if="formInline.taskNodeType == 'PHONE_OUTBOUND'">
              <scriptphone @on-template="scriptphoneontemplate"></scriptphone>
            </el-form-item> -->
            <el-form-item
              label="宣教模板"
              v-if="formInline.taskNodeType == 'PROPAGANDA_ARTICLE'"
            >
              <propaganda @on-template="propagandaontemplate"></propaganda>
            </el-form-item>
            <el-form-item
              label="提醒内容"
              v-if="formInline.taskNodeType == 'TEXT_REMIND'"
            >
              <el-input
                type="textarea"
                v-model="formInline.nodeContent"
                :rows="6"
                style="width: 600px"
                placeholder="请输入内容"
              />
            </el-form-item>
            <!-- <el-form-item label="人工随访模板" v-if="formInline.taskNodeType == 'ARTIFICIAL_FOLLOW_UP'">
              <question @on-template="questionontemplate"></question>
            </el-form-item> -->
          </el-form>
          <el-form
            :model="formInline"
            class="demo-form-inline"
            :inline="true"
            v-if="formInline.taskNodeType == 'QUESTIONNAIRE_SCALE'"
          >
            <el-form-item label="问卷模板">
              <question
                @on-template="questionontemplate"
                :node="formInline.phoneDialMethod"
              ></question>
            </el-form-item>
            <el-form-item label="开启人工随访" label-width="150px">
              <el-switch
                v-model="formInline.phoneDialMethod"
                active-color="#13ce66"
                active-value="COMMON"
                @change="changephoneDialMethodtwo"
                inactive-value="AI"
              >
              </el-switch>
            </el-form-item>
            <!-- <el-form-item label="问卷有效期">
              <el-input-number v-model="formInline.questionExpirationDate" :min="1" :max="99"
                label="描述文字"></el-input-number>
              天
            </el-form-item> -->
          </el-form>
        </div>
        <div
          v-if="
            formInline.taskNodeType == 'TEXT_REMIND' ||
            formInline.taskNodeType == 'PROPAGANDA_ARTICLE' ||
            formInline.taskNodeType == 'QUESTIONNAIRE_SCALE'
          "
        >
          <!-- <div class="PushMethodrg" v-if="formInline.taskNodeType == 'ARTIFICIAL_FOLLOW_UP'">
            <div class="flex">
              <div class="itemlist">推送方式：人工电话</div>
              <div class="itemlist">
                <el-switch v-model="formInline.phonePushSign" active-color="#13ce66" active-value="1"
                  inactive-value="0">
                </el-switch>
              </div>
            </div>
            <div class="flex">
              <div class="itemlist">
                重拨次数：
                <span>
                  <el-select v-model="formInline.phoneRedialTimes" style="width: 100px">
                    <el-option v-for="item in optionslistS" :key="item.dictValue" :label="item.dictLabel"
                      :value="item.dictValue">
                    </el-option>
                  </el-select>
                </span>
              </div>
              <div class="itemlist">
                时间间隔：
                <span>
                  <el-input v-model.number="formInline.phoneTimeInterval" oninput="value=value.replace(/[^\d]/g,'')"
                    style="width: 100px">
                  </el-input>
                </span>
              </div>
              <div class="itemlist">
                短信提醒：
                <el-select v-model="formInline.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="itemlist">
                短信模板：
                <span :class="formInline.phoneMessageRemind == 'NOT_SEND_MESSAGE' ? 'spanname' : ''">
                  <message style="width: 200px" @on-template="messageontemplateMESSAGE"
                    :templateId="formInline.phoneMessageTemplateId" :templateName="formInline.phoneMessageTemplateName">
                  </message>
                </span>
              </div>
            </div>
          </div> -->
          <div class="PushMethod">
            <span>推送方式：公众号</span>
            <div class="pushMethod">
              模板：
              <span>
                <officialAccount
                  @on-template="officialAccountontemplate"
                  :templateId="formInline.officialTemplateId"
                  :templateName="formInline.officialTemplateName"
                >
                </officialAccount>
              </span>
            </div>
            <el-switch
              v-model="formInline.officialPushSign"
              active-color="#13ce66"
              active-value="1"
              inactive-value="0"
            >
            </el-switch>
          </div>
          <div class="PushMethod">
            <span>推送方式：小程序</span>
            <div class="pushMethod">
              模板：
              <span>
                <miniProgram
                  @on-template="miniProgramtemplate"
                  :templateId="formInline.appletTemplateId"
                  :templateName="formInline.appletTemplateName"
                >
                </miniProgram>
              </span>
            </div>
            <el-switch
              v-model="formInline.appletPushSign"
              active-color="#13ce66"
              active-value="1"
              inactive-value="0"
            >
            </el-switch>
          </div>
          <div class="PushMethod">
            <span style="display: inline-block; width: 128px"
              >推送方式：短信</span
            >
            <div class="pushMethod">
              模板：
              <message
                @on-template="messageontemplateMESSAGEtwo"
                :templateId="formInline.phoneMessageTemplateId"
                :templateName="formInline.phoneMessageTemplateName"
              ></message>
            </div>
            <el-switch
              v-model="formInline.messagePushSign"
              active-color="#13ce66"
              active-value="1"
              inactive-value="0"
            >
            </el-switch>
          </div>
        </div>
        <div
          class="PushMethodrg"
          v-if="formInline.taskNodeType == 'PHONE_OUTBOUND'"
        >
          <div class="flex">
            <div class="itemlist">
              推送方式：
              <span>
                <el-radio-group
                  v-model="formInline.phoneDialMethod"
                  @change="changephoneDialMethod"
                >
                  <el-radio label="COMMON">人工电话</el-radio>
                  <el-radio label="AI">自动外呼</el-radio>
                </el-radio-group>
              </span>
            </div>
            <div class="itemlist">
              话术模板：
              <span>
                <scripts
                  @on-template="messageontemplateword"
                  :templateId="formInline.phoneId"
                  :node="formInline.phoneDialMethod"
                  :templateName="formInline.phoneTemplateName"
                ></scripts>
              </span>
            </div>
            <!-- <div class="itemlist" v-if="formInline.phoneDialMethod == 'COMMON' || !formInline.phoneDialMethod">
              问卷模板：
              <span  :class="formInline.phoneId ? 'spanname' : ''">
                <question @on-template="questionontemplate" :templateId="formInline.questionInfoId"
                  :templateName="formInline.questionnaireName"></question>
              </span>
            </div> -->
            <div class="itemlist">
              <el-switch
                v-model="formInline.phonePushSign"
                active-color="#13ce66"
                active-value="1"
                inactive-value="0"
              >
              </el-switch>
            </div>
          </div>
          <div class="flex">
            <div class="itemlist">
              重拨次数：
              <span>
                <el-select
                  v-model="formInline.phoneRedialTimes"
                  style="width: 100px"
                >
                  <el-option
                    v-for="item in optionslisttime"
                    :key="item.dictValue"
                    :label="item.dictLabel"
                    :value="item.dictValue"
                  >
                  </el-option>
                </el-select>
              </span>
            </div>
            <div class="itemlist">
              时间间隔(分)：
              <span>
                <el-input
                  v-model.number="formInline.phoneTimeInterval"
                  oninput="value=value.replace(/[^\d]/g,'')"
                  style="width: 100px"
                >
                </el-input>
              </span>
            </div>
            <div class="itemlist">
              短信提醒：
              <el-select
                v-model="formInline.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="itemlist">
              短信模板：
              <span
                :class="
                  formInline.phoneMessageRemind == 'NOT_SEND_MESSAGE'
                    ? 'spanname'
                    : ''
                "
              >
                <message
                  style="width: 200px"
                  @on-template="messageontemplateMESSAGE"
                  :templateId="formInline.phoneMessageTemplateId"
                  :templateName="formInline.phoneMessageTemplateName"
                >
                </message>
              </span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import propaganda from "../components/propaganda.vue";
import scriptphone from "../components/script.vue";
import scripts from "../components/script.vue";
import message from "../components/message.vue";
import question from "../components/question.vue";
import officialAccount from "../components/officialAccount.vue";
import miniProgram from "../components/miniProgram.vue";
import { signrouteadd } from "@/api/system/ManuallyCreatingTasks";
import { getAgencytype } from "@/api/system/agency";
import { list, triggerCondition, getList, } from "@/api/system/specialDiseaseNode";


export default {
  components: { scriptphone, question, propaganda, scripts, message, officialAccount, miniProgram },
  name: "ManuallyCreatingTasks",
  data() {
    return {
      // currentDate: '',
      time: '',
      datePickerVisible: true,
      show: 0,
      pickerOptions: {
        disabledDate(time) {
          // 选择今天以及今天之后的日期
          return time.getTime() < Date.now() - 8.64e7// 如果没有后面的-8.64e7就是不可以选择
          // 选择今天以及今天之前的日期
          // return time.getTime() > Date.now() - 8.64e7// 如果没有后面的-8.64e7就是不可以选择今天的
        }
      },
      heightLine: 0,
      optionsname: '',
      options: [],
      optionslist: [],
      optionslistS: [],
      optionslisttime: [],
      parentDictCodelist: [],
      updata: {
        sn: "",
        signPatientRecordId: "",
        patientId: "",
        patientName: "",
        departmentId: "",
        departmentName: "",
        routeName: "",
        suitRange: "OUTPATIENT_SERVICE_DISCHARGE",
        routeNodeList: [],
        triggerConditionList: [
          {
            routeId: "",
            routeName: "",
            triggerConditionName: "",
            triggerConditionOperator: "",
            triggerConditionValue: "",
          },
        ],
      },
      formInline: {
        routeNodeDay: "",
        taskNodeType: "",
        routeNodeName: "",
        // questionExpirationDate: 7,
        questionInfoId: "",
        questionnaireName: "",
        phoneId: "",
        phoneTemplateName: "",
        propagandaInfoId: "",
        propagandaTitle: "",
        nodeContent: "",
        officialPushSign: "0",
        messagePushSign: "0",
        appletPushSign: "0",
        phonePushSign: "1",
        phoneDialMethod: "",
      },
      list: [
        {
          routeNodeDay: "",
          taskNodeType: "",
          routeNodeName: "AFTER_VISIT_DISCHARGE",
          // questionExpirationDate: 7,
          questionInfoId: "",
          questionnaireName: "",
          phoneId: "",
          phoneTemplateName: "",
          propagandaInfoId: "",
          propagandaTitle: "",
          nodeContent: "",
          officialPushSign: "0",
          messagePushSign: "0",
          appletPushSign: "0",
          phonePushSign: "1",
          phoneDialMethod: "",
          plantype: "PLUSDAY",
          nodePlanTime: "",
          checked1: '',
          checked2: '',
          checked3: '',
        },
      ],
      listindex: 0,
      // optionstriggerConditionOperator: [], // 将这部分选项的
      // dictDataType: "",
    };
  },
  watch: {
  },

  created() {
    console.log(this.$route.query, 'this.$route.quer')

    this.infolist();
    this.infolistword();
    this.infolistMESSAGE();
    this.infolistoptionslistS();
    this.optiononditionOperators();
    this.optiononditionOperator();
    this.updata.signPatientRecordId = this.$route.query.signPatientRecordId;
    this.updata.patientId = this.$route.query.patientId;
    this.updata.sn = this.$route.query.sn;
    this.updata.patientName = this.$route.query.patientName;
    this.updata.departmentId = this.$route.query.departmentId;
    this.updata.departmentName = this.$route.query.departmentName;
    this.formInline = this.list[0];
    if (this.$route.query.path == '/patient/signRecord') {
      this.list[0].checked1 = 1
      this.list[0].routeNodeName = 'AFTER_VISIT_DISCHARGE'
      this.list[0].plantype = 'PLUSDAY'


    }
    if (this.$route.query.path == "/patient/patientinfoimport" || this.$route.query.path == "/task/Patientmanagement"
      || this.$route.query.path == "/patient/ImportDetails"

    ) {
      this.list[0].checked2 = 2
      this.list[0].routeNodeName = ''
      this.list[0].plantype = 'APPOINT'
    }

  },
  // computed: {
  //   currentDate() {
  //     return this.formatDate(new Date());
  //   },
  // },
  mounted() {
    this.getMaxTableHeight()
    this.screenChange()
  },
  methods: {
    formatDate(date) {
      // 格式化日期为想要的字符串格式
      // 例如: "2023-04-01 12:00:00"
      return `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')} ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}:${date.getSeconds().toString().padStart(2, '0')}`;
    },


    //  计划类型：plantype；
    // CURRENT：立即执行；
    // APPOINT：指定日期；
    // PLUSDAY：第几天
    // 第1行
    handleFocus(item) {
      console.log(item, 'item,index')
      item.checked1 = 1
      item.checked2 = ""
      item.checked3 = ""
      item.nodePlanTime = ""
      item.timedata = ""
      item.plantype = "PLUSDAY"

    },
    // 第1行
    handleFocusone(item) {
      item.checked1 = 1
      item.checked2 = ""
      item.checked3 = ""
      item.nodePlanTime = ""
      item.timedata = ""
      item.plantype = "PLUSDAY"


    },
    // 第2行
    setCurrentTime(item, index) {
      console.log(item, 'item,index')
      item.checked1 = ""
      item.checked2 = 2
      item.checked3 = ""
      // item.routeNodeName = ""
      item.routeNodeDay = ""
      item.plantype = "APPOINT"
      item.timedata = ""
    },

    input(item,index){
      this.$forceUpdate()
    //   const dateParts = item.nodePlanTime.split(' ');
    //  const date = new Date();
    //   // const year = date.getFullYear();
    // //   const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，所以需要加1
    // //   const day = String(date.getDate()).padStart(2, '0');
    //   const hours = String(date.getHours()).padStart(2, '0');
    //   const minutes = String(date.getMinutes()).padStart(2, '0');
    //   const ss = String(date.getSeconds()).padStart(2, '0');
    //   item.nodePlanTime  = dateParts[0]+ ' ' + hours + ':' + minutes + ':' + ss ;

    },
    // 出院/诊后
    handleCheckAllChange1(e, item) {
      console.log(e, item, 'value')
      item.checked2 = ""
      item.checked3 = ""
      item.checked1 = 1
      item.nodePlanTime = ""
      item.timedata = ""
      item.plantype = "PLUSDAY"
    },
    // 指定时间
    handleCheckAllChange2(e, item, index) {
      item.checked1 = ""
      item.checked3 = ""
      console.log(this.list, 'list')
      // item.routeNodeName = ""
      item.routeNodeDay = ""
      item.plantype = "APPOINT"
      item.timedata = ""
    },
    // 立即执行
    handleCheckAllChange3(e, item) {
      item.checked1 = ""
      item.checked2 = ""
      // item.routeNodeName = ""
      item.routeNodeDay = ""
      console.log(e, item, 'value3')
      let yy = new Date().getFullYear();
      let mm = (new Date().getMonth() + 1) < 10 ? '0' + (new Date().getMonth() + 1) : (new Date().getMonth() + 1);
      let dd = (new Date().getDate()) < 10 ? '0' + (new Date().getDate() + 1) : (new Date().getDate() + 1);
      let hh = new Date().getHours() < 10 ? '0' + new Date().getHours() : new Date().getHours();
      let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes();
      let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds();
      var data = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss
      item.timedata = data
      item.plantype = "CURRENT"
      item.nodePlanTime = ""
    },
    // 保存
    upload() {
      this.$confirm('保存此任务, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
      }).then(() => {
        this.updata.routeNodeList = this.list;
        var newObj = JSON.parse(JSON.stringify(this.updata));

        newObj.routeNodeList.forEach(e => {
          if (e.timedata) {
            e.nodePlanTime = e.timedata

          }
          const dateParts = e.nodePlanTime.split(' ');
          if (dateParts[1] == "00:00:00") {
            const date = new Date();
            const hours = String(date.getHours()).padStart(2, '0');
            const minutes = String(date.getMinutes()).padStart(2, '0');
            const ss = String(date.getSeconds()).padStart(2, '0');
            e.nodePlanTime = dateParts[0] + ' ' + hours + ':' + minutes + ':' + ss;
          }
          delete e.timedata;
          delete e.checked1;
          delete e.checked3;
        })
        // var nulllength= newObj.routeNodeList.filter(item => item.routeNodeName=="" || item.routeNodeName==null || item.routeNodeName==undefined);
        //   console.log(nulllength,'nulllength')
        //   if(nulllength.length>0){
        //     this.$message.error('节点名称不能为空！');
        //     return
        //   }

        console.log(newObj, 'this.newObj')
        console.log(this.updata, 'this.updata')
        // return
        signrouteadd(newObj).then((res) => {
          var message = ''
          if (this.$route.query.path == "/patient/signRecord") {
            message = '保存成功,即将返回签约患者列表'
          } else if (this.$route.query.path == "/patient/patientinfoimport") {
            message = '保存成功,即将返回患者导入列表'

          } else if (this.$route.query.path == "/patient/ImportDetails") {
            message = '保存成功,即将返回导入明细列表'
          }
          else if (this.$route.query.path == "/task/Patientmanagement") {
            message = '保存成功,即将返回创建任务列表'
          }
          this.$notify({
            type: "success",
            title: "提示",
            message: message,
            duration: 3000,
          });
          setTimeout(() => {
            this.$store
              .dispatch("tagsView/delView", this.$route)
              .then(({ visitedViews }) => {
                this.$router.push({
                  path: this.$route.query.path
                });
              });
          }, 3000);
        });
      })
    },

    //点击任务内容
    taskNodeTypechange(e) {
      if (e == 'PHONE_OUTBOUND') {
        this.formInline.phoneDialMethod = 'AI'
      } else {
        this.formInline.phoneDialMethod = ''
      }
    },
    // 且或
    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.updata.triggerConditionList.optionstriggerConditionOperator = res.data;
      // });
    },
    // 包含
    changetriggerLogic(e, index) {
      // this.openlist.triggerConditionList[index].triggerConditionOperatorName =
      //   this.openlist.triggerConditionList[index].optionstriggerConditionOperator.find(
      //     (el) => el.dictValue == e
      //   ).dictLabel;
      // this.updata.triggerConditionList[index].triggerConditionValue = null;
    },
    // 诊断
    changetriggerConditionName(e, index) {
      // var dictType = e;
      // getAgencytype(dictType).then((res) => {
      //   this.ConditionValue = res.data;
      // });
      // this.updata.triggerConditionList[index].triggerConditionName =
      //   this.optionsname.find((el) => el.dictValue == e).dictLabel;
      // this.updata.triggerConditionList[index].triggerConditionValue = null;
      // this.updata.triggerConditionList[index].triggerConditionOperator = null
      // this.dictDataType = this.optionsname.find((el) => el.dictValue == e).dictDataType;
      // this.handlelist(index)
      // this.updata.triggerConditionList[index].dictDataType =
      //   this.optionsname.find((el) => el.dictValue == e).dictDataType;
    },
    // 包含或等号接口
    handlelist(index) {
      // var dictType = "trigger_condition_operator";
      // // this.openlist.triggerConditionList[index].optionstriggerConditionOperator=[]
      // getList(dictType, this.dictDataType).then((res) => {
      //   this.$set(this.updata.triggerConditionList[index], 'optionstriggerConditionOperator', res.data)
      //   this.$forceUpdate();
      // });
    },
    // 包含
    optiononditionOperator() {
      // var dictType = "trigger_condition_operator";
      // getAgencytype(dictType).then((res) => {
      //   this.updata.triggerConditionList.optionstriggerConditionOperator = res.data;
      // });
    },
    // 且或
    changetriggerLogicsname(e, index) {
      // this.updata.triggerConditionList[index].triggerLogic = e;
      // this.updata.triggerConditionList[index].triggerLogicName = this.optionslistS.find((el) => el.dictValue == e).dictLabel;
    },
    // 弹框确定
    // submit() {
    //   const loading = this.$loading({
    //     lock: true,
    //     text: "Loading",
    //     spinner: "el-icon-loading",
    //     background: "rgba(0, 0, 0, 0.7)",
    //   });
    //   this.updata.triggerConditionList.forEach((e) => {
    //     e.routeId = this.$route.query.id;
    //     e.routeName = this.$route.query.routeName;
    //     delete e.optionstriggerConditionOperator
    //   });
    //   delete this.updata.triggerConditionList.optionstriggerConditionOperator
    //   loading.close();
    //   return;
    //   triggerCondition(this.updata).then((res) => {
    //     if (res.code == 200) {
    //       this.$notify({
    //         type: "success",
    //         title: "提示",
    //         message: "修改触发条件成功",
    //       });
    //       this.itemlist.routeName = res.data;
    //     }
    //     this.infolist();
    //     // this.handlelist();
    //     this.openfalse();
    //   });
    // },
    infolist() {
      var dictType = "suit_range";
      getAgencytype(dictType).then((res) => {
        this.options = res.data;
        if (this.options) {
          this.changeoptions(this.updata.suitRange)

        }
      });
    },
    infolistword() {
      var dictType = "text_message_remind";
      getAgencytype(dictType).then((res) => {
        this.optionslist = res.data;
      });
    },
    infolistMESSAGE() {
      var dictType = "redial_times";
      getAgencytype(dictType).then((res) => {
        this.optionslisttime = res.data;
      });
    },
    changeoptions(e) {
      console.log(e, 'e');
      let parentDictCode = this.options.find((el) => el.dictValue == e).dictCode;
      list(parentDictCode).then((res) => {
        this.parentDictCodelist = res.rows;
      });
    },
    // 删除属性
    delitemlistname(index, item) {
      // this.updata.triggerConditionList.splice(index, 1);
      // setTimeout(() => {
      //   this.getMaxTableHeight()
      // }, 20);
    },
    addtriggerCondition() {
      // var obj = {
      //   routeId: "",
      //   routeName: "",
      //   triggerConditionName: "",
      //   triggerConditionOperator: "",
      //   triggerConditionValue: "",
      //   triggerConditionOperatorName: "",
      //   dictDataType: "STRING",
      //   triggerLogic: "AND",
      //   triggerLogicName: "",
      // };
      // if (this.updata.triggerConditionList.length == 3) {
      //   this.$message.error("至多仅支持两种属性");
      // } else {
      //   this.updata.triggerConditionList.push(obj);
      // }
      // setTimeout(() => {
      //   this.getMaxTableHeight()
      // }, 20);
    },
    //宣教传值
    propagandaontemplate(item) {
      this.formInline.propagandaInfoId = item.templateId;
      this.formInline.propagandaTitle = item.templateName;
    },
    //问卷传值
    questionontemplate(item) {
      if (this.formInline.taskNodeType == "ARTIFICIAL_FOLLOW_UP") {
        this.formInline.followTemplateId = item.templateId;
        this.formInline.followTemplateName = item.templateName;
      } else {
        this.formInline.questionInfoId = item.templateId;
        this.formInline.questionnaireName = item.templateName;
      }
    },
    //话术传值
    scriptphoneontemplate(item) {
      this.formInline.phoneId = item.templateId;
      this.formInline.phoneTemplateName = item.templateName;
    },
    // 短信
    messageontemplateMESSAGE(item) {
      this.formInline.phoneMessageTemplateId = item.templateId;
      this.formInline.phoneMessageTemplateName = item.templateName;
      this.list[this.listindex].messageTemplateCode = item.messageTemplateCode

    },
    messageontemplateMESSAGEtwo(item) {
      this.formInline.messageTemplateId = item.templateId;
      this.formInline.messageTemplateName = item.templateName;
      this.list[this.listindex].messageTemplateCode = item.messageTemplateCode
    },
    // 话术
    messageontemplateword(item) {
      this.formInline.phoneId = item.templateId;
      this.formInline.phoneTemplateName = item.templateName;
      this.list[this.listindex].scriptInfoId = item.scriptInfoId
      this.list[this.listindex].phoneTemplateId = item.phoneTemplateId
    },
    //公众号传值
    officialAccountontemplate(item) {
      this.formInline.officialTemplateId = item.templateId;
      this.formInline.officialTemplateName = item.templateName;
      this.formInline.officialRemindContent = item.templateContent;
      this.list[this.listindex].officialTemplateCode = item.officialTemplateCode

    },
    //小程序传值
    miniProgramtemplate(item) {
      this.formInline.appletTemplateId = item.templateId;
      this.formInline.appletTemplateName = item.templateName;
      this.formInline.appletRemindContent = item.templateContent;
      this.list[this.listindex].appletTemplateCode = item.appletTemplateCode
    },
    clicktimelineitem(item, index) {
      this.formInline = item;
      this.listindex = index;
    },
    additem() {
      let routeNodeName = this.parentDictCodelist.length > 0 ? this.parentDictCodelist[0].dictValue : ""
      this.list.push({
        routeNodeDay: "",
        taskNodeType: "",
        routeNodeName: routeNodeName,
        // questionExpirationDate: 7,
        questionInfoId: "",
        questionnaireName: "",
        phoneId: "",
        phoneTemplateName: "",
        propagandaInfoId: "",
        propagandaTitle: "",
        nodeContent: "",
        officialPushSign: "0",
        messagePushSign: "0",
        appletPushSign: "0",
        phonePushSign: "1",
        phoneDialMethod: "",
        nodePlanTime: '',
        checked1: 1,
        checked2: "",
        checked3: "",

        timedata: "",

      });
      console.log(this.list, 'this.list');
    },
    delitem(item, index, list) {
      list.splice(index, 1);
    },
    changephoneDialMethodtwo() {
      this.formInline.questionInfoId = ''
      this.formInline.questionInfoName = ''
      this.formInline.phoneId = ''
      this.formInline.phoneTemplateName = ''
    },
    changephoneDialMethod(e) {
      if (e == 'AI') {
        this.formInline.phoneId = ''
        this.formInline.phoneTemplateName = ''
      } else if (e == 'COMMON') {
        this.formInline.questionInfoId = ''
        this.formInline.questionInfoName = ''
        this.formInline.phoneId = ''
        this.formInline.phoneTemplateName = ''
      }
    },
    // 获取表格最高高度
    getMaxTableHeight() {
      const windowInnerHeight = window.innerHeight // 屏幕可视高度
      const layoutDiv = this.$refs.layout
      this.heightLine =
        windowInnerHeight - 84 -
        this.getBoxHeight(layoutDiv)
    },
    // 屏幕resize监听
    screenChange() {
      // 屏幕resize监听事件：一旦屏幕宽高发生变化，就会执行resize
      window.addEventListener('resize', this.getMaxTableHeight, true)
      // 将屏幕监听事件移除
      // 这步是必须的。离开页面时不移除，再返回，或者进入到别的有相同元素的页面会报错
      // 或者将这里的方法直接写在beforeDestroy函数中也可以
      this.$once('hook:beforeDestroy', () => {
        window.removeEventListener('resize', this.getMaxTableHeight, true)
      })
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-form--inline .el-form-item__label {
  display: inline-block !important;
  float: inline-start !important;
}
::v-deep .el-input.is-disabled .el-input__inner {
  background: #fff;
}

.titlemengt {
  width: 98.5%;
  border-radius: 10px;
  padding: 10px 20px;
  margin: 0 auto;
  background-color: #fff;
  position: relative;
}

::-webkit-scrollbar {
  width: 5px;
}

::-webkit-scrollbar-thumb {
  border-radius: 5px;
  background: #c0c0c0;
}

::-webkit-scrollbar-track {
  width: 5px;
}

.chufatitle {
  display: flex;
  align-items: center;

  span {
    margin-right: 30px;
    font-size: 16px;
    font-weight: bold;
  }
}

.login-code-img {
  width: 84px;
  height: 100px;
  position: absolute;
  // background: red;
  z-index: 0;
  position: absolute;
  top: -90%;
}

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

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

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

      .spanname {
        pointer-events: none;
      }

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

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

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

  .node {
    margin-bottom: 10px;
    margin-left: 102px;

    .el-icon-delete {
      padding-left: 10px;
    }
  }
}
.PushMethod {
  height: 100px;
  padding: 20px;
  line-height: 60px;
  margin-top: 10px;
  border-radius: 10px;
  background-color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nodes {
  // height: var(--heightLine);
  background-color: #f1f3f5;
  // height: 700px;
  // height: calc(100vh - 300px);
  display: flex;
  justify-content: space-evenly;
  padding-top: 10px;

  .nodenames {
    border-radius: 10px;
    background-color: #fff;
    // height: calc(100vh - 320px);
    height: 100%;
    width: 25%;
    padding: 0 5px 20px 40px;
    background-color: #fff;

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

    ::v-deep .el-timeline {
      width: 100%;
      overflow-y: auto;
      height: calc(100% - 60px);
      padding: 15px 30px 0 0 !important;
    }
  }

  .nodetexts {
    padding-bottom: 20px;
    overflow-y: scroll;
    border-radius: 10px;
    width: 73%;
    // height: calc(100vh - 320px);
    height: 100%;
  }
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  .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__node--normal {
  left: 0px;
}
::v-deep .el-timeline-item__timestamp {
  margin: 0 !important;
  padding: 0 !important;
}

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

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

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

::v-deep .el-card {
  margin-top: 20px !important;
}

.dialog-footer {
  display: inline-block;
  float: right;
}

::v-deep .el-form-item__content {
  display: inline-block !important;
}
::v-deep .el-icon-circle-plus-outline {
  cursor: pointer;
}
::v-deep .el-icon-delete {
  cursor: pointer;
}
</style>
