sendMsgSopOpenTool.vue 41 KB

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