addSopTemp.vue 45 KB

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