WXL
10 天以前 4898664c53396d1a8ae0333198a94cf4d7fea5a5
src/views/followvisit/record/detailpage/index.vue
@@ -260,13 +260,37 @@
                  ></el-input> </el-form-item
              ></el-col>
            </el-row>
            <div style="margin-left: 30px">
              <el-button type="primary" plain @click="Editsingletasksonyic('')"
                >保存服务</el-button
              >
            </div>
          </div>
          <el-row :gutter="20" v-if="callStatus !== 'idle'">
            <el-col :span="24">
              <el-alert
                :title="callStatusText"
                :type="callStatusType"
                :closable="false"
                show-icon
              />
            </el-col>
          </el-row>
          <!-- 挂断按钮(仅在通话中显示) -->
          <el-row :gutter="20" v-if="callStatus === 'connected'">
            <el-col :span="24" style="text-align: center; margin-top: 10px">
              <el-button
                type="danger"
                icon="el-icon-phone"
                @click="endCurrentCall"
                :loading="isEndingCall"
              >
                挂断电话
              </el-button>
            </el-col>
          </el-row>
          <el-form-item label="随访记录">
            <el-input type="textarea" v-model="form.remark"></el-input>
          </el-form-item>
@@ -563,7 +587,7 @@
              完整语音:
              <mini-audio
                :audio-source="
                  voice ? voice : 'https://example.com/example.mp3'
                  voice ? voice : '@assets/order/example.mp3'
                "
              ></mini-audio>
            </div>
@@ -587,7 +611,7 @@
                        :audio-source="
                          item.questionvoice
                            ? item.questionvoice
                            : 'https://example.com/example.mp3'
                            : '@assets/order/example.mp3'
                        "
                      ></mini-audio>
                    </div>
@@ -796,6 +820,10 @@
      userid: "",
      currentPhoneNumber: "",
      callType: "", // 用于区分是哪个电话
      // 已有数据...
      callStatus: "idle", // idle, calling, connected, ended, failed
      isEndingCall: false,
      currentCall: null, // 当前通话对象
      input: "今天身体还不错",
      radio: "2",
      taskname: "",
@@ -854,9 +882,9 @@
      },
      pickerOptions: {
        disabledDate(time) {
        // 禁用今天及之前的日期
        return time.getTime() < Date.now() - 24 * 60 * 60 * 1000;
      },
          // 禁用今天及之前的日期
          return time.getTime() < Date.now() - 24 * 60 * 60 * 1000;
        },
        shortcuts: [
          {
            text: "七天后",
@@ -948,7 +976,28 @@
      patid: null,
    };
  },
  computed: {
    callStatusText() {
      const statusMap = {
        idle: "准备呼叫",
        calling: `正在呼叫 ${this.currentPhoneNumber}...`,
        connected: `已接通 ${this.currentPhoneNumber}`,
        ended: "通话已结束",
        failed: "呼叫失败",
      };
      return statusMap[this.callStatus];
    },
    callStatusType() {
      const typeMap = {
        idle: "info",
        calling: "warning",
        connected: "success",
        ended: "info",
        failed: "error",
      };
      return typeMap[this.callStatus];
    },
  },
  created() {
    this.taskid = this.$route.query.taskid;
    this.id = this.$route.query.id;
@@ -1217,28 +1266,95 @@
          console.error("发生错误:", error);
        });
    },
    // 验证手机号格式
    isValidPhone(phone) {
      return /^1[3-9]\d{9}$/.test(phone);
    },
    // 呼叫处理
    handleCall(phone, type) {
      if (this.isValidPhone(phone)) {
        this.currentPhoneNumber = phone;
        this.callType = type;
        // 等待下一个tick确保值已更新
        this.$nextTick(() => {
          this.$refs.callButton.startCall();
          // 可选:根据不同类型做不同处理
          if (type === "tel") {
            console.log("正在呼叫患者本人:", phone);
          } else {
            console.log("正在呼叫联系人:", phone);
          }
        });
    // 验证电话号码格式并返回错误信息
    validatePhoneNumber(phone) {
      if (!phone) {
        return { isValid: false, message: "请输入电话号码" };
      }
      // 手机号正则
      const mobileRegex = /^1[3-9]\d{9}$/;
      // 带区号的固定电话(完整格式)
      const landlineFullRegex = /^0\d{2,3}-?\d{7,8}$/;
      // 不带区号的固定电话(仅本地号码)
      const landlineLocalRegex = /^\d{7,8}$/;
      if (mobileRegex.test(phone)) {
        return { isValid: true, type: "mobile" };
      } else if (landlineFullRegex.test(phone)) {
        return { isValid: true, type: "landline" };
      } else if (landlineLocalRegex.test(phone)) {
        return {
          isValid: false,
          message: "本地号码请添加区号(如028-1234567)",
        };
      } else {
        return {
          isValid: false,
          message: "请输入正确的电话号码(手机号或带区号的固定电话)",
        };
      }
    },
    // 使用示例
    isValidPhone(phone) {
      return this.validatePhoneNumber(phone).isValid;
    },
    handleCall(phone, type) {
      if (!this.isValidPhone(phone)) {
        this.$message.error("请输入正确的手机号码");
        return;
      }
      this.currentPhoneNumber = phone;
      this.callType = type;
      this.callStatus = "calling";
      this.$nextTick(() => {
        this.$refs.callButton.startCall();
        // 监听通话状态变化
        this.$refs.callButton.$on("call-status-change", (status) => {
          this.handleCallStatusChange(status);
        });
      });
    },
    // 处理通话状态变化
    handleCallStatusChange(status) {
      console.log(status, "status");
      this.callStatus = status.type;
      if (status.type === "connected") {
        this.currentCall = {
          phone: this.currentPhoneNumber,
          type: this.callType,
          startTime: new Date(),
        };
      } else if (status.type === "ended" || status.type === "failed") {
        this.currentCall = null;
      }
      // 可以根据状态执行其他操作
      if (status.type === "failed") {
        this.$message.error(`呼叫失败: ${status.text}`);
      }
    },
    // 结束当前通话
    endCurrentCall() {
      if (!this.currentCall) return;
      this.isEndingCall = true;
      this.$refs.callButton.endCall();
      // 3秒后重置状态
      setTimeout(() => {
        this.isEndingCall = false;
      }, 3000);
    },
    yuyingetdetail() {
      this.tableDatatop.forEach((item, index) => {
@@ -1285,7 +1401,7 @@
            })
            .catch(() => {
              if (this.form.serviceType == 13) {
                if (this.visitCount!=1) {
                if (this.visitCount != 1) {
                  this.$router.push({
                    path: "/logisticsservice/zbAgain",
                  });
@@ -1295,7 +1411,7 @@
                  });
                }
              } else if (form.serviceType == 2) {
                if (this.visitCount!=1) {
                if (this.visitCount != 1) {
                  this.$router.push({
                    path: "/followvisit/again",
                  });
@@ -1331,13 +1447,12 @@
          this.form = res.rows[0].serviceSubtaskList.find(
            (item) => item.id == this.id
          );
          console.log(this.form.serviceType,'serviceType');
          console.log(this.form.serviceType, "serviceType");
          this.logsheetlist = res.rows[0].serviceSubtaskList;
          this.templateid = this.logsheetlist[0].templateid;
          const targetDate = new Date(this.form.longSendTime); // 目标日期
          const now = new Date(); // 当前时间
          this.form.endtime = this.formatTime(this.form.endtime);
          if (now < targetDate && this.form.sendstate == 2) {
            this.$confirm("当前服务未到发送时间请谨慎修改", "提示", {
              confirmButtonText: "确定",
@@ -1482,6 +1597,10 @@
    setupsubtask() {
      this.$refs["zcform"].validate((valid) => {
        if (valid) {
          if (this.form.date1 && new Date(this.form.date1) < new Date()) {
            this.$message.error("随访时间不能小于当前时间");
            return false;
          }
          this.form.remark =
            this.form.remark + "【" + this.getCurrentTime() + "】";
          let form = structuredClone(this.form);
@@ -1501,7 +1620,7 @@
          }
          // form.id = null;
          form.sendstate = 2;
          console.log(form.serviceType,'form.serviceType');
          console.log(form.serviceType, "form.serviceType");
          addserviceSubtask(form).then((res) => {
            if (res.code == 200) {