WXL (wul)
6 天以前 a5cba9ab040f6f97558046885dce3017f9bab7e9
src/views/patient/propaganda/QuestionnaireTask.vue
@@ -69,17 +69,7 @@
                    placeholder="请输入任务描述"
                  />
                </el-form-item>
                <!-- <el-form-item label="服务形式">
                  <el-radio-group v-model="checkList">
                    <el-radio
                      v-for="(item, index) in checkboxlist"
                      :key="index"
                      :label="item.value"
                    >
                      {{ item.label }}</el-radio
                    >
                  </el-radio-group>
                </el-form-item> -->
                <el-form-item label="服务形式">
                  <SortCheckbox
                    v-model="checkList"
@@ -90,6 +80,7 @@
                    @change="checkSelectionChange"
                  />
                </el-form-item>
                <el-form-item label="执行周期" prop="longTask">
                  <el-radio-group v-model="form.longTask">
                    <el-radio :label="0">自定义周期</el-radio>
@@ -207,14 +198,51 @@
                    </div>
                  </div>
                </el-form-item>
                <el-form-item label="任务关联" prop="longTask">
                  <el-radio-group v-model="form.appltype">
                    <el-radio label="1">科室关联</el-radio>
                    <el-radio label="2">病区关联</el-radio>
                    <el-radio label="3">疾病关联</el-radio>
                    <el-radio label="4">手术关联</el-radio>
                    <el-radio label="6" v-if="orgname == '省立同德翠苑院区'"
                      >药品关联</el-radio
                    >
                    <el-radio label="5">任务组</el-radio>
                  </el-radio-group>
                </el-form-item>
                <!-- 药品关联 -->
                <el-row v-if="form.appltype == 6">
                  <el-col :span="20">
                    <el-form-item label="关联药品" prop="region">
                      <el-select
                        v-model="medicalCodes"
                        @remove-tag="removeMedical"
                        style="width: 400px"
                        size="medium"
                        multiple
                        filterable
                        remote
                        reserve-keyword
                        :remote-method="remoteSearchMedical"
                        placeholder="请输入药品名称搜索"
                        loading-text="搜索中..."
                      >
                        <el-option
                          v-for="item in medicalOptions"
                          :key="item.id"
                          :label="
                            item.itemName + ' (' + item.manufacturerName + ')'
                          "
                          :value="item.itemCode"
                        />
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <!-- 科室关联 -->
                <el-row v-if="form.appltype == 1">
                  <el-col :span="20"
                    ><el-form-item label="适用科室" prop="region">
@@ -237,6 +265,8 @@
                      </el-select> </el-form-item
                  ></el-col>
                </el-row>
                <!-- 病区关联 -->
                <el-row v-if="form.appltype == 2">
                  <el-col :span="20"
                    ><el-form-item label="适用病区" prop="region">
@@ -259,30 +289,9 @@
                      </el-select> </el-form-item
                  ></el-col>
                </el-row>
                <!-- 疾病关联 -->
                <el-row v-if="form.appltype == 3">
                  <!-- <el-col :span="20"
                    ><el-form-item label="适用疾病" prop="region">
                      <el-select
                        v-model="illnesscodes"
                        style="width: 400px"
                        @remove-tag="removediagg"
                        size="medium"
                        :remote-method="remotedonor"
                        multiple
                        filterable
                        remote
                        placeholder="请选择病区"
                      >
                        <el-option
                          class="ruleFormaa"
                          v-for="item in donorchargeList"
                          :key="item.icdcode"
                          :label="item.icdname"
                          :value="item.icdcode"
                        >
                        </el-option>
                      </el-select> </el-form-item
                  ></el-col> -->
                  <div class="xinz-infs">
                    <el-form-item>
                      <template #label>
@@ -311,34 +320,456 @@
                      >
                        {{ tag.icdname }}
                      </el-tag>
                      <!-- <el-tag v-if="hasMore" type="info">+{{ remaining }} more</el-tag> -->
                    </el-form-item>
                  </div>
                </el-row>
                <el-row v-if="form.appltype == 4">
                  <el-col :span="20"
                    ><el-form-item label="适用手术" prop="region">
                      <el-select
                        v-model="operationcodes"
                        style="width: 400px"
                        @remove-tag="removeopera"
                        size="medium"
                        :remote-method="remoteopcode"
                        multiple
                        filterable
                        remote
                        placeholder="请选择手术"
                      >
                        <el-option
                          class="ruleFormaa"
                          v-for="item in baseoperaList"
                          :label="item.opdesc"
                          :value="item.opcode"
                  <div
                    style="
                      margin-bottom: 20px;
                      padding: 8px 12px;
                      background-color: #f0f9ff;
                      border-left: 4px solid #409eff;
                    "
                  >
                    <p style="margin: 0; color: #606266; font-size: 13px">
                      <i
                        class="el-icon-info"
                        style="color: #409eff; margin-right: 6px"
                      ></i>
                      针对同一疾病在多科室/病区下存在的情况,可选择性配置固定科室/病区
                    </p>
                  </div>
                  <el-row :gutter="20" style="margin-top: 20px">
                    <el-col :span="12">
                      <el-form-item label="关联科室" prop="diseaseDept">
                        <el-select
                          v-model="diseaseDept"
                          style="width: 100%"
                          clearable
                          filterable
                          placeholder="请选择科室(可选)"
                          value-key="deptCode"
                          @change="handleDiseaseDeptChange"
                        >
                        </el-option>
                      </el-select> </el-form-item
                  ></el-col>
                          <el-option
                            v-for="item in belongDepts"
                            :key="item.deptCode"
                            :label="item.deptName"
                            :value="item"
                          ></el-option>
                        </el-select>
                        <div v-if="diseaseDept" class="selected-info">
                          已选择: {{ diseaseDept.deptName }} ({{
                            diseaseDept.deptCode
                          }})
                        </div>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="关联病区" prop="diseaseWard">
                        <el-select
                          v-model="diseaseWard"
                          style="width: 100%"
                          clearable
                          filterable
                          placeholder="请选择病区(可选)"
                          value-key="districtCode"
                          @change="handleDiseaseWardChange"
                        >
                          <el-option
                            v-for="item in belongWards"
                            :key="item.districtCode"
                            :label="item.districtName"
                            :value="item"
                          ></el-option>
                        </el-select>
                        <div v-if="diseaseWard" class="selected-info">
                          已选择: {{ diseaseWard.districtName }} ({{
                            diseaseWard.districtCode
                          }})
                        </div>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-row>
                <!-- 手术关联 -->
                <el-row v-if="form.appltype == 4">
                  <el-form-item label="适用手术" prop="region">
                    <el-select
                      v-model="form.oplevelcode"
                      style="width: 400px"
                      @remove-tag="removeopera"
                      size="medium"
                      :remote-method="remoteopcode"
                      filterable
                      remote
                      placeholder="请选择手术"
                    >
                      <el-option
                        class="ruleFormaa"
                        v-for="item in baseoperaList"
                        :label="item.label"
                        :value="item.value"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <div
                    style="
                      margin-bottom: 20px;
                      padding: 8px 12px;
                      background-color: #f0f9ff;
                      border-left: 4px solid #409eff;
                    "
                  >
                    <p style="margin: 0; color: #606266; font-size: 13px">
                      <i
                        class="el-icon-info"
                        style="color: #409eff; margin-right: 6px"
                      ></i>
                      针对同一手术类型在多科室/病区下存在的情况,可选择性配置固定科室/病区
                    </p>
                  </div>
                  <el-row :gutter="20" style="margin-top: 20px">
                    <el-col :span="12">
                      <el-form-item label="关联科室" prop="diseaseDept">
                        <el-select
                          v-model="diseaseDept"
                          style="width: 100%"
                          clearable
                          filterable
                          placeholder="请选择科室(可选)"
                          value-key="deptCode"
                          @change="handleDiseaseDeptChange"
                        >
                          <el-option
                            v-for="item in belongDepts"
                            :key="item.deptCode"
                            :label="item.deptName"
                            :value="item"
                          ></el-option>
                        </el-select>
                        <div v-if="diseaseDept" class="selected-info">
                          已选择: {{ diseaseDept.deptName }} ({{
                            diseaseDept.deptCode
                          }})
                        </div>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="关联病区" prop="diseaseWard">
                        <el-select
                          v-model="diseaseWard"
                          style="width: 100%"
                          clearable
                          filterable
                          placeholder="请选择病区(可选)"
                          value-key="districtCode"
                          @change="handleDiseaseWardChange"
                        >
                          <el-option
                            v-for="item in belongWards"
                            :key="item.districtCode"
                            :label="item.districtName"
                            :value="item"
                          ></el-option>
                        </el-select>
                        <div v-if="diseaseWard" class="selected-info">
                          已选择: {{ diseaseWard.districtName }} ({{
                            diseaseWard.districtCode
                          }})
                        </div>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-row>
                <!-- ========= 任务组 (appltype=5) ========= -->
                <div v-if="form.appltype == 5">
                  <el-divider content-position="left">任务组主计划</el-divider>
                  <el-form-item label="执行方式">
                    <el-radio-group
                      v-model="form.serviceTaskScheduleVO.scheduleStyle"
                    >
                      <el-radio :label="0">非循环</el-radio>
                      <el-radio :label="1">循环</el-radio>
                    </el-radio-group>
                  </el-form-item>
                  <div v-if="form.serviceTaskScheduleVO.scheduleStyle == 1">
                    <el-row :gutter="20" style="margin-top: 20px">
                      <el-col :span="12">
                        <el-form-item label="循环间隔">
                          <el-input-number
                            v-model="form.serviceTaskScheduleVO.scheduleTimeNum"
                            :min="1"
                            style="width: 120px"
                          />
                          <el-select
                            v-model="
                              form.serviceTaskScheduleVO.scheduleTimeUnit
                            "
                            placeholder="单位"
                            style="width: 100px; margin-left: 8px"
                          >
                            <el-option label="天" :value="1" />
                            <el-option label="周" :value="2" />
                            <el-option label="月" :value="3" />
                            <el-option label="年" :value="4" />
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="最大轮次">
                          <el-input-number
                            v-model="form.serviceTaskScheduleVO.maxLoopCount"
                            :min="0"
                            :step="1"
                            placeholder="0表示无限"
                          />
                        </el-form-item>
                      </el-col>
                    </el-row>
                  </div>
                  <el-row :gutter="20" style="margin-top: 20px">
                    <el-col :span="12">
                      <el-form-item label="基准时间">
                        <el-radio-group
                          v-model="form.serviceTaskScheduleVO.scheduleBenchmark"
                        >
                          <el-radio :label="0">自定义</el-radio>
                          <el-radio :label="1">入院时间</el-radio>
                          <el-radio :label="2">出院时间</el-radio>
                          <el-radio :label="3">就诊时间</el-radio>
                          <el-radio :label="4">入组时间</el-radio>
                        </el-radio-group>
                      </el-form-item>
                    </el-col>
                    <el-col
                      :span="12"
                      v-if="form.serviceTaskScheduleVO.scheduleBenchmark == 0"
                    >
                      <el-form-item label="自定义基准时间">
                        <el-date-picker
                          v-model="
                            form.serviceTaskScheduleVO
                              .scheduleBenchmarkCustomTime
                          "
                          type="datetime"
                          placeholder="选择日期时间"
                          value-format="yyyy-MM-dd HH:mm:ss"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="下次执行时间">
                        <el-date-picker
                          v-model="form.serviceTaskScheduleVO.nextExecuteTime"
                          type="datetime"
                          placeholder="选择首次执行时间"
                          value-format="yyyy-MM-dd HH:mm:ss"
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="20" style="margin-top: 20px">
                    <el-col :span="12">
                      <el-form-item label="关联科室" prop="diseaseDept">
                        <el-select
                          v-model="diseaseDept"
                          style="width: 100%"
                          clearable
                          filterable
                          placeholder="请选择科室(可选)"
                          value-key="deptCode"
                          @change="handleDiseaseDeptChange"
                        >
                          <el-option
                            v-for="item in belongDepts"
                            :key="item.deptCode"
                            :label="item.deptName"
                            :value="item"
                          ></el-option>
                        </el-select>
                        <div v-if="diseaseDept" class="selected-info">
                          已选择: {{ diseaseDept.deptName }} ({{
                            diseaseDept.deptCode
                          }})
                        </div>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="关联病区" prop="diseaseWard">
                        <el-select
                          v-model="diseaseWard"
                          style="width: 100%"
                          clearable
                          filterable
                          placeholder="请选择病区(可选)"
                          value-key="districtCode"
                          @change="handleDiseaseWardChange"
                        >
                          <el-option
                            v-for="item in belongWards"
                            :key="item.districtCode"
                            :label="item.districtName"
                            :value="item"
                          ></el-option>
                        </el-select>
                        <div v-if="diseaseWard" class="selected-info">
                          已选择: {{ diseaseWard.districtName }} ({{
                            diseaseWard.districtCode
                          }})
                        </div>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <div class="xinz-infs">
                      <el-form-item>
                        <template #label>
                          <el-tooltip
                            class="item"
                            effect="light"
                            content="选择好适用疾病后,可以方便您通过疾病诊断查找到对应的病人!"
                            placement="top-start"
                          >
                            <i class="el-icon-warning-outline"></i>
                          </el-tooltip>
                        </template>
                        <div style="margin-bottom: 10px">
                          <el-button
                            type="warning"
                            @click="$refs.child.handleAddpatient()"
                            >添加疾病诊断</el-button
                          >
                        </div>
                        <el-tag
                          v-for="tag in diagglist"
                          @close="removediagg(tag.icd10code)"
                          type="warning"
                          closable
                          :disable-transitions="false"
                        >
                          {{ tag.icdname }}
                        </el-tag>
                      </el-form-item>
                    </div>
                  </el-row>
                  <!-- 明细列表 -->
                  <el-row :gutter="20" style="margin-top: 20px">
                    <el-col :span="24">
                      <el-divider content-position="left"
                        >任务明细列表</el-divider
                      >
                      <el-button
                        type="primary"
                        size="small"
                        icon="el-icon-plus"
                        @click="addDetail"
                        >添加明细</el-button
                      >
                      <el-table
                        :data="form.serviceTaskScheduleVO.detailList"
                        border
                        style="width: 100%; margin-top: 10px"
                      >
                        <el-table-column label="序号" width="80" align="center">
                          <template slot-scope="scope">{{
                            scope.row.seq
                          }}</template>
                        </el-table-column>
                        <el-table-column label="间隔天数" width="120">
                          <template slot-scope="scope">
                            <el-input-number
                              v-model="scope.row.dayOffset"
                              :min="0"
                              size="small"
                              controls-position="right"
                            />
                          </template>
                        </el-table-column>
                        <el-table-column label="模板" min-width="200">
                          <template slot-scope="scope">
                            <el-select
                              v-model="scope.row.templateid"
                              filterable
                              remote
                              :remote-method="remoteTemplate"
                              placeholder="搜索模板"
                              size="small"
                              @change="
                                handleTemplateSelect(scope.$index, scope.row)
                              "
                            >
                              <el-option
                                v-for="item in templateOptions"
                                :key="item.svyid"
                                :label="item.svyname"
                                :value="item.svyid"
                              >
                                <span style="float: left">{{
                                  item.svyname
                                }}</span>
                                <span
                                  style="
                                    float: right;
                                    color: #8492a6;
                                    font-size: 12px;
                                  "
                                  >{{ item.createBy }}</span
                                >
                              </el-option>
                            </el-select>
                            <span
                              style="
                                margin-left: 5px;
                                font-size: 12px;
                                color: #909399;
                              "
                              >{{ scope.row.templatename }}</span
                            >
                          </template>
                        </el-table-column>
                        <el-table-column label="开场白" min-width="150">
                          <template slot-scope="scope">
                            <el-input
                              v-model="scope.row.kcb"
                              size="small"
                              placeholder="可选"
                            />
                          </template>
                        </el-table-column>
                        <el-table-column label="结束语" min-width="150">
                          <template slot-scope="scope">
                            <el-input
                              v-model="scope.row.jsy"
                              size="small"
                              placeholder="可选"
                            />
                          </template>
                        </el-table-column>
                        <el-table-column
                          label="操作"
                          width="100"
                          align="center"
                        >
                          <template slot-scope="scope">
                            <el-button
                              size="mini"
                              type="danger"
                              icon="el-icon-delete"
                              @click="removeDetail(scope.$index)"
                            ></el-button>
                          </template>
                        </el-table-column>
                      </el-table>
                    </el-col>
                  </el-row>
                </div>
                <!-- ===== 任务组结束 ===== -->
                <el-row>
                  <el-col :span="12"
                    ><el-form-item label="开场白" prop="kcb">
@@ -375,10 +806,6 @@
                      placeholder="请点击右侧选择"
                    />
                    <el-button
                      v-if="
                        (form.templateid && form.sendState == 1) ||
                        !form.templateid
                      "
                      style="margin-left: 10px"
                      type="primary"
                      icon="el-icon-edit"
@@ -423,11 +850,6 @@
                    </el-table-column>
                    <el-table-column label="操作" align="center">
                      <template slot-scope="scope">
                        <!-- <el-button
                          size="mini"
                          @click="variableEdit(scope.$index, scope.row)"
                          >编辑</el-button
                        > -->
                        <el-button
                          size="mini"
                          type="danger"
@@ -451,7 +873,6 @@
          @click="submitForm('ruleForm')"
          >{{ quote ? "立即创建" : "确认服务配置" }}</el-button
        >
        <!-- <el-button @click="resetForm('ruleForm')">重置</el-button> -->
      </div>
      <!-- 任务详情 -->
      <div v-if="Editprogress == 2">
@@ -492,22 +913,7 @@
                        >新增</el-button
                      >
                    </el-col>
                    <!-- <el-col :span="1.5">
                      <el-button
                        type="danger"
                        plain
                        icon="el-icon-delete"
                        size="medium"
                        :disabled="multiple"
                        @click="handleDelete"
                        >删除</el-button
                      >
                    </el-col> -->
                    <!-- <el-col :span="1.5"> </el-col> -->
                  </el-row>
                  <!-- 选中患者列表 -->
                  <SFtable
                    @details="detailhz"
                    @handleUpdate="handleUpdate"
@@ -519,13 +925,6 @@
                    :controlxz="false"
                    :typeinfo="2"
                  />
                  <!-- <pagination
                    v-show="total > 0"
                    :total="total"
                    :page.sync="topqueryParams.pageNum"
                    :limit.sync="topqueryParams.pageSize"
                    @pagination="getList"
                  /> -->
                </el-row>
              </div>
            </div>
@@ -538,7 +937,6 @@
          @click="submitForm('ruleForm')"
          >{{ quote ? "立即创建" : "确认服务配置" }}</el-button
        >
        <!-- <el-button @click="resetForm('ruleForm')">重置</el-button> -->
      </div>
    </div>
    <!-- 添加患者 -->
@@ -552,7 +950,6 @@
      <div class="examine-jic">
        <div class="jic-value">
          <el-row :gutter="20">
            <!--用户数据-->
            <el-form
              :model="patientqueryParams"
              ref="queryForm"
@@ -608,7 +1005,6 @@
                >
              </el-form-item>
            </el-form>
            <!-- 选择患者列表 -->
            <SFtable
              ref="multipleTable"
              @handleSelectionChange="handleSelectionChange"
@@ -639,8 +1035,8 @@
    <!-- 模板预览 -->
    <el-dialog title="模板预览" :visible.sync="previewtf" width="70%">
      <el-tabs type="border-card">
        <el-tab-pane label="模板基础数据"
          ><div class="preview-left">
        <el-tab-pane label="模板基础数据">
          <div class="preview-left">
            <el-form :model="objyl" label-width="100px" class="demo-objyl">
              <el-row :gutter="10">
                <el-col :span="14">
@@ -730,10 +1126,11 @@
                >
                </el-input
              ></el-form-item>
            </el-form></div
        ></el-tab-pane>
        <el-tab-pane label="问题展示"
          ><div class="preview-left">
            </el-form>
          </div>
        </el-tab-pane>
        <el-tab-pane label="问题展示">
          <div class="preview-left">
            <div v-for="item in questionList">
              <!-- 单选 -->
              <div
@@ -742,7 +1139,7 @@
                v-if="item.scriptType == 1"
              >
                <div class="dev-text">
                  {{ item.sort }}、[单选]<span>{{ item.scriptContent }}</span>
                  {{ item.sort }}. [单选]<span>{{ item.scriptContent }}</span>
                </div>
                <div class="dev-xx">
                  <el-radio-group v-model="item.remark">
@@ -762,7 +1159,7 @@
                v-if="item.scriptType == 2"
              >
                <div class="dev-text">
                  {{ item.sort }}、[多选]<span>{{ item.scriptContent }}</span>
                  {{ item.sort }}. [多选]<span>{{ item.scriptContent }}</span>
                </div>
                <div class="dev-xx">
                  <el-checkbox-group v-model="item.qremark">
@@ -783,7 +1180,7 @@
                v-if="item.scriptType == 4"
              >
                <div class="dev-text">
                  {{ item.sort }}、[问答]<span>{{ item.scriptContent }}</span>
                  {{ item.sort }}. [问答]<span>{{ item.scriptContent }}</span>
                </div>
                <div class="dev-xx">
                  <el-input
@@ -794,8 +1191,9 @@
                  </el-input>
                </div>
              </div>
            </div></div
        ></el-tab-pane>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
      <span slot="footer" class="dialog-footer">
@@ -804,21 +1202,6 @@
          >保存使用</el-button
        >
      </span>
      <!-- <span slot="footer" class="dialog-footer">
        <el-button
          v-if="(form.templateid && form.sendState == 1) || !form.templateid"
          type="primary"
          @click="Departmenttreatment"
          >{{ form.templateid ? "替换使用" : "选择使用" }}</el-button
        >
        <el-button
          :type="previewtftype ? 'success' : 'warning'"
          @click="previewGo"
          >{{
            previewtftype ? "前往修改已选择模板" : "新增保存并前往修改"
          }}</el-button
        >
      </span> -->
    </el-dialog>
    <el-drawer
      title="问卷内容列表"
@@ -830,8 +1213,6 @@
      <div class="examine-jic">
        <div class="jic-value">
          <el-row :gutter="20">
            <!--用户数据-->
            <el-form
              :model="topqueryParams"
              ref="queryForm"
@@ -846,17 +1227,6 @@
                  @keyup.enter.native="handleQuerymb"
                ></el-input>
              </el-form-item>
              <!-- <el-form-item label="适用形式" prop="status">
                <el-select v-model="topqueryParams.topica" placeholder="请选择">
                  <el-option
                    v-for="item in taskoptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item> -->
              <el-form-item>
                <el-button
                  type="primary"
@@ -874,7 +1244,6 @@
              </el-form-item>
            </el-form>
            <el-divider></el-divider>
            <!-- 选择模板列表 -->
            <SFtable
              @selectfn="selectfn"
              :currentList="userList"
@@ -904,7 +1273,6 @@
    />
  </div>
</template>
<script>
import { messagelistpatient } from "@/api/patient/homepage";
import store from "@/store";
@@ -917,6 +1285,7 @@
  Externallist,
  getQtemplatelist,
  getQtemplateobj,
  taskgetQtemplateobj,
  TaskQuestioncomit,
  deleteTaskQuestioncomit,
  Questionnairetaskgetson,
@@ -928,12 +1297,14 @@
  taskdepthospgetsondel,
  taskdepthospgetsonlist,
  taskdiaggetlist,
  rwztaskdepthospgetsonlist,
  rwztaskdiaggetlist,
  taskopergetlist,
} from "@/api/AiCentre/index";
import OptionalForm from "@/components/OptionalForm"; //疾病添加组件
import SFtable from "@/components/SFtable"; //表格组件
import SortCheckbox from "@/components/SortCheckbox"; //表格组件
import { listMedication } from "@/api/knowledge/drug";
import OptionalForm from "@/components/OptionalForm";
import SFtable from "@/components/SFtable";
import SortCheckbox from "@/components/SortCheckbox";
import { MessageBox } from "element-ui";
export default {
@@ -941,38 +1312,42 @@
  data() {
    return {
      title: "宣教内容列表",
      currenttype: 1, //1宣教2门诊3出院4复诊5体检6问卷
      id: "", //
      previewid: "", //任务模板传递id
      currenttype: 1,
      id: "",
      previewid: "",
      libName: "",
      templateor: false,
      submitLoading: false, // 控制按钮加载状态
      submitLoading: false,
      objyl: {},
      overallCase: [], //选择患者总
      overallCase: [],
      allpids: [],
      appraiselist: [],
      optionsclass: [],
      illnesslist: [],
      mode: [],
      libId: null, //模板库模板id
      Editprogress: 1, //编辑进度
      drawermb: false, //选择模板弹窗
      previewtf: false, //预览
      loading: false, // 遮罩层
      patientloading: false, // 遮罩层
      previewtftype: 0, //预览情况0新模板预览1已选择模板修改
      dialogVisiblepatient: false, //添加患者弹框
      dialogVisiblepatientjb: false, //添加疾病弹框
      deptcodesWards: [], //科室数据
      leavehospitaldistrictcodes: [], //病区数据
      operationcodes: [], //手术数据
      illnesscodes: [], //疾病数据
      libId: null,
      Editprogress: 1,
      drawermb: false,
      previewtf: false,
      loading: false,
      patientloading: false,
      previewtftype: 0,
      dialogVisiblepatient: false,
      dialogVisiblepatientjb: false,
      deptcodesWards: [],
      leavehospitaldistrictcodes: [],
      illnesscodes: [],
      radio: 1,
      checkboxlist: [],
      tableLabel: [],
      questionList: [],
      donorchargeList: [],
      baseoperaList: [],
      baseoperaList: [
        { value: "1", label: "一级手术" },
        { value: "2", label: "二级手术" },
        { value: "3", label: "三级手术" },
        { value: "4", label: "四级手术" },
      ],
      usable: [
        { value: "0", label: "可用" },
        { value: "1", label: "停用" },
@@ -983,7 +1358,6 @@
      ],
      props: { multiple: true, value: "deptCode", label: "deptName" },
      propstask: { value: "deptCode", label: "deptName" },
      // 患者表单
      tableLabelhz: [
        { label: "出院日期", width: "150", prop: "inhosptime" },
        { label: "患者", width: "", prop: "name" },
@@ -997,7 +1371,6 @@
        { label: "科室", width: "240", prop: "dept" },
        { label: "病区", width: "240", prop: "leavehospitaldistrictname" },
      ],
      // 患者表单
      tableLabelhzwb: [
        { label: "出院日期", width: "150", prop: "endtime" },
        { label: "患者", width: "", prop: "name" },
@@ -1012,14 +1385,12 @@
        { label: "科室", width: "180", prop: "deptName" },
        { label: "病区", width: "150", prop: "leavehospitaldistrictname" },
      ],
      tableLabelwj: [
        { label: "问卷标题", width: "", prop: "svyname" },
        { label: "问卷描述", width: "", prop: "description" },
        { label: "修改日期", width: "", prop: "updateTime" },
        { label: "创建人", width: "", prop: "createBy" },
      ],
      // 变量
      tableLabelvariable: [
        { label: "变量名称", width: "", prop: "variablename" },
        { label: "匹配符", width: "", prop: "character" },
@@ -1038,46 +1409,45 @@
        { label: "线下(纸质)", value: 10 },
        { label: "线上(短信/钉钉的文本、问卷链接)", value: 11 },
      ],
      // 时间处理
      daytime: [], //日期
      applydaytime: [], //计算日期
      time1: "", //上午时间段
      time2: "", //下午时间段
      time3: "", //晚上时间段
      time4: "", //晚上时间段
      daytime: [],
      applydaytime: [],
      diseaseDept: null,
      diseaseWard: null,
      diseaseDepts: "",
      diseaseWards: "",
      time1: "",
      time2: "",
      time3: "",
      time4: "",
      topqueryParams: {
        pageNum: 1, //
        pageNum: 1,
        pageSize: 10,
      },
      checkList: "",
      selectedOrder: [],
      deliverytopqueryParams: {
        pageNum: 1, //
        pageNum: 1,
        pageSize: 10,
      },
      patientqueryParams: {
        pageNum: 1, //
        pageNum: 1,
        pageSize: 10,
        leavehospitaldistrictcodes: [],
        leaveldeptcodes: [],
      },
      topicoptions: [{ children: [{ children: [] }] }],
      showSearch: true, //
      total: 0, //
      sontotal: 0, //
      patienttotal: 0, //
      // 选中数组
      showSearch: true,
      total: 0,
      sontotal: 0,
      patienttotal: 0,
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 用户表格数据
      userList: [], //模板列表
      multiplechoice: [], //多选结果
      patientuserList: [], //选择患者列表
      sonuserList: [], //选中患者列表
      delvariableList: [], //删除变量临时存储
      userList: [],
      multiplechoice: [],
      patientuserList: [],
      sonuserList: [],
      delvariableList: [],
      longtype: [
        { value: 0, label: "自定义周期" },
        { value: 1, label: "长期任务" },
@@ -1101,7 +1471,7 @@
          fill: "派发时自动匹配",
          default: true,
        },
      ], //变量列表
      ],
      transitionList: [
        {
          name: "姓名",
@@ -1123,8 +1493,9 @@
        },
      ],
      variableListTime: [],
      tasktopic: null, //新增类型
      tasktopic: null,
      SelectPatientslist: [],
      orgname: localStorage.getItem("orgname"),
      form: {
        patTaskRelevances: [],
        sendType: 1,
@@ -1137,59 +1508,46 @@
          localStorage.getItem("orgname") +
          "的医护人员,为了更好地了解您的康复情况,请您抽一点宝贵时间,观看这份宣教资讯。",
        jsy: "请您注意休息和营养,生活上要劳逸结合,适当锻炼,戒烟限酒,保持心情舒畅,定期复诊。那本次宣教内容就到这里,祝您身体健康!",
        // ===== 任务组主对象 =====
        serviceTaskScheduleVO: {
          scheduleStyle: 0,
          scheduleTimeNum: null,
          scheduleTimeUnit: null,
          maxLoopCount: 0,
          currentLoopCount: 0,
          currentSeq: 0,
          nextSeq: 0,
          nextExecuteTime: "",
          scheduleBenchmark: 0,
          scheduleBenchmarkCustomTime: "",
          detailList: [],
        },
      },
      taskoptions: [
        {
          value: "4",
          label: "出院病人",
        },
        {
          value: "1",
          label: "在院病人",
        },
        {
          value: "2",
          label: "门诊病人",
        },
        {
          value: "3",
          label: "体检病人",
        },
        {
          value: "6",
          label: "院外患者",
        },
        {
          value: "5",
          label: "手术病人",
        },
        { value: "4", label: "出院病人" },
        { value: "1", label: "在院病人" },
        { value: "2", label: "门诊病人" },
        { value: "3", label: "体检病人" },
        { value: "6", label: "院外患者" },
        { value: "5", label: "手术病人" },
      ],
      source: [
        {
          value: 0,
          label: "所属患者",
        },
        {
          value: 1,
          label: "科室患者",
        },
        {
          value: 2,
          label: "病区患者",
        },
        { value: 0, label: "所属患者" },
        { value: 1, label: "科室患者" },
        { value: 2, label: "病区患者" },
      ],
      tasktypes: store.getters.tasktypes,
      // 科室/病区
      belongWards: [],
      deptlist: [],
      hosplist: [],
      diagglist: [],
      operlist: [],
      tempDetpRelevanceslist: [], //科室数据
      tempDetpRelevanceslistform: [], //科室数据
      tempbelongWards: [], //病区数据
      tempbelongWardsform: [], //病区数据
      medicalCodes: [],
      medicalOptions: [],
      tempDetpRelevanceslist: [],
      tempDetpRelevanceslistform: [],
      tempbelongWards: [],
      tempbelongWardsform: [],
      rules: {
        taskName: [
          { required: true, message: "任务名称不能为空", trigger: "blur" },
@@ -1203,22 +1561,20 @@
        sendType: [
          { required: true, message: "发送设置不能为空", trigger: "blur" },
        ],
        deptcode: [
          { required: true, message: "适用科室不能为空", trigger: "blur" },
        longTask: [
          { required: true, message: "请选择执行周期", trigger: "blur" },
        ],
        // leavehospitaldistrictcode: [
        //   { required: true, message: "适用病区不能为空", trigger: "blur" },
        // ],
      },
      belongDepts: [],
      // 科室院区查询入参
      queryParamsdept: {},
      quote: false,
      serviceType: null,
      // 模板搜索
      templateOptions: [],
      templateLoading: false,
    };
  },
  components: { SFtable, OptionalForm, SortCheckbox },
  created() {
    this.appraiselist = store.getters.appraiselist;
    this.belongWards = store.getters.belongWards;
@@ -1244,20 +1600,17 @@
  },
  computed: {
    displayedTags() {
      // 返回前10个tag
      return this.illnesslist.slice(0, 10);
    },
    hasMore() {
      // 判断是否有更多的tag
      return this.illnesslist.length > 10;
    },
    remaining() {
      // 计算剩余的tag数量
      return this.illnesslist.length - 10;
    },
  },
  methods: {
    // 变量转换对象转数组
    // ---------- 工具方法 ----------
    convertFormat1ToFormat2(data) {
      let result = [];
      for (let key in data) {
@@ -1270,7 +1623,6 @@
      }
      return result;
    },
    // 数组转对象
    convertFormat2ToFormat1(data) {
      let result = {};
      data.forEach((item) => {
@@ -1280,7 +1632,15 @@
      });
      return result;
    },
    // 获取当前类型
    daysBetween(endDate) {
      if (!endDate) return "";
      const now = new Date();
      const end = new Date(endDate);
      const diff = Math.floor((now - end) / (1000 * 60 * 60 * 24));
      return diff > 0 ? diff : 0;
    },
    // ---------- 数据加载 ----------
    Acquisitiontype() {
      let queryParams = {
        pageNum: this.topqueryParams.pageNum,
@@ -1292,23 +1652,10 @@
      this.tableLabel = this.tableLabelwj;
      if (this.form.serviceType == 1) {
        this.checkboxlist = [
          {
            value: "1",
            label: "人工",
          },
          {
            value: "2",
            label: "纸质",
          },
          {
            value: "4",
            label: "短信",
          },
          {
            value: "5",
            label: "微信公众号",
          },
          { value: "1", label: "人工" },
          { value: "2", label: "纸质" },
          { value: "4", label: "短信" },
          { value: "5", label: "微信公众号" },
          { label: "微信小程序", value: "6" },
        ];
      } else if (
@@ -1317,27 +1664,11 @@
        this.form.serviceType == 15
      ) {
        this.checkboxlist = [
          {
            value: "3",
            label: "智能语音",
          },
          {
            value: "4",
            label: "短信",
          },
          {
            value: "5",
            label: "微信公众号",
          },
          {
            value: "6",
            label: "微信小程序",
          },
          // {
          //   value: "8",
          //   label: "智能机器人",
          // },
          { value: "1", label: "人工" },
          { value: "3", label: "智能语音" },
          { value: "4", label: "短信" },
          { value: "5", label: "微信公众号" },
          { value: "6", label: "微信小程序" },
        ];
      } else if (
        this.form.serviceType == 7 ||
@@ -1349,68 +1680,29 @@
        this.form.serviceType == 9
      ) {
        this.checkboxlist = [
          {
            value: "1",
            label: "人工",
          },
          {
            value: "2",
            label: "纸质",
          },
          {
            value: "3",
            label: "智能语音",
          },
          {
            value: "4",
            label: "短信",
          },
          {
            value: "5",
            label: "微信公众号",
          },
          {
            value: "6",
            label: "微信小程序",
          },
          {
            value: "7",
            label: "术后随访",
          },
          { value: "1", label: "人工" },
          { value: "2", label: "纸质" },
          { value: "3", label: "智能语音" },
          { value: "4", label: "短信" },
          { value: "5", label: "微信公众号" },
          { value: "6", label: "微信小程序" },
          { value: "7", label: "术后随访" },
        ];
      } else if (
        this.form.serviceType == 2 ||
        this.form.serviceType == 3 ||
        this.form.serviceType == 5 ||
        this.form.serviceType == 16 ||
        this.form.serviceType == 18 ||
        this.form.serviceType == 19 ||
        this.form.serviceType == 4
      ) {
        this.checkboxlist = [
          {
            value: "1",
            label: "人工",
          },
          {
            value: "3",
            label: "智能语音",
          },
          {
            value: "4",
            label: "短信",
          },
          {
            value: "5",
            label: "微信公众号",
          },
          {
            value: "6",
            label: "微信小程序",
          },
          // {
          //   value: "8",
          //   label: "智能机器人",
          // },
          { value: "1", label: "人工" },
          { value: "3", label: "智能语音" },
          { value: "4", label: "短信" },
          { value: "5", label: "微信公众号" },
          { value: "6", label: "微信小程序" },
        ];
      }
      getQtemplatelist(this.topqueryParams).then((response) => {
@@ -1418,219 +1710,15 @@
        this.total = response.total;
      });
    },
    nextstep() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.Editprogress <= 3) {
            return this.Editprogress++;
          }
        } else {
          this.$modal.msgError("表单内容未完善,请检查");
        }
    getQtemplateclassify() {
      getQtemplateclassify({}).then((res) => {
        this.optionsclass = res.rows;
      });
    },
    // 保存
    submitForm(formName) {
      console.log(this.submitLoading);
      if (this.submitLoading) {
        return;
      }
      // 第二步:开启加载状态,禁用按钮
      this.submitLoading = true;
      console.log(this.submitLoading);
      try {
        if (this.time4 && this.form.sendType == 3)
          this.form.showTimeMorn = this.time4;
        this.form.sendTimeslot = [
          {
            begantime: this.time4,
            endtime: "",
            xh: 1,
          },
        ];
        if (this.form.appltype == 1) {
          this.leavehospitaldistrictcodes = [];
          this.operationcodes = [];
          this.illnesscodes = [];
        } else if (this.form.appltype == 2) {
          this.deptcodesWards = [];
          this.operationcodes = [];
          this.illnesscodes = [];
        } else if (this.form.appltype == 3) {
          this.deptcodesWards = [];
          this.leavehospitaldistrictcodes = [];
          this.operationcodes = [];
        } else if (this.form.appltype == 4) {
          this.deptcodesWards = [];
          this.illnesscodes = [];
          this.leavehospitaldistrictcodes = [];
        }
        if (this.checkList) {
          this.form.preachform = this.checkList.join(",");
          this.form.preachformList = this.selectedOrder;
        } else {
          this.$modal.msgError("请选择服务类型");
          return;
        }
        console.log(this.operationcodes[0]);
        console.log(this.operationcodes);
        if (
          this.deptcodesWards[0] ||
          this.leavehospitaldistrictcodes[0] ||
          this.diagglist[0] ||
          this.operationcodes[0] ||
          this.form.longTask == 2 ||
          this.serviceType == 3
        ) {
        } else {
          this.$modal.msgError("请选择任务关联条件");
          return;
        }
        //暂停任务患者限制
        // if (!this.form.patTaskRelevances[0] && !this.form.longTask) {
        //   this.$modal.msgError("请选择病人");
        //   return;
        // }
        if (!this.form.templatename && !this.templateor) {
          this.$modal.msgError("未选择模板");
          return;
        }
        if (
          (this.form.sendType == 1 && this.time1) ||
          this.form.sendType == 2
        ) {
        } else if (
          (this.form.sendType == 3 && this.time4) ||
          this.form.longTask
        ) {
        } else {
          return this.$modal.msgError("时间信息缺失");
        }
        const filteredArray = this.variableList.filter(
          (item) =>
            item.name !== "姓名" && item.name !== "电话" && item.name !== "地址"
        );
        this.form.textParam = this.convertFormat2ToFormat1(filteredArray);
        if (this.form.taskid) {
          this.form.isoperation = 2;
        } else {
          this.form.isoperation = 1;
        }
        if (!this.form.type) {
          this.form.type = this.$route.query.type;
        }
        this.form.serviceType = this.serviceType;
        this.form.deptcode = this.deptcodesWards.join(",");
        this.form.leavehospitaldistrictcode =
          this.leavehospitaldistrictcodes.join(",");
        this.form.opcode = this.operationcodes.join(",");
        this.form.icd10code = this.diagglist
          .map((item) => item.icdcode)
          .join(",");
        Editsingletask(this.form).then((res) => {
          if (res.code == 200) {
            if (this.form.taskid) {
              this.$modal.msgSuccess("修改成功");
            } else {
              this.$modal.msgSuccess("新增成功");
            }
            this.$router.push({
              path: "/followvisit/tasklist",
              query: { tasktopic: this.form.serviceType },
            });
            this.submitLoading = false;
          }
        });
      } catch (error) {
        this.submitLoading = false;
      } finally {
        // 第四步:无论成功或失败,最终都关闭加载状态
      }
    },
    // ----------------------表格子组件事件
    // 选择预览
    selectfn(row, type) {
      // 模板情况下获取模板信息
      if (type == 1) {
        this.libName = row.svyname;
        this.libId = row.svyid;
        this.questionList = row.svyTemplateLibScripts;
        getQtemplateobj({ svyid: row.svyid }).then((res) => {
          if (res.code == 200) {
            this.objyl = res.rows[0];
            if (this.form.longTask) {
              this.objyl.longTemp = 1;
            }
            this.tempDetpRelevanceslist = [];
            this.tempbelongWards = [];
            this.objyl.suitway = this.objyl.suitway.split(",");
            this.questionList = res.rows[0].svyTemplateLibScripts;
            this.questionList.forEach((item) => {
              item.qremark = [];
            });
            this.getillness(row.svyid);
            this.previewtf = true;
          }
        });
        this.previewid = row.svyid;
        this.Variablehandling(row.svyTemplateLibScripts, 1);
      } else if (type == 2) {
      } else if (type == 3) {
      }
    },
    // 预览
    previewfnmb() {
      getTaskQuestioncomit(this.form.templateid).then((res) => {
        if (res.code == 200) {
          console.log(res, "预览数据");
          this.objyl = res.data;
          if (this.objyl.suitway)
            this.objyl.suitway = this.objyl.suitway.split(",");
          this.getillness(this.form.libtemplateid);
          this.previewtf = true;
          getQtemplateobj({ svyid: this.form.libtemplateid }).then((res) => {
            if (res.code == 200) {
              this.questionList = res.rows[0].svyTemplateLibScripts;
              this.questionList.forEach((item) => {
                item.qremark = [];
              });
              this.previewtftype = 1;
              this.objyl.svyTemplateLibScripts =
                res.rows[0].svyTemplateLibScripts;
            }
          });
        }
    getillnesslist() {
      getillnesslist({ pageNum: 1, pageSize: 1000 }).then((res) => {
        this.donorchargeList = res.rows;
      });
    },
    checkSelectionChange(selectedValues, selectedOrder) {
      this.selectedOrder = selectedValues;
      console.log("当前选中:", selectedValues);
      console.log("选中顺序:", selectedOrder);
    },
    // 服务形式选取
    handleCheckedCitiesChange(row) {
      console.log(row, "服务");
      this.foncheckList = this.checkboxlist.filter((obj) =>
        row.includes(obj.value)
      );
    },
    // 服务形式删除
    handleClosetag(tag) {
      console.log(tag, "tag");
      console.log(this.foncheckList, "foncheckList");
      this.checkList = this.checkList.filter((item) => item != tag.value);
      this.foncheckList = this.foncheckList.filter(
        (obj) => obj.value !== tag.value
      );
    },
    getillness(id) {
      if (id) {
@@ -1642,72 +1730,481 @@
        });
      }
    },
    getillnesslist() {
      getillnesslist({
        pageNum: 1,
        pageSize: 1000,
      }).then((res) => {
        this.donorchargeList = res.rows;
      });
      getbaseopera({
        pageNum: 1,
        pageSize: 1000,
      }).then((res) => {
        this.baseoperaList = res.rows;
      });
    },
    // 手术查询
    remoteopcode(name) {
      if (name) {
        getbaseopera({
          pageNum: 1,
          pageSize: 1000,
          opdesc: name,
        }).then((res) => {
          this.baseoperaList = res.rows;
    Getdetails() {
      this.form = {
        patTaskRelevances: [],
        sendType: 1,
        sendDay: 5,
        templatename: "",
        templateid: null,
        libtemplateid: null,
        kcb:
          "亲爱的患者/家属,我们是" +
          localStorage.getItem("orgname") +
          "的医护人员,为了更好地了解您的康复情况,请您抽一点宝贵时间,完成这份随访问卷。",
        jsy: "请您注意休息和营养,生活上要劳逸结合,适当锻炼,戒烟限酒,保持心情舒畅,定期复诊。那本次回访就到这里,祝您身体健康!",
        serviceTaskScheduleVO: {
          scheduleStyle: 0,
          scheduleTimeNum: null,
          scheduleTimeUnit: null,
          maxLoopCount: 0,
          currentLoopCount: 0,
          currentSeq: 0,
          nextSeq: 0,
          nextExecuteTime: "",
          scheduleBenchmark: 0,
          scheduleBenchmarkCustomTime: "",
          detailList: [],
        },
      };
      this.questionList = [];
      if (this.id) {
        Questionnairetaskgetson({ taskid: this.id }).then((res) => {
          if (res.code == 200) {
            this.form = res.data;
            // 如果返回了 serviceTaskScheduleVO,解析明细中的 content
            if (
              this.form.serviceTaskScheduleVO &&
              this.form.serviceTaskScheduleVO.detailList
            ) {
              this.form.serviceTaskScheduleVO.detailList.forEach((item) => {
                if (item.content) {
                  try {
                    const contentObj = JSON.parse(item.content);
                    item.kcb = contentObj.kcb || "";
                    item.jsy = contentObj.jsy || "";
                    item.textParam = contentObj.text_param || {};
                  } catch (e) {
                    item.kcb = "";
                    item.jsy = "";
                    item.textParam = {};
                  }
                } else {
                  item.kcb = "";
                  item.jsy = "";
                  item.textParam = {};
                }
              });
            } else {
              // 若后台未返回,则初始化为空
              this.form.serviceTaskScheduleVO = {
                scheduleStyle: 0,
                scheduleTimeNum: null,
                scheduleTimeUnit: null,
                maxLoopCount: 0,
                currentLoopCount: 0,
                currentSeq: 0,
                nextSeq: 0,
                nextExecuteTime: "",
                scheduleBenchmark: 0,
                scheduleBenchmarkCustomTime: "",
                detailList: [],
              };
            }
            this.form.serviceType = this.serviceType;
            this.form.patTaskRelevances = this.form.patTaskRelevances
              ? this.form.patTaskRelevances
              : [];
            this.diseaseDept = {
              deptCode: this.form.deptcode,
              deptName: this.form.deptname,
            };
            this.diseaseWard = {
              districtCode: this.form.leavehospitaldistrictcode,
              districtName: this.form.leavehospitaldistrictname,
            };
            // 药品关联回显
            if (this.form.medicalCode) {
              this.medicalCodes = this.form.medicalCode
                .split(",")
                .filter(Boolean);
              // 加载已选药品的选项列表(用于展示 label)
              const codes = this.form.medicalCode;
              listMedication({
                itemCode: codes,
                pageNum: 1,
                pageSize: 200,
              }).then((res) => {
                this.medicalOptions = res.rows || [];
              });
            }
            this.overallCase = this.form.patTaskRelevances.concat();
            this.checkList = this.form.preachform
              ? this.form.preachform.split(",")
              : "";
            this.selectedOrder = this.form.preachformList || [];
            this.overallCase.forEach((item) => {
              if (item.endtime) {
                item.endDay = this.daysBetween(item.endtime);
              }
            });
            if (this.form.showDate)
              this.daytime = this.form.showDate.split(",");
            if (this.form.showTimeMorn) {
              if (this.form.sendType == 3) {
                this.time4 = this.form.showTimeMorn;
              } else {
                this.time1 = this.form.showTimeMorn.split(",");
              }
            }
            if (this.form.taskid) {
              this.listDept();
            }
            if (this.form.showTimeNoon)
              this.time2 = this.form.showTimeNoon.split(",");
            if (this.form.showTimeNight)
              this.time3 = this.form.showTimeNight.split(",");
            let filteredArray = this.convertFormat1ToFormat2(
              this.form.textParam || {}
            );
            this.variableList = this.transitionList.concat(filteredArray);
          } else {
            this.$modal.msgError(res.code);
          }
          if (this.newadd) {
            this.neWaddfn();
          }
        });
      }
    },
    // 疾病查询
    remotedonor(name) {
      if (name) {
        getbaseopera({
          pageNum: 1,
          pageSize: 1000,
          opdesc: name,
        }).then((res) => {
          this.baseoperaList = res.rows;
        });
    neWaddfn() {
      this.id = null;
      this.form.taskName = "";
      this.form.taskid = null;
      this.overallCase = [];
      this.form.patTaskRelevances = [];
      this.daytime = [];
      this.applydaytime = [];
      this.time1 = "";
      this.time2 = "";
      this.time3 = "";
      this.time4 = "";
      // 重置任务组
      this.form.serviceTaskScheduleVO = {
        scheduleStyle: 0,
        scheduleTimeNum: null,
        scheduleTimeUnit: null,
        maxLoopCount: 0,
        currentLoopCount: 0,
        currentSeq: 0,
        nextSeq: 0,
        nextExecuteTime: "",
        scheduleBenchmark: 0,
        scheduleBenchmarkCustomTime: "",
        detailList: [],
      };
    },
    // ---------- 任务组明细操作 ----------
    addDetail() {
      const detailList = this.form.serviceTaskScheduleVO.detailList;
      const seq = detailList.length + 1;
      detailList.push({
        seq: seq,
        dayOffset: 0,
        templateid: null,
        libtemplateid: null,
        templatename: "",
        content: "",
        kcb: "",
        jsy: "",
        textParam: {},
      });
    },
    removeDetail(index) {
      this.form.serviceTaskScheduleVO.detailList.splice(index, 1);
      this.form.serviceTaskScheduleVO.detailList.forEach((item, idx) => {
        item.seq = idx + 1;
      });
    },
    handleTemplateSelect(index, row) {
      const selected = this.templateOptions.find(
        (item) => item.svyid === row.templateid
      );
      if (selected) {
        row.templatename = selected.svyname;
        row.libtemplateid = selected.svyid; // 模板库ID
      } else {
        row.templatename = "";
        row.libtemplateid = null;
      }
    },
    // 处理问题层变量
    remoteTemplate(query) {
      if (query !== "") {
        this.templateLoading = true;
        getQtemplatelist({ svyname: query, pageNum: 1, pageSize: 20 })
          .then((res) => {
            this.templateOptions = res.rows;
            this.templateLoading = false;
          })
          .catch(() => {
            this.templateLoading = false;
          });
      } else {
        this.templateOptions = [];
      }
    },
    // ---------- 步骤导航 ----------
    nextstep() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.Editprogress <= 3) this.Editprogress++;
        } else {
          this.$modal.msgError("表单内容未完善,请检查");
        }
      });
    },
    laststep() {
      this.Editprogress--;
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    // ---------- 关联选择 ----------
    handleDiseaseDeptChange(dept) {
      this.diseaseDept = dept;
    },
    handleDiseaseWardChange(ward) {
      this.diseaseWard = ward;
    },
    // ---------- 模板相关 ----------
    selectfn(row, type) {
      if (type == 1) {
        this.libName = row.svyname;
        this.libId = row.svyid;
        this.questionList = row.svyTemplateLibScripts;
        getQtemplateobj({ svyid: row.svyid }).then((res) => {
          if (res.code == 200) {
            this.objyl = res.rows[0];
            if (this.form.longTask) {
              this.objyl.longTemp = 1;
            }
            this.tempDetpRelevanceslist = [];
            this.tempbelongWards = [];
            this.objyl.suitway = this.objyl.suitway
              ? this.objyl.suitway.split(",")
              : [];
            this.questionList = res.rows[0].svyTemplateLibScripts;
            this.questionList.forEach((item) => {
              item.qremark = [];
            });
            this.getillness(row.svyid);
            this.previewtf = true;
          }
        });
        this.previewid = row.svyid;
        this.Variablehandling(row.svyTemplateLibScripts, 1);
      }
    },
    previewfnmb() {
      getTaskQuestioncomit(this.form.templateid).then((res) => {
        if (res.code == 200) {
          this.objyl = res.data;
          if (this.objyl.suitway)
            this.objyl.suitway = this.objyl.suitway.split(",");
          this.getillness(this.form.libtemplateid);
          this.previewtf = true;
          taskgetQtemplateobj({ id: this.form.templateid }).then((res) => {
            if (res.code == 200) {
              this.questionList = res.data.svyTaskTemplateScriptVOS;
              this.questionList.forEach((item) => {
                item.qremark = [];
                item.svyLibTemplateTargetoptions =
                  item.svyTaskTemplateTargetoptions;
              });
              this.previewtftype = 1;
              this.objyl.svyTemplateLibScripts =
                res.data.svyTaskTemplateScriptVOS;
            }
          });
        }
      });
    },
    Variablehandling(arr, type) {
      let Variablist = [];
      if (type == 1) {
        // 循环问题
        arr.forEach((res) => {
          // 循环选项
          JSON.parse(res.otherdata).forEach((item) => {
            if (item.default != 1) {
              Variablist.push({
                value: item.variate,
                fill: "",
                name: item.variatename,
              });
            }
          });
          if (res.otherdata) {
            JSON.parse(res.otherdata).forEach((item) => {
              if (item.default != 1) {
                Variablist.push({
                  value: item.variate,
                  fill: "",
                  name: item.variatename,
                });
              }
            });
          }
        });
        const Aarr = Variablist.filter(
          (obj, index, self) =>
            index ===
            self.findIndex((t) => t.name === obj.name && t.value === obj.value)
        );
        this.variableList = this.transitionList.concat(Aarr);
        // this.form.textParam = this.convertFormat2ToFormat1(this.variableList);
      }
    },
    // 子任务二级弹框
    variableDelete(index, row) {
      this.variableList.splice(index, 1);
      row.isoperation = 3;
      this.delvariableList.push(row);
    },
    // ---------- 科室/病区/疾病/手术 操作 ----------
    listDept() {
      this.leavehospitaldistrictcodes = [];
      this.deptcodesWards = [];
      // this.queryParamsdept.taskId = this.form.taskid;
      this.queryParamsdept.taskId = this.form.taskid;
      if (this.form.appltype == 5) {
        rwztaskdepthospgetsonlist(this.queryParamsdept).then((res) => {
          if (res.code == 200) {
            let arr = res.rows;
            arr.forEach((item) => {
              if (item.deptType == 1) {
                this.deptlist.push(item);
                this.deptcodesWards.push(item.deptCode);
              } else if (item.deptType == 2) {
                this.hosplist.push(item);
                this.leavehospitaldistrictcodes.push(item.deptCode);
              }
            });
          }
        });
        rwztaskdiaggetlist(this.queryParamsdept).then((res) => {
          if (res.code == 200) {
            let arr = res.rows;
            arr.forEach((item) => {
              if (localStorage.getItem("orgname") == "南华大学附属第一医院") {
                item.icdname = item.icd10name;
                this.diagglist.push(item);
              } else {
                this.diagglist.push(item);
              }
              this.illnesscodes.push(item.icd10code);
            });
          }
        });
      } else {
        taskdepthospgetsonlist(this.queryParamsdept).then((res) => {
          if (res.code == 200) {
            let arr = res.rows;
            arr.forEach((item) => {
              if (item.deptType == 1) {
                this.deptlist.push(item);
                this.deptcodesWards.push(item.deptCode);
              } else if (item.deptType == 2) {
                this.hosplist.push(item);
                this.leavehospitaldistrictcodes.push(item.deptCode);
              }
            });
          }
        });
        taskdiaggetlist(this.queryParamsdept).then((res) => {
          if (res.code == 200) {
            let arr = res.rows;
            arr.forEach((item) => {
              if (localStorage.getItem("orgname") == "南华大学附属第一医院") {
                item.icdname = item.icd10name;
                this.diagglist.push(item);
              } else {
                getillnesslist({ icdname: item.icd10name }).then((res) => {
                  item.icdname = res.rows[0].icdname;
                  this.diagglist.push(item);
                });
              }
              this.illnesscodes.push(item.icd10code);
            });
          }
        });
      }
      taskopergetlist(this.queryParamsdept).then((res) => {
        if (res.code == 200) {
          let arr = res.rows;
          arr.forEach((item) => {
            this.operlist.push(item);
            this.operationcodes.push(item.opcode);
          });
        }
      });
    },
    removetag(row) {
      let result = this.deptlist
        .filter((item) => item.deptCode == row)
        .map((item) => item.id);
      if (result.length) {
        taskdepthospgetsondel(result).then((res) => {
          if (res.code) this.$modal.msgSuccess("删除成功");
        });
      }
    },
    removehpsp(row) {
      let result = this.hosplist
        .filter((item) => item.deptCode == row)
        .map((item) => item.id);
      if (result.length) {
        taskdepthospgetsondel(result).then((res) => {
          if (res.code) this.$modal.msgSuccess("删除成功");
        });
      }
    },
    removeopera(row) {
      let result = this.operlist
        .filter((item) => item.opcode == row)
        .map((item) => item.id);
      if (result.length) {
        taskoperhospgetsondel(result).then((res) => {
          if (res.code) this.$modal.msgSuccess("删除成功");
        });
      }
    },
    removediagg(row) {
      // 任务组:本地删除即可,后端保存时统一更新
      if (this.form.appltype == 5) {
        this.diagglist = this.diagglist.filter((item) => item.icd10code != row);
        return;
      }
      // 普通疾病关联:调后端接口逐条删除
      let result = this.diagglist
        .filter((item) => item.icd10code == row)
        .map((item) => item.id);
      if (result.length) {
        taskdiaghospgetsondel(result).then((res) => {
          if (res.code) {
            this.diagglist = this.diagglist.filter(
              (item) => item.icd10code != row
            );
            this.$modal.msgSuccess("删除成功");
          }
        });
      }
    },
    remoteopcode(name) {
      // 占位
    },
    // 远程搜索药品
    remoteSearchMedical(query) {
      if (!query) {
        this.medicalOptions = [];
        return;
      }
      listMedication({ itemName: query, pageNum: 1, pageSize: 20 }).then(
        (res) => {
          this.medicalOptions = res.rows || [];
        }
      );
    },
    // 删除已选药品
    removeMedical(code) {
      this.medicalCodes = this.medicalCodes.filter((c) => c !== code);
    },
    // ---------- 患者选择 ----------
    handleAddpatient(row) {
      this.allpids = [];
      this.overallCase.forEach((item) => {
@@ -1715,7 +2212,6 @@
      });
      if (this.patientqueryParams.allhosp == 4) {
        this.tableLabelhz = [
          // { label: "入院日期", width: "170", prop: "starttime" },
          { label: "出院日期", width: "150", prop: "endtime" },
          { label: "患者", width: "", prop: "name" },
          { label: "患者诊断", width: "", prop: "leavediagname" },
@@ -1765,8 +2261,6 @@
      } else {
        this.patientqueryParams.pids = null;
      }
      // 来源判断
      if (this.patientqueryParams.allhosp == 4) {
        this.patientqueryParams.hospitaldistrictcodes = [];
        this.patientqueryParams.deptcodes = [];
@@ -1791,15 +2285,9 @@
      });
      this.dialogVisiblepatient = true;
    },
    handleUpdate() {},
    handleDelete() {},
    handleExport() {},
    // 选择患者表数据
    handleSelectionChange(selection) {
      this.SelectPatientslist = structuredClone(selection);
      this.multiple = !selection.length;
      // 赋值给整体选中数组
      this.SelectPatientslist.forEach((item) => {
        const isExist = this.overallCase.find((obj) => obj.name == item.name);
        if (!isExist) {
@@ -1807,51 +2295,43 @@
          item.patid = item.id;
          item.hospType = this.patientqueryParams.allhosp;
          item.sfzh = item.idcardno;
          item.telshortcode = item.telshortcode;
          item.deptCode = item.deptcode;
          item.deptName = item.dept;
          item.admindate = item.inhosptime;
          item.diagname = item.leavediagname;
          item.sfzh = item.idcardno;
          if (this.patientqueryParams.allhosp == 6) {
            item.patfrom = 1;
          }
          if (this.patientqueryParams.allhosp == 1) {
          if (this.patientqueryParams.allhosp == 6) item.patfrom = 1;
          if (this.patientqueryParams.allhosp == 1)
            item.visittime = item.endtime;
          } else if (this.patientqueryParams.allhosp == 4) {
          else if (this.patientqueryParams.allhosp == 4)
            item.visittime = item.starttime;
          } else if (this.patientqueryParams.allhosp == 2) {
          else if (this.patientqueryParams.allhosp == 2)
            item.visittime = item.admitdate;
          }
          this.overallCase.push(item);
          this.form.patTaskRelevances.push(item);
        }
      });
    },
    // 切换页后恢复选中
    Restorecheck() {
      const allid = this.overallCase.map((item) => item.patid);
      const overlap = this.patientuserList.filter((value) => {
        return allid.includes(value.patid);
      });
      // 保持ids和当前页面的同步性
      const overlap = this.patientuserList.filter((value) =>
        allid.includes(value.patid)
      );
      this.SelectPatientslist = overlap;
      this.toggleSelection(overlap);
    },
    // 挂载选择状态
    toggleSelection(rows) {
      if (rows) {
        this.decision = true;
        this.$nextTick(() => {
          rows.forEach((row) => {
            this.$refs.multipleTable.toggleRowSelection(row, true);
          });
          this.decision = false;
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    // 删除选中患者
    detailhz(row, info) {
      this.$modal
        .confirm('是否确认删除患者"' + row.name + '"的服务项?')
@@ -1867,17 +2347,15 @@
          this.$modal.msgSuccess("删除成功");
        });
    },
    getList() {},
    handleQuery() {
      // 获取外部患者
      if (this.patientqueryParams.allhosp == 6) {
        this.Externallist();
        console.log();
        return;
      }
      if (this.patientqueryParams.searchscope == 1) {
      if (
        this.patientqueryParams.searchscope == 1 ||
        this.patientqueryParams.allhosp == 2
      ) {
        this.patientqueryParams.leaveldeptcodes = store.getters.belongDepts.map(
          (obj) => obj.deptCode
        );
@@ -1905,7 +2383,6 @@
        this.patientqueryParams.leaveldeptcodes = null;
      this.handleAddpatient();
    },
    // 获取外部患者导入列表
    Externallist() {
      this.tableLabelhz = [
        { label: "患者", width: "", prop: "name" },
@@ -1916,7 +2393,6 @@
        { label: "出院天数", width: "", prop: "endDay" },
      ];
      this.patientqueryParams.pageSize = 1000;
      Externallist(this.patientqueryParams).then((response) => {
        this.patientuserList = response.rows;
        this.patientuserList.forEach((item) => {
@@ -1929,16 +2405,15 @@
        this.loading = false;
      });
    },
    resetQuerymb() {
      this.topqueryParams = { svyname: "" };
      this.handleQuerymb();
    },
    resetQuery() {
      this.patientqueryParams = {
        pageNum: 1, //
        pageNum: 1,
        pageSize: 10,
        topica: 1, //0全部1科室2病区
        topica: 1,
        leavehospitaldistrictcodes: [],
        leaveldeptcodes: [],
      };
@@ -1953,219 +2428,20 @@
    handleClosehz() {
      this.dialogVisiblepatient = false;
    },
    // 上一步
    laststep() {
      this.Editprogress--;
    },
    // 提交表单
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    // 预览模板
    PreviewTemplate() {},
    Acknowledgereference() {
      this.quote = true;
    },
    // 获取详情
    Getdetails() {
      this.form = {
        patTaskRelevances: [],
        sendType: 1,
        sendDay: 5,
        templatename: "",
        templateid: null,
        libtemplateid: null,
        kcb:
          "亲爱的患者/家属,我们是" +
          localStorage.getItem("orgname") +
          "的医护人员,为了更好地了解您的康复情况,请您抽一点宝贵时间,完成这份随访问卷。",
        jsy: "请您注意休息和营养,生活上要劳逸结合,适当锻炼,戒烟限酒,保持心情舒畅,定期复诊。那本次回访就到这里,祝您身体健康!",
      };
      this.questionList = [];
      if (this.id) {
        Questionnairetaskgetson({ taskid: this.id }).then((res) => {
          let filteredArray = "";
          if (res.code == 200) {
            this.form = res.data;
            this.form.serviceType = this.serviceType;
            this.form.patTaskRelevances = this.form.patTaskRelevances
              ? this.form.patTaskRelevances
              : [];
            this.overallCase = this.form.patTaskRelevances.concat();
            this.checkList = this.form.preachform.split(",");
            this.selectedOrder = this.form.preachformList;
            this.overallCase.forEach((item) => {
              if (item.endtime) {
                item.endDay = this.daysBetween(item.endtime);
              }
            });
            if (this.form.showDate)
              this.daytime = this.form.showDate.split(",");
            if (this.form.showTimeMorn) {
              if (this.form.sendType == 3) {
                this.time4 = this.form.showTimeMorn;
              } else {
                this.time1 = this.form.showTimeMorn.split(",");
              }
            }
            // 获取任务科室
            if (this.form.taskid) {
              this.listDept();
            }
            if (this.form.showTimeNoon)
              this.time2 = this.form.showTimeNoon.split(",");
            if (this.form.showTimeNight)
              this.time3 = this.form.showTimeNight.split(",");
            filteredArray = this.convertFormat1ToFormat2(this.form.textParam);
            this.variableList = this.transitionList.concat(filteredArray);
          } else {
            this.$modal.msgError(res.code);
          }
          if (this.newadd) {
            this.neWaddfn();
          }
        });
      }
    },
    // 依照新增时处理
    neWaddfn() {
      this.id = null;
      this.form.taskName = "";
      this.form.taskid = null;
      this.overallCase = [];
      this.form.patTaskRelevances = [];
      this.daytime = []; //日期
      this.applydaytime = []; //计算日期
      this.time1 = ""; //上午时间段
      this.time2 = ""; //下午时间段
      this.time3 = ""; //晚上时间段
      this.time4 = ""; //晚上时间段
    },
    // 获取各类
    listDept() {
      this.leavehospitaldistrictcodes = [];
      this.deptcodesWards = [];
      this.queryParamsdept.taskId = this.form.taskid;
      taskdepthospgetsonlist(this.queryParamsdept).then((res) => {
        if (res.code == 200) {
          let arr = res.rows;
          arr.forEach((item) => {
            if (item.deptType == 1) {
              this.deptlist.push(item);
              this.deptcodesWards.push(item.deptCode);
            } else if (item.deptType == 2) {
              this.hosplist.push(item);
              this.leavehospitaldistrictcodes.push(item.deptCode);
            }
          });
        }
      });
      taskdiaggetlist(this.queryParamsdept).then((res) => {
        if (res.code == 200) {
          let arr = res.rows;
          arr.forEach((item) => {
            getillnesslist({
              icdcode: item.icd10code,
            }).then((res) => {
              item.icdname = res.rows[0].icdname;
              this.diagglist.push(item);
            });
            this.illnesscodes.push(item.icd10code);
          });
        }
      });
      taskopergetlist(this.queryParamsdept).then((res) => {
        if (res.code == 200) {
          let arr = res.rows;
          arr.forEach((item) => {
            this.operlist.push(item);
            this.operationcodes.push(item.opcode);
          });
        }
      });
    },
    // 任务科室删除触发
    removetag(row) {
      let result = this.deptlist
        .filter((item) => item.deptCode == row)
        .map((item) => item.id);
      if (result.length) {
        taskdepthospgetsondel(result).then((res) => {
          if (res.code) {
            this.$modal.msgSuccess("删除成功");
          }
        });
      }
    },
    // 院区删除删除触发
    removehpsp(row) {
      let result = this.hosplist
        .filter((item) => item.deptCode == row)
        .map((item) => item.id);
      if (result.length) {
        taskdepthospgetsondel(result).then((res) => {
          if (res.code) {
            this.$modal.msgSuccess("删除成功");
          }
        });
      }
    },
    // 手术删除触发
    removeopera(row) {
      let result = this.operlist
        .filter((item) => item.opcode == row)
        .map((item) => item.id);
      if (result.length) {
        taskoperhospgetsondel(result).then((res) => {
          if (res.code) {
            this.$modal.msgSuccess("删除成功");
          }
        });
      }
    },
    // 疾病删除触发
    removediagg(row) {
      let result = this.diagglist
        .filter((item) => item.icd10code == row)
        .map((item) => item.id);
      if (result.length) {
        taskdiaghospgetsondel(result).then((res) => {
          if (res.code) {
            this.diagglist = this.diagglist.filter(
              (item) => item.icd10code != row
            );
            this.$modal.msgSuccess("删除成功");
          }
        });
      }
    },
    getQtemplateclassify() {
      getQtemplateclassify({}).then((res) => {
        this.optionsclass = res.rows;
      });
    },
    // 新增派送患者
    AddDispatchpatients() {
      // this.SelectPatientslist.forEach((item) => {
      //   item.isoperation = 1;
      // });
      // this.form.patTaskRelevances.push(...this.SelectPatientslist);
      // this.overallCase.push(...this.SelectPatientslist);
      this.dialogVisiblepatient = false;
    },
    handleUpdate() {},
    handleDelete() {},
    handleExport() {},
    variableDelete(index, row) {
      this.variableList.splice(index, 1);
      row.isoperation = 3;
      this.delvariableList.push(row);
    // ---------- 服务形式排序 ----------
    checkSelectionChange(selectedValues, selectedOrder) {
      this.selectedOrder = selectedValues;
    },
    // 时间----------
    changeTime(row) {
    // ---------- 时间处理 ----------
    changeTime() {
      this.processingTime();
    },
    Totaldate(row) {
@@ -2181,27 +2457,19 @@
    getDates(startDate, endDate) {
      const dates = [];
      let currentDate = new Date(startDate);
      while (currentDate <= endDate) {
        dates.push(this.$moment(currentDate).format("YYYY-MM-DD"));
        currentDate.setDate(currentDate.getDate() + 1);
      }
      return dates;
    },
    // 时间最终处理方法
    processingTime() {
      const combinedData = [];
      let serialnumber = 1;
      if (this.time3[0]) {
        serialnumber = 3;
      } else if (this.time2[0]) {
        serialnumber = 2;
      } else if (this.time1[0]) {
        serialnumber = 1;
      } else {
        return;
      }
      if (this.time3 && this.time3[0]) serialnumber = 3;
      else if (this.time2 && this.time2[0]) serialnumber = 2;
      else if (this.time1 && this.time1[0]) serialnumber = 1;
      else return;
      for (let i = 0; i < this.applydaytime.length; i++) {
        combinedData.push({
@@ -2225,58 +2493,60 @@
        }
      }
      this.form.sendTimeslot = combinedData;
      // 展示数据临时存储日期、早、中、晚
      this.form.showDate = this.daytime.join(",");
      if (this.time1) this.form.showTimeMorn = this.time1.join(",");
      if (this.time2) this.form.showTimeNoon = this.time2.join(",");
      if (this.time3) this.form.showTimeNight = this.time3.join(",");
    },
    // 查看模板
    // ---------- 模板保存与替换 ----------
    previewGo() {
      this.$modal.confirm("是否前往修改任务模板详细内容?").then(() => {
        this.drawermb = false; //选择模板弹窗
        this.previewtf = false; //预览
        this.drawermb = false;
        this.previewtf = false;
        this.$router.push({
          path: "/knowledge/tpuconfigurat/",
          query: { id: this.previewid, task: true, data: this.form },
        });
      });
    },
    // 保存/更新任务模板
    previewFn() {
      if (Array.isArray(this.objyl.suitway)) {
        this.objyl.suitway = this.objyl.suitway.join(",");
      }
      this.objyl.templateid = this.objyl.svyid;
      this.objyl.isoperation = 1;
      this.objyl.taskid = this.form.taskid;
      this.objyl.svyTemplateLibScripts.forEach((item) => {
        item.qremark = [];
        item.svyTaskTemplateTargetoptions = item.svyLibTemplateTargetoptions;
      });
      this.objyl.svyTaskTemplateScriptVOS = this.objyl.svyTemplateLibScripts;
      if (this.objyl.id) {
        deleteTaskQuestioncomit(this.objyl.id).then((res) => {
          if (res.code == 200) {
            (this.objyl.id = null),
              TaskQuestioncomit(this.objyl).then((response) => {
                this.previewtf = false;
                this.form.libtemplateid = this.objyl.svyid;
                this.form.templateid = response.data;
                this.form.templatename = this.objyl.svyname;
                this.$modal.msgSuccess("选择模板成功");
              });
            this.objyl.id = null;
            TaskQuestioncomit(this.objyl).then((response) => {
              this.previewtf = false;
              this.form.libtemplateid = this.objyl.svyid;
              this.form.libtemplatename = this.objyl.svyname;
              this.form.templateid = response.data;
              this.form.templatename = this.objyl.svyname;
              this.$modal.msgSuccess("选择模板成功");
            });
          }
        });
      } else {
        TaskQuestioncomit(this.objyl).then((response) => {
          this.previewtf = false;
          this.form.libtemplateid = this.objyl.svyid;
          this.form.libtemplatename = this.objyl.svyname;
          this.form.templateid = response.data;
          this.form.templatename = this.objyl.svyname;
          this.$modal.msgSuccess("选择模板成功");
        });
      }
    },
    // 保存科室/病区
    putbelongDepts(id) {
      this.tempDetpRelevanceslistform.forEach((item) => {
        item.tempid = id;
@@ -2297,8 +2567,6 @@
        }
      });
    },
    // 科室处理
    Departmenttreatment() {
      if (!this.form.taskid) {
        this.templateor = true;
@@ -2340,19 +2608,221 @@
        }, 1000);
      }
    },
    // ---------- 提交表单 ----------
    submitForm(formName) {
      if (this.submitLoading) return;
      this.submitLoading = true;
      try {
        if (this.time4 && this.form.sendType == 3) {
          this.form.showTimeMorn = this.time4;
        }
        this.form.sendTimeslot = [
          {
            begantime: this.time4,
            endtime: "",
            xh: 1,
          },
        ];
        if (this.form.appltype == 1) {
          this.leavehospitaldistrictcodes = [];
          this.form.oplevelcode = null;
          this.illnesscodes = [];
        } else if (this.form.appltype == 2) {
          this.deptcodesWards = [];
          this.form.oplevelcode = null;
          this.illnesscodes = [];
        } else if (this.form.appltype == 3) {
          this.deptcodesWards = [];
          this.leavehospitaldistrictcodes = [];
          this.form.oplevelcode = null;
        } else if (this.form.appltype == 4) {
          this.deptcodesWards = [];
          this.illnesscodes = [];
          this.leavehospitaldistrictcodes = [];
        } else if (this.form.appltype == 6) {
          this.deptcodesWards = [];
          this.leavehospitaldistrictcodes = [];
          this.illnesscodes = [];
          this.form.oplevelcode = null;
        }
        // 服务形式校验
        if (this.checkList) {
          this.form.preachform = this.checkList.join(",");
          this.form.preachformList = this.selectedOrder;
        } else {
          this.$modal.msgError("请选择服务类型");
          this.submitLoading = false;
          return;
        }
        // 任务关联条件校验(任务组跳过强制关联)
        const hasCondition =
          this.deptcodesWards[0] ||
          this.leavehospitaldistrictcodes[0] ||
          this.diagglist[0] ||
          this.form.oplevelcode ||
          this.medicalCodes[0] ||
          this.form.longTask == 2 ||
          this.serviceType == 3 ||
          this.form.appltype == 5;
        if (!hasCondition) {
          this.$modal.msgError("请选择任务关联条件");
          this.submitLoading = false;
          return;
        }
        if (!this.form.templatename && !this.templateor) {
          this.$modal.msgError("未选择模板");
          this.submitLoading = false;
          return;
        }
        const isValidTime =
          (this.form.sendType == 1 && this.time1) ||
          this.form.sendType == 2 ||
          (this.form.sendType == 3 && this.time4) ||
          this.form.longTask;
        if (!isValidTime) {
          this.submitLoading = false;
          this.$modal.msgError("时间信息缺失");
          return;
        }
        // 处理变量
        const filteredArray = this.variableList.filter(
          (item) =>
            item.name !== "姓名" && item.name !== "电话" && item.name !== "地址"
        );
        this.form.textParam = this.convertFormat2ToFormat1(filteredArray);
        // 处理任务组明细的 content
        if (this.form.appltype == 5 && this.form.serviceTaskScheduleVO) {
          this.form.serviceTaskScheduleVO.detailList.forEach((item) => {
            const contentObj = {
              kcb: item.kcb || "",
              jsy: item.jsy || "",
              text_param: item.textParam || {},
            };
            item.content = JSON.stringify(contentObj);
            delete item.kcb;
            delete item.jsy;
            delete item.textParam;
          });
          // 将主对象放入 form 提交(已存在)
        }
        if (this.form.taskid) {
          this.form.isoperation = 2;
        } else {
          this.form.isoperation = 1;
        }
        if (!this.form.type) {
          this.form.type = this.$route.query.type;
        }
        console.log(this.diseaseDept, this.diseaseWard);
        if (this.form.appltype == 1 || this.form.appltype == 2) {
          this.form.deptcode = this.deptcodesWards.join(",");
          this.form.leavehospitaldistrictcode =
            this.leavehospitaldistrictcodes.join(",");
        } else {
          if (this.diseaseDept) {
            this.form.deptcode = this.diseaseDept.deptCode;
            this.form.deptname = this.diseaseDept.deptName;
          }
          if (this.diseaseWard) {
            this.form.leavehospitaldistrictcode = this.diseaseWard.districtCode;
            this.form.leavehospitaldistrictname = this.diseaseWard.districtName;
          }
        }
        // 药品关联:组装逗号分隔的编码/名称/厂家
        if (this.form.appltype == 6) {
          const selectedMeds = this.medicalOptions.filter((m) =>
            this.medicalCodes.includes(m.itemCode)
          );
          this.form.medicalCode = this.medicalCodes.join(",");
          this.form.medicalName = selectedMeds.map((m) => m.itemName).join(",");
          this.form.medicalCompany = selectedMeds
            .map((m) => m.manufacturerName)
            .join(",");
        }
        this.form.serviceType = this.serviceType;
        this.form.icd10code = this.diagglist
          .map((item) => item.icdcode)
          .join(",");
        this.form.icd10name = this.diagglist
          .map((item) => item.icdname)
          .join(",");
        // 疾病/手术关联的科室/病区校验
        if (this.form.appltype == 3 || this.form.appltype == 4) {
          const hasDept = this.diseaseDept?.deptCode;
          const hasWard = this.diseaseWard?.districtCode;
          if (!hasDept && !hasWard) {
            this.$modal.msgError("需关联科室或病区");
            this.submitLoading = false;
            return;
          }
          this.form.deptcode = hasDept;
          this.form.leavehospitaldistrictcode = hasWard;
        }
        // 任务组的数据处理
        if (this.form.appltype == 5) {
          this.form.serviceTaskScheduleVO.icd10codes = this.form.icd10code;
          this.form.serviceTaskScheduleVO.wardCodes =
            this.form.leavehospitaldistrictcode;
          this.form.serviceTaskScheduleVO.deptCodes = this.form.deptcode;
        }
        Editsingletask(this.form)
          .then((res) => {
            if (res.code == 200) {
              if (this.form.taskid) {
                this.$modal.msgSuccess("修改成功");
              } else {
                this.$modal.msgSuccess("新增成功");
              }
              this.$router.push({
                path: "/followvisit/tasklist",
                query: { tasktopic: this.form.serviceType },
              });
            } else {
              this.$modal.msgError(res.msg || "操作失败");
            }
          })
          .catch((error) => {
            console.error("提交失败:", error);
            this.$modal.msgError(error.message || "网络异常,请稍后重试");
          })
          .finally(() => {
            this.submitLoading = false;
          });
      } catch (error) {
        console.error("表单提交异常:", error);
        this.$modal.msgError(error.message || "表单提交异常");
        this.submitLoading = false;
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.Questionnairemanagement {
}
.leftvlue-jbxx {
  margin-top: 10px;
}
.sidecolumn {
  width: 100%;
  // min-height: 12vh;
  margin: 20px;
  margin-bottom: 0;
  padding: 30px;
@@ -2361,20 +2831,20 @@
  -webkit-box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.12),
    0 0 6px 0 rgba(0, 0, 0, 0.04);
}
.leftvlue {
  //   display: flex;
  //   flex: 1;
  width: 100%;
  margin-top: 20px;
  //   margin: 20px;
  padding: 30px;
  background: #ffff;
  border: 1px solid #dcdfe6;
  -webkit-box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.12),
    0 0 6px 0 rgba(0, 0, 0, 0.04);
}
.examine-jic {
  margin: 20px;
  .headline {
    font-size: 24px;
    height: 40px;
@@ -2382,32 +2852,37 @@
    padding-left: 5px;
    margin-bottom: 10px;
    display: flex;
    // justify-content: space-between;
    .Add-details {
      font-size: 18px;
      color: #02a7f0;
      cursor: pointer;
    }
  }
  .jic-value {
    font-size: 20px;
    border-top: 1px solid #a7abac;
    padding: 10px;
    margin-bottom: 10px;
    .details-jic {
      padding: 10px 15px;
      border: 1px solid #dcdfe6;
      -webkit-box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.12),
        0 0 6px 0 rgba(0, 0, 0, 0.04);
      .details-title {
        display: flex;
        justify-content: space-between;
        margin-bottom: 10px;
        div:nth-child(2) {
          color: #02a7f0;
          cursor: pointer;
        }
      }
      .details-renw {
        background: #e4ebfc;
        padding: 15px 5px;
@@ -2417,6 +2892,7 @@
    }
  }
}
.xinz-infs {
  font-size: 18px;
  line-height: 48px;
@@ -2425,58 +2901,45 @@
    margin-left: 10px;
  }
}
// .leftvlue-jbxx {
//   margin-bottom: 50px;
//   font-size: 20px;
//   span {
//     position: absolute;
//     right: 80px;
//   }
//   .demo-cascader {
//     margin-right: 20px;
//   }
//   .PreviewTemplate {
//     color: #02a7f0;
//     cursor: pointer;
//     font-size: 20px;
//     margin: 0 20px;
//   }
// }
.preview-left {
  margin: 20px;
  //   margin: 20px;
  padding: 30px;
  background: #ffff;
  // border: 1px solid #dcdfe6;
  // -webkit-box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.12),
  //   0 0 6px 0 rgba(0, 0, 0, 0.04);
  .scriptTopic-dev {
    margin-bottom: 25px;
    font-size: 20px !important;
    .dev-text {
      margin-bottom: 10px;
    }
  }
}
.jic-value {
  font-size: 20px;
  border-top: 1px solid #a7abac;
  padding: 10px;
  margin-bottom: 10px;
  .details-jic {
    padding: 10px 15px;
    border: 1px solid #dcdfe6;
    -webkit-box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.12),
      0 0 6px 0 rgba(0, 0, 0, 0.04);
    .details-title {
      display: flex;
      justify-content: space-between;
      margin-bottom: 10px;
      div:nth-child(2) {
        color: #02a7f0;
        cursor: pointer;
      }
    }
    .details-renw {
      background: #e4ebfc;
      padding: 15px 5px;
@@ -2485,6 +2948,7 @@
    }
  }
}
::v-deep .addtopic-input {
  input {
    background: #02a7f0;
@@ -2492,42 +2956,44 @@
    width: 150px;
  }
}
::v-deep.el-step.is-vertical .el-step__title {
  font-size: 25px;
}
::v-deep.el-row {
  margin-bottom: 10px;
}
// ::v-deep.el-input--medium {
//   font-size: 24px !important;
// }
::v-deep.ruleFormaa.el-select {
  display: inline-block;
  position: relative;
  width: 700px;
}
.el-select__tags {
  font-size: 20px;
  max-width: 888px !important;
}
::v-deep.el-radio__inner {
  width: 22px;
  height: 22px;
}
// ::v-deep.topic-dev.el-radio__label {
//   font-size: 24px;
// }
::v-deep.el-radio-group {
  span {
    font-size: 18px;
  }
}
::v-deep.el-input.is-disabled .el-input__inner {
  background-color: #f5f7fa;
  border-color: #dfe4ed;
  color: rgb(253, 66, 66);
  cursor: not-allowed;
}
::v-deep.el-checkbox-group {
  span {
    font-size: 18px;