WXL (wul)
5 天以前 2736806c9fbccb6e3fdf981a6f48a9343e21fa4a
src/views/followvisit/record/detailpage/components/AdviceList.vue
@@ -1,89 +1,71 @@
<template>
  <div class="advice-list">
    <!-- 搜索栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="70px">
      <el-form-item label="建议类型" prop="adviceType">
        <el-select v-model="queryParams.adviceType" placeholder="全部类型" clearable style="width: 140px">
          <el-option label="投诉" value="1" />
          <el-option label="建议" value="2" />
          <el-option label="表扬" value="3" />
        </el-select>
      </el-form-item>
      <el-form-item label="内容" prop="content">
        <el-input v-model="queryParams.content" placeholder="请输入内容关键字" clearable style="width: 180px" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
  <div class="advice-blocks">
    <!-- 类型 Tab 展示 -->
    <el-tabs v-model="activeType">
      <el-tab-pane
        v-for="type in adviceTypes"
        :key="type.value"
        :name="type.value"
      >
        <span slot="label">
          <span class="tab-icon">{{ type.icon }}</span> {{ type.label }}
        </span>
    <!-- 操作栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
    </el-row>
        <!-- 有记录 -->
        <div v-if="getAdviceByType(type.value)" class="advice-content" :class="type.className">
          <div class="advice-head">
            <span class="advice-label">{{ type.label }}内容</span>
            <el-button size="mini" type="primary" plain icon="el-icon-edit" @click="handleEdit(type.value)">修改</el-button>
          </div>
          <div class="advice-text">{{ getAdviceByType(type.value).content }}</div>
          <div class="advice-meta" v-if="getAdviceByType(type.value).deptCodes || getAdviceByType(type.value).wardCodes">
            <span v-if="getAdviceByType(type.value).deptCodes" class="meta-item">
              <i class="el-icon-office-building"></i>{{ getDeptNames(getAdviceByType(type.value).deptCodes) }}
            </span>
            <span v-if="getAdviceByType(type.value).wardCodes" class="meta-item">
              <i class="el-icon-s-home"></i>{{ getWardNames(getAdviceByType(type.value).wardCodes) }}
            </span>
          </div>
          <div class="advice-meta" v-if="getAdviceByType(type.value).involvedUsers">
            <span class="meta-item"><i class="el-icon-user"></i>涉及人员:{{ getAdviceByType(type.value).involvedUsers }}</span>
          </div>
          <div class="advice-meta" v-if="getAdviceByType(type.value).remark">
            <span class="meta-item">备注:{{ getAdviceByType(type.value).remark }}</span>
          </div>
          <div class="advice-foot">
            <span>{{ getAdviceByType(type.value).createBy || "-" }}</span>
            <span>{{ getAdviceByType(type.value).createTime || "-" }}</span>
          </div>
        </div>
    <!-- 表格 -->
    <el-table v-loading="loading" :data="adviceList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50" align="center" />
      <el-table-column label="建议类型" align="center" prop="adviceType" width="100">
        <template slot-scope="scope">
          <el-tag :type="adviceTypeTag(scope.row.adviceType)" size="small">
            {{ adviceTypeText(scope.row.adviceType) }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="内容" align="center" prop="content" min-width="200" :show-overflow-tooltip="true" />
      <el-table-column label="涉及科室" align="center" prop="deptCodes" width="140" :show-overflow-tooltip="true">
        <template slot-scope="scope">{{ getDeptNames(scope.row.deptCodes) }}</template>
      </el-table-column>
      <el-table-column label="涉及病区" align="center" prop="wardCodes" width="140" :show-overflow-tooltip="true">
        <template slot-scope="scope">{{ getWardNames(scope.row.wardCodes) }}</template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" min-width="150" :show-overflow-tooltip="true" />
      <el-table-column label="创建者" align="center" prop="createBy" width="100" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="160" />
      <el-table-column label="操作" align="center" width="120" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" style="color: #f56c6c" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
        <!-- 空态 -->
        <div v-else class="advice-empty">
          <span class="empty-icon">{{ type.icon }}</span>
          <p>暂无{{ type.label }}记录</p>
          <el-button size="small" type="primary" plain icon="el-icon-plus" @click="handleAdd(type.value)">新增{{ type.label }}</el-button>
        </div>
      </el-tab-pane>
    </el-tabs>
    <!-- 新增/编辑弹窗 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="建议类型" prop="adviceType">
          <el-radio-group v-model="form.adviceType">
            <el-radio label="1">投诉</el-radio>
            <el-radio label="2">建议</el-radio>
            <el-radio label="3">表扬</el-radio>
          </el-radio-group>
    <el-dialog
      :title="dialogTitle"
      :visible.sync="open"
      width="560px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-form-item label="类型">
          <el-tag :type="currentTypeTag" size="small">{{ currentTypeText }}</el-tag>
        </el-form-item>
        <el-form-item label="涉及科室" prop="deptCodes">
          <el-select v-model="form.deptCodes" multiple filterable clearable placeholder="请选择涉及科室" style="width: 100%">
          <el-select v-model="form.deptCodes" multiple filterable clearable placeholder="请选择涉及科室(可多选)" style="width: 100%">
            <el-option v-for="d in deptOptions" :key="d.value" :label="d.label" :value="d.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="涉及病区" prop="wardCodes">
          <el-select v-model="form.wardCodes" multiple filterable clearable placeholder="请选择涉及病区" style="width: 100%">
          <el-select v-model="form.wardCodes" multiple filterable clearable placeholder="请选择涉及病区(可多选)" style="width: 100%">
            <el-option v-for="w in wardOptions" :key="w.value" :label="w.label" :value="w.value" />
          </el-select>
        </el-form-item>
@@ -91,7 +73,7 @@
          <el-input v-model="form.involvedUsers" placeholder="涉及人员代码,多个用逗号分隔" />
        </el-form-item>
        <el-form-item label="内容" prop="content">
          <el-input type="textarea" :rows="3" v-model="form.content" placeholder="请输入投诉/建议/表扬内容" />
          <el-input type="textarea" :rows="4" v-model="form.content" :placeholder="'请输入' + currentTypeText + '内容'" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input type="textarea" :rows="2" v-model="form.remark" placeholder="请输入备注" />
@@ -106,7 +88,7 @@
</template>
<script>
import { listAdvice, getAdvice, addAdvice, updateAdvice, delAdvice } from "@/api/followvisit/advice";
import { listAdvice, getAdvice, addAdvice, updateAdvice } from "@/api/followvisit/advice";
import store from "@/store";
export default {
@@ -123,23 +105,19 @@
    return {
      loading: false,
      adviceList: [],
      total: 0,
      ids: [],
      single: true,
      multiple: true,
      title: "",
      activeType: "1",
      open: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        adviceType: undefined,
        content: undefined
      },
      dialogTitle: "",
      currentType: "1",
      form: {},
      rules: {
        adviceType: [{ required: true, message: "请选择建议类型", trigger: "change" }],
        content: [{ required: true, message: "请输入内容", trigger: "blur" }]
      }
      },
      adviceTypes: [
        { value: "1", label: "投诉", icon: "⚠️", className: "type-complaint", tagType: "danger" },
        { value: "2", label: "建议", icon: "💡", className: "type-suggest", tagType: "primary" },
        { value: "3", label: "表扬", icon: "👍", className: "type-praise", tagType: "success" }
      ]
    };
  },
  computed: {
@@ -148,77 +126,56 @@
    },
    wardOptions() {
      return (store.getters.belongWards || []).map(w => ({ label: w.districtName, value: w.districtCode }));
    },
    currentTypeText() {
      const t = this.adviceTypes.find(x => x.value === this.currentType);
      return t ? t.label : "";
    },
    currentTypeTag() {
      const t = this.adviceTypes.find(x => x.value === this.currentType);
      return t ? t.tagType : "info";
    }
  },
  created() {
    this.getList();
  },
  methods: {
    adviceTypeText(t) {
      const map = { "1": "投诉", "2": "建议", "3": "表扬" };
      return map[t] || "未知";
    },
    adviceTypeTag(t) {
      const map = { "1": "danger", "2": "primary", "3": "success" };
      return map[t] || "info";
    getAdviceByType(type) {
      return this.adviceList.find(item => String(item.adviceType) === String(type));
    },
    getDeptNames(codes) {
      if (!codes) return "-";
      const arr = codes.split(",").filter(Boolean);
      const names = arr.map(c => {
      if (!codes) return "";
      return codes.split(",").filter(Boolean).map(c => {
        const found = this.deptOptions.find(d => d.value == c);
        return found ? found.label : c;
      });
      return names.join("、") || "-";
      }).join("、");
    },
    getWardNames(codes) {
      if (!codes) return "-";
      const arr = codes.split(",").filter(Boolean);
      const names = arr.map(c => {
      if (!codes) return "";
      return codes.split(",").filter(Boolean).map(c => {
        const found = this.wardOptions.find(w => w.value == c);
        return found ? found.label : c;
      });
      return names.join("、") || "-";
      }).join("、");
    },
    getList() {
      this.loading = true;
      // 分页参数走 query,过滤条件走 body
      const body = {
        subid: this.subid || undefined,
        taskid: this.taskid || undefined,
        patid: this.patid || undefined,
        adviceType: this.queryParams.adviceType || undefined,
        content: this.queryParams.content || undefined
        patid: this.patid || undefined
      };
      const query = {
        pageNum: this.queryParams.pageNum,
        pageSize: this.queryParams.pageSize
      };
      const query = { pageNum: 1, pageSize: 100 };
      listAdvice(body, query).then(res => {
        this.adviceList = res.rows || [];
        this.total = res.total || 0;
        this.loading = false;
      }).catch(() => { this.loading = false; });
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.queryParams.adviceType = undefined;
      this.queryParams.content = undefined;
      this.handleQuery();
    },
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    reset() {
    resetForm() {
      this.form = {
        id: undefined,
        adviceType: "1",
        adviceType: this.currentType,
        deptCodes: [],
        wardCodes: [],
        involvedUsers: "",
@@ -226,28 +183,35 @@
        remark: ""
      };
    },
    handleAdd() {
      this.reset();
      this.title = "新增投诉建议";
    handleAdd(type) {
      this.currentType = type;
      this.resetForm();
      this.dialogTitle = "新增" + this.currentTypeText;
      this.open = true;
    },
    handleUpdate(row) {
      this.reset();
      this.title = "修改投诉建议";
      getAdvice(row.id).then(res => {
        const data = res.data || {};
        this.form = {
          id: data.id,
          adviceType: data.adviceType || "1",
          deptCodes: data.deptCodes ? data.deptCodes.split(",").filter(Boolean) : [],
          wardCodes: data.wardCodes ? data.wardCodes.split(",").filter(Boolean) : [],
          involvedUsers: data.involvedUsers || "",
          content: data.content || "",
          remark: data.remark || ""
        };
        this.open = true;
      });
    handleEdit(type) {
      this.currentType = type;
      const existing = this.getAdviceByType(type);
      if (existing) {
        getAdvice(existing.id).then(res => {
          const data = res.data || existing;
          this.form = {
            id: data.id,
            adviceType: data.adviceType || type,
            deptCodes: data.deptCodes ? data.deptCodes.split(",").filter(Boolean) : [],
            wardCodes: data.wardCodes ? data.wardCodes.split(",").filter(Boolean) : [],
            involvedUsers: data.involvedUsers || "",
            content: data.content || "",
            remark: data.remark || ""
          };
          this.dialogTitle = "修改" + this.currentTypeText;
          this.open = true;
        });
      }
    },
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (!valid) return;
@@ -275,41 +239,77 @@
          }
        });
      });
    },
    handleDelete(row) {
      const ids = row.id ? [row.id] : this.ids;
      if (!ids.length) {
        this.$modal.msgWarning("请选择要删除的数据");
        return;
      }
      this.$modal.confirm("是否确认删除所选投诉建议?").then(() => {
        return delAdvice(ids.join(","));
      }).then(res => {
        if (res.code === 200) {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }
      }).catch(() => {});
    },
    handleExport() {
      this.download(
        "/system/serviceSubtaskAdvice/export",
        {
          subid: this.subid,
          taskid: this.taskid,
          patid: this.patid,
          adviceType: this.queryParams.adviceType,
          content: this.queryParams.content
        },
        `随访建议数据_${new Date().getTime()}.xlsx`
      );
    }
  }
};
</script>
<style lang="scss" scoped>
.advice-list {
  padding: 10px 0;
.advice-blocks {
  padding: 0;
  ::v-deep .el-tabs__item {
    .tab-icon {
      margin-right: 4px;
    }
  }
}
.advice-content {
  padding: 16px 20px;
  border-radius: 6px;
  border-left: 4px solid transparent;
  background: #fafafa;
  &.type-complaint { border-left-color: #f56c6c; }
  &.type-suggest { border-left-color: #409eff; }
  &.type-praise { border-left-color: #67c23a; }
  .advice-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    .advice-label {
      font-size: 14px;
      font-weight: 600;
      color: #303133;
    }
  }
  .advice-text {
    font-size: 14px;
    color: #303133;
    line-height: 1.7;
    margin-bottom: 10px;
    word-break: break-all;
  }
  .advice-meta {
    font-size: 13px;
    color: #909399;
    margin-bottom: 6px;
    .meta-item {
      display: inline-block;
      margin-right: 16px;
      i { margin-right: 4px; color: #606266; }
    }
  }
  .advice-foot {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #c0c4cc;
    padding-top: 10px;
    border-top: 1px solid #ebeef5;
  }
}
.advice-empty {
  padding: 50px 0;
  text-align: center;
  .empty-icon { font-size: 36px; display: block; margin-bottom: 12px; }
  p { color: #c0c4cc; font-size: 14px; margin-bottom: 16px; }
}
</style>