sendMsgOpenTool.vue 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  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. 此功能用于给 选中的 营期 内【所有的】客户发送 消息
  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 { sendMsgSopType,} 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: "sendMsgOpenTool",
  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. startTime: null,
  346. sendTime: null,
  347. draftStrategy:1,
  348. },
  349. // 表单校验
  350. rules: {},
  351. batchRules:{
  352. paramTime: [
  353. { required: true, message: '选择的时间不能为空', trigger: 'blur' }
  354. ],
  355. },
  356. msgRules:{},
  357. };
  358. },
  359. created() {
  360. this.getDicts("sys_qwSopAi_contentType").then(response => {
  361. this.sysQwSopAiContentType = response.data;
  362. });
  363. this.getDicts("sys_fs_sop_watch_status").then(response => {
  364. this.sysFsSopWatchStatus = response.data;
  365. });
  366. courseList().then(response => {
  367. this.courseList = response.list;
  368. });
  369. },
  370. methods: {
  371. qwUserVideoResult(val) {
  372. // 根据选中的内容,将返回的数据更新到相应的表单项
  373. const content = this.videoNumOptions.content;
  374. const setList = content[this.videoNumOptions.contentIndex];
  375. setList.nickname = val.nickname;
  376. setList.avatar = val.avatar;
  377. setList.coverUrl = val.coverUrl;
  378. setList.thumbUrl = val.thumbUrl;
  379. setList.desc = val.desc;
  380. setList.url = val.url;
  381. setList.extras = val.extras;
  382. setList.videoId = val.id;
  383. console.info(setList)
  384. this.videoNumOptions.open = false;
  385. },
  386. oneClickGroupSending(val,type,corpId){
  387. this.sendMsgOpen.open= true;
  388. this.msgForm.ids = val;
  389. this.msgForm.type = type;
  390. this.msgForm.corpId = corpId;
  391. },
  392. courseChange() {
  393. if (this.msgForm.courseId != null ) {
  394. const selectedCourse = this.courseList.find(course => parseInt(course.dictValue) === this.msgForm.courseId);
  395. for (let i = 0; i < this.setting.length; i++) {
  396. //响应式直接给链接的标题/封面上值
  397. if (selectedCourse && this.msgForm.courseId != null) {
  398. if ( this.setting[i].contentType == 3 || this.setting[i].contentType == 9 ){
  399. this.$set(this.setting[i], 'linkTitle', selectedCourse.dictLabel);
  400. this.$set(this.setting[i], 'linkImageUrl', selectedCourse.dictImgUrl);
  401. }
  402. if ( this.setting[i].contentType == 4 || this.setting[i].contentType == 10 ){
  403. this.$set(this.setting[i], 'miniprogramPicUrl', selectedCourse.dictImgUrl);
  404. }
  405. }
  406. }
  407. }
  408. videoList(this.msgForm.courseId).then(response => {
  409. this.videoList=response.list;
  410. });
  411. },
  412. videoIdChange() {
  413. if (this.msgForm.videoId != null ) {
  414. // 查找选中的课节对应的 label
  415. const selectedVideo = this.videoList.find(course => parseInt(course.dictValue) === this.msgForm.videoId);
  416. for (let i = 0; i < this.setting.length; i++) {
  417. //响应式直接给链接的描述上值
  418. if (selectedVideo && this.msgForm.videoId != null) {
  419. if (this.setting[i].contentType == 3 || this.setting[i].contentType == 9 ){
  420. this.$set(this.setting[i], 'linkDescribe', selectedVideo.dictLabel);
  421. if (this.projectFrom == 'sxjz' && selectedVideo.dictImgUrl) {
  422. this.$set(this.setting[i], 'linkImageUrl', selectedVideo.dictImgUrl);
  423. }
  424. }
  425. if (this.setting[i].contentType == 4 || this.setting[i].contentType == 10 ){
  426. this.$set(this.setting[i], 'miniprogramTitle', selectedVideo.dictLabel);
  427. if (this.projectFrom == 'sxjz' && selectedVideo.dictImgUrl) {
  428. this.$set(this.setting[i], 'miniprogramPicUrl', selectedVideo.dictImgUrl);
  429. }
  430. }
  431. }
  432. }
  433. }
  434. },
  435. handleAvatarSuccessFile(res, file, item) {
  436. if (res.code === 200) {
  437. // 使用 $set 确保响应式更新
  438. this.$set(item, 'fileUrl', res.url);
  439. } else {
  440. this.msgError(res.msg);
  441. }
  442. },
  443. beforeAvatarUploadFile(file){
  444. const isLt1M = file.size / 1024 / 1024 < 10;
  445. if (!isLt1M) {
  446. this.$message.error('上传大小不能超过 10MB!');
  447. }
  448. return isLt1M;
  449. },
  450. //下载文件
  451. downloadUrl(materialUrl) {
  452. // 直接返回文件 URL
  453. return materialUrl;
  454. },
  455. handleAvatarSuccessVideo(res, file, item) {
  456. if(res.code==200){
  457. // 使用 $set 确保响应式更新
  458. this.$set(item, 'videoUrl', res.url);
  459. }
  460. else{
  461. this.msgError(res.msg);
  462. }
  463. },
  464. beforeAvatarUploadVideo(file){
  465. const isLt30M = file.size / 1024 / 1024 < 10;
  466. const isMP4 = file.type === 'video/mp4';
  467. if (!isMP4) {
  468. this.$message.error('仅支持上传 MP4 格式的视频文件!');
  469. return false;
  470. }
  471. if (!isLt30M) {
  472. this.$message.error('上传大小不能超过 10MB!');
  473. return false;
  474. }
  475. return true;
  476. },
  477. handleInputVideoText(value,content){
  478. // 允许的字符:中文、英文(大小写)、数字和指定标点符号(,。!?)
  479. const regex = /^[\u4e00-\u9fa5,。!?,!?]+$/;
  480. // 删除不符合条件的字符
  481. const filteredValue = value.split('').filter(char => regex.test(char)).join('');
  482. this.$set(content, 'value', filteredValue);
  483. },
  484. //选择视频号
  485. hanldeSelectVideoNum(content, index) {
  486. this.videoNumOptions.content = content;
  487. this.videoNumOptions.contentIndex = index;
  488. this.videoNumOptions.open = true;
  489. },
  490. delSetList(index){
  491. this.setting.splice(index,1)
  492. },
  493. addSetList(){
  494. const newSetting = {
  495. contentType:'1',
  496. value: '',
  497. };
  498. // 将新设置项添加到 content.setting 数组中
  499. this.setting.push(newSetting);
  500. },
  501. handleKeydown(event, index) {
  502. const item = this.setting[index];
  503. const textarea = this.$refs[`textarea-${index}`][0].$refs.textarea;
  504. const cursorPosition = textarea.selectionStart;
  505. // 检查是否按下了 Backspace 或 Delete 键
  506. if (event.key === 'Backspace' || event.key === 'Delete') {
  507. const tags = ['#销售称呼#', '#客户称呼#']; // 需要检查的标签
  508. const value = item.value;
  509. // 遍历标签,检查是否需要删除
  510. for (const tag of tags) {
  511. let start, end;
  512. if (event.key === 'Backspace') {
  513. // 检查光标前是否是当前标签的一部分
  514. start = cursorPosition - tag.length;
  515. if (start >= 0 && value.slice(start, cursorPosition) === tag) {
  516. // 删除整个标签
  517. item.value = value.slice(0, start) + value.slice(cursorPosition);
  518. // 更新光标位置
  519. this.$nextTick(() => {
  520. textarea.setSelectionRange(start, start);
  521. });
  522. // 更新状态
  523. if (tag === '#销售称呼#') item.isSalesCallAdded = false;
  524. if (tag === '#客户称呼#') item.isSalesCallCustomerAdded = false;
  525. event.preventDefault(); // 阻止默认删除行为
  526. break; // 找到匹配的标签后退出循环
  527. }
  528. } else if (event.key === 'Delete') {
  529. // 检查光标后是否是当前标签的一部分
  530. end = cursorPosition + tag.length;
  531. if (end <= value.length && value.slice(cursorPosition, end) === tag) {
  532. // 删除整个标签
  533. item.value = value.slice(0, cursorPosition) + value.slice(end);
  534. // 更新状态
  535. if (tag === '#销售称呼#') item.isSalesCallAdded = false;
  536. if (tag === '#客户称呼#') item.isSalesCallCustomerAdded = false;
  537. event.preventDefault(); // 阻止默认删除行为
  538. break; // 找到匹配的标签后退出循环
  539. }
  540. }
  541. // 检查光标是否位于标签的中间
  542. for (let i = 0; i <= tag.length; i++) {
  543. const tagStart = cursorPosition - i;
  544. const tagEnd = tagStart + tag.length;
  545. if (
  546. tagStart >= 0 &&
  547. tagEnd <= value.length &&
  548. value.slice(tagStart, tagEnd) === tag
  549. ) {
  550. // 删除整个标签
  551. item.value = value.slice(0, tagStart) + value.slice(tagEnd);
  552. // 更新光标位置
  553. this.$nextTick(() => {
  554. textarea.setSelectionRange(tagStart, tagStart);
  555. });
  556. // 更新状态
  557. if (tag === '#销售称呼#') item.isSalesCallAdded = false;
  558. if (tag === '#客户称呼#') item.isSalesCallCustomerAdded = false;
  559. event.preventDefault(); // 阻止默认删除行为
  560. break; // 找到匹配的标签后退出循环
  561. }
  562. }
  563. }
  564. }
  565. },
  566. // 切换添加销售称呼按钮点击事件
  567. toggleSalesCall(index) {
  568. const item = this.setting[index];
  569. const salesCall = '#销售称呼#';
  570. const textarea = this.$refs[`textarea-${index}`][0].$refs.textarea;
  571. // 获取当前光标位置
  572. const cursorPosition = textarea.selectionStart;
  573. if (item.isSalesCallAdded) {
  574. // 移除所有的 #销售称呼#
  575. item.value = item.value.replace(new RegExp(salesCall, 'g'), '');
  576. } else {
  577. // 添加 #销售称呼#
  578. item.value = item.value.slice(0, cursorPosition) + salesCall + item.value.slice(cursorPosition);
  579. }
  580. // 切换状态
  581. item.isSalesCallAdded = !item.isSalesCallAdded;
  582. // 保持光标位置
  583. this.$nextTick(() => {
  584. textarea.setSelectionRange(cursorPosition, cursorPosition);
  585. });
  586. },
  587. toggleSalesCallCustomer(index) {
  588. const item = this.setting[index];
  589. const salesCall = '#客户称呼#';
  590. const textarea = this.$refs[`textarea-${index}`][0].$refs.textarea;
  591. // 获取当前光标位置
  592. const cursorPosition = textarea.selectionStart;
  593. if (item.isSalesCallCustomerAdded) {
  594. // 移除所有的 #销售称呼#
  595. item.value = item.value.replace(new RegExp(salesCall, 'g'), '');
  596. } else {
  597. // 添加 #客户称呼#
  598. item.value = item.value.slice(0, cursorPosition) + salesCall + item.value.slice(cursorPosition);
  599. }
  600. // 切换状态
  601. item.isSalesCallCustomerAdded = !item.isSalesCallCustomerAdded;
  602. // 保持光标位置
  603. this.$nextTick(() => {
  604. textarea.setSelectionRange(cursorPosition, cursorPosition);
  605. });
  606. },
  607. handleContentTypeChange() {
  608. //如果是链接的才上
  609. if (this.msgForm.courseId != null ) {
  610. const selectedCourse = this.courseList.find(course => parseInt(course.dictValue) === this.msgForm.courseId);
  611. for (let i = 0; i < this.setting.length; i++) {
  612. //响应式直接给链接的标题/封面上值
  613. if (selectedCourse && this.msgForm.courseId != null) {
  614. if (this.setting[i].contentType == 3 || this.setting[i].contentType == 9){
  615. this.$set(this.setting[i], 'linkTitle', selectedCourse.dictLabel);
  616. this.$set(this.setting[i], 'linkImageUrl', selectedCourse.dictImgUrl);
  617. }
  618. if (this.setting[i].contentType == 4 || this.setting[i].contentType == 10 ){
  619. this.$set(this.setting[i], 'miniprogramPicUrl', selectedCourse.dictImgUrl);
  620. }
  621. }
  622. }
  623. }
  624. if (this.msgForm.videoId != null ) {
  625. // 查找选中的课节对应的 label
  626. const selectedVideo = this.videoList.find(course => parseInt(course.dictValue) === this.msgForm.videoId);
  627. for (let i = 0; i < this.setting.length; i++) {
  628. //响应式直接给链接的描述上值
  629. if (selectedVideo && this.msgForm.videoId != null) {
  630. if (this.setting[i].contentType == 3 || this.setting[i].contentType == 9){
  631. this.$set(this.setting[i], 'linkDescribe', selectedVideo.dictLabel);
  632. if (this.projectFrom == 'sxjz' && selectedVideo.dictImgUrl) {
  633. this.$set(this.setting[i], 'linkImageUrl', selectedVideo.dictImgUrl);
  634. }
  635. }
  636. if (this.setting[i].contentType == 4 || this.setting[i].contentType == 10){
  637. this.$set(this.setting[i], 'miniprogramTitle', selectedVideo.dictLabel);
  638. if (this.projectFrom == 'sxjz' && selectedVideo.dictImgUrl) {
  639. this.$set(this.setting[i], 'miniprogramPicUrl', selectedVideo.dictImgUrl);
  640. }
  641. }
  642. }
  643. }
  644. }
  645. },
  646. resetSendMsgSop() {
  647. this.msgForm = {
  648. videoId:null,
  649. courseId:null,
  650. courseType:null,
  651. setting:null,
  652. sendTime:null,
  653. draftStrategy:1,
  654. };
  655. this.resetForm("msgForm");
  656. },
  657. // 多选框选中数据
  658. handleSelectionChange(selection) {
  659. this.ids = selection.map(item => item.id)
  660. this.single = selection.length!==1
  661. this.multiple = !selection.length
  662. },
  663. submitMsgForm(){
  664. this.$refs["msgForm"].validate(valid => {
  665. if (valid) {
  666. if (this.msgForm.draftStrategy==1){
  667. this.msgForm.setting=JSON.stringify(this.setting)
  668. if (this.setting.length <= 0) {
  669. return this.$message.error("请添加规则")
  670. }
  671. if (this.msgForm.courseId===null || this.msgForm.courseId===''){
  672. return this.$message.error("课程不能为空")
  673. }
  674. if (this.msgForm.videoId===null || this.msgForm.videoId===''){
  675. return this.$message.error("课节不能为空")
  676. }
  677. if (this.msgForm.courseType===null || this.msgForm.courseType===''){
  678. return this.$message.error("消息类型不能为空")
  679. }
  680. for (let i = 0; i < this.setting.length; i++) {
  681. if (this.setting[i].contentType == 1 && (this.setting[i].value == null || this.setting[i].value == "")) {
  682. return this.$message.error("内容不能为空")
  683. }
  684. if (this.setting[i].contentType == 2 && (this.setting[i].imgUrl == null || this.setting[i].imgUrl == "")) {
  685. return this.$message.error("图片不能为空")
  686. }
  687. if ((this.setting[i].contentType == 3 || this.setting[i].contentType == 9 ) && (this.setting[i].linkTitle == null || this.setting[i].linkTitle == "")) {
  688. return this.$message.error("链接标题不能为空")
  689. }
  690. if ((this.setting[i].contentType == 3 || this.setting[i].contentType == 9 ) && (this.setting[i].linkDescribe == null || this.setting[i].linkDescribe == "")) {
  691. return this.$message.error("链接描述不能为空")
  692. }
  693. if ((this.setting[i].contentType == 3 || this.setting[i].contentType == 9 ) && (this.setting[i].linkImageUrl == null || this.setting[i].linkImageUrl == "")) {
  694. return this.$message.error("链接图片不能为空")
  695. }
  696. 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 == "")) {
  697. return this.$message.error("链接地址不能为空")
  698. }
  699. if ((this.setting[i].contentType == 4 || this.setting[i].contentType == 10 ) && (this.setting[i].miniprogramTitle == null || this.setting[i].miniprogramTitle == "")) {
  700. return this.$message.error("小程序消息标题不能为空")
  701. }
  702. if ((this.setting[i].contentType == 4 || this.setting[i].contentType == 10 ) && (this.setting[i].miniprogramPicUrl == null || this.setting[i].miniprogramPicUrl == "")) {
  703. return this.$message.error("小程序封面地址不能为空")
  704. }
  705. if (this.setting[i].contentType == 10 && (this.setting[i].miniprogramPage == null || this.setting[i].miniprogramPage == "")) {
  706. return this.$message.error("小程序page地址不能为空")
  707. }
  708. if (this.setting[i].contentType == 5 && (this.setting[i].fileUrl == null || this.setting[i].fileUrl == "")) {
  709. return this.$message.error("文件不能为空")
  710. }
  711. if (this.setting[i].contentType == 6 && (this.setting[i].videoUrl == null || this.setting[i].videoUrl == "")) {
  712. return this.$message.error("视频不能为空")
  713. }
  714. if (this.setting[i].contentType == 7 && (this.setting[i].value == null || this.setting[i].value == "")) {
  715. return this.$message.error("语音不能为空")
  716. }
  717. }
  718. }
  719. this.sendMsgOpen.open = false;
  720. const loading = this.$loading({
  721. lock: true,
  722. text: '正在执行中请稍后~~请不要刷新页面!!',
  723. spinner: 'el-icon-loading',
  724. background: 'rgba(0, 0, 0, 0.7)'
  725. });
  726. sendMsgSopType(this.msgForm).then(response => {
  727. this.msgSuccess("一键群发成功");
  728. loading.close();
  729. this.setting=[];
  730. this.resetSendMsgSop();
  731. }).finally(()=>{
  732. loading.close();
  733. });
  734. }
  735. });
  736. },
  737. cancelMsgForm(){
  738. this.sendMsgOpen.open = false;
  739. this.resetSendMsgSop();
  740. },
  741. }
  742. };
  743. </script>