detail.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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="list" label="预设音频:" prop="takeId">
  5. <div v-if="data.form.takeId" class="file" @click="getDialog">
  6. <img src="@/assets/icons/svg/file.svg" width="70" height="70" />
  7. <span>{{ data.form.takeName }}</span>
  8. </div>
  9. <el-button v-else icon="Plus" @click="getDialog">新增</el-button>
  10. </el-form-item>
  11. <el-form-item label="播放时间:" prop="listDate">
  12. <div class="date" v-for="(item, index) in data.dateList">
  13. <el-time-picker ref="picker" v-model="data.dateList[index]" is-range format="HH:mm:ss" value-format="HH:mm:ss"
  14. start-placeholder="开始时间" end-placeholder="结束时间" @change="handleChangeDate($event, index)" />
  15. <el-link v-show="data.dateList.length > 1" icon="CircleClose" :underline="false" @click="handleDeleteDate(index)" />
  16. <el-link v-show="data.dateList.length - 1 === index" icon="CirclePlus" :underline="false"
  17. @click="handlePushDate" />
  18. </div>
  19. </el-form-item>
  20. <el-form-item label="关联设备:" style="width: 900px">
  21. <el-table :data="data.form.tpresetContentInfoReq">
  22. <el-table-column label="所属企业" align="center">
  23. <template #default="scope">
  24. <el-form-item :prop="`tpresetContentInfoReq.${scope.$index}.tenantId`"
  25. :rules="{ required: true, trigger: 'change' }">
  26. <el-select v-model="scope.row.tenantId" placeholder="请选择企业" style="width: 200px" filterable remote
  27. :remote-method="businessRemote" remote-show-suffix @change="handleChange">
  28. <el-option v-for="item in businessData.options" :key="item.id" :value="item.id" :label="item.name" />
  29. </el-select>
  30. </el-form-item>
  31. </template>
  32. </el-table-column>
  33. <el-table-column label="所属门店" align="center">
  34. <template #default="scope">
  35. <el-form-item :prop="`tpresetContentInfoReq.${scope.$index}.storeId`"
  36. :rules="{ required: true, trigger: 'change' }">
  37. <el-select v-model="scope.row.storeId" placeholder="请选择门店" style="width: 200px" filterable remote
  38. :remote-method="storeRemote" remote-show-suffix>
  39. <el-option v-for="item in storeData.options" :key="item.id" :value="item.id" :label="item.name" />
  40. </el-select>
  41. </el-form-item>
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="所属设备" align="center">
  45. <template #default="scope">
  46. <el-form-item :prop="`tpresetContentInfoReq.${scope.$index}.deviceType`"
  47. :rules="{ required: true, trigger: 'change' }">
  48. <el-select v-model="scope.row.deviceType" placeholder="请选择所属设备">
  49. <el-option v-for="item in deviceOptions" :key="item.clientTypeId" :value="item.clientTypeId"
  50. :label="item.name" />
  51. </el-select>
  52. </el-form-item>
  53. </template>
  54. </el-table-column>
  55. <el-table-column label="操作" align="center">
  56. <template #default="scope">
  57. <el-button type="danger" link>删除</el-button>
  58. </template>
  59. </el-table-column>
  60. </el-table>
  61. </el-form-item>
  62. <el-form-item style="width: 800px">
  63. <el-button icon="Plus" @click="getAdd">新增关联</el-button>
  64. </el-form-item>
  65. </el-form>
  66. <div class="form-btn">
  67. <el-button @click="getClose">取消</el-button>
  68. <el-button type="primary" @click="getSubmit">确定</el-button>
  69. </div>
  70. <el-dialog v-model="dialogVisible" title="导入内容" width="970">
  71. <el-form inline>
  72. <el-form-item v-for="item in data.tableData" :key="item.takeId">
  73. <div class="file hover" @click="handleChecked(item)">
  74. <img src="@/assets/icons/svg/file.svg" width="70" height="70" />
  75. <span>{{ item.takeName }}</span>
  76. </div>
  77. </el-form-item>
  78. </el-form>
  79. </el-dialog>
  80. </div>
  81. </template>
  82. <script setup>
  83. import { list, timeSubmit } from '@/api/content/scene.js'
  84. import { useBusinessSelect, useStoreSelect, useDeviceList } from '@/hooks/index.js'
  85. // 公共方法
  86. const { deviceOptions } = useDeviceList()
  87. const { storeData, getStore, storeRemote } = useStoreSelect(true)
  88. const { businessData, getBusiness, businessRemote } = useBusinessSelect(true)
  89. getBusiness()
  90. const { proxy } = getCurrentInstance();
  91. // 遮罩层
  92. const loading = ref(false)
  93. const data = reactive({
  94. form: {
  95. listDate: [],
  96. tpresetContentInfoReq: [{}]
  97. },
  98. rules: {
  99. takeId: [{ required: true, message: '请选择预设音频', trigger: 'change' }],
  100. listDate: [{ type: 'array', required: true, message: '请选择播放时间', trigger: 'change' }]
  101. },
  102. dialogForm: {
  103. pageNum: 1,
  104. pageSize: 10
  105. },
  106. // 播放时间数组
  107. dateList: [[]],
  108. tableData: []
  109. })
  110. const total = ref(0)
  111. // 列表
  112. function getList() {
  113. loading.value = true
  114. list(data.dialogForm).then(res => {
  115. if (res.code === 0) {
  116. data.tableData = res.data.records
  117. total.value = res.data.total
  118. loading.value = false
  119. }
  120. })
  121. }
  122. // 弹窗
  123. const dialogVisible = ref(false)
  124. // 打开弹窗
  125. function getDialog() {
  126. dialogVisible.value = true
  127. getList()
  128. }
  129. // 选择预设音频
  130. function handleChecked(item) {
  131. data.form.takeId = item.takeId
  132. data.form.takeName = item.takeName
  133. dialogVisible.value = false
  134. proxy.$modal.msgSuccess('选择成功!')
  135. }
  136. // 增加时间
  137. function handlePushDate() {
  138. let boolean = false
  139. data.dateList.map(i => boolean = i.length === 0 ? true : false)
  140. if (boolean) {
  141. proxy.$modal.msgError('有时间段未填')
  142. } else {
  143. data.dateList.push([])
  144. }
  145. }
  146. // 删除时间
  147. function handleDeleteDate(index) {
  148. data.dateList.splice(index, 1)
  149. }
  150. // 校验时间
  151. const handleChangeDate = (e, index) => {
  152. if (e !== null) {
  153. data.listDate = []
  154. data.form.listDate = []
  155. const start = proxy.hoursToSeconds(e[0])
  156. const end = proxy.hoursToSeconds(e[1])
  157. for (let i = 0; i < data.dateList.length; i++) {
  158. if (i !== index) {
  159. let st = proxy.hoursToSeconds(data.dateList[i][0])
  160. let en = proxy.hoursToSeconds(data.dateList[i][1])
  161. if (start >= st && start <= en || end >= st && end <= en || start <= st && end >= en) {
  162. data.dateList.splice(index, 1)
  163. proxy.$modal.msgError("该时间段已设置!")
  164. return false
  165. }
  166. }
  167. }
  168. data.dateList.map(i => {
  169. data.form.listDate.push({
  170. startTime: i[0],
  171. endTime: i[1]
  172. })
  173. })
  174. }
  175. }
  176. // 添加门店
  177. const getAdd = () => {
  178. data.form.tpresetContentInfoReq.push({})
  179. }
  180. const handleChange = (e) => {
  181. storeData.form.tenantId = e
  182. getStore()
  183. }
  184. // 提交
  185. const getSubmit = () => {
  186. proxy.$refs.form.validate(valid => {
  187. if (valid) {
  188. timeSubmit(data.form).then(res => {
  189. if (res.code === 0) {
  190. proxy.$modal.msgSuccess('提交成功!')
  191. getClose()
  192. }
  193. })
  194. } else {
  195. return false
  196. }
  197. })
  198. }
  199. // 取消
  200. const getClose = () => {
  201. proxy.$tab.closeOpenPage('/content/scene')
  202. }
  203. </script>
  204. <style lang="scss" scoped>
  205. .form {
  206. .el-form-item {
  207. width: 500px;
  208. }
  209. .el-table__row {
  210. .el-form-item {
  211. width: 100%;
  212. }
  213. }
  214. }
  215. .list {
  216. :deep(.el-form-item__content) {
  217. display: flex;
  218. flex-direction: column;
  219. align-items: flex-start;
  220. }
  221. }
  222. .file {
  223. width: 200px;
  224. height: 200px;
  225. border: 1px solid #e9e9eb;
  226. border-radius: 8px;
  227. margin-bottom: 15px;
  228. display: flex;
  229. flex-direction: column;
  230. justify-content: center;
  231. align-items: center;
  232. box-shadow: 0 0 6px 0 #e9e9eb;
  233. line-height: 10px;
  234. cursor: pointer;
  235. span {
  236. margin-top: 20px;
  237. }
  238. }
  239. .hover:hover {
  240. box-shadow: 0 0 10px 2px #a0cfff;
  241. transition: all 0.5s;
  242. }
  243. .date {
  244. display: flex;
  245. align-items: center;
  246. margin-bottom: 15px;
  247. .el-link {
  248. margin-left: 10px;
  249. font-size: 16px;
  250. }
  251. }
  252. .date:last-child {
  253. margin: 0;
  254. }
  255. </style>