updateSopTemp2.vue 42 KB

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