sendMsgOpenTool.vue 37 KB

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