sendMsgOpenTool.vue 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  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. <div v-if="item.contentType == 21">
  199. <el-card class="box-card">
  200. <el-form-item label="短信模板" >
  201. <el-select v-model="item.smsTemplateId"
  202. placeholder="请选择短信模板" size="mini"
  203. @change="getSmsTemplateInfo(item)" >
  204. <el-option
  205. v-for="template in smsTemplateList"
  206. :key="template.tempId"
  207. :label="template.title"
  208. :value="template.tempId"
  209. />
  210. </el-select>
  211. </el-form-item>
  212. <el-form-item label="内容预览" v-if="item.smsTemplateContent">
  213. <div style="color: #666; font-size: 12px; padding: 8px; border: 1px solid #eee; border-radius: 4px; background-color: #f9f9f9; max-height: 100px; overflow-y: auto;">
  214. {{ item.smsTemplateContent }}
  215. </div>
  216. </el-form-item>
  217. </el-card>
  218. </div>
  219. </el-form-item>
  220. <el-form-item label="添加短链" v-if="item.contentType == 1 " >
  221. <el-tooltip content="请先根据课程选定课程小节之后再添加" effect="dark" :disabled="!!msgForm.videoId">
  222. <el-switch
  223. v-model="item.isBindUrl"
  224. :disabled="!msgForm.videoId"
  225. active-color="#13ce66"
  226. inactive-color="#DCDFE6"
  227. active-value="1"
  228. inactive-value="2">
  229. </el-switch>
  230. </el-tooltip>
  231. <span v-if="item.isBindUrl == '1'" style="margin-left: 10px; color: #13ce66">添加URL</span>
  232. <span v-if="item.isBindUrl == '2'" style="margin-left: 10px; color: #b1b4ba">不加URL</span>
  233. </el-form-item>
  234. <el-form-item label="课节过期时间" v-if="item.isBindUrl == '1'
  235. && item.contentType != 2
  236. && item.contentType != 5
  237. && item.contentType != 6
  238. && item.contentType != 8"
  239. style="margin-top: 1%" label-width="100px">
  240. <el-row>
  241. <el-input-number v-model="item.expiresDays" :min="1" :max="100" ></el-input-number>
  242. (天)
  243. </el-row>
  244. <el-row>
  245. <span class="tip">填写0或不填时,默认为系统配置的默认时间</span>
  246. </el-row>
  247. </el-form-item>
  248. </el-form>
  249. </el-col>
  250. <el-col :span="1" :offset="1">
  251. <i class="el-icon-delete" @click="delSetList(index)" style="margin-top: 20px;" v-if="setting.length>1"></i>
  252. </el-col>
  253. </el-row>
  254. </div>
  255. <el-link type="primary" class="el-icon-plus" :underline="false" @click='addSetList()' >添加内容</el-link>
  256. </el-form-item>
  257. <el-form-item label="发送时间" prop="sendTime" v-if="msgForm.draftStrategy==1" >
  258. <el-time-picker
  259. class="custom-input"
  260. v-model="msgForm.sendTime"
  261. value-format="HH:mm"
  262. format="HH:mm"
  263. placeholder="时间"
  264. style="width: 100px;height: 20px;">
  265. </el-time-picker>
  266. <span class="tip" style="margin-left: 2%"> 不填时,默认为系统当前时间(立即发送)</span>
  267. </el-form-item>
  268. </el-form>
  269. <div slot="footer" class="dialog-footer">
  270. <el-button type="primary" @click="submitMsgForm">确 定</el-button>
  271. <el-button @click="cancelMsgForm">取 消</el-button>
  272. </div>
  273. </el-dialog>
  274. <el-dialog :title="videoNumOptions.title" :visible.sync="videoNumOptions.open" width="1500px" append-to-body>
  275. <userVideo ref="QwUserVideo" @videoResult="qwUserVideoResult"></userVideo>
  276. </el-dialog>
  277. </div>
  278. </template>
  279. <script>
  280. import { sendMsgSopType,} from "../../../api/qw/sopUserLogsInfo";
  281. import ImageUpload from "@/views/qw/sop/ImageUpload.vue";
  282. import {courseList, videoList} from "@/api/qw/sop";
  283. import userVideo from "@/views/qw/userVideo/userVideo";
  284. import { getSmsTempList } from "@/api/company/companySmsTemp";
  285. export default {
  286. name: "sendMsgOpenTool",
  287. components: {ImageUpload,userVideo},
  288. data() {
  289. return {
  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. smsTemplateList: [],
  354. // 表单参数
  355. form: {},
  356. setting:[{contentType:'1', value: '',}],
  357. msgForm:{
  358. videoId:null,
  359. courseId:null,
  360. courseType:null,
  361. userIdParam:null,
  362. setting:null,
  363. ids:null,
  364. type:null,
  365. corpId:null,
  366. sopId: 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.getDicts("sys_qwSopAi_contentType").then(response => {
  383. this.sysQwSopAiContentType = response.data;
  384. });
  385. this.getDicts("sys_fs_sop_watch_status").then(response => {
  386. this.sysFsSopWatchStatus = response.data;
  387. });
  388. courseList().then(response => {
  389. this.courseList = response.list;
  390. });
  391. this.loadSmsTemplates();
  392. },
  393. methods: {
  394. // 获取短信模板信息(类似福袋的处理方式)
  395. getSmsTemplateInfo(content) {
  396. // 如果短信模板列表为空,先加载数据
  397. if (this.smsTemplateList.length === 0) {
  398. getSmsTempList().then(response => {
  399. this.smsTemplateList = response.rows || response.data || [];
  400. // 加载完成后再次调用自身来处理选中项
  401. this.processSelectedSmsTemplate(content);
  402. }).catch(error => {
  403. console.error('加载短信模板失败:', error);
  404. this.$message.error('加载短信模板失败');
  405. });
  406. } else {
  407. // 直接处理选中项
  408. this.processSelectedSmsTemplate(content);
  409. }
  410. },
  411. // 处理选中的短信模板
  412. processSelectedSmsTemplate(content) {
  413. const selectedTemplate = this.smsTemplateList.find(item => item.tempId === content.smsTemplateId);
  414. if (selectedTemplate) {
  415. // 自动填充模板内容预览
  416. this.$set(content, 'smsTemplateContent', selectedTemplate.content || selectedTemplate.templateContent || '');
  417. } else {
  418. // 清空相关内容
  419. this.$set(content, 'smsTemplateContent', '');
  420. }
  421. },
  422. // 加载短信模板列表
  423. loadSmsTemplates() {
  424. if (this.smsTemplateList.length > 0) {
  425. return; // 如果已经有数据,不再重复加载
  426. }
  427. getSmsTempList().then(response => {
  428. this.smsTemplateList = response.rows || response.data || [];
  429. if (this.smsTemplateList.length === 0) {
  430. this.$message.info('暂无可用的短信模板');
  431. }
  432. }).catch(error => {
  433. console.error('加载短信模板失败:', error);
  434. this.$message.error('加载短信模板失败');
  435. });
  436. },
  437. qwUserVideoResult(val) {
  438. // 根据选中的内容,将返回的数据更新到相应的表单项
  439. const content = this.videoNumOptions.content;
  440. const setList = content[this.videoNumOptions.contentIndex];
  441. setList.nickname = val.nickname;
  442. setList.avatar = val.avatar;
  443. setList.coverUrl = val.coverUrl;
  444. setList.thumbUrl = val.thumbUrl;
  445. setList.desc = val.desc;
  446. setList.url = val.url;
  447. setList.extras = val.extras;
  448. setList.videoId = val.id;
  449. console.info(setList)
  450. this.videoNumOptions.open = false;
  451. },
  452. oneClickGroupSending(val,type,corpId){
  453. this.sendMsgOpen.open= true;
  454. this.msgForm.ids = val;
  455. this.msgForm.type = type;
  456. this.msgForm.corpId = corpId;
  457. },
  458. courseChange() {
  459. if (this.msgForm.courseId != null ) {
  460. const selectedCourse = this.courseList.find(course => parseInt(course.dictValue) === this.msgForm.courseId);
  461. for (let i = 0; i < this.setting.length; i++) {
  462. //响应式直接给链接的标题/封面上值
  463. if (selectedCourse && this.msgForm.courseId != null) {
  464. if ( this.setting[i].contentType == 3 || this.setting[i].contentType == 9 ){
  465. this.$set(this.setting[i], 'linkTitle', selectedCourse.dictLabel);
  466. this.$set(this.setting[i], 'linkImageUrl', selectedCourse.dictImgUrl);
  467. }
  468. if ( this.setting[i].contentType == 4 || this.setting[i].contentType == 10 ){
  469. this.$set(this.setting[i], 'miniprogramPicUrl', selectedCourse.dictImgUrl);
  470. }
  471. }
  472. }
  473. }
  474. videoList(this.msgForm.courseId).then(response => {
  475. this.videoList=response.list;
  476. });
  477. },
  478. videoIdChange() {
  479. if (this.msgForm.videoId != null ) {
  480. // 查找选中的课节对应的 label
  481. const selectedVideo = this.videoList.find(course => parseInt(course.dictValue) === this.msgForm.videoId);
  482. for (let i = 0; i < this.setting.length; i++) {
  483. //响应式直接给链接的描述上值
  484. if (selectedVideo && this.msgForm.videoId != null) {
  485. if (this.setting[i].contentType == 3 || this.setting[i].contentType == 9 ){
  486. this.$set(this.setting[i], 'linkDescribe', selectedVideo.dictLabel);
  487. }
  488. if (this.setting[i].contentType == 4 || this.setting[i].contentType == 10 ){
  489. this.$set(this.setting[i], 'miniprogramTitle', selectedVideo.dictLabel);
  490. }
  491. }
  492. }
  493. }
  494. },
  495. handleAvatarSuccessFile(res, file, item) {
  496. if (res.code === 200) {
  497. // 使用 $set 确保响应式更新
  498. this.$set(item, 'fileUrl', res.url);
  499. } else {
  500. this.msgError(res.msg);
  501. }
  502. },
  503. beforeAvatarUploadFile(file){
  504. const isLt1M = file.size / 1024 / 1024 < 10;
  505. if (!isLt1M) {
  506. this.$message.error('上传大小不能超过 10MB!');
  507. }
  508. return isLt1M;
  509. },
  510. //下载文件
  511. downloadUrl(materialUrl) {
  512. // 直接返回文件 URL
  513. return materialUrl;
  514. },
  515. handleAvatarSuccessVideo(res, file, item) {
  516. if(res.code==200){
  517. // 使用 $set 确保响应式更新
  518. this.$set(item, 'videoUrl', res.url);
  519. }
  520. else{
  521. this.msgError(res.msg);
  522. }
  523. },
  524. beforeAvatarUploadVideo(file){
  525. const isLt30M = file.size / 1024 / 1024 < 10;
  526. const isMP4 = file.type === 'video/mp4';
  527. if (!isMP4) {
  528. this.$message.error('仅支持上传 MP4 格式的视频文件!');
  529. return false;
  530. }
  531. if (!isLt30M) {
  532. this.$message.error('上传大小不能超过 10MB!');
  533. return false;
  534. }
  535. return true;
  536. },
  537. handleInputVideoText(value,content){
  538. // 允许的字符:中文、英文(大小写)、数字和指定标点符号(,。!?)
  539. const regex = /^[\u4e00-\u9fa5,。!?,!?]+$/;
  540. // 删除不符合条件的字符
  541. const filteredValue = value.split('').filter(char => regex.test(char)).join('');
  542. this.$set(content, 'value', filteredValue);
  543. },
  544. //选择视频号
  545. hanldeSelectVideoNum(content, index) {
  546. this.videoNumOptions.content = content;
  547. this.videoNumOptions.contentIndex = index;
  548. this.videoNumOptions.open = true;
  549. },
  550. delSetList(index){
  551. this.setting.splice(index,1)
  552. },
  553. addSetList(){
  554. const newSetting = {
  555. contentType:'1',
  556. value: '',
  557. };
  558. // 将新设置项添加到 content.setting 数组中
  559. this.setting.push(newSetting);
  560. },
  561. handleKeydown(event, index) {
  562. const item = this.setting[index];
  563. const textarea = this.$refs[`textarea-${index}`][0].$refs.textarea;
  564. const cursorPosition = textarea.selectionStart;
  565. // 检查是否按下了 Backspace 或 Delete 键
  566. if (event.key === 'Backspace' || event.key === 'Delete') {
  567. const tags = ['#销售称呼#', '#客户称呼#']; // 需要检查的标签
  568. const value = item.value;
  569. // 遍历标签,检查是否需要删除
  570. for (const tag of tags) {
  571. let start, end;
  572. if (event.key === 'Backspace') {
  573. // 检查光标前是否是当前标签的一部分
  574. start = cursorPosition - tag.length;
  575. if (start >= 0 && value.slice(start, cursorPosition) === tag) {
  576. // 删除整个标签
  577. item.value = value.slice(0, start) + value.slice(cursorPosition);
  578. // 更新光标位置
  579. this.$nextTick(() => {
  580. textarea.setSelectionRange(start, start);
  581. });
  582. // 更新状态
  583. if (tag === '#销售称呼#') item.isSalesCallAdded = false;
  584. if (tag === '#客户称呼#') item.isSalesCallCustomerAdded = false;
  585. event.preventDefault(); // 阻止默认删除行为
  586. break; // 找到匹配的标签后退出循环
  587. }
  588. } else if (event.key === 'Delete') {
  589. // 检查光标后是否是当前标签的一部分
  590. end = cursorPosition + tag.length;
  591. if (end <= value.length && value.slice(cursorPosition, end) === tag) {
  592. // 删除整个标签
  593. item.value = value.slice(0, cursorPosition) + value.slice(end);
  594. // 更新状态
  595. if (tag === '#销售称呼#') item.isSalesCallAdded = false;
  596. if (tag === '#客户称呼#') item.isSalesCallCustomerAdded = false;
  597. event.preventDefault(); // 阻止默认删除行为
  598. break; // 找到匹配的标签后退出循环
  599. }
  600. }
  601. // 检查光标是否位于标签的中间
  602. for (let i = 0; i <= tag.length; i++) {
  603. const tagStart = cursorPosition - i;
  604. const tagEnd = tagStart + tag.length;
  605. if (
  606. tagStart >= 0 &&
  607. tagEnd <= value.length &&
  608. value.slice(tagStart, tagEnd) === tag
  609. ) {
  610. // 删除整个标签
  611. item.value = value.slice(0, tagStart) + value.slice(tagEnd);
  612. // 更新光标位置
  613. this.$nextTick(() => {
  614. textarea.setSelectionRange(tagStart, tagStart);
  615. });
  616. // 更新状态
  617. if (tag === '#销售称呼#') item.isSalesCallAdded = false;
  618. if (tag === '#客户称呼#') item.isSalesCallCustomerAdded = false;
  619. event.preventDefault(); // 阻止默认删除行为
  620. break; // 找到匹配的标签后退出循环
  621. }
  622. }
  623. }
  624. }
  625. },
  626. // 切换添加销售称呼按钮点击事件
  627. toggleSalesCall(index) {
  628. const item = this.setting[index];
  629. const salesCall = '#销售称呼#';
  630. const textarea = this.$refs[`textarea-${index}`][0].$refs.textarea;
  631. // 获取当前光标位置
  632. const cursorPosition = textarea.selectionStart;
  633. if (item.isSalesCallAdded) {
  634. // 移除所有的 #销售称呼#
  635. item.value = item.value.replace(new RegExp(salesCall, 'g'), '');
  636. } else {
  637. // 添加 #销售称呼#
  638. item.value = item.value.slice(0, cursorPosition) + salesCall + item.value.slice(cursorPosition);
  639. }
  640. // 切换状态
  641. item.isSalesCallAdded = !item.isSalesCallAdded;
  642. // 保持光标位置
  643. this.$nextTick(() => {
  644. textarea.setSelectionRange(cursorPosition, cursorPosition);
  645. });
  646. },
  647. toggleSalesCallCustomer(index) {
  648. const item = this.setting[index];
  649. const salesCall = '#客户称呼#';
  650. const textarea = this.$refs[`textarea-${index}`][0].$refs.textarea;
  651. // 获取当前光标位置
  652. const cursorPosition = textarea.selectionStart;
  653. if (item.isSalesCallCustomerAdded) {
  654. // 移除所有的 #销售称呼#
  655. item.value = item.value.replace(new RegExp(salesCall, 'g'), '');
  656. } else {
  657. // 添加 #客户称呼#
  658. item.value = item.value.slice(0, cursorPosition) + salesCall + item.value.slice(cursorPosition);
  659. }
  660. // 切换状态
  661. item.isSalesCallCustomerAdded = !item.isSalesCallCustomerAdded;
  662. // 保持光标位置
  663. this.$nextTick(() => {
  664. textarea.setSelectionRange(cursorPosition, cursorPosition);
  665. });
  666. },
  667. handleContentTypeChange() {
  668. //如果是链接的才上
  669. if (this.msgForm.courseId != null ) {
  670. const selectedCourse = this.courseList.find(course => parseInt(course.dictValue) === this.msgForm.courseId);
  671. for (let i = 0; i < this.setting.length; i++) {
  672. //响应式直接给链接的标题/封面上值
  673. if (selectedCourse && this.msgForm.courseId != null) {
  674. if (this.setting[i].contentType == 3 || this.setting[i].contentType == 9){
  675. this.$set(this.setting[i], 'linkTitle', selectedCourse.dictLabel);
  676. this.$set(this.setting[i], 'linkImageUrl', selectedCourse.dictImgUrl);
  677. }
  678. if (this.setting[i].contentType == 4 || this.setting[i].contentType == 10 ){
  679. this.$set(this.setting[i], 'miniprogramPicUrl', selectedCourse.dictImgUrl);
  680. }
  681. }
  682. }
  683. }
  684. if (this.msgForm.videoId != null ) {
  685. // 查找选中的课节对应的 label
  686. const selectedVideo = this.videoList.find(course => parseInt(course.dictValue) === this.msgForm.videoId);
  687. for (let i = 0; i < this.setting.length; i++) {
  688. //响应式直接给链接的描述上值
  689. if (selectedVideo && this.msgForm.videoId != null) {
  690. if (this.setting[i].contentType == 3 || this.setting[i].contentType == 9){
  691. this.$set(this.setting[i], 'linkDescribe', selectedVideo.dictLabel);
  692. }
  693. if (this.setting[i].contentType == 4 || this.setting[i].contentType == 10){
  694. this.$set(this.setting[i], 'miniprogramTitle', selectedVideo.dictLabel);
  695. }
  696. }
  697. }
  698. }
  699. },
  700. resetSendMsgSop() {
  701. this.msgForm = {
  702. videoId:null,
  703. courseId:null,
  704. courseType:null,
  705. setting:null,
  706. sendTime:null,
  707. draftStrategy:1,
  708. };
  709. this.resetForm("msgForm");
  710. },
  711. // 多选框选中数据
  712. handleSelectionChange(selection) {
  713. this.ids = selection.map(item => item.id)
  714. this.single = selection.length!==1
  715. this.multiple = !selection.length
  716. },
  717. submitMsgForm(){
  718. this.$refs["msgForm"].validate(valid => {
  719. if (valid) {
  720. if (this.msgForm.draftStrategy==1){
  721. this.msgForm.setting=JSON.stringify(this.setting)
  722. if (this.setting.length <= 0) {
  723. return this.$message.error("请添加规则")
  724. }
  725. if (this.msgForm.courseId===null || this.msgForm.courseId===''){
  726. return this.$message.error("课程不能为空")
  727. }
  728. if (this.msgForm.videoId===null || this.msgForm.videoId===''){
  729. return this.$message.error("课节不能为空")
  730. }
  731. if (this.msgForm.courseType===null || this.msgForm.courseType===''){
  732. return this.$message.error("消息类型不能为空")
  733. }
  734. for (let i = 0; i < this.setting.length; i++) {
  735. if (this.setting[i].contentType == 1 && (this.setting[i].value == null || this.setting[i].value == "")) {
  736. return this.$message.error("内容不能为空")
  737. }
  738. if (this.setting[i].contentType == 2 && (this.setting[i].imgUrl == null || this.setting[i].imgUrl == "")) {
  739. return this.$message.error("图片不能为空")
  740. }
  741. if ((this.setting[i].contentType == 3 || this.setting[i].contentType == 9 ) && (this.setting[i].linkTitle == null || this.setting[i].linkTitle == "")) {
  742. return this.$message.error("链接标题不能为空")
  743. }
  744. if ((this.setting[i].contentType == 3 || this.setting[i].contentType == 9 ) && (this.setting[i].linkDescribe == null || this.setting[i].linkDescribe == "")) {
  745. return this.$message.error("链接描述不能为空")
  746. }
  747. if ((this.setting[i].contentType == 3 || this.setting[i].contentType == 9 ) && (this.setting[i].linkImageUrl == null || this.setting[i].linkImageUrl == "")) {
  748. return this.$message.error("链接图片不能为空")
  749. }
  750. 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 == "")) {
  751. return this.$message.error("链接地址不能为空")
  752. }
  753. if ((this.setting[i].contentType == 4 || this.setting[i].contentType == 10 ) && (this.setting[i].miniprogramTitle == null || this.setting[i].miniprogramTitle == "")) {
  754. return this.$message.error("小程序消息标题不能为空")
  755. }
  756. if ((this.setting[i].contentType == 4 || this.setting[i].contentType == 10 ) && (this.setting[i].miniprogramPicUrl == null || this.setting[i].miniprogramPicUrl == "")) {
  757. return this.$message.error("小程序封面地址不能为空")
  758. }
  759. if (this.setting[i].contentType == 10 && (this.setting[i].miniprogramPage == null || this.setting[i].miniprogramPage == "")) {
  760. return this.$message.error("小程序page地址不能为空")
  761. }
  762. if (this.setting[i].contentType == 5 && (this.setting[i].fileUrl == null || this.setting[i].fileUrl == "")) {
  763. return this.$message.error("文件不能为空")
  764. }
  765. if (this.setting[i].contentType == 6 && (this.setting[i].videoUrl == null || this.setting[i].videoUrl == "")) {
  766. return this.$message.error("视频不能为空")
  767. }
  768. if (this.setting[i].contentType == 7 && (this.setting[i].value == null || this.setting[i].value == "")) {
  769. return this.$message.error("语音不能为空")
  770. }
  771. // 短信模板验证
  772. if (this.setting[i].contentType == 21 && (this.setting[i].smsTemplateId == null || this.setting[i].smsTemplateId === "")) {
  773. return this.$message.error("短信模板不能为空")
  774. }else {
  775. // 根据选中的短信模板ID查找对应的模板信息
  776. const selectedTemplate = this.smsTemplateList.find(template => template.tempId === this.setting[i].smsTemplateId);
  777. if (selectedTemplate) {
  778. // 设置短信模板的相关字段
  779. this.$set(this.setting[i], 'smsTemplateCode', selectedTemplate.tempCode || '');
  780. this.$set(this.setting[i], 'smsTemplateTitle', selectedTemplate.title || '');
  781. }
  782. }
  783. }
  784. }
  785. this.sendMsgOpen.open = false;
  786. const loading = this.$loading({
  787. lock: true,
  788. text: '正在执行中请稍后~~请不要刷新页面!!',
  789. spinner: 'el-icon-loading',
  790. background: 'rgba(0, 0, 0, 0.7)'
  791. });
  792. sendMsgSopType(this.msgForm).then(response => {
  793. this.msgSuccess("一键群发成功");
  794. loading.close();
  795. this.setting=[];
  796. this.resetSendMsgSop();
  797. }).finally(()=>{
  798. loading.close();
  799. });
  800. }
  801. });
  802. },
  803. cancelMsgForm(){
  804. this.sendMsgOpen.open = false;
  805. this.resetSendMsgSop();
  806. },
  807. }
  808. };
  809. </script>