index.vue 10.0 KB

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