sendMsgOpenTool.vue 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  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. },
  461. videoIdChange() {
  462. if (this.msgForm.videoId != null ) {
  463. // 查找选中的课节对应的 label
  464. const selectedVideo = this.videoList.find(course => parseInt(course.dictValue) === this.msgForm.videoId);
  465. for (let i = 0; i < this.setting.length; i++) {
  466. //响应式直接给链接的描述上值
  467. if (selectedVideo && this.msgForm.videoId != null) {
  468. if (this.setting[i].contentType == 3 || this.setting[i].contentType == 9 ){
  469. this.$set(this.setting[i], 'linkDescribe', selectedVideo.dictLabel);
  470. if (this.projectFrom == 'sxjz' && selectedVideo.dictImgUrl) {
  471. this.$set(this.setting[i], 'linkImageUrl', selectedVideo.dictImgUrl);
  472. }
  473. }
  474. if (this.setting[i].contentType == 4 || this.setting[i].contentType == 10 ){
  475. this.$set(this.setting[i], 'miniprogramTitle', selectedVideo.dictLabel);
  476. if (this.projectFrom == 'sxjz' && selectedVideo.dictImgUrl) {
  477. this.$set(this.setting[i], 'miniprogramPicUrl', selectedVideo.dictImgUrl);
  478. }
  479. }
  480. }
  481. }
  482. }
  483. },
  484. handleAvatarSuccessFile(res, file, item) {
  485. if (res.code === 200) {
  486. // 使用 $set 确保响应式更新
  487. this.$set(item, 'fileUrl', res.url);
  488. } else {
  489. this.msgError(res.msg);
  490. }
  491. },
  492. beforeAvatarUploadFile(file){
  493. const isLt1M = file.size / 1024 / 1024 < 10;
  494. if (!isLt1M) {
  495. this.$message.error('上传大小不能超过 10MB!');
  496. }
  497. return isLt1M;
  498. },
  499. //下载文件
  500. downloadUrl(materialUrl) {
  501. // 直接返回文件 URL
  502. return materialUrl;
  503. },
  504. handleAvatarSuccessVideo(res, file, item) {
  505. if(res.code==200){
  506. // 使用 $set 确保响应式更新
  507. this.$set(item, 'videoUrl', res.url);
  508. }
  509. else{
  510. this.msgError(res.msg);
  511. }
  512. },
  513. beforeAvatarUploadVideo(file){
  514. const isLt30M = file.size / 1024 / 1024 < 10;
  515. const isMP4 = file.type === 'video/mp4';
  516. if (!isMP4) {
  517. this.$message.error('仅支持上传 MP4 格式的视频文件!');
  518. return false;
  519. }
  520. if (!isLt30M) {
  521. this.$message.error('上传大小不能超过 10MB!');
  522. return false;
  523. }
  524. return true;
  525. },
  526. handleInputVideoText(value,content){
  527. // 允许的字符:中文、英文(大小写)、数字和指定标点符号(,。!?)
  528. const regex = /^[\u4e00-\u9fa5,。!?,!?]+$/;
  529. // 删除不符合条件的字符
  530. const filteredValue = value.split('').filter(char => regex.test(char)).join('');
  531. this.$set(content, 'value', filteredValue);
  532. },
  533. //选择视频号
  534. hanldeSelectVideoNum(content, index) {
  535. this.videoNumOptions.content = content;
  536. this.videoNumOptions.contentIndex = index;
  537. this.videoNumOptions.open = true;
  538. },
  539. delSetList(index){
  540. this.setting.splice(index,1)
  541. },
  542. addSetList(){
  543. const newSetting = {
  544. contentType:'1',
  545. value: '',
  546. };
  547. // 将新设置项添加到 content.setting 数组中
  548. this.setting.push(newSetting);
  549. },
  550. handleKeydown(event, index) {
  551. const item = this.setting[index];
  552. const textarea = this.$refs[`textarea-${index}`][0].$refs.textarea;
  553. const cursorPosition = textarea.selectionStart;
  554. // 检查是否按下了 Backspace 或 Delete 键
  555. if (event.key === 'Backspace' || event.key === 'Delete') {
  556. const tags = ['#销售称呼#', '#客户称呼#']; // 需要检查的标签
  557. const value = item.value;
  558. // 遍历标签,检查是否需要删除
  559. for (const tag of tags) {
  560. let start, end;
  561. if (event.key === 'Backspace') {
  562. // 检查光标前是否是当前标签的一部分
  563. start = cursorPosition - tag.length;
  564. if (start >= 0 && value.slice(start, cursorPosition) === tag) {
  565. // 删除整个标签
  566. item.value = value.slice(0, start) + value.slice(cursorPosition);
  567. // 更新光标位置
  568. this.$nextTick(() => {
  569. textarea.setSelectionRange(start, start);
  570. });
  571. // 更新状态
  572. if (tag === '#销售称呼#') item.isSalesCallAdded = false;
  573. if (tag === '#客户称呼#') item.isSalesCallCustomerAdded = false;
  574. event.preventDefault(); // 阻止默认删除行为
  575. break; // 找到匹配的标签后退出循环
  576. }
  577. } else if (event.key === 'Delete') {
  578. // 检查光标后是否是当前标签的一部分
  579. end = cursorPosition + tag.length;
  580. if (end <= value.length && value.slice(cursorPosition, end) === tag) {
  581. // 删除整个标签
  582. item.value = value.slice(0, cursorPosition) + value.slice(end);
  583. // 更新状态
  584. if (tag === '#销售称呼#') item.isSalesCallAdded = false;
  585. if (tag === '#客户称呼#') item.isSalesCallCustomerAdded = false;
  586. event.preventDefault(); // 阻止默认删除行为
  587. break; // 找到匹配的标签后退出循环
  588. }
  589. }
  590. // 检查光标是否位于标签的中间
  591. for (let i = 0; i <= tag.length; i++) {
  592. const tagStart = cursorPosition - i;
  593. const tagEnd = tagStart + tag.length;
  594. if (
  595. tagStart >= 0 &&
  596. tagEnd <= value.length &&
  597. value.slice(tagStart, tagEnd) === tag
  598. ) {
  599. // 删除整个标签
  600. item.value = value.slice(0, tagStart) + value.slice(tagEnd);
  601. // 更新光标位置
  602. this.$nextTick(() => {
  603. textarea.setSelectionRange(tagStart, tagStart);
  604. });
  605. // 更新状态
  606. if (tag === '#销售称呼#') item.isSalesCallAdded = false;
  607. if (tag === '#客户称呼#') item.isSalesCallCustomerAdded = false;
  608. event.preventDefault(); // 阻止默认删除行为
  609. break; // 找到匹配的标签后退出循环
  610. }
  611. }
  612. }
  613. }
  614. },
  615. // 切换添加销售称呼按钮点击事件
  616. toggleSalesCall(index) {
  617. const item = this.setting[index];
  618. const salesCall = '#销售称呼#';
  619. const textarea = this.$refs[`textarea-${index}`][0].$refs.textarea;
  620. // 获取当前光标位置
  621. const cursorPosition = textarea.selectionStart;
  622. if (item.isSalesCallAdded) {
  623. // 移除所有的 #销售称呼#
  624. item.value = item.value.replace(new RegExp(salesCall, 'g'), '');
  625. } else {
  626. // 添加 #销售称呼#
  627. item.value = item.value.slice(0, cursorPosition) + salesCall + item.value.slice(cursorPosition);
  628. }
  629. // 切换状态
  630. item.isSalesCallAdded = !item.isSalesCallAdded;
  631. // 保持光标位置
  632. this.$nextTick(() => {
  633. textarea.setSelectionRange(cursorPosition, cursorPosition);
  634. });
  635. },
  636. toggleSalesCallCustomer(index) {
  637. const item = this.setting[index];
  638. const salesCall = '#客户称呼#';
  639. const textarea = this.$refs[`textarea-${index}`][0].$refs.textarea;
  640. // 获取当前光标位置
  641. const cursorPosition = textarea.selectionStart;
  642. if (item.isSalesCallCustomerAdded) {
  643. // 移除所有的 #销售称呼#
  644. item.value = item.value.replace(new RegExp(salesCall, 'g'), '');
  645. } else {
  646. // 添加 #客户称呼#
  647. item.value = item.value.slice(0, cursorPosition) + salesCall + item.value.slice(cursorPosition);
  648. }
  649. // 切换状态
  650. item.isSalesCallCustomerAdded = !item.isSalesCallCustomerAdded;
  651. // 保持光标位置
  652. this.$nextTick(() => {
  653. textarea.setSelectionRange(cursorPosition, cursorPosition);
  654. });
  655. },
  656. handleContentTypeChange() {
  657. //如果是链接的才上
  658. if (this.msgForm.courseId != null ) {
  659. const selectedCourse = this.courseList.find(course => parseInt(course.dictValue) === this.msgForm.courseId);
  660. for (let i = 0; i < this.setting.length; i++) {
  661. //响应式直接给链接的标题/封面上值
  662. if (selectedCourse && this.msgForm.courseId != null) {
  663. if (this.setting[i].contentType == 3 || this.setting[i].contentType == 9){
  664. this.$set(this.setting[i], 'linkTitle', selectedCourse.dictLabel);
  665. this.$set(this.setting[i], 'linkImageUrl', selectedCourse.dictImgUrl);
  666. }
  667. if (this.setting[i].contentType == 4 || this.setting[i].contentType == 10 ){
  668. this.$set(this.setting[i], 'miniprogramPicUrl', selectedCourse.dictImgUrl);
  669. }
  670. }
  671. }
  672. }
  673. if (this.msgForm.videoId != null ) {
  674. // 查找选中的课节对应的 label
  675. const selectedVideo = this.videoList.find(course => parseInt(course.dictValue) === this.msgForm.videoId);
  676. for (let i = 0; i < this.setting.length; i++) {
  677. //响应式直接给链接的描述上值
  678. if (selectedVideo && this.msgForm.videoId != null) {
  679. if (this.setting[i].contentType == 3 || this.setting[i].contentType == 9){
  680. this.$set(this.setting[i], 'linkDescribe', selectedVideo.dictLabel);
  681. if (this.projectFrom == 'sxjz' && selectedVideo.dictImgUrl) {
  682. this.$set(this.setting[i], 'linkImageUrl', selectedVideo.dictImgUrl);
  683. }
  684. }
  685. if (this.setting[i].contentType == 4 || this.setting[i].contentType == 10){
  686. this.$set(this.setting[i], 'miniprogramTitle', selectedVideo.dictLabel);
  687. if (this.projectFrom == 'sxjz' && selectedVideo.dictImgUrl) {
  688. this.$set(this.setting[i], 'miniprogramPicUrl', selectedVideo.dictImgUrl);
  689. }
  690. }
  691. }
  692. }
  693. }
  694. },
  695. resetSendMsgSop() {
  696. this.msgForm = {
  697. videoId:null,
  698. courseId:null,
  699. courseType:null,
  700. setting:null,
  701. sendTime:null,
  702. draftStrategy:1,
  703. };
  704. this.resetForm("msgForm");
  705. },
  706. // 多选框选中数据
  707. handleSelectionChange(selection) {
  708. this.ids = selection.map(item => item.id)
  709. this.single = selection.length!==1
  710. this.multiple = !selection.length
  711. },
  712. submitMsgForm(){
  713. this.$refs["msgForm"].validate(valid => {
  714. if (valid) {
  715. if (this.msgForm.draftStrategy==1){
  716. this.msgForm.setting=JSON.stringify(this.setting)
  717. if (this.setting.length <= 0) {
  718. return this.$message.error("请添加规则")
  719. }
  720. if (this.msgForm.courseId===null || this.msgForm.courseId===''){
  721. return this.$message.error("课程不能为空")
  722. }
  723. if (this.msgForm.videoId===null || this.msgForm.videoId===''){
  724. return this.$message.error("课节不能为空")
  725. }
  726. if (this.msgForm.courseType===null || this.msgForm.courseType===''){
  727. return this.$message.error("消息类型不能为空")
  728. }
  729. for (let i = 0; i < this.setting.length; i++) {
  730. if (this.setting[i].contentType == 1 && (this.setting[i].value == null || this.setting[i].value == "")) {
  731. return this.$message.error("内容不能为空")
  732. }
  733. if (this.setting[i].contentType == 2 && (this.setting[i].imgUrl == null || this.setting[i].imgUrl == "")) {
  734. return this.$message.error("图片不能为空")
  735. }
  736. if ((this.setting[i].contentType == 3 || this.setting[i].contentType == 9 ) && (this.setting[i].linkTitle == null || this.setting[i].linkTitle == "")) {
  737. return this.$message.error("链接标题不能为空")
  738. }
  739. if ((this.setting[i].contentType == 3 || this.setting[i].contentType == 9 ) && (this.setting[i].linkDescribe == null || this.setting[i].linkDescribe == "")) {
  740. return this.$message.error("链接描述不能为空")
  741. }
  742. if ((this.setting[i].contentType == 3 || this.setting[i].contentType == 9 ) && (this.setting[i].linkImageUrl == null || this.setting[i].linkImageUrl == "")) {
  743. return this.$message.error("链接图片不能为空")
  744. }
  745. 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 == "")) {
  746. return this.$message.error("链接地址不能为空")
  747. }
  748. if ((this.setting[i].contentType == 4 || this.setting[i].contentType == 10 ) && (this.setting[i].miniprogramTitle == null || this.setting[i].miniprogramTitle == "")) {
  749. return this.$message.error("小程序消息标题不能为空")
  750. }
  751. if ((this.setting[i].contentType == 4 || this.setting[i].contentType == 10 ) && (this.setting[i].miniprogramPicUrl == null || this.setting[i].miniprogramPicUrl == "")) {
  752. return this.$message.error("小程序封面地址不能为空")
  753. }
  754. if (this.setting[i].contentType == 10 && (this.setting[i].miniprogramPage == null || this.setting[i].miniprogramPage == "")) {
  755. return this.$message.error("小程序page地址不能为空")
  756. }
  757. if (this.setting[i].contentType == 5 && (this.setting[i].fileUrl == null || this.setting[i].fileUrl == "")) {
  758. return this.$message.error("文件不能为空")
  759. }
  760. if (this.setting[i].contentType == 6 && (this.setting[i].videoUrl == null || this.setting[i].videoUrl == "")) {
  761. return this.$message.error("视频不能为空")
  762. }
  763. if (this.setting[i].contentType == 7 && (this.setting[i].value == null || this.setting[i].value == "")) {
  764. return this.$message.error("语音不能为空")
  765. }
  766. }
  767. }
  768. this.sendMsgOpen.open = false;
  769. const loading = this.$loading({
  770. lock: true,
  771. text: '正在执行中请稍后~~请不要刷新页面!!',
  772. spinner: 'el-icon-loading',
  773. background: 'rgba(0, 0, 0, 0.7)'
  774. });
  775. sendMsgSopType(this.msgForm).then(response => {
  776. this.msgSuccess("一键群发成功");
  777. loading.close();
  778. this.setting=[];
  779. this.resetSendMsgSop();
  780. }).finally(()=>{
  781. loading.close();
  782. });
  783. }
  784. });
  785. },
  786. cancelMsgForm(){
  787. this.sendMsgOpen.open = false;
  788. this.resetSendMsgSop();
  789. },
  790. }
  791. };
  792. </script>