detail.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. <template>
  2. <div class='app-container'>
  3. <el-form class="form" label-width="100px" ref="form" :model="data.form" :rules="data.rules">
  4. <el-form-item class="chooseAudio" label="选择音频:" prop="audioList">
  5. <div class="audioList" v-for="(item, index) in data.form.audioList" :key="item.id">
  6. <el-tag v-show="item.type === 0 || item.type === 1" size="large" :closable="checkClose()"
  7. @close="handleClose(index)">
  8. {{ item.audioName }}
  9. </el-tag>
  10. <div v-show="item.type === 2" class="audio">
  11. <img src="@/assets/icons/svg/file.svg" width="70" height="70" />
  12. <span>{{ item.audioName }}</span>
  13. </div>
  14. </div>
  15. <el-button v-if="checkClose()" icon="Plus" @click="getDialog">新增</el-button>
  16. </el-form-item>
  17. <el-form-item label="内容名称:" prop="name">
  18. <el-input v-model="data.form.name" placeholder="请输入内容名称" />
  19. </el-form-item>
  20. <el-form-item label="播放时间:" prop="listDate">
  21. <div class="date" v-for="(item, index) in data.dateList">
  22. <el-date-picker v-model="data.dateList[index]" type="datetimerange" start-placeholder="开始时间"
  23. end-placeholder="结束时间" format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss"
  24. @change="handleChangeDate($event, index)" />
  25. <el-link v-show="data.dateList.length > 1" icon="CircleClose" :underline="false"
  26. @click="handleDeleteDate(index)" />
  27. <el-link v-show="data.dateList.length - 1 === index" icon="CirclePlus" :underline="false"
  28. @click="handlePushDate" />
  29. </div>
  30. </el-form-item>
  31. <el-form-item label="关联设备:" style="width: 900px" prop="tpresetContentInfoReq">
  32. <el-table :data="data.form.tpresetContentInfoReq">
  33. <el-table-column label="所属企业" align="center">
  34. <template #default="scope">
  35. <el-form-item :prop="`tpresetContentInfoReq.${scope.$index}.tenantId`"
  36. :rules="{ required: true, trigger: 'change' }">
  37. <el-select v-model="scope.row.tenantId" placeholder="请搜索并选择企业" style="width: 200px" filterable remote
  38. :remote-method="businessRemote" remote-show-suffix @change="handleChangeTenant($event, scope.$index)">
  39. <el-option v-for="item in businessData.options" :key="item.id" :value="item.id.toString()"
  40. :label="item.name" />
  41. </el-select>
  42. </el-form-item>
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="所属门店" align="center">
  46. <template #default="scope">
  47. <el-form-item :prop="`tpresetContentInfoReq.${scope.$index}.storeId`"
  48. :rules="{ required: true, trigger: 'change' }">
  49. <el-select v-model="scope.row.storeId" placeholder="请搜索并选择门店" style="width: 200px" filterable remote
  50. :remote-method="storeRemote" remote-show-suffix>
  51. <el-option v-for="item in data.business_store[scope.$index]" :key="item.id"
  52. :value="item.id.toString()" :label="item.name" />
  53. </el-select>
  54. </el-form-item>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="所属设备" align="center">
  58. <template #default="scope">
  59. <el-form-item :prop="`tpresetContentInfoReq.${scope.$index}.deviceType`"
  60. :rules="{ required: true, trigger: 'change' }">
  61. <el-select v-model="scope.row.deviceType" filterable placeholder="请选择所属设备">
  62. <el-option v-for="item in deviceOptions" :key="item.clientTypeId" :value="item.clientTypeId"
  63. :label="item.name" />
  64. </el-select>
  65. </el-form-item>
  66. </template>
  67. </el-table-column>
  68. <el-table-column label="操作" align="center">
  69. <template #default="scope">
  70. <el-button type="danger" link @click="getDelete(scope.$index)">删除</el-button>
  71. </template>
  72. </el-table-column>
  73. </el-table>
  74. </el-form-item>
  75. <el-form-item style="width: 800px">
  76. <el-button icon="Plus" @click="getAdd">新增关联</el-button>
  77. </el-form-item>
  78. </el-form>
  79. <div class="form-btn">
  80. <el-button @click="getClose">取消</el-button>
  81. <el-button type="primary" @click="getSubmit">确定</el-button>
  82. </div>
  83. <el-dialog v-model="dialogVisible" title="导入内容" width="1000px">
  84. <el-form inline>
  85. <el-form-item label="内容分类:">
  86. <el-select v-model="audioData.form.type" placeholder="请选择内容分类">
  87. <el-option v-for="item in data.radioOptions" :key="item.value" :value="item.value" :label="item.label" />
  88. </el-select>
  89. </el-form-item>
  90. <el-form-item label="名称:">
  91. <el-input v-model="audioData.form.name" placeholder="请输入名称" />
  92. </el-form-item>
  93. <el-form-item label="分类:">
  94. <el-select v-model="audioData.form.sceneId" placeholder="请选择分类">
  95. <el-option v-for="item in audioClassData.options" :key="item.id" :value="item.id" :label="item.name" />
  96. </el-select>
  97. </el-form-item>
  98. <el-form-item label="当前状态:">
  99. <el-select v-model="audioData.form.status" placeholder="请选择当前状态">
  100. <el-option v-for="item in sys_change_status" :key="item.value" :value="item.value" :label="item.label" />
  101. </el-select>
  102. </el-form-item>
  103. <el-form-item>
  104. <el-button type="primary" icon="Search" @click="getSearch">搜索</el-button>
  105. <el-button icon="Refresh" @click="getRefresh">重置</el-button>
  106. </el-form-item>
  107. </el-form>
  108. <el-table v-if="audioData.form.type !== 2" ref="table" :data="audioData.tableData" :row-key="rowKey"
  109. @selection-change="handleSelectionChange" v-loading="audioData.loading">
  110. <el-table-column type="selection" width="55" />
  111. <el-table-column label="ID" prop="id" align="center" show-overflow-tooltip />
  112. <el-table-column label="名称" prop="name" align="center" show-overflow-tooltip />
  113. <el-table-column label="时长" prop="playTime" align="center">
  114. <template #default="scope">
  115. {{ playTime(scope.row.playTime) }}
  116. </template>
  117. </el-table-column>
  118. <el-table-column label="分类" prop="sceneId" align="center" :formatter="sceneFormatter" />
  119. <el-table-column label="当前状态" prop="status" align="center" :formatter="statusFormatter" />
  120. <el-table-column label="更新时间" prop="updateTime" align="center" show-overflow-tooltip />
  121. </el-table>
  122. <div class="audio_table" v-else>
  123. <div class="audio" v-for="item in audioData.tableData" :key="item.id" @click="handleChooseAudio(item)">
  124. <img src="@/assets/icons/svg/file.svg" width="70" height="70" />
  125. <span>{{ item.name }}</span>
  126. </div>
  127. </div>
  128. <pagination v-show="audioData.total > 0" :total="audioData.total" v-model:page="audioData.form.pageNum"
  129. v-model:limit="audioData.form.pageSize" @pagination="getAudio" />
  130. <template #footer>
  131. <el-button type="primary" @click="getPush">确定</el-button>
  132. </template>
  133. </el-dialog>
  134. </div>
  135. </template>
  136. <script setup>
  137. import { submit, detail } from '@/api/content/setting'
  138. import { useAudioList, useAudioClass, useBusinessSelect, useStoreSelect, useDeviceList } from '@/hooks/index'
  139. const { proxy } = getCurrentInstance();
  140. const { audioData, getAudio } = useAudioList()
  141. const { audioClassData, getAudioClass } = useAudioClass()
  142. getAudioClass()
  143. const { deviceOptions } = useDeviceList()
  144. const { storeData, getStore, storeRemote } = useStoreSelect(true)
  145. const { businessData, getBusiness, businessRemote } = useBusinessSelect(true)
  146. getBusiness()
  147. const { sys_change_status } = proxy.useDict("sys_change_status")
  148. const data = reactive({
  149. // 表单
  150. form: {
  151. audioList: [],
  152. listDate: [],
  153. tpresetContentInfoReq: [{}]
  154. },
  155. // 时间段
  156. dateList: [[]],
  157. // 分页
  158. radioOptions: [{
  159. value: 0,
  160. label: '内容列表'
  161. }, {
  162. value: 1,
  163. label: 'Ohplay音频'
  164. }, {
  165. value: 2,
  166. label: '场景预设'
  167. }],
  168. // 多选
  169. selectionList: [],
  170. // 校验
  171. rules: {
  172. audioList: [{
  173. required: true, message: '请选择音频', trigger: 'change'
  174. }],
  175. name: [{
  176. required: true, message: '请输入内容名称', trigger: 'blur'
  177. }],
  178. listDate: [{
  179. required: true, message: '请选择播放时间', trigger: 'change'
  180. }],
  181. tpresetContentInfoReq: [{
  182. required: true, message: '请新增关联', trigger: 'change'
  183. }]
  184. },
  185. business_store: []
  186. })
  187. const getPushTime = (e) => {
  188. if (e.startTime) {
  189. let y = new Date().getFullYear()
  190. let m = new Date().getMonth() + 1
  191. let d = new Date().getDate()
  192. let startTime = proxy.parseTime(new Date(`${y}-${m}-${d} ${e.startTime}`).getTime(), '{y}-{m}-{d} {h}:{i}:{s}')
  193. let endTime = proxy.parseTime(new Date(`${y}-${m}-${d} ${e.endTime}`).getTime(), '{y}-{m}-{d} {h}:{i}:{s}')
  194. data.dateList[0] = [startTime, endTime]
  195. data.form.listDate.push({
  196. startTime: startTime,
  197. endTime: endTime
  198. })
  199. }
  200. }
  201. // 传参
  202. const getAudioList = () => {
  203. if (proxy.$route.query.audioList) {
  204. var e = JSON.parse(proxy.$route.query.audioList)
  205. data.form.audioList.push({
  206. audioId: e.id,
  207. audioName: e.name,
  208. audioType: e.audioType,
  209. categoryId: e.sceneId,
  210. type: e.type,
  211. })
  212. getPushTime(e)
  213. }
  214. }
  215. getAudioList()
  216. // 详情
  217. const getDetail = () => {
  218. let e = proxy.$route.query
  219. if (e.id) {
  220. detail({ id: e.id, storeId: e.storeId }).then(res => {
  221. if (res.code === 0) {
  222. data.form = res.data
  223. data.dateList = []
  224. res.data.listDate.map(i => {
  225. data.dateList.push([i.startTime, i.endTime])
  226. })
  227. }
  228. })
  229. }
  230. }
  231. getDetail()
  232. // 检测是否是编辑
  233. const checkClose = () => {
  234. return proxy.$route.query.disabled == undefined ? true : false
  235. }
  236. // 弹窗
  237. const dialogVisible = ref(false)
  238. // 打开弹窗
  239. function getDialog() {
  240. dialogVisible.value = true
  241. getAudio()
  242. // 监听
  243. watch(() => audioData.tableData, (val) => {
  244. if (audioData.form.type !== 2) {
  245. nextTick(() => {
  246. proxy.$refs.table.clearSelection()
  247. if (val && data.form.audioList.length > 0) {
  248. data.form.audioList.map(i => {
  249. let row = val.find(j => j.id === i.audioId)
  250. if (row) {
  251. proxy.$refs.table.toggleRowSelection(row, true)
  252. }
  253. })
  254. }
  255. })
  256. }
  257. })
  258. }
  259. // 搜索
  260. const getSearch = () => {
  261. audioData.form.pageNum = 1
  262. getAudio()
  263. }
  264. // 重置
  265. const getRefresh = () => {
  266. audioData.form = {
  267. pageNum: 1,
  268. pageSize: 10,
  269. type: 0
  270. }
  271. getAudio()
  272. }
  273. // 返回id
  274. const rowKey = (e) => {
  275. return e.id
  276. }
  277. // 多选
  278. const handleSelectionChange = (e) => {
  279. data.selectionList = []
  280. e.map(i => {
  281. if (data.selectionList.findIndex(j => j.id === i.id) === -1) {
  282. data.selectionList.push({
  283. audioId: i.id,
  284. audioName: i.name,
  285. audioType: i.audioType,
  286. categoryId: i.sceneId,
  287. type: i.type
  288. })
  289. }
  290. })
  291. }
  292. // 单选
  293. const handleChooseAudio = (e) => {
  294. data.form.audioList = []
  295. data.form.audioList.push({
  296. audioId: e.id,
  297. audioName: e.name,
  298. audioType: e.audioType,
  299. categoryId: e.sceneId,
  300. type: e.type
  301. })
  302. getPushTime(e)
  303. proxy.$modal.msgSuccess('选择成功!')
  304. dialogVisible.value = false
  305. }
  306. // 确定
  307. const getPush = () => {
  308. data.form.audioList = []
  309. data.form.audioList = JSON.parse(JSON.stringify(data.selectionList))
  310. proxy.$modal.msgSuccess('选择成功!')
  311. dialogVisible.value = false
  312. }
  313. // 删除音频
  314. const handleClose = (index) => {
  315. data.form.audioList.splice(index, 1)
  316. }
  317. // 删除所属门店
  318. const getDelete = (index) => {
  319. data.form.tpresetContentInfoReq.splice(index, 1)
  320. }
  321. // 增加时间
  322. function handlePushDate() {
  323. let boolean = false
  324. data.dateList.map(i => boolean = i.length === 0 ? true : false)
  325. if (boolean) {
  326. proxy.$modal.msgError('有时间段未填')
  327. } else {
  328. data.dateList.push([])
  329. }
  330. }
  331. // 删除时间
  332. function handleDeleteDate(index) {
  333. data.dateList.splice(index, 1)
  334. }
  335. // 校验时间
  336. const handleChangeDate = (e, index) => {
  337. if (e !== null) {
  338. data.listDate = []
  339. data.form.listDate = []
  340. const start = new Date(e[0]).getTime()
  341. const end = new Date(e[1]).getTime()
  342. for (let i = 0; i < data.dateList.length; i++) {
  343. if (i !== index) {
  344. let st = new Date(data.dateList[i][0]).getTime()
  345. let en = new Date(data.dateList[i][1]).getTime()
  346. if (start >= st && start <= en || end >= st && end <= en || start <= st && end >= en || end <= st && start >= en) {
  347. data.dateList.splice(index, 1)
  348. proxy.$modal.msgError("该时间段已设置!")
  349. return false
  350. }
  351. }
  352. data.form.listDate.push({
  353. startTime: data.dateList[i][0],
  354. endTime: data.dateList[i][1]
  355. })
  356. }
  357. }
  358. }
  359. // 新增关联
  360. const getAdd = () => {
  361. data.form.tpresetContentInfoReq.push({})
  362. }
  363. // 所属企业
  364. const index = ref(0)
  365. const handleChangeTenant = (e, i) => {
  366. storeData.form.tenantId = e
  367. index.value = i
  368. getStore()
  369. }
  370. watch(() => data.form.tpresetContentInfoReq, (val) => {
  371. if (val.length > 0) {
  372. val.map(i => {
  373. if (data.form.id && businessData.options.find(j => j.id == i.tenantId == undefined)) {
  374. businessData.options.push({
  375. id: i.tenantId,
  376. name: i.tenantName
  377. })
  378. }
  379. storeData.form.tenantId = i.tenantId
  380. getStore()
  381. })
  382. }
  383. })
  384. watch(() => storeData.options, (val) => {
  385. data.business_store[index.value] = val
  386. data.form.tpresetContentInfoReq.map(i => {
  387. if (data.form.id && val.find(j => j.id == i.storeId) == undefined) {
  388. storeData.options.push({
  389. id: i.storeId,
  390. name: i.storeName
  391. })
  392. }
  393. })
  394. })
  395. // 取消
  396. const getClose = () => {
  397. proxy.$tab.closeOpenPage('/content/setting')
  398. }
  399. // 提交
  400. const getSubmit = () => {
  401. proxy.$refs.form.validate(valid => {
  402. if (valid) {
  403. submit(data.form).then(res => {
  404. if (res.code === 0) {
  405. proxy.$modal.msgSuccess('提交成功!')
  406. getClose()
  407. }
  408. })
  409. } else {
  410. return false
  411. }
  412. })
  413. }
  414. // 字典
  415. const statusFormatter = (row) => {
  416. return proxy.selectDictLabel(sys_change_status.value, row.status)
  417. }
  418. const sceneFormatter = (row) => {
  419. let e = audioClassData.options.find(i => i.id === row.sceneId)
  420. if (row.sceneId && e) {
  421. return audioClassData.options.find(i => i.id === row.sceneId).name
  422. }
  423. }
  424. // 监听
  425. watch(() => audioData.form.type, (val) => {
  426. data.selectionList = []
  427. getAudio()
  428. })
  429. </script>
  430. <style lang="scss" scoped>
  431. .form {
  432. .el-form-item {
  433. width: 500px;
  434. }
  435. .el-table__row {
  436. .el-form-item {
  437. width: 100%;
  438. }
  439. }
  440. }
  441. .chooseAudio {
  442. :deep(.el-form-item__content) {
  443. display: flex;
  444. flex-direction: column;
  445. align-items: flex-start;
  446. .audioList {
  447. display: flex;
  448. flex-direction: column;
  449. align-items: flex-start;
  450. .el-tag {
  451. margin-bottom: 15px;
  452. }
  453. }
  454. }
  455. }
  456. .audio_table {
  457. display: flex;
  458. flex-wrap: wrap;
  459. .audio {
  460. margin: 10px;
  461. }
  462. }
  463. .audio {
  464. width: 200px;
  465. height: 200px;
  466. border: 1px solid #e9e9eb;
  467. border-radius: 8px;
  468. margin-bottom: 15px;
  469. display: flex;
  470. flex-direction: column;
  471. justify-content: center;
  472. align-items: center;
  473. box-shadow: 0 0 6px 0 #e9e9eb;
  474. span {
  475. width: 160px;
  476. height: 40px;
  477. line-height: 40px;
  478. overflow: hidden;
  479. white-space: nowrap;
  480. text-overflow: ellipsis;
  481. text-align: center;
  482. }
  483. }
  484. .date {
  485. display: flex;
  486. align-items: center;
  487. margin-bottom: 15px;
  488. .el-link {
  489. margin-left: 10px;
  490. font-size: 16px;
  491. }
  492. }
  493. </style>