sendMsgSopOpenTool.vue 34 KB

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