WXL (wul)
8 天以前 ffa22cc18c75c0a73a3fd987e2b62fbf55316db2
src/components/Assistant/index.vue
@@ -152,17 +152,76 @@
                  d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"
                />
              </svg>
              <!-- ✅ 新增短信图标 -->
              <svg
                v-else-if="action.icon === 'IconMessageSquare'"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="2"
              >
                <rect x="3" y="3" width="18" height="18" rx="2" ry="2" />
                <line x1="8" y1="9" x2="16" y2="9" />
                <line x1="8" y1="13" x2="14" y2="13" />
                <line x1="8" y1="17" x2="12" y2="17" />
              </svg>
            </div>
            <div class="action-label">{{ action.label }}</div>
          </div>
        </div>
      </div>
    </transition>
    <!-- 短信发送对话框 -->
    <el-dialog
      title="短信发送"
      :visible.sync="smsDialogVisible"
      width="500px"
      :close-on-click-modal="false"
      append-to-body
    >
      <el-form ref="smsForm" :model="smsForm" label-width="100px">
        <el-form-item label="患者名称">
          <el-input v-model="smsForm.sendname" readonly></el-input>
        </el-form-item>
        <el-form-item label="年龄">
          <el-input v-model="smsForm.age" readonly></el-input>
        </el-form-item>
        <el-form-item label="电话">
          <el-input v-model="smsForm.telcode" readonly></el-input>
        </el-form-item>
        <el-form-item label="科室">
          <el-input v-model="smsForm.deptname" readonly></el-input>
        </el-form-item>
        <el-form-item label="病区">
          <el-input
            v-model="smsForm.leavehospitaldistrictname"
            readonly
          ></el-input>
        </el-form-item>
        <el-form-item label="短信内容">
          <el-input
            type="textarea"
            :rows="4"
            v-model="smsContent"
            placeholder="请输入短信内容..."
            maxlength="500"
            show-word-limit
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="smsDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="sendSms" :loading="smsLoading">
          确认发送
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { getCurrentUserServiceSubtaskCount } from "@/api/AiCentre/index";
import { sendMsg } from "@/api/AiCentre/index";
export default {
  name: "FloatBall",
@@ -210,6 +269,17 @@
      hideTimer: null,
      updateTime: "",
      roles: null,
      // 短信发送对话框
      // smsDialogVisible: false,
      smsLoading: false, // ✅ 新增加载状态
      smsContent: "",
      smsForm: {
        sendname: "",
        age: "",
        telcode: "",
        deptname: "",
        leavehospitaldistrictname: "",
      },
      // 统计数据
      statsItems: [
        {
@@ -269,12 +339,12 @@
          icon: "IconPhone",
          url: "/followvisit/particty?type=1&serviceType=2",
        },
        // {
        //   id: 'chat',
        //   label: '在线聊天',
        //   icon: 'IconMessageCircle',
        //   url: '/chat'
        // }
        {
          id: "sendSms", // ✅ 新增短信发送
          label: "短信发送",
          icon: "IconMessageSquare",
          action: "openSmsDialog", // 标记为弹框操作
        },
      ],
    };
  },
@@ -283,8 +353,35 @@
    totalUnread() {
      return this.statsItems.reduce((sum, item) => sum + item.unread, 0);
    },
    // ✅ Vuex 双向绑定
    smsDialogVisible: {
      get() {
        return this.$store.state.sms.smsDialogVisible;
      },
      set(val) {
        if (!val) {
          this.$store.dispatch("sms/closeSmsDialog");
        }
      },
    },
  },
  watch: {
    // ✅ 监听 Vuex 对话框状态
    "$store.state.sms.smsDialogVisible"(val) {
      if (val) {
        const patientData = this.$store.state.sms.patientData;
        this.smsForm = { ...patientData };
        this.smsContent = this.$store.state.sms.smsTemplate || "";
        // 展开悬浮球
        if (!this.isExpanded) {
          this.isExpanded = true;
          this.isHidden = false;
          clearTimeout(this.hideTimer);
        }
      }
    },
  },
  mounted() {
    this.roles = this.$store.state.user.roles;
    this.loadPosition();
@@ -424,6 +521,15 @@
    },
    handleActionClick(action) {
      // 如果是短信发送操作,打开对话框
      console.log(action);
      if (action.action === "openSmsDialog") {
        this.openSmsDialog();
        return;
      }
      // 原有逻辑保持不变
      console.log(this.roles, "this.roles");
      if (
        action.url &&
@@ -435,7 +541,53 @@
        this.$modal.msgError("非管理员用户暂无创建任务权限");
      }
    },
    // 打开短信发送对话框
    openSmsDialog() {
      // 从悬浮球内部打开时,清空表单(因为没有选中患者)
      this.$store.dispatch("sms/openSmsDialog", {
        name: "",
        age: "",
        phone: "",
        deptName: "",
        wardName: "",
        smsTemplate: "",
      });
    },
    // 发送短信
    async sendSms() {
      if (!this.smsContent.trim()) {
        this.$modal.msgError("请输入短信内容");
        return;
      }
      if (!this.smsForm.telcode) {
        this.$modal.msgError("患者电话不能为空");
        return;
      }
      this.smsLoading = true;
      try {
        const res = await sendMsg({
          phone: this.smsForm.telcode,
          content: this.smsContent,
        });
        if (res.code === 200) {
          this.$modal.msgSuccess("短信发送成功");
          // ✅ 通过 Vuex 关闭对话框
          this.$store.dispatch("sms/closeSmsDialog");
          this.smsContent = "";
        } else {
          this.$modal.msgError(res.msg || "发送失败");
        }
      } catch (error) {
        console.error("发送短信失败:", error);
        this.$modal.msgError("发送失败,请稍后重试");
      } finally {
        this.smsLoading = false;
      }
    },
    async updateStats() {
      try {
        // 这里可以替换为实际的 API 调用