sendMsgSopOpenTool.vue 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  1. <template>
  2. <div class="app-container">
  3. <el-dialog :title="sendMsgOpen.title" :visible.sync="sendMsgOpen.open" width="1000px" append-to-body>
  4. <el-alert
  5. type="error"
  6. :closable="false"
  7. show-icon>
  8. <template #title>
  9. <span style="font-size: 25px; line-height: 1.5;">
  10. 此功能用于给 选中的 SOP营期 内【所有的】客户发送 消息
  11. </span>
  12. </template>
  13. </el-alert>
  14. <el-form ref="msgForm" :model="msgForm" :rules="msgRules" label-width="100px">
  15. <el-form-item label="策略" prop="draftStrategy">
  16. <el-radio-group v-model="msgForm.draftStrategy">
  17. <el-radio :label="1">正常群发</el-radio>
  18. <el-radio :label="2">清除草稿</el-radio>
  19. <el-radio :label="3">发送草稿</el-radio>
  20. </el-radio-group>
  21. </el-form-item>
  22. <el-form-item label="选择课程" v-if="msgForm.draftStrategy==1">
  23. <el-select v-model="msgForm.courseId" placeholder="请选择课程" style=" margin-right: 10px;" size="mini"
  24. @change="courseChange()">
  25. <el-option
  26. v-for="dict in courseList"
  27. :key="dict.dictValue"
  28. :label="dict.dictLabel"
  29. :value="parseInt(dict.dictValue)"
  30. />
  31. </el-select>
  32. <el-select v-model="msgForm.videoId" placeholder="请选择小节" size="mini" style=" margin-right: 10px;"
  33. @change="videoIdChange()">
  34. <el-option
  35. v-for="dict in videoList"
  36. :key="dict.dictValue"
  37. :value="parseInt(dict.dictValue)"
  38. :label="dict.dictLabel">
  39. <span style="float: left">{{ dict.dictLabel }}</span>
  40. <el-tooltip
  41. v-if="dict.remark"
  42. :content="dict.remark"
  43. placement="top"
  44. effect="light">
  45. <span
  46. style="float: right; color: #8492a6; font-size: 13px; max-width: 150px; display: inline-block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
  47. {{ dict.remark }}
  48. </span>
  49. </el-tooltip>
  50. </el-option>
  51. </el-select>
  52. <el-select v-model="msgForm.courseType" placeholder="请选择消息类型" size="mini" style=" margin-right: 10px;">
  53. <el-option
  54. v-for="dict in sysFsSopWatchStatus"
  55. :key="dict.dictValue"
  56. :label="dict.dictLabel"
  57. :value="parseInt(dict.dictValue)"
  58. />
  59. </el-select>
  60. </el-form-item>
  61. <el-form-item label="规则" prop="setting" v-if="msgForm.draftStrategy==1">
  62. <div v-for="(item, index) in setting" :key="index"
  63. style="background-color: #fdfdfd; border: 1px solid #e6e6e6; margin-bottom: 20px;">
  64. <el-row>
  65. <el-col :span="22">
  66. <el-form :model="item" label-width="70px">
  67. <el-form-item label="内容类别" style="margin: 2%">
  68. <el-radio-group v-model="item.contentType">
  69. <el-radio :label="item.dictValue" v-for="item in sysQwSopAiContentType"
  70. @change="handleContentTypeChange()">{{ item.dictLabel }}
  71. </el-radio>
  72. </el-radio-group>
  73. </el-form-item>
  74. <el-form-item label="内容" style="margin-bottom: 2%">
  75. <el-input
  76. v-if="item.contentType == 1"
  77. v-model="item.value"
  78. type="textarea"
  79. :rows="3"
  80. placeholder="内容"
  81. style="width: 90%; margin-top: 10px;"
  82. @keydown.native="handleKeydown($event, index)"
  83. :ref="`textarea-${index}`"
  84. >
  85. </el-input>
  86. <el-link
  87. v-if="item.contentType == 1"
  88. type="primary"
  89. @click="toggleSalesCall(index)"
  90. style="margin-top: 10px;"
  91. >
  92. {{ item.isSalesCallAdded ? '移除#销售称呼#' : '添加#销售称呼#' }}
  93. </el-link>
  94. <el-link
  95. v-if="item.contentType == 1"
  96. type="primary"
  97. @click="toggleSalesCallCustomer(index)"
  98. style="margin-top: 10px;margin-left: 2%"
  99. >
  100. {{ item.isSalesCallCustomerAdded ? '移除#客户称呼#' : '添加#客户称呼#' }}
  101. </el-link>
  102. <ImageUpload v-if="item.contentType == 2 " v-model="item.imgUrl" type="image" :num="1" :width="150"
  103. :height="150"/>
  104. <div v-if="item.contentType == 3 || item.contentType ==9 ">
  105. <el-card class="box-card">
  106. <el-form-item label="链接标题:" label-width="100px">
  107. <el-input v-model="item.linkTitle" placeholder="请输入链接标题" style="width: 90%;"/>
  108. </el-form-item>
  109. <el-form-item label="链接描述:" label-width="100px">
  110. <el-input type="textarea" :rows="3" v-model="item.linkDescribe" placeholder="请输入链接描述"
  111. style="width: 90%;margin-top: 1%;"/>
  112. </el-form-item>
  113. <el-form-item label="链接封面:" label-width="100px">
  114. <ImageUpload v-model="item.linkImageUrl" type="image" :num="1" :file-size="2" :width="150"
  115. :height="150" style="margin-top: 1%;"/>
  116. </el-form-item>
  117. <el-form-item label="链接地址:" label-width="100px">
  118. <el-tag type="warning" v-model="item.isBindUrl=1">选择的课程小节 即为卡片链接地址</el-tag>
  119. </el-form-item>
  120. </el-card>
  121. </div>
  122. <div v-if="item.contentType == 4 || item.contentType == 10 ">
  123. <el-card class="box-card">
  124. <el-form-item label="标题" prop="miniprogramTitle">
  125. <el-input v-model="item.miniprogramTitle" placeholder="请输入小程序消息标题,最长为64字"/>
  126. </el-form-item>
  127. <el-form-item label="封面" prop="miniprogramPicUrl">
  128. <ImageUpload v-model="item.miniprogramPicUrl" type="image" :num="10" :width="150"
  129. :height="150"/>
  130. </el-form-item>
  131. <el-form-item label="appid" prop="miniprogramAppid" v-show="false">
  132. <el-input v-model="item.miniprogramAppid='wx73f85f8d62769119' " disabled/>
  133. </el-form-item>
  134. <el-form-item label="page路径" prop="miniprogramPage" v-show="item.contentType == 10"
  135. label-width="100px" style="margin-left: -30px">
  136. <el-input v-model="item.miniprogramPage" placeholder="小程序消息打开后的路径" type="textarea"
  137. :rows="3"/>
  138. </el-form-item>
  139. </el-card>
  140. </div>
  141. <div v-if="item.contentType == 5 ">
  142. <el-form-item label="上传文件:" prop="fileUrl" label-width="100px">
  143. <el-upload
  144. v-model="item.fileUrl"
  145. class="avatar-uploader"
  146. :action="uploadUrl"
  147. :headers="uploadHeaders"
  148. :show-file-list="false"
  149. :on-success="(res, file) => handleAvatarSuccessFile(res, file, item)"
  150. :before-upload="beforeAvatarUploadFile">
  151. <i class="el-icon-plus avatar-uploader-icon"></i>
  152. </el-upload>
  153. <el-link v-if="item.fileUrl" type="primary" :href="downloadUrl(item.fileUrl)" download>
  154. {{ item.fileUrl }}
  155. </el-link>
  156. </el-form-item>
  157. </div>
  158. <div v-if="item.contentType == 6 ">
  159. <el-form-item label="上传视频:" prop="videoUrl" label-width="100px">
  160. <el-upload
  161. v-model="item.videoUrl"
  162. class="avatar-uploader"
  163. :action="uploadUrl"
  164. :headers="uploadHeaders"
  165. :show-file-list="false"
  166. :on-success="(res, file) => handleAvatarSuccessVideo(res, file, item)"
  167. :before-upload="beforeAvatarUploadVideo">
  168. <i class="el-icon-plus avatar-uploader-icon"></i>
  169. </el-upload>
  170. <video v-if="item.videoUrl"
  171. :src="item.videoUrl"
  172. controls style="width: 200px;height: 100px">
  173. </video>
  174. </el-form-item>
  175. </div>
  176. <div v-if="item.contentType == 7 ">
  177. <el-input
  178. v-model="item.value"
  179. type="textarea" :rows="3" maxlength="66" show-word-limit
  180. placeholder="输入要转为语音的内容" style="width: 90%;margin-top: 10px;"
  181. @input="handleInputVideoText(item.value,item)"/>
  182. </div>
  183. <div v-if="item.contentType == 8">
  184. <el-button type="primary"
  185. style="margin-bottom: 1%"
  186. @click="hanldeSelectVideoNum(setting,index)">
  187. 选择视频号
  188. </el-button>
  189. <el-card class="box-card" v-if="item.coverUrl">
  190. <el-form-item label="封面标题:" label-width="100px">
  191. <el-input v-model="item.nickname"
  192. style="width: 90%;margin-bottom: 1%" disabled/>
  193. </el-form-item>
  194. <el-form-item label="头像:" label-width="100px">
  195. <el-image
  196. v-if="item.avatar != null"
  197. :src="item.avatar"
  198. :preview-src-list="[item.avatar]"
  199. :style="{ width: '50px', height: '50px' }"
  200. ></el-image>
  201. </el-form-item>
  202. <el-form-item label="封面:" label-width="100px">
  203. <el-image
  204. v-if="item.coverUrl != null"
  205. :src="item.coverUrl"
  206. :preview-src-list="[item.coverUrl]"
  207. :style="{ width: '200px', height: '200px' }"
  208. ></el-image>
  209. </el-form-item>
  210. <el-form-item label="简介:" label-width="100px">
  211. <el-input type="textarea" :rows="3"
  212. v-model="item.desc"
  213. style="width: 90%;margin-top: 1%;" disabled/>
  214. </el-form-item>
  215. <el-form-item label="视频地址:" label-width="100px"
  216. style="margin-top: 1%">
  217. <el-input v-model="item.url"
  218. style="width: 90%;" disabled/>
  219. </el-form-item>
  220. </el-card>
  221. </div>
  222. </el-form-item>
  223. <el-form-item label="添加短链" v-if="item.contentType == 1 ">
  224. <el-tooltip content="请先根据课程选定课程小节之后再添加" effect="dark"
  225. :disabled="!!msgForm.videoId">
  226. <el-switch
  227. v-model="item.isBindUrl"
  228. :disabled="!msgForm.videoId"
  229. active-color="#13ce66"
  230. inactive-color="#DCDFE6"
  231. active-value="1"
  232. inactive-value="2">
  233. </el-switch>
  234. </el-tooltip>
  235. <span v-if="item.isBindUrl == '1'" style="margin-left: 10px; color: #13ce66">添加URL</span>
  236. <span v-if="item.isBindUrl == '2'" style="margin-left: 10px; color: #b1b4ba">不加URL</span>
  237. </el-form-item>
  238. <el-form-item label="课节过期时间" v-if="item.isBindUrl == '1'
  239. && item.contentType != 2
  240. && item.contentType != 5
  241. && item.contentType != 6
  242. && item.contentType != 8"
  243. style="margin-top: 1%" label-width="100px">
  244. <el-row>
  245. <el-input-number v-model="item.expiresDays" :min="1" :max="100"></el-input-number>
  246. (天)
  247. </el-row>
  248. <el-row>
  249. <span class="tip">填写0或不填时,默认为系统配置的默认时间</span>
  250. </el-row>
  251. </el-form-item>
  252. </el-form>
  253. </el-col>
  254. <el-col :span="1" :offset="1">
  255. <i class="el-icon-delete" @click="delSetList(index)" style="margin-top: 20px;"
  256. v-if="setting.length>1"></i>
  257. </el-col>
  258. </el-row>
  259. </div>
  260. <el-link type="primary" class="el-icon-plus" :underline="false" @click='addSetList()'>添加内容</el-link>
  261. </el-form-item>
  262. <el-form-item label="发送时间" prop="sendTime" v-if="msgForm.draftStrategy==1">
  263. <el-time-picker
  264. class="custom-input"
  265. v-model="msgForm.sendTime"
  266. value-format="HH:mm"
  267. format="HH:mm"
  268. placeholder="时间"
  269. style="width: 100px;height: 20px;">
  270. </el-time-picker>
  271. <span class="tip" style="margin-left: 2%"> 不填时,默认为系统当前时间(立即发送)</span>
  272. </el-form-item>
  273. </el-form>
  274. <div slot="footer" class="dialog-footer">
  275. <el-button type="primary" @click="submitMsgForm">确 定</el-button>
  276. <el-button @click="cancelMsgForm">取 消</el-button>
  277. </div>
  278. </el-dialog>
  279. <el-dialog :title="videoNumOptions.title" :visible.sync="videoNumOptions.open" width="1500px" append-to-body>
  280. <userVideo ref="QwUserVideo" @videoResult="qwUserVideoResult"></userVideo>
  281. </el-dialog>
  282. </div>
  283. </template>
  284. <script>
  285. import { getToken } from '@/utils/auth';
  286. import {sendMsg,} from "../../../api/qw/sopUserLogsInfo";
  287. import ImageUpload from "@/views/qw/sop/ImageUpload.vue";
  288. import {courseList, videoList} from "@/api/qw/sop";
  289. import userVideo from "@/views/qw/userVideo/userVideo";
  290. export default {
  291. name: "sendMsgSopOpenTool",
  292. components: {ImageUpload, userVideo},
  293. data() {
  294. return {
  295. uploadHeaders: { Authorization: 'Bearer ' + getToken() },
  296. projectFrom: process.env.VUE_APP_PROJECT_FROM,
  297. videoNumOptions: {
  298. title: '选择视频号',
  299. open: false,
  300. content: null,
  301. contentIndex: null,
  302. },
  303. //上传语音的遮罩层
  304. voiceLoading: false,
  305. uploadUrl: process.env.VUE_APP_BASE_API + "/common/uploadOSS",
  306. uploadUrlByVoice: process.env.VUE_APP_BASE_API + "/common/uploadOSSByHOOKVoice",
  307. // 遮罩层
  308. loading: true,
  309. // 导出遮罩层
  310. exportLoading: false,
  311. // 选中数组
  312. ids: [],
  313. // 非单个禁用
  314. single: true,
  315. // 非多个禁用
  316. multiple: true,
  317. // 显示搜索条件
  318. showSearch: true,
  319. // 总条数
  320. total: 0,
  321. // sopUserLogsInfo表格数据
  322. sopUserLogsInfoList: [],
  323. sysFsSopWatchStatus: [],
  324. isSalesCallAdded: false,
  325. isSalesCallCustomerAdded: false,
  326. tagList: [],
  327. selectTags: [],
  328. // 弹出层标题
  329. title: "",
  330. // 是否显示弹出层
  331. open: false,
  332. updateOpen: false,
  333. // 查询参数
  334. queryParams: {
  335. pageNum: 1,
  336. pageSize: 10,
  337. tagIds: null,
  338. remark: null,
  339. sopId: null,
  340. userLogsId: null,
  341. userIdParam: null,
  342. startTimeParam: null,
  343. externalContactId: null,
  344. qwUserId: null,
  345. corpId: null,
  346. externalId: null,
  347. fsUserId: null,
  348. externalUserName: null,
  349. createTime: null,
  350. },
  351. courseList: [],
  352. videoList: [],
  353. //插件版
  354. sysQwSopAiContentType: [],
  355. sendMsgOpen: {
  356. title: '一键批量群发',
  357. open: false,
  358. ids: null,
  359. },
  360. // 表单参数
  361. form: {},
  362. setting: [{contentType: '1', value: '',}],
  363. msgForm: {
  364. videoId: null,
  365. courseId: null,
  366. courseType: null,
  367. userIdParam: null,
  368. setting: null,
  369. ids: null,
  370. type: null,
  371. corpId: null,
  372. sopId: null,
  373. sopIds: null,
  374. startTime: null,
  375. sendTime: null,
  376. draftStrategy: 1,
  377. },
  378. // 表单校验
  379. rules: {},
  380. batchRules: {
  381. paramTime: [
  382. {required: true, message: '选择的时间不能为空', trigger: 'blur'}
  383. ],
  384. },
  385. msgRules: {},
  386. };
  387. },
  388. created() {
  389. this.getDicts("sys_qwSopAi_contentType").then(response => {
  390. this.sysQwSopAiContentType = response.data;
  391. });
  392. this.getDicts("sys_fs_sop_watch_status").then(response => {
  393. this.sysFsSopWatchStatus = response.data;
  394. });
  395. courseList().then(response => {
  396. this.courseList = response.list;
  397. });
  398. },
  399. methods: {
  400. qwUserVideoResult(val) {
  401. // 根据选中的内容,将返回的数据更新到相应的表单项
  402. const content = this.videoNumOptions.content;
  403. const setList = content[this.videoNumOptions.contentIndex];
  404. setList.nickname = val.nickname;
  405. setList.avatar = val.avatar;
  406. setList.coverUrl = val.coverUrl;
  407. setList.thumbUrl = val.thumbUrl;
  408. setList.desc = val.desc;
  409. setList.url = val.url;
  410. setList.extras = val.extras;
  411. setList.videoId = val.id;
  412. console.info(setList)
  413. this.videoNumOptions.open = false;
  414. },
  415. oneClickGroupSending(val, type, corpId) {
  416. this.sendMsgOpen.open = true;
  417. this.msgForm.sopIds = val;
  418. this.msgForm.type = type;
  419. this.msgForm.corpId = corpId;
  420. },
  421. courseChange() {
  422. if (this.msgForm.courseId != null) {
  423. const selectedCourse = this.courseList.find(course => parseInt(course.dictValue) === this.msgForm.courseId);
  424. for (let i = 0; i < this.setting.length; i++) {
  425. //响应式直接给链接的标题/封面上值
  426. if (selectedCourse && this.msgForm.courseId != null) {
  427. if (this.setting[i].contentType == 3 || this.setting[i].contentType == 9) {
  428. this.$set(this.setting[i], 'linkTitle', selectedCourse.dictLabel);
  429. this.$set(this.setting[i], 'linkImageUrl', selectedCourse.dictImgUrl);
  430. }
  431. if (this.setting[i].contentType == 4 || this.setting[i].contentType == 10) {
  432. this.$set(this.setting[i], 'miniprogramPicUrl', selectedCourse.dictImgUrl);
  433. }
  434. }
  435. }
  436. }
  437. videoList(this.msgForm.courseId).then(response => {
  438. this.videoList = response.list;
  439. });
  440. },
  441. videoIdChange() {
  442. if (this.msgForm.videoId != null) {
  443. // 查找选中的课节对应的 label
  444. const selectedVideo = this.videoList.find(course => parseInt(course.dictValue) === this.msgForm.videoId);
  445. for (let i = 0; i < this.setting.length; i++) {
  446. //响应式直接给链接的描述上值
  447. if (selectedVideo && this.msgForm.videoId != null) {
  448. if (this.setting[i].contentType == 3 || this.setting[i].contentType == 9) {
  449. this.$set(this.setting[i], 'linkDescribe', selectedVideo.dictLabel);
  450. if (this.projectFrom == 'sxjz' && selectedVideo.dictImgUrl) {
  451. this.$set(this.setting[i], 'linkImageUrl', selectedVideo.dictImgUrl);
  452. }
  453. }
  454. if (this.setting[i].contentType == 4 || this.setting[i].contentType == 10) {
  455. this.$set(this.setting[i], 'miniprogramTitle', selectedVideo.dictLabel);
  456. if (this.projectFrom == 'sxjz' && selectedVideo.dictImgUrl) {
  457. this.$set(this.setting[i], 'miniprogramPicUrl', selectedVideo.dictImgUrl);
  458. }
  459. }
  460. }
  461. }
  462. }
  463. },
  464. handleAvatarSuccessFile(res, file, item) {
  465. if (res.code === 200) {
  466. // 使用 $set 确保响应式更新
  467. this.$set(item, 'fileUrl', res.url);
  468. } else {
  469. this.msgError(res.msg);
  470. }
  471. },
  472. beforeAvatarUploadFile(file) {
  473. const isLt1M = file.size / 1024 / 1024 < 10;
  474. if (!isLt1M) {
  475. this.$message.error('上传大小不能超过 10MB!');
  476. }
  477. return isLt1M;
  478. },
  479. //下载文件
  480. downloadUrl(materialUrl) {
  481. // 直接返回文件 URL
  482. return materialUrl;
  483. },
  484. handleAvatarSuccessVideo(res, file, item) {
  485. if (res.code == 200) {
  486. // 使用 $set 确保响应式更新
  487. this.$set(item, 'videoUrl', res.url);
  488. } else {
  489. this.msgError(res.msg);
  490. }
  491. },
  492. beforeAvatarUploadVideo(file) {
  493. const isLt30M = file.size / 1024 / 1024 < 10;
  494. const isMP4 = file.type === 'video/mp4';
  495. if (!isMP4) {
  496. this.$message.error('仅支持上传 MP4 格式的视频文件!');
  497. return false;
  498. }
  499. if (!isLt30M) {
  500. this.$message.error('上传大小不能超过 10MB!');
  501. return false;
  502. }
  503. return true;
  504. },
  505. handleInputVideoText(value, content) {
  506. // 允许的字符:中文、英文(大小写)、数字和指定标点符号(,。!?)
  507. const regex = /^[\u4e00-\u9fa5,。!?,!?]+$/;
  508. // 删除不符合条件的字符
  509. const filteredValue = value.split('').filter(char => regex.test(char)).join('');
  510. this.$set(content, 'value', filteredValue);
  511. },
  512. delSetList(index) {
  513. this.setting.splice(index, 1)
  514. },
  515. addSetList() {
  516. const newSetting = {
  517. contentType: '1',
  518. value: '',
  519. };
  520. // 将新设置项添加到 content.setting 数组中
  521. this.setting.push(newSetting);
  522. },
  523. //选择视频号
  524. hanldeSelectVideoNum(content, index) {
  525. this.videoNumOptions.content = content;
  526. this.videoNumOptions.contentIndex = index;
  527. this.videoNumOptions.open = true;
  528. },
  529. handleKeydown(event, index) {
  530. const item = this.setting[index];
  531. const textarea = this.$refs[`textarea-${index}`][0].$refs.textarea;
  532. const cursorPosition = textarea.selectionStart;
  533. // 检查是否按下了 Backspace 或 Delete 键
  534. if (event.key === 'Backspace' || event.key === 'Delete') {
  535. const tags = ['#销售称呼#', '#客户称呼#']; // 需要检查的标签
  536. const value = item.value;
  537. // 遍历标签,检查是否需要删除
  538. for (const tag of tags) {
  539. let start, end;
  540. if (event.key === 'Backspace') {
  541. // 检查光标前是否是当前标签的一部分
  542. start = cursorPosition - tag.length;
  543. if (start >= 0 && value.slice(start, cursorPosition) === tag) {
  544. // 删除整个标签
  545. item.value = value.slice(0, start) + value.slice(cursorPosition);
  546. // 更新光标位置
  547. this.$nextTick(() => {
  548. textarea.setSelectionRange(start, start);
  549. });
  550. // 更新状态
  551. if (tag === '#销售称呼#') item.isSalesCallAdded = false;
  552. if (tag === '#客户称呼#') item.isSalesCallCustomerAdded = false;
  553. event.preventDefault(); // 阻止默认删除行为
  554. break; // 找到匹配的标签后退出循环
  555. }
  556. } else if (event.key === 'Delete') {
  557. // 检查光标后是否是当前标签的一部分
  558. end = cursorPosition + tag.length;
  559. if (end <= value.length && value.slice(cursorPosition, end) === tag) {
  560. // 删除整个标签
  561. item.value = value.slice(0, cursorPosition) + value.slice(end);
  562. // 更新状态
  563. if (tag === '#销售称呼#') item.isSalesCallAdded = false;
  564. if (tag === '#客户称呼#') item.isSalesCallCustomerAdded = false;
  565. event.preventDefault(); // 阻止默认删除行为
  566. break; // 找到匹配的标签后退出循环
  567. }
  568. }
  569. // 检查光标是否位于标签的中间
  570. for (let i = 0; i <= tag.length; i++) {
  571. const tagStart = cursorPosition - i;
  572. const tagEnd = tagStart + tag.length;
  573. if (
  574. tagStart >= 0 &&
  575. tagEnd <= value.length &&
  576. value.slice(tagStart, tagEnd) === tag
  577. ) {
  578. // 删除整个标签
  579. item.value = value.slice(0, tagStart) + value.slice(tagEnd);
  580. // 更新光标位置
  581. this.$nextTick(() => {
  582. textarea.setSelectionRange(tagStart, tagStart);
  583. });
  584. // 更新状态
  585. if (tag === '#销售称呼#') item.isSalesCallAdded = false;
  586. if (tag === '#客户称呼#') item.isSalesCallCustomerAdded = false;
  587. event.preventDefault(); // 阻止默认删除行为
  588. break; // 找到匹配的标签后退出循环
  589. }
  590. }
  591. }
  592. }
  593. },
  594. // 切换添加销售称呼按钮点击事件
  595. toggleSalesCall(index) {
  596. const item = this.setting[index];
  597. const salesCall = '#销售称呼#';
  598. const textarea = this.$refs[`textarea-${index}`][0].$refs.textarea;
  599. // 获取当前光标位置
  600. const cursorPosition = textarea.selectionStart;
  601. if (item.isSalesCallAdded) {
  602. // 移除所有的 #销售称呼#
  603. item.value = item.value.replace(new RegExp(salesCall, 'g'), '');
  604. } else {
  605. // 添加 #销售称呼#
  606. item.value = item.value.slice(0, cursorPosition) + salesCall + item.value.slice(cursorPosition);
  607. }
  608. // 切换状态
  609. item.isSalesCallAdded = !item.isSalesCallAdded;
  610. // 保持光标位置
  611. this.$nextTick(() => {
  612. textarea.setSelectionRange(cursorPosition, cursorPosition);
  613. });
  614. },
  615. toggleSalesCallCustomer(index) {
  616. const item = this.setting[index];
  617. const salesCall = '#客户称呼#';
  618. const textarea = this.$refs[`textarea-${index}`][0].$refs.textarea;
  619. // 获取当前光标位置
  620. const cursorPosition = textarea.selectionStart;
  621. if (item.isSalesCallCustomerAdded) {
  622. // 移除所有的 #销售称呼#
  623. item.value = item.value.replace(new RegExp(salesCall, 'g'), '');
  624. } else {
  625. // 添加 #客户称呼#
  626. item.value = item.value.slice(0, cursorPosition) + salesCall + item.value.slice(cursorPosition);
  627. }
  628. // 切换状态
  629. item.isSalesCallCustomerAdded = !item.isSalesCallCustomerAdded;
  630. // 保持光标位置
  631. this.$nextTick(() => {
  632. textarea.setSelectionRange(cursorPosition, cursorPosition);
  633. });
  634. },
  635. handleContentTypeChange() {
  636. //如果是链接的才上
  637. if (this.msgForm.courseId != null) {
  638. const selectedCourse = this.courseList.find(course => parseInt(course.dictValue) === this.msgForm.courseId);
  639. for (let i = 0; i < this.setting.length; i++) {
  640. //响应式直接给链接的标题/封面上值
  641. if (selectedCourse && this.msgForm.courseId != null) {
  642. if (this.setting[i].contentType == 3 || this.setting[i].contentType == 9) {
  643. this.$set(this.setting[i], 'linkTitle', selectedCourse.dictLabel);
  644. this.$set(this.setting[i], 'linkImageUrl', selectedCourse.dictImgUrl);
  645. }
  646. if (this.setting[i].contentType == 4 || this.setting[i].contentType == 10) {
  647. this.$set(this.setting[i], 'miniprogramPicUrl', selectedCourse.dictImgUrl);
  648. }
  649. }
  650. }
  651. }
  652. if (this.msgForm.videoId != null) {
  653. // 查找选中的课节对应的 label
  654. const selectedVideo = this.videoList.find(course => parseInt(course.dictValue) === this.msgForm.videoId);
  655. for (let i = 0; i < this.setting.length; i++) {
  656. //响应式直接给链接的描述上值
  657. if (selectedVideo && this.msgForm.videoId != null) {
  658. if (this.setting[i].contentType == 3 || this.setting[i].contentType == 9) {
  659. this.$set(this.setting[i], 'linkDescribe', selectedVideo.dictLabel);
  660. if (this.projectFrom == 'sxjz' && selectedVideo.dictImgUrl) {
  661. this.$set(this.setting[i], 'linkImageUrl', selectedVideo.dictImgUrl);
  662. }
  663. }
  664. if (this.setting[i].contentType == 4 || this.setting[i].contentType == 10) {
  665. this.$set(this.setting[i], 'miniprogramTitle', selectedVideo.dictLabel);
  666. if (this.projectFrom == 'sxjz' && selectedVideo.dictImgUrl) {
  667. this.$set(this.setting[i], 'miniprogramPicUrl', selectedVideo.dictImgUrl);
  668. }
  669. }
  670. }
  671. }
  672. }
  673. },
  674. resetSendMsgSop() {
  675. this.msgForm = {
  676. videoId: null,
  677. courseId: null,
  678. courseType: null,
  679. setting: null,
  680. sendTime: null,
  681. draftStrategy: 1,
  682. };
  683. this.resetForm("msgForm");
  684. },
  685. // 多选框选中数据
  686. handleSelectionChange(selection) {
  687. this.ids = selection.map(item => item.id)
  688. this.single = selection.length !== 1
  689. this.multiple = !selection.length
  690. },
  691. submitMsgForm() {
  692. this.$refs["msgForm"].validate(valid => {
  693. if (valid) {
  694. if (this.msgForm.draftStrategy == 1) {
  695. this.msgForm.setting = JSON.stringify(this.setting)
  696. if (this.setting.length <= 0) {
  697. return this.$message.error("请添加规则")
  698. }
  699. if (this.msgForm.courseId === null || this.msgForm.courseId === '') {
  700. return this.$message.error("课程不能为空")
  701. }
  702. if (this.msgForm.videoId === null || this.msgForm.videoId === '') {
  703. return this.$message.error("课节不能为空")
  704. }
  705. if (this.msgForm.courseType === null || this.msgForm.courseType === '') {
  706. return this.$message.error("消息类型不能为空")
  707. }
  708. for (let i = 0; i < this.setting.length; i++) {
  709. if (this.setting[i].contentType == 1 && (this.setting[i].value == null || this.setting[i].value == "")) {
  710. return this.$message.error("内容不能为空")
  711. }
  712. if (this.setting[i].contentType == 2 && (this.setting[i].imgUrl == null || this.setting[i].imgUrl == "")) {
  713. return this.$message.error("图片不能为空")
  714. }
  715. if ((this.setting[i].contentType == 3 || this.setting[i].contentType == 9) && (this.setting[i].linkTitle == null || this.setting[i].linkTitle == "")) {
  716. return this.$message.error("链接标题不能为空")
  717. }
  718. if ((this.setting[i].contentType == 3 || this.setting[i].contentType == 9) && (this.setting[i].linkDescribe == null || this.setting[i].linkDescribe == "")) {
  719. return this.$message.error("链接描述不能为空")
  720. }
  721. if ((this.setting[i].contentType == 3 || this.setting[i].contentType == 9) && (this.setting[i].linkImageUrl == null || this.setting[i].linkImageUrl == "")) {
  722. return this.$message.error("链接图片不能为空")
  723. }
  724. if ((this.setting[i].contentType == 3 || this.setting[i].contentType == 9) && this.setting[i].type == 1 && (this.setting[i].linkUrl == null || this.setting[i].linkUrl == "")) {
  725. return this.$message.error("链接地址不能为空")
  726. }
  727. if ((this.setting[i].contentType == 4 || this.setting[i].contentType == 10) && (this.setting[i].miniprogramTitle == null || this.setting[i].miniprogramTitle == "")) {
  728. return this.$message.error("小程序消息标题不能为空")
  729. }
  730. if ((this.setting[i].contentType == 4 || this.setting[i].contentType == 10) && (this.setting[i].miniprogramPicUrl == null || this.setting[i].miniprogramPicUrl == "")) {
  731. return this.$message.error("小程序封面地址不能为空")
  732. }
  733. if (this.setting[i].contentType == 10 && (this.setting[i].miniprogramPage == null || this.setting[i].miniprogramPage == "")) {
  734. return this.$message.error("小程序page地址不能为空")
  735. }
  736. if (this.setting[i].contentType == 5 && (this.setting[i].fileUrl == null || this.setting[i].fileUrl == "")) {
  737. return this.$message.error("文件不能为空")
  738. }
  739. if (this.setting[i].contentType == 6 && (this.setting[i].videoUrl == null || this.setting[i].videoUrl == "")) {
  740. return this.$message.error("视频不能为空")
  741. }
  742. if (this.setting[i].contentType == 7 && (this.setting[i].value == null || this.setting[i].value == "")) {
  743. return this.$message.error("语音不能为空")
  744. }
  745. }
  746. }
  747. this.sendMsgOpen.open = false;
  748. const loading = this.$loading({
  749. lock: true,
  750. text: '正在执行中请稍后~~请不要刷新页面!!',
  751. spinner: 'el-icon-loading',
  752. background: 'rgba(0, 0, 0, 0.7)'
  753. });
  754. sendMsg(this.msgForm).then(response => {
  755. this.msgSuccess("一键群发成功");
  756. loading.close();
  757. this.setting = [];
  758. this.resetSendMsgSop();
  759. }).finally(() => {
  760. loading.close();
  761. });
  762. }
  763. });
  764. },
  765. cancelMsgForm() {
  766. this.sendMsgOpen.open = false;
  767. this.resetSendMsgSop();
  768. },
  769. }
  770. };
  771. </script>