sendMsgSopOpenTool.vue 42 KB

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