addSopTemp.vue 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981
  1. <template>
  2. <div class="app-container">
  3. <div style="margin: 30px;" v-if="this.form.sendType == 1 "> sop规则【企微接口】模板</div>
  4. <div style="margin: 30px;" v-if="this.form.sendType == 2 "> sop规则【AI插件】模板</div>
  5. <div style="margin-top: 10px;margin-left: 50px;margin-right: 100px;margin-bottom: 60px;">
  6. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  7. <el-form-item label="名称" prop="name">
  8. <el-input v-model="form.name" placeholder="请输入模板标题" />
  9. </el-form-item>
  10. <el-form-item label="状态">
  11. <el-radio-group v-model="form.status">
  12. <el-radio
  13. v-for="dict in statusOptions"
  14. :key="dict.dictValue"
  15. :label="dict.dictValue"
  16. >{{dict.dictLabel}}</el-radio>
  17. </el-radio-group>
  18. </el-form-item>
  19. <el-form-item label="间隔天数" prop="gap">
  20. <el-input-number v-model="form.gap" :min="1" label="间隔天数"></el-input-number>
  21. </el-form-item>
  22. <el-form-item label="排序" prop="sort">
  23. <el-input-number v-model="form.sort" :min="0" label="排序"></el-input-number>
  24. </el-form-item>
  25. <el-form-item label="规则" prop="setting">
  26. <el-timeline >
  27. <el-timeline-item :timestamp="'第'+(1+(form.gap*index))+'天'" :color="'#0bbd87'" placement="top" v-for="(item, index) in setting" style="margin-top: 10px;">
  28. <el-row>
  29. <el-col :span="22">
  30. <div style="background-color: #fbfbfb;padding: 15px; border: 1px solid #e6e6e6; margin-bottom: 20px;">
  31. <el-form :model="item" label-width="80px">
  32. <el-form-item label="内容名称" style="height: 50px;">
  33. <el-input v-model="item.name" placeholder="内容名称,仅内部可见" />
  34. </el-form-item>
  35. <el-form-item label="规则" >
  36. <div v-for="(content, contentIndex) in item.content" style="background-color: #fdfdfd;padding: 15px; border: 1px solid #e6e6e6; margin-bottom: 20px;">
  37. <el-row>
  38. <el-col el-col :span="22" >
  39. <el-form :model="content" label-width="70px">
  40. <el-form-item label="时间" prop="time" >
  41. <el-time-picker
  42. class="custom-input"
  43. v-model="content.time"
  44. value-format="HH:mm"
  45. format="HH:mm"
  46. :picker-options="{ selectableRange: '00:21:00 - 23:59:59' }"
  47. placeholder="时间"
  48. style="width: 100px;height: 20px;" >
  49. </el-time-picker>
  50. </el-form-item>
  51. <el-form-item label="消息类别" >
  52. <el-radio-group v-model="content.type" @change="() => content.contentType = '1'" >
  53. <el-radio
  54. :label="1"
  55. >普通</el-radio>
  56. <el-radio
  57. :label="2"
  58. >课程</el-radio>
  59. <el-radio
  60. :label="3"
  61. >订单</el-radio>
  62. <el-radio
  63. :label="4"
  64. >AI触达</el-radio>
  65. </el-radio-group>
  66. </el-form-item>
  67. <el-form-item label="课程" v-if="content.type == 2 ">
  68. <el-select v-model="content.courseId" placeholder="请选择课程" style=" margin-right: 10px;" size="mini" @change="courseChange(content,index,contentIndex)">
  69. <el-option
  70. v-for="dict in courseList"
  71. :key="dict.dictValue"
  72. :label="dict.dictLabel"
  73. :value="parseInt(dict.dictValue)"
  74. />
  75. </el-select>
  76. <el-select v-model="content.videoId" placeholder="请选择小节" size="mini" style=" margin-right: 10px;" @change="videoIdChange(content,index,contentIndex)" >
  77. <el-option
  78. v-for="dict in videoList[index][contentIndex]"
  79. :key="dict.dictValue"
  80. :label="dict.dictLabel"
  81. :value="parseInt(dict.dictValue)"
  82. />
  83. </el-select>
  84. <el-select v-model="content.courseType" placeholder="请选择消息类型" size="mini" style=" margin-right: 10px;" v-if="content.type != 4 ">
  85. <el-option
  86. v-for="dict in sysFsSopWatchStatus"
  87. :key="dict.dictValue"
  88. :label="dict.dictLabel"
  89. :value="parseInt(dict.dictValue)"
  90. />
  91. </el-select>
  92. </el-form-item>
  93. <el-form-item label="Ai触达" v-if="content.type == 4 ">
  94. <el-select v-model="content.aiTouch" placeholder="请选择Ai触达类型" size="mini" style=" margin-right: 10px;" v-if="content.type == 4 ">
  95. <el-option label="非首次交流" value="非首次交流"></el-option>
  96. <el-option label="首次交流1" value="首次交流1"></el-option>
  97. <el-option label="首次交流2" value="首次交流2"></el-option>
  98. <el-option label="交流状态1" value="交流状态1"></el-option>
  99. <el-option label="交流状态2" value="交流状态2"></el-option>
  100. <el-option label="交流状态3" value="交流状态3"></el-option>
  101. </el-select>
  102. </el-form-item>
  103. <!-- <el-form-item label="内容类型" >-->
  104. <div v-for="(setList, setIndex) in content.setting" :key="setIndex" style="background-color: #fdfdfd; border: 1px solid #e6e6e6; margin-bottom: 20px;" v-if="content.type != 4 ">
  105. <el-row>
  106. <el-col :span="22">
  107. <el-form :model="setList" label-width="70px">
  108. <el-form-item label="内容类别" style="margin: 2%">
  109. <div v-if="form.sendType == 1 ">
  110. <el-radio-group v-model="setList.contentType" >
  111. <el-radio
  112. v-for="item in sysQwSopContentType"
  113. :label="item.dictValue"
  114. :disabled="item.dictValue === '1' && content.setting.some(s => s.contentType == '1')">
  115. {{ item.dictLabel }}
  116. </el-radio>
  117. </el-radio-group>
  118. </div>
  119. <div v-if="form.sendType == 2 ">
  120. <!-- <div v-if="content.type == 2 ">-->
  121. <!-- <el-radio-group v-model="setList.contentType" @change="handleContentTypeChange(setList,index,setIndex)">-->
  122. <!-- <el-radio :label="item.dictValue" v-for="item in sysQwSopSettingType">{{item.dictLabel}}</el-radio>-->
  123. <!-- </el-radio-group>-->
  124. <!-- </div>-->
  125. <!-- <div v-else>-->
  126. <el-radio-group v-model="setList.contentType" @change="handleContentTypeChange(content,index,contentIndex,setIndex)">
  127. <el-radio :label="item.dictValue" v-for="item in sysQwSopAiContentType">{{item.dictLabel}}</el-radio>
  128. </el-radio-group>
  129. <!-- </div>-->
  130. </div>
  131. </el-form-item>
  132. <el-form-item label="内容" >
  133. <el-input v-if="setList.contentType == 1 " v-model="setList.value" type="textarea" :rows="3" placeholder="内容" style="width: 90%;margin-top: 10px;"/>
  134. <ImageUpload v-if="setList.contentType == 2 " v-model="setList.imgUrl" type="image" :num="1" :width="150" :height="150" />
  135. <div v-if="setList.contentType == 3 ">
  136. <el-card class="box-card">
  137. <el-form-item label="链接标题:" label-width="100px">
  138. <el-input v-model="setList.linkTitle" placeholder="请输入链接标题" style="width: 90%;"/>
  139. </el-form-item>
  140. <el-form-item label="链接描述:" label-width="100px" >
  141. <el-input type="textarea" :rows="3" v-model="setList.linkDescribe" placeholder="请输入链接描述" style="width: 90%;margin-top: 1%;"/>
  142. </el-form-item>
  143. <el-form-item label="链接封面:" label-width="100px">
  144. <ImageUpload v-model="setList.linkImageUrl" type="image" :num="1" :file-size="2" :width="150" :height="150" style="margin-top: 1%;" />
  145. </el-form-item>
  146. <div v-if="content.type!=2" style="margin-top: 1%">
  147. <el-form-item label="链接地址:" label-width="100px" >
  148. <el-input v-model="setList.linkUrl" placeholder="请输入链接地址" style="width: 90%;"/>
  149. </el-form-item>
  150. </div>
  151. <div v-if="content.type==2">
  152. <el-form-item label="链接地址:" label-width="100px" >
  153. <el-tag type="warning" v-model="setList.isBindUrl=1">选择的课程小节 即为卡片链接地址</el-tag>
  154. </el-form-item>
  155. </div>
  156. </el-card>
  157. </div>
  158. <div v-if="setList.contentType == 4">
  159. <el-card class="box-card">
  160. <el-form-item label="标题" prop="miniprogramTitle">
  161. <el-input v-model="setList.miniprogramTitle" placeholder="请输入小程序消息标题,最长为64字" />
  162. </el-form-item>
  163. <el-form-item label="封面" prop="miniprogramPicUrl">
  164. <ImageUpload v-model="setList.miniprogramPicUrl" type="image" :num="10" :width="150" :height="150" />
  165. </el-form-item>
  166. <el-form-item label="appid" prop="miniprogramAppid" v-show="false" >
  167. <el-input v-model="setList.miniprogramAppid='wx73f85f8d62769119' " disabled />
  168. </el-form-item>
  169. <el-form-item label="page路径" prop="miniprogramPage" v-show="false" label-width="100px" style="margin-left: -30px">
  170. <el-input v-model="setList.miniprogramPage" placeholder="小程序消息打开后的路径" disabled />
  171. </el-form-item>
  172. </el-card>
  173. </div>
  174. <div v-if="setList.contentType == 5 ">
  175. <el-form-item label="上传文件:" prop="fileUrl" label-width="100px">
  176. <el-upload
  177. v-model="setList.fileUrl"
  178. class="avatar-uploader"
  179. :action="uploadUrl"
  180. :show-file-list="false"
  181. :on-success="(res, file) => handleAvatarSuccessFile(res, file, setList)"
  182. :before-upload="beforeAvatarUploadFile">
  183. <i class="el-icon-plus avatar-uploader-icon"></i>
  184. </el-upload>
  185. <el-link v-if="setList.fileUrl" type="primary" :href="downloadUrl(setList.fileUrl)" download>
  186. {{setList.fileUrl}}
  187. </el-link>
  188. </el-form-item>
  189. </div>
  190. <div v-if="setList.contentType == 6 ">
  191. <el-form-item label="上传视频:" prop="videoUrl" label-width="100px">
  192. <el-upload
  193. v-model="setList.videoUrl"
  194. class="avatar-uploader"
  195. :action="uploadUrl"
  196. :show-file-list="false"
  197. :on-success="(res, file) => handleAvatarSuccessVideo(res, file, setList)"
  198. :before-upload="beforeAvatarUploadVideo">
  199. <i class="el-icon-plus avatar-uploader-icon"></i>
  200. </el-upload>
  201. <video v-if="setList.videoUrl"
  202. :src="setList.videoUrl"
  203. controls style="width: 200px;height: 100px">
  204. </video>
  205. </el-form-item>
  206. </div>
  207. <div v-if="setList.contentType == 7 ">
  208. <el-input
  209. v-model="setList.value"
  210. type="textarea" :rows="3" maxlength="66" show-word-limit
  211. placeholder="输入要转为语音的内容" style="width: 90%;margin-top: 10px;"
  212. @input="handleInputVideoText(setList.value,setList)"/>
  213. </div>
  214. <div v-if="setList.contentType == 8 ">
  215. <el-button type="primary" style="margin-bottom: 1%" @click="hanldeSelectVideoNum(content,index,contentIndex,setIndex)">选择视频号</el-button>
  216. <el-card class="box-card" v-if="setList.coverUrl">
  217. <el-form-item label="封面标题:" label-width="100px">
  218. <el-input v-model="setList.nickname" style="width: 90%;margin-bottom: 1%" disabled/>
  219. </el-form-item>
  220. <el-form-item label="头像:" label-width="100px" >
  221. <el-image
  222. v-if="setList.avatar != null"
  223. :src="setList.avatar"
  224. :preview-src-list="[setList.avatar]"
  225. :style="{ width: '50px', height: '50px' }"
  226. ></el-image>
  227. </el-form-item>
  228. <el-form-item label="封面:" label-width="100px" >
  229. <el-image
  230. v-if="setList.coverUrl != null"
  231. :src="setList.coverUrl"
  232. :preview-src-list="[setList.coverUrl]"
  233. :style="{ width: '200px', height: '200px' }"
  234. ></el-image>
  235. </el-form-item>
  236. <el-form-item label="简介:" label-width="100px" >
  237. <el-input type="textarea" :rows="3" v-model="setList.desc" style="width: 90%;margin-top: 1%;" disabled />
  238. </el-form-item>
  239. <el-form-item label="视频地址:" label-width="100px" style="margin-top: 1%" >
  240. <el-input v-model="setList.url" style="width: 90%;" disabled />
  241. </el-form-item >
  242. </el-card>
  243. </div>
  244. </el-form-item>
  245. <el-form-item label="添加短链" v-if="content.type == 2 && setList.contentType == 1 " >
  246. <el-tooltip content="请先根据课程选定课程小节之后再添加" effect="dark" :disabled="!!content.videoId">
  247. <el-switch
  248. v-model="setList.isBindUrl"
  249. :disabled="!content.videoId"
  250. active-color="#13ce66"
  251. inactive-color="#DCDFE6"
  252. active-value="1"
  253. inactive-value="2">
  254. </el-switch>
  255. </el-tooltip>
  256. <span v-if="setList.isBindUrl == '1'" style="margin-left: 10px; color: #13ce66">添加URL</span>
  257. <span v-if="setList.isBindUrl == '2'" style="margin-left: 10px; color: #b1b4ba">不加URL</span>
  258. </el-form-item>
  259. <el-form-item label="课节过期时间" v-if="content.type == 2 && setList.isBindUrl == '1' && setList.contentType != 2 && setList.contentType != 5 && setList.contentType != 6 && setList.contentType != 8 " style="margin-top: 1%">
  260. <el-row>
  261. <el-input-number v-model="setList.expiresDays" :min="0" :max="100" ></el-input-number>
  262. (天)
  263. </el-row>
  264. <el-row>
  265. <span class="tip">填写0或不填时,默认为系统配置的默认时间</span>
  266. </el-row>
  267. </el-form-item>
  268. </el-form>
  269. </el-col>
  270. <el-col :span="1" :offset="1">
  271. <i class="el-icon-delete" @click="delSetList(index,contentIndex,setIndex)" style="margin-top: 20px;" v-if="content.setting.length>1"></i>
  272. </el-col>
  273. </el-row>
  274. </div>
  275. <el-link type="primary" class="el-icon-plus" :underline="false" @click='addSetList(contentIndex,item.content)' v-if="content.type != 4 ">添加内容</el-link>
  276. <!-- </el-form-item>-->
  277. </el-form>
  278. </el-col>
  279. <el-col :span="1" :offset="1">
  280. <i class="el-icon-delete" @click="delContent(index,contentIndex)" style="margin-top: 20px;" v-if="item.content.length>1"></i>
  281. </el-col>
  282. </el-row>
  283. </div>
  284. <el-link type="primary" class="el-icon-plus" :underline="false" @click='addContent(index)'>添加规则</el-link>
  285. </el-form-item>
  286. </el-form>
  287. </div>
  288. </el-col>
  289. <el-col :span="1" :offset="1">
  290. <i class="el-icon-delete-solid" @click="delSetting(index)" v-if="setting.length>1"></i>
  291. </el-col>
  292. </el-row>
  293. </el-timeline-item>
  294. </el-timeline>
  295. <el-link type="primary" class="el-icon-plus" :underline="false" @click='addSetting()'>添加天数</el-link>
  296. </el-form-item>
  297. </el-form>
  298. <div slot="footer" class="dialog-footer" style="display: flex;justify-content: flex-end;">
  299. <el-button type="primary" @click="submitForm">确 定</el-button>
  300. <el-button @click="cancel">取 消</el-button>
  301. </div>
  302. </div>
  303. <el-dialog :title="videoNumOptions.title" :visible.sync="videoNumOptions.open" style="width: 1500px;height: 100%" append-to-body>
  304. <userVideo ref="QwUserVideo" @videoResult="qwUserVideoResult" ></userVideo>
  305. </el-dialog>
  306. </div>
  307. </template>
  308. <script>
  309. import { listSopTemp, getSopTemp, delSopTemp, addSopTemp, updateSopTemp, exportSopTemp } from "@/api/qw/sopTemp";
  310. import { courseList,videoList } from "@/api/qw/sop";
  311. import ImageUpload from "@/views/qw/sop/ImageUpload";
  312. import FriendMaterial from "@/views/qw/friendMaterial/index.vue";
  313. import userVideo from "@/views/qw/userVideo/userVideo.vue";
  314. import {updateFastgptChatKeyword} from "@/api/fastGpt/fastGptChatKeyword";
  315. export default {
  316. name: "addSopTemp",
  317. components: { ImageUpload,FriendMaterial,userVideo},
  318. data() {
  319. return {
  320. //图片放大
  321. dialogVisible: false,
  322. dialogImageUrl:null,
  323. uploadUrl:process.env.VUE_APP_BASE_API+"/common/uploadOSS2",
  324. uploadUrlByVoice:process.env.VUE_APP_BASE_API+"/common/uploadOSSByHOOKVoice",
  325. //上传语音的遮罩层
  326. voiceLoading :false,
  327. // 遮罩层
  328. loading: true,
  329. // 导出遮罩层
  330. exportLoading: false,
  331. // 选中数组
  332. ids: [],
  333. sysFsSopWatchStatus: [],
  334. //消息内容类型 企微版
  335. sysQwSopContentType:[],
  336. //插件版
  337. sysQwSopAiContentType:[],
  338. //链接版类别
  339. sysQwSopSettingType:[],
  340. // 非单个禁用
  341. single: true,
  342. // 非多个禁用
  343. multiple: true,
  344. // 显示搜索条件
  345. showSearch: true,
  346. // 总条数
  347. total: 0,
  348. // sop模板表格数据
  349. setting: [],
  350. courseList:[],
  351. videoList:[],
  352. // 弹出层标题
  353. title: "",
  354. // 是否显示弹出层
  355. open: false,
  356. // 状态字典
  357. statusOptions: [],
  358. // 查询参数
  359. form: {
  360. name: null,
  361. setting: null,
  362. status: "1",
  363. sort: 1,
  364. companyId: null,
  365. gap:1,
  366. },
  367. videoNumOptions:{
  368. title:'选择视频号',
  369. open:false,
  370. content:null,
  371. contentIndex:null,
  372. setIndex:null,
  373. },
  374. // 表单校验
  375. rules: {
  376. name: [
  377. { required: true, message: '名称不能为空', trigger: 'blur' }
  378. ],
  379. status: [
  380. { required: true, message: '状态不能为空', trigger: 'blur' }
  381. ],
  382. sort: [
  383. { required: true, message: '排序不能为空', trigger: 'blur' }
  384. ],
  385. gap: [
  386. { required: true, message: '间隔天数不能为空', trigger: 'blur' }
  387. ],
  388. },
  389. contentRules:{
  390. time:[{ required: true, message: '时间不能为空', trigger: 'blur' }],
  391. }
  392. };
  393. },
  394. created() {
  395. this.getDicts("sys_company_status").then(response => {
  396. this.statusOptions = response.data;
  397. });
  398. courseList().then(response => {
  399. this.courseList = response.list;
  400. });
  401. this.getDicts("sys_fs_sop_watch_status").then(response => {
  402. this.sysFsSopWatchStatus = response.data;
  403. });
  404. this.getDicts("sys_qwSopAi_contentType").then(response => {
  405. this.sysQwSopAiContentType = response.data;
  406. });
  407. this.getDicts("sys_qwSop_contentType").then(response => {
  408. this.sysQwSopContentType = response.data;
  409. });
  410. this.getDicts("sys_qwSop_settingType").then(response => {
  411. this.sysQwSopSettingType = response.data;
  412. });
  413. this.form.sendType = this.$route.params && this.$route.params.command;
  414. setTimeout(() => {
  415. this.getList();
  416. }, 200);
  417. },
  418. methods: {
  419. handleInputVideoText(value,content){
  420. // 允许的字符:中文、英文(大小写)、数字和指定标点符号(,。!?)
  421. const regex = /^[\u4e00-\u9fa5,。!?,!?]+$/;
  422. // 删除不符合条件的字符
  423. const filteredValue = value.split('').filter(char => regex.test(char)).join('');
  424. this.$set(content, 'value', filteredValue);
  425. },
  426. addSetList(contentIndex, content) {
  427. if (this.form.sendType == 1) {
  428. for (let i = 0; i < content.length; i++) {
  429. if (content[i].setting.length > 9) {
  430. return this.$message.error("因为企微接口限制,企微模板一条消息只能设置最多~9个内容!!")
  431. } else {
  432. // 动态生成新的设置项
  433. const newSetting = content[i].setting.some(item => item.contentType === '1')
  434. ? {contentType: '2', imgUrl: ''} // 如果存在 contentType = '1',添加 contentType = '2'
  435. : {contentType: '1', value: ''}; // 如果不存在 contentType = '1',添加 contentType = '1'
  436. // 将新设置项添加到 content[i].setting 数组中
  437. content[i].setting.push(newSetting);
  438. }
  439. }
  440. } else {
  441. const newSetting = {
  442. contentType: '1',
  443. value: '',
  444. };
  445. // 将新设置项添加到 content.setting 数组中
  446. content[contentIndex].setting.push(newSetting);
  447. }
  448. },
  449. delSetList(index, contentIndex, setIndex) {
  450. this.setting[index].content[contentIndex].setting.splice(setIndex, 1)
  451. },
  452. addContent(index) {
  453. if (this.setting[index].content.length > 0 && this.form.sendType == 1) {
  454. return this.$message.error("因为企微接口限制,企微模板一天只能设置一条消息~")
  455. } else {
  456. this.setting[index].content.push({type: 1, contentType: '1', setting: [{contentType: '1', value: "",}]})
  457. this.videoList[index].push([])
  458. }
  459. },
  460. delContent(index, contentIndex) {
  461. this.setting[index].content.splice(contentIndex, 1)
  462. this.videoList[index].splice(contentIndex, 1)
  463. },
  464. addSetting() {
  465. this.setting.push({name: null, content: [{type: 1, contentType: '1', setting: [{contentType: '1', value: "",}]}]})
  466. this.videoList.push([])
  467. },
  468. delSetting(index) {
  469. this.setting.splice(index, 1)
  470. this.videoList.splice(index, 1)
  471. },
  472. //上传文件
  473. handleAvatarSuccessFile(res, file, content) {
  474. if (res.code === 200) {
  475. // 使用 $set 确保响应式更新
  476. this.$set(content, 'fileUrl', res.url);
  477. } else {
  478. this.msgError(res.msg);
  479. }
  480. },
  481. beforeAvatarUploadFile(file) {
  482. const isLt1M = file.size / 1024 / 1024 < 10;
  483. if (!isLt1M) {
  484. this.$message.error('上传大小不能超过 10MB!');
  485. }
  486. return isLt1M;
  487. },
  488. //下载文件
  489. downloadUrl(materialUrl) {
  490. // 直接返回文件 URL
  491. return materialUrl;
  492. },
  493. //选择视频号
  494. hanldeSelectVideoNum(content,index,contentIndex,setIndex){
  495. this.videoNumOptions.content = content;
  496. this.videoNumOptions.contentIndex = contentIndex;
  497. this.videoNumOptions.setIndex = setIndex;
  498. this.videoNumOptions.open=true;
  499. },
  500. qwUserVideoResult(val){
  501. // 根据选中的内容,将返回的数据更新到相应的表单项
  502. const content = this.videoNumOptions.content;
  503. const setList = content.setting[this.videoNumOptions.setIndex];
  504. setList.nickname = val.nickname;
  505. setList.avatar = val.avatar;
  506. setList.coverUrl = val.coverUrl;
  507. setList.thumbUrl = val.thumbUrl;
  508. setList.desc = val.desc;
  509. setList.url = val.url;
  510. setList.extras = val.extras;
  511. this.videoNumOptions.open=false;
  512. },
  513. handleAvatarSuccessVideo(res, file, content) {
  514. if (res.code == 200) {
  515. // 使用 $set 确保响应式更新
  516. this.$set(content, 'videoUrl', res.url);
  517. } else {
  518. this.msgError(res.msg);
  519. }
  520. },
  521. handleAvatarSuccessVoice(res, file, content) {
  522. if (res.code == 200) {
  523. // 创建 Audio 对象加载音频
  524. const audio = new Audio(res.mp3Url);
  525. audio.addEventListener('loadedmetadata', () => {
  526. // 获取音频时长
  527. this.$set(content, 'voiceDuration', Math.ceil(audio.duration));
  528. });
  529. // 使用 $set 确保响应式更新
  530. this.$set(content, 'voiceUrl', res.silkUrl);
  531. this.$set(content, 'mp3Url', res.mp3Url);
  532. } else {
  533. this.msgError(res.msg);
  534. }
  535. this.voiceLoading = false;
  536. },
  537. beforeAvatarUploadVideo(file) {
  538. const isLt30M = file.size / 1024 / 1024 < 10;
  539. const isMP4 = file.type === 'video/mp4';
  540. if (!isMP4) {
  541. this.$message.error('仅支持上传 MP4 格式的视频文件!');
  542. return false;
  543. }
  544. if (!isLt30M) {
  545. this.$message.error('上传大小不能超过 10MB!');
  546. return false;
  547. }
  548. return true;
  549. },
  550. beforeAvatarUploadVoice(file) {
  551. return new Promise((resolve, reject) => {
  552. const isLt10M = file.size / 1024 / 1024 < 10; // 假设语音文件大小限制为10MB
  553. const isVoiceType = ['audio/mp3', 'audio/mpeg', 'audio/wav', 'audio/x-wav'].includes(file.type);
  554. if (!isVoiceType) {
  555. this.$message.error('仅支持上传 MP3, WAV, X-WAV 格式的语音文件!');
  556. return reject(false); // 不允许继续上传
  557. }
  558. if (!isLt10M) {
  559. this.$message.error('上传大小不能超过 10MB!');
  560. return reject(false); // 不允许继续上传
  561. }
  562. // 使用 FileReader 读取文件
  563. const reader = new FileReader();
  564. reader.onload = (event) => {
  565. const audio = new Audio(event.target.result);
  566. audio.addEventListener('loadedmetadata', () => {
  567. // 获取时长并保存
  568. if (Math.ceil(audio.duration) > 30) {
  569. this.$message.error('音频时长不能超过30秒!');
  570. this.voiceLoading = false;
  571. return reject(false); // 不允许继续上传
  572. }
  573. resolve(true); // 允许上传
  574. });
  575. };
  576. reader.onerror = () => {
  577. this.$message.error('无法读取音频文件!请上传正确的音频文件');
  578. reject(false); // 不允许继续上传
  579. };
  580. this.voiceLoading = true;
  581. reader.readAsDataURL(file); // 开始读取文件
  582. });
  583. },
  584. handleClosegroupUser(list) {
  585. const index = this.userSelectList.findIndex(t => t === list);
  586. if (index !== -1) {
  587. this.userSelectList.splice(index, 1);
  588. }
  589. },
  590. courseChange(content, index, countIndex) {
  591. this.$set(content, 'videoId', null);
  592. let selectedCourse;
  593. if (content.courseId != null) {
  594. // 查找选中的课程对应的 label
  595. selectedCourse = this.courseList.find(course => parseInt(course.dictValue) === content.courseId);
  596. }
  597. for (let i = 0; i < content.setting.length; i++) {
  598. //如果是链接的才上
  599. if (selectedCourse && content.type == 2 && content.courseId != null) {
  600. if (content.setting[i].contentType == 3){
  601. //响应式直接给链接的标题/封面上值
  602. this.$set(content.setting[i], 'linkTitle', selectedCourse.dictLabel);
  603. this.$set(content.setting[i], 'linkImageUrl', selectedCourse.dictImgUrl);
  604. }
  605. if (content.setting[i].contentType == 4){
  606. this.$set(content.setting[i], 'miniprogramPicUrl', selectedCourse.dictImgUrl);
  607. }
  608. }
  609. }
  610. videoList(content.courseId).then(response => {
  611. this.videoList[index].splice(countIndex, 1, response.list);
  612. });
  613. },
  614. handleContentTypeChange(content, index, countIndex, setIndex) {
  615. //如果是链接的才上
  616. if (content.courseId != null && content.type == 2) {
  617. const selectedCourse = this.courseList.find(course => parseInt(course.dictValue) === content.courseId);
  618. for (let i = 0; i < content.setting.length; i++) {
  619. //响应式直接给链接的标题/封面上值
  620. if (selectedCourse && content.type == 2 && content.courseId != null) {
  621. if (content.setting[i].contentType == 3){
  622. this.$set(content.setting[i], 'linkTitle', selectedCourse.dictLabel);
  623. this.$set(content.setting[i], 'linkImageUrl', selectedCourse.dictImgUrl);
  624. }
  625. if (this.setting[i].contentType == 4){
  626. this.$set(content.setting[i], 'miniprogramPicUrl', selectedCourse.dictImgUrl);
  627. }
  628. }
  629. }
  630. }
  631. if (content.videoId != null && content.type == 2) {
  632. // 查找选中的课节对应的 label
  633. const selectedVideo = this.videoList[index][countIndex].find(course => parseInt(course.dictValue) === content.videoId);
  634. for (let i = 0; i < content.setting.length; i++) {
  635. //响应式直接给链接的描述上值
  636. if (selectedVideo && content.type == 2 && content.videoId != null) {
  637. if (content.setting[i].contentType == 3){
  638. this.$set(content.setting[i], 'linkDescribe', selectedVideo.dictLabel);
  639. }
  640. if (this.setting[i].contentType == 4){
  641. this.$set(content.setting[i], 'miniprogramTitle', selectedVideo.dictLabel);
  642. }
  643. }
  644. }
  645. }
  646. },
  647. videoIdChange(content, index, countIndex) {
  648. //选择了课程小节则 默认绑上
  649. let selectedVideo;
  650. // 查找选中的课程对应的 label
  651. if (content.videoId != null) {
  652. selectedVideo = this.videoList[index][countIndex].find(course => parseInt(course.dictValue) === content.videoId);
  653. }
  654. for (let i = 0; i < content.setting.length; i++) {
  655. //课程消息-文本内容
  656. if (content.setting[i].contentType == 1 && content.type == 2) {
  657. this.$set(content.setting[i], 'isBindUrl', '1');
  658. }
  659. //如果是链接的才上
  660. if (selectedVideo && content.type == 2 && content.videoId != null) {
  661. //响应式直接给链接的描述上值
  662. if (content.setting[i].contentType == 3 ){
  663. this.$set(content.setting[i], 'linkDescribe', selectedVideo.dictLabel);
  664. }
  665. if (content.setting[i].contentType == 4){
  666. this.$set(content.setting[i], 'miniprogramTitle', selectedVideo.dictLabel);
  667. }
  668. }
  669. }
  670. },
  671. /** 查询sop模板列表 */
  672. getList() {
  673. this.loading = true;
  674. listSopTemp(this.queryParams).then(response => {
  675. this.sopTempList = response.rows;
  676. this.total = response.total;
  677. this.loading = false;
  678. });
  679. },
  680. // 取消按钮
  681. cancel() {
  682. this.$store.dispatch("tagsView/delView", this.$route);
  683. this.$router.replace('/qw/conversion/sopTemp')
  684. this.reset();
  685. },
  686. // 表单重置
  687. reset() {
  688. this.form = {
  689. id: null,
  690. name: null,
  691. setting: null,
  692. status: "0",
  693. sort: null,
  694. createTime: null,
  695. createBy: null,
  696. companyId: null,
  697. };
  698. this.resetForm("form");
  699. },
  700. /** 搜索按钮操作 */
  701. handleQuery() {
  702. this.queryParams.pageNum = 1;
  703. this.getList();
  704. },
  705. /** 重置按钮操作 */
  706. resetQuery() {
  707. this.resetForm("queryForm");
  708. this.handleQuery();
  709. },
  710. // 多选框选中数据
  711. handleSelectionChange(selection) {
  712. this.ids = selection.map(item => item.id)
  713. this.single = selection.length !== 1
  714. this.multiple = !selection.length
  715. },
  716. /** 新增按钮操作 */
  717. handleAdd() {
  718. this.reset();
  719. this.open = true;
  720. this.title = "添加sop模板";
  721. },
  722. /** 修改按钮操作 */
  723. handleUpdate(row) {
  724. this.reset();
  725. const id = row.id || this.ids
  726. getSopTemp(id).then(response => {
  727. this.form = response.data;
  728. this.open = true;
  729. this.title = "修改sop模板";
  730. });
  731. },
  732. /** 提交按钮 */
  733. submitForm() {
  734. this.$refs["form"].validate(valid => {
  735. if (valid) {
  736. this.form.setting = JSON.stringify(this.setting)
  737. if (this.setting.length <= 0) {
  738. return this.$message("请添加规则")
  739. }
  740. for (let i = 0; i < this.setting.length; i++) {
  741. for (let j = 0; j < this.setting[i].content.length; j++) {
  742. if (this.setting[i].name == null || this.setting[i].name == "") {
  743. return this.$message.error("内容名称不能为空")
  744. }
  745. if (this.setting[i].content[j].time == null || this.setting[i].content[j].time == "") {
  746. return this.$message.error("时间不能为空")
  747. }
  748. if (this.setting[i].content[j].type != 4) {
  749. for (let k = 0; k < this.setting[i].content[j].setting.length; k++) {
  750. if (this.setting[i].content[j].setting[k].contentType == 1 && (this.setting[i].content[j].setting[k].value == null || this.setting[i].content[j].setting[k].value == "")) {
  751. return this.$message.error("内容不能为空")
  752. }
  753. if (this.setting[i].content[j].setting[k].contentType == 2 && (this.setting[i].content[j].setting[k].imgUrl == null || this.setting[i].content[j].setting[k].imgUrl == "")) {
  754. return this.$message.error("图片不能为空")
  755. }
  756. if (this.setting[i].content[j].setting[k].contentType == 3 && (this.setting[i].content[j].setting[k].linkTitle == null || this.setting[i].content[j].setting[k].linkTitle == "")) {
  757. return this.$message.error("链接标题不能为空")
  758. }
  759. if (this.setting[i].content[j].setting[k].contentType == 3 && (this.setting[i].content[j].setting[k].linkDescribe == null || this.setting[i].content[j].setting[k].linkDescribe == "")) {
  760. return this.$message.error("链接描述不能为空")
  761. }
  762. if (this.setting[i].content[j].setting[k].contentType == 3 && (this.setting[i].content[j].setting[k].linkImageUrl == null || this.setting[i].content[j].setting[k].linkImageUrl == "")) {
  763. return this.$message.error("链接图片不能为空")
  764. }
  765. if (this.setting[i].content[j].setting[k].contentType == 3 && this.setting[i].content[j].setting[k].type == 1 && (this.setting[i].content[j].setting[k].linkUrl == null || this.setting[i].content[j].setting[k].linkUrl == "")) {
  766. return this.$message.error("链接地址不能为空")
  767. }
  768. if (this.setting[i].content[j].setting[k].contentType == 4 && (this.setting[i].content[j].setting[k].miniprogramTitle == null || this.setting[i].content[j].setting[k].miniprogramTitle == "")) {
  769. return this.$message.error("小程序消息标题不能为空")
  770. }
  771. if (this.setting[i].content[j].setting[k].contentType == 4 && (this.setting[i].content[j].setting[k].miniprogramPicUrl == null || this.setting[i].content[j].setting[k].miniprogramPicUrl == "")) {
  772. return this.$message.error("小程序封面地址不能为空")
  773. }
  774. if (this.setting[i].content[j].setting[k].contentType == 5 && (this.setting[i].content[j].setting[k].fileUrl == null || this.setting[i].content[j].setting[k].fileUrl == "")) {
  775. return this.$message.error("文件不能为空")
  776. }
  777. if (this.setting[i].content[j].setting[k].contentType == 6 && (this.setting[i].content[j].setting[k].videoUrl == null || this.setting[i].content[j].setting[k].videoUrl == "")) {
  778. return this.$message.error("视频不能为空")
  779. }
  780. if (this.setting[i].content[j].setting[k].contentType == 7 && (this.setting[i].content[j].setting[k].value == null || this.setting[i].content[j].setting[k].value == "")) {
  781. return this.$message.error("语音文本不能为空")
  782. }
  783. if (this.setting[i].content[j].setting[k].contentType == 8 && (this.setting[i].content[j].setting[k].url == null || this.setting[i].content[j].setting[k].url == "")) {
  784. return this.$message.error("视频号信息不能为空")
  785. }
  786. }
  787. } else {
  788. if (this.setting[i].content[j].aiTouch == null || this.setting[i].content[j].aiTouch == '') {
  789. return this.$message.error("AI触达不能为空")
  790. }
  791. }
  792. }
  793. }
  794. if (this.form.id != null) {
  795. updateSopTemp(this.form).then(response => {
  796. this.msgSuccess("修改成功");
  797. this.$store.dispatch("tagsView/delView", this.$route);
  798. // this.$router.replace('/qw/conversion/sopTemp')
  799. window.location.replace('/qw/conversion/sopTemp')
  800. this.reset();
  801. });
  802. } else {
  803. addSopTemp(this.form).then(response => {
  804. this.msgSuccess("新增成功");
  805. this.$store.dispatch("tagsView/delView", this.$route);
  806. // this.$router.replace('/qw/conversion/sopTemp')
  807. window.location.replace('/qw/conversion/sopTemp')
  808. this.reset();
  809. });
  810. }
  811. }
  812. });
  813. },
  814. /** 删除按钮操作 */
  815. handleDelete(row) {
  816. const ids = row.id || this.ids;
  817. this.$confirm('是否确认删除sop模板编号为"' + ids + '"的数据项?', "警告", {
  818. confirmButtonText: "确定",
  819. cancelButtonText: "取消",
  820. type: "warning"
  821. }).then(function () {
  822. return delSopTemp(ids);
  823. }).then(() => {
  824. this.getList();
  825. this.msgSuccess("删除成功");
  826. }).catch(() => {
  827. });
  828. },
  829. /** 导出按钮操作 */
  830. handleExport() {
  831. const queryParams = this.queryParams;
  832. this.$confirm('是否确认导出所有sop模板数据项?', "警告", {
  833. confirmButtonText: "确定",
  834. cancelButtonText: "取消",
  835. type: "warning"
  836. }).then(() => {
  837. this.exportLoading = true;
  838. return exportSopTemp(queryParams);
  839. }).then(response => {
  840. this.download(response.msg);
  841. this.exportLoading = false;
  842. }).catch(() => {
  843. });
  844. }
  845. }
  846. };
  847. </script>
  848. <style scoped>
  849. .custom-input /deep/ .el-input__inner {
  850. height: 20px;
  851. text-align: center;
  852. }
  853. .custom-input /deep/ .el-input__icon {
  854. line-height: 10px;
  855. }
  856. </style>