sendMsgSopOpenTool.vue 42 KB

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