Jelajahi Sumber

获客链接管理增加通过电话号码发送短信的功能

cgp 2 hari lalu
induk
melakukan
9d8c716b3a
2 mengubah file dengan 160 tambahan dan 10 penghapusan
  1. 8 0
      src/api/qw/acquisitionAssistant.js
  2. 152 10
      src/views/qw/acquisitionAssistant/index.vue

+ 8 - 0
src/api/qw/acquisitionAssistant.js

@@ -83,3 +83,11 @@ export function deleteAssistant(id) {
     method: 'get'
   })
 }
+
+//发送获客链接短信
+export function sendAcquisitionMessage(id, phone) {
+  return request({
+    url: `/qw/acquisitionAssistant/sendAcquisitionMessage/${id}/${phone}`,
+    method: 'get'
+  })
+}

+ 152 - 10
src/views/qw/acquisitionAssistant/index.vue

@@ -96,8 +96,20 @@
       </el-table-column>
       <el-table-column label="链接ID" prop="linkId" width="200" :show-overflow-tooltip="true" />
       <el-table-column label="链接名称" prop="linkName" width="150" :show-overflow-tooltip="true" />
-      <el-table-column label="链接URL" prop="url" width="200" :show-overflow-tooltip="true" />
-      <el-table-column label="pageParam" prop="pageParam" width="150" :show-overflow-tooltip="true" />
+      <el-table-column label="获客链接" prop="url" width="200" :show-overflow-tooltip="true" />
+      <el-table-column label="链接后缀" prop="pageParam" width="150" :show-overflow-tooltip="true" />
+      <el-table-column label="加微链接" width="200" :show-overflow-tooltip="true">
+        <template slot-scope="scope">
+          <el-link
+            :href="getFullUrl(scope.row)"
+            target="_blank"
+            type="primary"
+            :underline="false"
+          >
+            {{ getFullUrl(scope.row) }}
+          </el-link>
+        </template>
+      </el-table-column>
       <el-table-column label="使用范围" prop="rangeDesc" width="200" :show-overflow-tooltip="true" />
       <el-table-column label="状态" width="80" align="center">
         <template slot-scope="scope">
@@ -146,6 +158,13 @@
             @click="handleGenerateQRCode(scope.row)"
             style="color: #67C23A;"
           >生成二维码</el-button>
+          <el-button
+            size="mini"
+            type="text"
+            icon="el-icon-message"
+            style="color: #E6A23C;"
+            @click="handleSendSms(scope.row)"
+          >发送短信</el-button>
         </template>
       </el-table-column>
     </el-table>
@@ -343,6 +362,42 @@
         <el-button @click="qrCodeDialog.visible = false">关 闭</el-button>
       </div>
     </el-dialog>
+
+    <!-- 发送短信弹窗 -->
+    <el-dialog
+      title="发送获客链接短信"
+      :visible.sync="smsDialog.visible"
+      width="400px"
+      append-to-body
+      @close="handleSmsDialogClose"
+    >
+      <el-form :model="smsDialog" label-width="100px">
+        <el-form-item label="手机号码" required>
+          <el-input
+            v-model="smsDialog.phone"
+            placeholder="请输入手机号码"
+            clearable
+          />
+          <div class="el-form-item__tips" style="color: #909399; font-size: 12px; margin-top: 5px;">
+            请输入11位手机号码
+          </div>
+        </el-form-item>
+        <el-form-item label="链接名称">
+          <span>{{ smsDialog.linkName }}</span>
+        </el-form-item>
+        <el-form-item label="完整链接">
+          <el-link :href="smsDialog.fullUrl" target="_blank" type="primary" :underline="false">
+            {{ smsDialog.fullUrl }}
+          </el-link>
+        </el-form-item>
+      </el-form>
+      <div slot="footer" class="dialog-footer">
+        <el-button type="primary" @click="confirmSendSms" :loading="smsDialog.sending">
+          确 定 发 送
+        </el-button>
+        <el-button @click="smsDialog.visible = false">取 消</el-button>
+      </div>
+    </el-dialog>
   </div>
 </template>
 
@@ -355,7 +410,8 @@ import {
   deleteAssistant,
   getQwUserList,
   getQwUserListByIds,
-  qwUserCompanyList
+  qwUserCompanyList,
+  sendAcquisitionMessage
 } from '@/api/qw/acquisitionAssistant'
 
 import QRCode from 'qrcodejs2'
@@ -398,6 +454,16 @@ export default {
         pageParam: '',
         rowData: null
       },
+      // 短信发送弹窗数据
+      smsDialog: {
+        visible: false,
+        sending: false,
+        phone: '',
+        linkId: '',
+        linkName: '',
+        fullUrl: '',
+        rowData: null
+      },
       // 查询参数 - corpId作为全局筛选条件
       queryParams: {
         pageNum: 1,
@@ -617,6 +683,60 @@ export default {
       // 目前不需要特殊处理
     },
 
+    /** 发送短信按钮操作 */
+    handleSendSms(row) {
+      // 重置表单数据
+      this.smsDialog = {
+        visible: true,
+        sending: false,
+        phone: '',
+        linkId: row.id,
+        linkName: row.linkName,
+        fullUrl: this.getFullUrl(row),
+        rowData: row
+      }
+    },
+
+    /** 确认发送短信 */
+    confirmSendSms() {
+      // 验证手机号码
+      const phone = this.smsDialog.phone.trim()
+      if (!phone) {
+        this.$message.warning('请输入手机号码')
+        return
+      }
+
+      // 验证手机号码格式
+      const phoneRegex = /^1[3-9]\d{9}$/
+      if (!phoneRegex.test(phone)) {
+        this.$message.warning('请输入正确的11位手机号码')
+        return
+      }
+
+      // 发送请求
+      this.smsDialog.sending = true
+
+      sendAcquisitionMessage(this.smsDialog.linkId, phone)
+        .then(response => {
+          this.$message.success('短信发送成功')
+          this.smsDialog.visible = false
+        })
+        .catch(error => {
+          console.error('发送短信失败:', error)
+          const errorMsg = error.response?.data?.msg || error.message || '发送失败'
+          this.$message.error(errorMsg)
+        })
+        .finally(() => {
+          this.smsDialog.sending = false
+        })
+    },
+
+    /** 短信弹窗关闭后的处理 */
+    handleSmsDialogClose() {
+      this.smsDialog.phone = ''
+      this.smsDialog.sending = false
+    },
+
     /** 格式化时间 */
     parseTime(time, pattern) {
       if (arguments.length === 0 || !time) {
@@ -974,6 +1094,18 @@ export default {
       this.open = true
       this.title = '添加获客链接'
 
+      // 新增时添加关联成员必填校验
+      this.rules.selectedUserIds = [
+        { required: true, message: '请选择关联成员', trigger: 'change' }
+      ]
+
+      // 如果表单已渲染,需要重新设置校验规则
+      this.$nextTick(() => {
+        if (this.$refs.form) {
+          this.$refs.form.clearValidate()
+        }
+      })
+
       // 预加载用户数据
       this.loadUsersByCorp()
     },
@@ -1024,18 +1156,24 @@ export default {
         if (data.userList) {
           if (typeof data.userList === 'string') {
             try {
-              // 处理类似 "[\"TongKe\"]" 的字符串
               const parsed = JSON.parse(data.userList)
-              this.form.userListParam = Array.isArray(parsed) ? parsed : [parsed]
+              // 检查 parsed 是否包含 userList 字段
+              if (parsed && parsed.userList && Array.isArray(parsed.userList)) {
+                this.form.userListParam = parsed.userList
+              } else if (Array.isArray(parsed)) {
+                this.form.userListParam = parsed
+              } else {
+                this.form.userListParam = []
+              }
             } catch (e) {
-              // 如果不是标准JSON格式,尝试按逗号分割
-              this.form.userListParam = data.userList
-                .replace(/[\[\]"]/g, '')  // 去除方括号和引号
-                .split(',')
-                .filter(id => id.trim())
+              console.error('解析 userList 失败:', e)
+              this.form.userListParam = []
             }
           } else if (Array.isArray(data.userList)) {
             this.form.userListParam = data.userList
+          } else if (data.userList && data.userList.userList) {
+            // 处理已经是对象的情况
+            this.form.userListParam = data.userList.userList
           }
         }
 
@@ -1172,6 +1310,10 @@ export default {
 
             // ========== 优先分配相关 ==========
             priorityUserList: JSON.stringify(this.form.priorityUserListParam || []),
+
+            userListParam: this.form.userListParam || [],
+            departmentListParam: this.form.departmentListParam || [],
+            priorityUserListParam: this.form.priorityUserListParam || []
           }
 
           console.log('提交的数据:', submitData)