WXL (wul)
昨天 feb5a669dced68415bc7e32f237f77bf9842fe8b
src/components/optionalModule/index.vue
@@ -28,8 +28,6 @@
      </el-form>
    </div>
    <!-- 模板选择抽屉 -->
    <el-drawer
      title="问卷内容列表"
@@ -52,6 +50,15 @@
              @keyup.enter.native="handleSearch"
            ></el-input>
          </el-form-item>
          <el-form-item label="患者范围" prop="status">
            <el-cascader
              v-model="scopetype"
              placeholder="默认全部"
              :options="sourcetype"
              :props="{ expandTrigger: 'hover' }"
              @change="handleChange"
            ></el-cascader>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
@@ -60,10 +67,7 @@
              @click="handleSearch"
              >搜索</el-button
            >
            <el-button
              icon="el-icon-refresh"
              size="medium"
              @click="handleReset"
            <el-button icon="el-icon-refresh" size="medium" @click="handleReset"
              >重置</el-button
            >
          </el-form-item>
@@ -211,12 +215,9 @@
          <div class="preview-content">
            <div v-for="item in questionList" :key="item.sort">
              <!-- 单选 -->
              <div
                class="scriptTopic-dev"
                v-if="item.scriptType == 1"
              >
              <div class="scriptTopic-dev" 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" disabled>
@@ -232,12 +233,9 @@
              </div>
              <!-- 多选 -->
              <div
                class="scriptTopic-dev"
                v-if="item.scriptType == 2"
              >
              <div class="scriptTopic-dev" 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" disabled>
@@ -253,12 +251,9 @@
              </div>
              <!-- 填空 -->
              <div
                class="scriptTopic-dev"
                v-if="item.scriptType == 4"
              >
              <div class="scriptTopic-dev" 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
@@ -282,11 +277,7 @@
        >
          选择使用
        </el-button>
        <el-button
          v-else
          type="primary"
          @click="handleConfirmReplace"
        >
        <el-button v-else type="primary" @click="handleConfirmReplace">
          替换使用
        </el-button>
      </span>
@@ -295,67 +286,86 @@
</template>
<script>
import { getQtemplatelist, getQtemplateobj, getQtemplateclassify } from "@/api/AiCentre/index";
import {
  getSviLibTemplateByDeptCode,
  getQtemplateobj,
  getQtemplateclassify,
} from "@/api/AiCentre/index";
import store from "@/store";
import pagination from "@/components/Pagination";
export default {
  name: "TemplateSelector",
  components: {
    pagination
    pagination,
  },
  props: {
    // 当前选中的模板ID
    value: {
      type: [String, Number],
      default: null
      default: null,
    },
    // 当前选中的模板名称
    templateName: {
      type: String,
      default: ''
      default: "",
    },
    // 是否可编辑
    isEditable: {
      type: Boolean,
      default: true
      default: true,
    },
    // 是否显示变量配置
    showVariableConfig: {
      type: Boolean,
      default: true
      default: true,
    },
    // 服务类型,用于过滤模板
    serviceType: {
      type: [String, Number],
      default: null
    }
      default: null,
    },
  },
  data() {
    return {
      // 组件状态
      drawerVisible: false,
      previewVisible: false,
      activeTab: 'basic',
      activeTab: "basic",
      loading: false,
      // 模板数据
      selectedTemplateId: null,
      selectedTemplateName: '',
      selectedTemplateName: "",
      selectedTemplateData: null,
      scopetype: [],
      // 列表数据
      templateList: [],
      questionList: [],
      variableList: [],
      previewData: {},
      sourcetype: [
        {
          value: 1,
          label: "科室",
          children: [],
        },
        {
          value: 2,
          label: "病区",
          children: [],
        },
        {
          value: 3,
          label: "全部",
        },
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        svyname: '',
        isenable: ''
        type: 1,
        deptType: "1",
        svyname: "",
        deptCode: "",
      },
      total: 0,
@@ -364,7 +374,7 @@
      appraisalOptions: store.getters.appraiselist || [],
      usableOptions: [
        { value: "0", label: "可用" },
        { value: "1", label: "停用" }
        { value: "1", label: "停用" },
      ],
      // 默认变量
@@ -373,21 +383,21 @@
          name: "姓名",
          value: "${name}",
          fill: "派发时自动匹配",
          default: true
          default: true,
        },
        {
          name: "地址",
          value: "${dzz}",
          fill: "派发时自动匹配",
          default: true
          default: true,
        },
        {
          name: "智能语音",
          value: "${dhh}",
          fill: "派发时自动匹配",
          default: true
        }
      ]
          default: true,
        },
      ],
    };
  },
  watch: {
@@ -395,26 +405,36 @@
      immediate: true,
      handler(newVal) {
        this.selectedTemplateId = newVal;
      }
      },
    },
    templateName: {
      immediate: true,
      handler(newVal) {
        this.selectedTemplateName = newVal;
      }
      },
    },
    selectedTemplateId(newVal) {
      this.$emit('input', newVal);
      this.$emit("input", newVal);
    },
    selectedTemplateName(newVal) {
      this.$emit('update:templateName', newVal);
    }
      this.$emit("update:templateName", newVal);
    },
  },
  created() {
    this.sourcetype[0].children = store.getters.belongDepts.map((dept) => {
      return {
        label: dept.deptName,
        value: dept.deptCode,
      };
    });
    this.sourcetype[1].children = store.getters.belongWards.map((dept) => {
      return {
        label: dept.districtName,
        value: dept.districtCode,
      };
    });
    this.loadCategories();
      this.handleSearch();
    this.handleSearch();
  },
  methods: {
    // 加载模板分类
@@ -425,7 +445,7 @@
          this.categoryOptions = response.rows;
        }
      } catch (error) {
        console.error('加载分类失败:', error);
        console.error("加载分类失败:", error);
      }
    },
@@ -433,26 +453,29 @@
    async handleSearch() {
      try {
        this.loading = true;
        const response = await getQtemplatelist(this.queryParams);
        const response = await getSviLibTemplateByDeptCode(this.queryParams);
        if (response.code === 200) {
          this.templateList = response.rows;
          this.total = response.total;
        }
      } catch (error) {
        console.error('搜索模板失败:', error);
        this.$modal.msgError('搜索模板失败');
        console.error("搜索模板失败:", error);
        this.$modal.msgError("搜索模板失败");
      } finally {
        this.loading = false;
      }
    },
    handleChange(value) {
      this.queryParams.deptType = value[0].toString();
      this.queryParams.deptCode = value.slice(-1)[0];
    },
    // 重置搜索
    handleReset() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        svyname: '',
        isenable: ''
        svyname: "",
        isenable: "",
      };
      this.handleSearch();
    },
@@ -480,7 +503,7 @@
          this.questionList = templateData.svyTemplateLibScripts || [];
          // 初始化问题状态
          this.questionList.forEach(item => {
          this.questionList.forEach((item) => {
            item.qremark = [];
          });
@@ -491,8 +514,8 @@
          this.drawerVisible = false;
        }
      } catch (error) {
        console.error('加载模板详情失败:', error);
        this.$modal.msgError('加载模板详情失败');
        console.error("加载模板详情失败:", error);
        this.$modal.msgError("加载模板详情失败");
      } finally {
        this.loading = false;
      }
@@ -502,20 +525,20 @@
    extractVariables(scripts) {
      let variableList = [];
      scripts.forEach(script => {
      scripts.forEach((script) => {
        try {
          const otherData = JSON.parse(script.otherdata || '[]');
          otherData.forEach(item => {
          const otherData = JSON.parse(script.otherdata || "[]");
          otherData.forEach((item) => {
            if (item.default != 1) {
              variableList.push({
                value: item.variate,
                fill: "",
                name: item.variatename
                name: item.variatename,
              });
            }
          });
        } catch (e) {
          console.warn('解析otherdata失败:', e);
          console.warn("解析otherdata失败:", e);
        }
      });
@@ -523,9 +546,7 @@
      const uniqueVariables = variableList.filter(
        (obj, index, self) =>
          index ===
          self.findIndex(
            t => t.name === obj.name && t.value === obj.value
          )
          self.findIndex((t) => t.name === obj.name && t.value === obj.value)
      );
      this.variableList = [...this.transitionList, ...uniqueVariables];
@@ -534,7 +555,7 @@
    // 预览已选模板
    handlePreview() {
      if (!this.selectedTemplateId) {
        this.$modal.msgWarning('请先选择模板');
        this.$modal.msgWarning("请先选择模板");
        return;
      }
@@ -544,7 +565,7 @@
    // 确认选择模板
    handleConfirmSelect() {
      if (!this.selectedTemplateData) {
        this.$modal.msgWarning('请先选择模板');
        this.$modal.msgWarning("请先选择模板");
        return;
      }
@@ -553,27 +574,29 @@
      // 转换变量格式
      const filteredVariables = this.variableList.filter(
        item => item.name !== "姓名" && item.name !== "电话" && item.name !== "地址"
        (item) =>
          item.name !== "姓名" && item.name !== "电话" && item.name !== "地址"
      );
      const textParam = this.convertFormat2ToFormat1(filteredVariables);
      // 触发选择事件
      this.$emit('select', {
      this.$emit("select", {
        templateId: this.selectedTemplateId,
        templateName: this.selectedTemplateName,
        templateData: this.previewData,
        variableList: this.variableList,
        textParam: textParam
        textParam: textParam,
      });
      this.previewVisible = false;
      this.$modal.msgSuccess('选择模板成功');
      this.$modal.msgSuccess("选择模板成功");
    },
    // 确认替换模板
    handleConfirmReplace() {
      this.$modal.confirm('确定要替换当前模板吗?')
      this.$modal
        .confirm("确定要替换当前模板吗?")
        .then(() => {
          this.handleConfirmSelect();
        })
@@ -583,31 +606,31 @@
    // 取消预览
    handleCancelPreview() {
      this.previewVisible = false;
      this.$emit('cancel');
      this.$emit("cancel");
    },
    // 关闭抽屉
    handleDrawerClose(done) {
      done();
      this.$emit('drawer-close');
      this.$emit("drawer-close");
    },
    // 关闭预览
    handlePreviewClose(done) {
      done();
      this.$emit('preview-close');
      this.$emit("preview-close");
    },
    // 删除变量
    handleVariableDelete(index, row) {
      this.variableList.splice(index, 1);
      this.$emit('variable-delete', row);
      this.$emit("variable-delete", row);
    },
    // 变量格式转换:数组转对象
    convertFormat2ToFormat1(data) {
      let result = {};
      data.forEach(item => {
      data.forEach((item) => {
        let innerObj = {};
        innerObj[item.value] = item.fill;
        result[item.name] = innerObj;
@@ -623,7 +646,7 @@
        result.push({
          name: key,
          value: innerKey,
          fill: data[key][innerKey]
          fill: data[key][innerKey],
        });
      }
      return result;
@@ -640,20 +663,21 @@
    // 清除选择
    clear() {
      this.selectedTemplateId = null;
      this.selectedTemplateName = '';
      this.selectedTemplateName = "";
      this.selectedTemplateData = null;
      this.variableList = [...this.transitionList];
      this.$emit('clear');
      this.$emit("clear");
    },
    // 获取变量数据
    getVariables() {
      const filteredVariables = this.variableList.filter(
        item => item.name !== "姓名" && item.name !== "电话" && item.name !== "地址"
        (item) =>
          item.name !== "姓名" && item.name !== "电话" && item.name !== "地址"
      );
      return this.convertFormat2ToFormat1(filteredVariables);
    }
  }
    },
  },
};
</script>