sendMsgSopOpenTool.vue 35 KB

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