index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <template>
  2. <el-form class="search" inline>
  3. <el-form-item>
  4. <el-select v-model="organizationIds" placeholder="请选择企业" style="width: 200px" filterable remote
  5. :remote-method="businessRemote" remote-show-suffix>
  6. <el-option v-for="item in businessData.options" :key="item.id" :value="item.id" :label="item.name" />
  7. </el-select>
  8. </el-form-item>
  9. <el-form-item>
  10. <el-select v-model="storeId" placeholder="请选择门店" style="width: 200px" filterable remote
  11. :remote-method="storeRemote" remote-show-suffix>
  12. <el-option v-for="item in storeData.options" :key="item.id" :value="item.id" :label="item.name" />
  13. </el-select>
  14. </el-form-item>
  15. <el-form-item style="float:right; margin: 0">
  16. <el-button type="primary" plain icon="Plus" @click="getDetail()"
  17. v-hasPermi="['content:setting:add', 'scene:presets:add', 'insert:insertContent:add']">新增</el-button>
  18. </el-form-item>
  19. </el-form>
  20. <div class="chart">
  21. <div class="time" v-for="item in data.timeList" :key="item">
  22. <div class="label">{{ item }}:00</div>
  23. <div class="line" />
  24. </div>
  25. <div class="grid">
  26. <draggable class="label_box" v-model="data.list" group="componentGroup" item-key="item"
  27. chosen-class="chosenClass">
  28. <template #item="{ element, index }">
  29. <div :style="{
  30. display: getDisplay(element), top: getTop(element), left: getLeft(element),
  31. height: getHeight(element), width: getWidth(element)
  32. }" :class="[element.status === 0 ? 'grid-item' : 'grid-item-disabled']">
  33. <el-popover placement="right" width="300px" popper-class="popper" :popper-style="popperStyle"
  34. :hide-after="0" trigger="click">
  35. <div class="title">
  36. <h2>{{ element.name }}</h2>
  37. <div style="display:flex; justify-content: space-between;">
  38. {{ element.startTime }} - {{ element.endTime }}
  39. <div style="display:flex; align-items: center">
  40. <el-icon style="margin-right: 10px" @click="getDetail({ ...element, disabled: true })"
  41. v-hasPermi="['content:setting:edit', 'scene:presets:edit', 'insert:insertContent:edit']">
  42. <Edit />
  43. </el-icon>
  44. <el-icon @click="getDelete(element)"
  45. v-hasPermi="['content:setting:delete', 'scene:presets:delete', 'insert:insertContent:delete']">
  46. <Delete />
  47. </el-icon>
  48. </div>
  49. </div>
  50. </div>
  51. <div class="main">
  52. <span>当前门店:{{ storeName(element.storeId) }}</span>
  53. <span>当前设备:{{ deviceName(element.deviceIds) }}</span>
  54. <span>当前状态:{{ proxy.selectDictLabel(sys_change_status, element.status) }}</span>
  55. </div>
  56. <template #reference>
  57. <div style="height: 100%">
  58. <div class="info">{{ element.startTime }} - {{ element.endTime }}</div>
  59. <div class="info">{{ element.name }}</div>
  60. </div>
  61. </template>
  62. </el-popover>
  63. </div>
  64. </template>
  65. </draggable>
  66. </div>
  67. </div>
  68. </template>
  69. <script setup>
  70. import { settimgTime, removeSetting } from '@/api/content/setting'
  71. import { sceneTime, removeScene } from '@/api/scene/presets'
  72. import { insetTime } from '@/api/insert/insertContent'
  73. import { useBusinessSelect, useStoreSelect, useDeviceList } from '@/hooks/index'
  74. import { checkPermi } from '@/utils/permission'
  75. const { storeData, getStore, storeRemote } = useStoreSelect()
  76. const { businessData, getBusiness, businessRemote } = useBusinessSelect(true)
  77. getBusiness()
  78. const { deviceOptions } = useDeviceList()
  79. const { proxy } = getCurrentInstance();
  80. const { sys_change_status } = proxy.useDict("sys_change_status");
  81. const props = defineProps({
  82. path: String,
  83. type: String,
  84. date: Date
  85. })
  86. const data = reactive({
  87. timeList: ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23'],
  88. list: [],
  89. number: {}
  90. })
  91. // 时间轴表单
  92. const organizationIds = ref(null)
  93. const storeId = ref(null)
  94. const nowDate = ref(new Date(props.date))
  95. const popperStyle = ref({
  96. padding: 0,
  97. borderRadius: '10px'
  98. })
  99. // 时间轴
  100. function getTimeList() {
  101. if (props.type === 'scene') {
  102. sceneTime({ storeId: storeId.value }).then(res => {
  103. modal(res)
  104. })
  105. } else if (props.type === 'setting') {
  106. settimgTime({ nowDate: proxy.parseTime(nowDate.value.getTime(), "{y}-{m}-{d}"), storeId: storeId.value }).then(res => {
  107. modal(res)
  108. })
  109. } else {
  110. insetTime({ nowDate: proxy.parseTime(nowDate.value.getTime(), "{y}-{m}-{d}"), storeId: storeId.value }).then(res => {
  111. modal(res)
  112. })
  113. }
  114. }
  115. const modal = (res) => {
  116. data.list = []
  117. data.number = []
  118. if (res.code === 0 && res.data) {
  119. res.data.forEach(i => {
  120. i.listDate.forEach(j => {
  121. data.list.push({
  122. startTime: props.type === 'scene' ? j.startTime : j.startTime.split(' ')[1],
  123. endTime: props.type === 'scene' ? j.endTime : j.endTime.split(' ')[1],
  124. timeId: j.timeId,
  125. id: i.id,
  126. deviceIds: i.deviceIds,
  127. name: i.name ? i.name : i.takeName,
  128. status: i.status,
  129. storeId: i.storeId,
  130. sort: 0,
  131. index: 0,
  132. request: true
  133. })
  134. })
  135. })
  136. data.list.sort((a, b) => proxy.hoursToSeconds(a.startTime) - proxy.hoursToSeconds(b.startTime))
  137. for (let i = 0; i < data.list.length; i++) {
  138. if (data.list[i + 1] !== undefined) {
  139. let st = proxy.hoursToSeconds(data.list[i + 1].startTime)
  140. let start = proxy.hoursToSeconds(data.list[i].startTime)
  141. let end = proxy.hoursToSeconds(data.list[i].endTime)
  142. if (st >= start && st < end) {
  143. data.list[i + 1].sort = data.list[i].sort
  144. data.list[i + 1].index = data.list[i].index + 1
  145. } else {
  146. data.list[i + 1].sort = data.list[i].sort + 1
  147. data.list[i + 1].index = 0
  148. }
  149. }
  150. }
  151. for (let i = 0; i < data.list.length; i++) {
  152. const index = data.list[i].sort
  153. if (data.number[index]) {
  154. data.number[index].push(data.list[i])
  155. } else {
  156. data.number[index] = [data.list[i]]
  157. }
  158. }
  159. }
  160. }
  161. watch(() => props.date, (val) => {
  162. nowDate.value = val
  163. getTimeList()
  164. })
  165. // 删除
  166. const getDelete = (row) => {
  167. let name = row.name ? row.name : row.takeName
  168. proxy.$modal.confirm(`是否删除预设名称为:${name}的数据?`).then(() => {
  169. if (props.type === 'setting') {
  170. removeSetting({ id: row.id }).then(res => {
  171. if (res.code === 0) {
  172. proxy.$modal.msgSuccess('删除成功!')
  173. getTimeList()
  174. }
  175. })
  176. } else if (props.type === 'scene') {
  177. removeScene({ id: row.id }).then(res => {
  178. if (res.code === 0) {
  179. proxy.$modal.msgSuccess('删除成功!')
  180. getTimeList()
  181. }
  182. })
  183. } else {
  184. removeInsert({ id: row.id }).then(res => {
  185. if (res.code === 0) {
  186. proxy.$modal.msgSuccess('删除成功!')
  187. getTimeList()
  188. }
  189. })
  190. }
  191. }).catch(() => { })
  192. }
  193. watch(() => businessData.options, (val) => {
  194. if (val.length > 0) {
  195. organizationIds.value = val[0].id
  196. }
  197. })
  198. watch(organizationIds, (val) => {
  199. if (val) {
  200. storeData.form.tenantId = val
  201. getStore()
  202. }
  203. })
  204. watch(() => storeData.storeId, (val) => {
  205. storeId.value = val
  206. })
  207. watch(storeId, (val) => {
  208. if (val) {
  209. getTimeList()
  210. }
  211. })
  212. // 新增预设
  213. function getDetail(query) {
  214. proxy.$router.push({
  215. path: props.path,
  216. query
  217. })
  218. }
  219. // 计算
  220. const deviceName = (val) => {
  221. let e = deviceOptions.value.find(i => i.clientTypeId == val)
  222. return e ? e.name : val
  223. }
  224. const storeName = (val) => {
  225. let e = storeData.options.find(i => i.id == val)
  226. return e ? e.name : val
  227. }
  228. const getDisplay = (val) => {
  229. return val.startTime ? '' : 'none'
  230. }
  231. const getTop = (val) => {
  232. if (val.startTime && val.request) {
  233. return proxy.hoursToSeconds(val.startTime) / 3600 * 60 + 'px'
  234. }
  235. }
  236. const getLeft = (val) => {
  237. if (val.startTime && val.request) {
  238. return val.index * (100 / data.number[val.sort].length) + '%'
  239. }
  240. }
  241. const getHeight = (val) => {
  242. if (val.request) {
  243. if (val.startTime) {
  244. return (proxy.hoursToSeconds(val.endTime) - proxy.hoursToSeconds(val.startTime)) / 3600 * 60 + 'px'
  245. }
  246. } else {
  247. return 0
  248. }
  249. }
  250. const getWidth = (val) => {
  251. if (val.startTime && val.request) {
  252. let e = 100 / data.number[val.sort].length + '%'
  253. return `calc(${e} - 10px)`
  254. }
  255. }
  256. </script>
  257. <style lang="scss" scoped>
  258. .chart {
  259. height: 100vh;
  260. overflow-y: auto;
  261. position: relative;
  262. margin-left: 20px;
  263. user-select: none;
  264. .time {
  265. width: 100%;
  266. height: 60px;
  267. display: flex;
  268. .label {
  269. width: 50px;
  270. height: 100%;
  271. line-height: 60px
  272. }
  273. .line {
  274. width: calc(100% - 50px);
  275. border-top-width: 1px;
  276. border-left-width: 1px;
  277. border-right-width: 1px;
  278. border-bottom-width: 0;
  279. border-style: solid;
  280. border-color: #e3e3e3;
  281. }
  282. }
  283. .time:nth-child(24) .line {
  284. border-bottom-width: 1px;
  285. }
  286. .grid {
  287. position: absolute;
  288. top: 0;
  289. left: 50px;
  290. width: calc(100% - 50px);
  291. .label_box {
  292. height: 1440px;
  293. }
  294. .grid-item {
  295. position: absolute;
  296. margin: 0 5px;
  297. background-color: rgb(57 121 249 / 10%);
  298. border-left: 4px solid #3979F9;
  299. border-radius: 4px;
  300. overflow: hidden;
  301. color: #337ecc;
  302. .info {
  303. padding: 10px 0 0 10px;
  304. }
  305. }
  306. .grid-item-disabled {
  307. position: absolute;
  308. margin: 0 5px;
  309. background-color: rgb(144 147 153 / 20%);
  310. border-left: 4px solid #909399;
  311. border-radius: 4px;
  312. overflow: hidden;
  313. color: #909399;
  314. .info {
  315. padding: 10px 0 0 10px;
  316. }
  317. }
  318. }
  319. }
  320. .popper {
  321. .title,
  322. .main {
  323. line-height: 35px;
  324. padding: 20px;
  325. }
  326. .title {
  327. background-color: #337ecc;
  328. color: #FFF;
  329. border-radius: 10px 10px 0 0;
  330. font-size: 16px;
  331. }
  332. .main {
  333. display: flex;
  334. flex-direction: column;
  335. }
  336. }
  337. .search {
  338. padding-left: 70px;
  339. }
  340. .chosenClass {
  341. background: rgba(57, 121, 249, 0.1) !important;
  342. }
  343. </style>