sendMsgSopOpenTool.vue 34 KB

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