index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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.listDate">{{ element.listDate.startTime.split(' ')[0] }}</div>
  38. <div v-if="element.listDate">
  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. if(i === 23) {
  128. end = start + 3600000
  129. }
  130. }
  131. data.timeList[i].timer[0] = start
  132. data.timeList[i].timer[1] = end
  133. }
  134. }
  135. getTime()
  136. const popperStyle = ref({
  137. padding: 0,
  138. borderRadius: '10px'
  139. })
  140. // 时间轴
  141. function getTimeList() {
  142. data.timeList.map(i => i.list = [])
  143. if (props.type === 'scene') {
  144. sceneTime({ storeId: storeId.value }).then(res => {
  145. modal(res)
  146. })
  147. } else {
  148. settimgTime({ nowDate: proxy.parseTime(nowDate.value.getTime(), "{y}-{m}-{d}"), storeId: storeId.value }).then(res => {
  149. modal(res)
  150. })
  151. }
  152. }
  153. const modal = (res) => {
  154. res.data.forEach(i => {
  155. i.listDate.forEach(j => {
  156. let start = null
  157. let end = null
  158. if (props.type === 'scene') {
  159. start = proxy.hoursToSeconds(j.startTime)
  160. end = proxy.hoursToSeconds(j.endTime)
  161. } else {
  162. start = new Date(j.startTime).getTime()
  163. end = new Date(j.endTime).getTime()
  164. }
  165. const list = data.timeList.filter((e, index) => {
  166. let st = e.timer[0]
  167. let en = e.timer[1]
  168. if (index !== 24) {
  169. return start >= st && end <= en || start <= st && end >= en
  170. }
  171. })
  172. list.map(e => {
  173. e.list.push({ ...i, listDate: j })
  174. })
  175. })
  176. })
  177. }
  178. watch(() => props.date, (val) => {
  179. nowDate.value = val
  180. getTime()
  181. getTimeList()
  182. })
  183. // 拖拽内容
  184. function onMove(params) {
  185. console.log(1);
  186. if (params.to.childElementCount < 1) {
  187. return true
  188. } else {
  189. return false
  190. }
  191. }
  192. // 拖拽结束
  193. function onEnd(params) {
  194. console.log(2);
  195. if (params.from.className === 'contentList' &&
  196. params.to.className === 'label_box' ||
  197. params.from.className === 'label_box' &&
  198. params.from.__draggable_component__.itemKey !== params.to.__draggable_component__.itemKey) {
  199. let query = {
  200. value: params.item._underlying_vm_.value,
  201. label: params.item._underlying_vm_.label
  202. }
  203. getDetail(query)
  204. }
  205. }
  206. // 删除
  207. const getDelete = (row) => {
  208. proxy.$modal.confirm(`是否删除预设名称为:${row.takeName}的数据?`).then(() => {
  209. if (props.type === 'setting') {
  210. removeSetting({ id: row.id }).then(res => {
  211. if (res.code === 0) {
  212. proxy.$modal.msgSuccess('删除成功!')
  213. getTimeList()
  214. }
  215. })
  216. } else {
  217. removeScene({ id: row.id }).then(res => {
  218. if (res.code === 0) {
  219. proxy.$modal.msgSuccess('删除成功!')
  220. getTimeList()
  221. }
  222. })
  223. }
  224. }).catch(() => { })
  225. }
  226. watch(() => businessData.options, (val) => {
  227. if (val.length > 0) {
  228. organizationIds.value = val[0].id
  229. }
  230. })
  231. watch(organizationIds, (val) => {
  232. if (val) {
  233. storeData.form.tenantId = val
  234. getStore()
  235. }
  236. })
  237. watch(() => storeData.storeId, (val) => {
  238. data.timeList.map(i => i.list = [])
  239. storeId.value = val
  240. if (val) {
  241. getTimeList()
  242. }
  243. })
  244. // 新增预设
  245. function getDetail(query) {
  246. proxy.$router.push({
  247. path: props.path,
  248. query
  249. })
  250. }
  251. // 计算
  252. const deviceName = (val) => {
  253. let e = deviceOptions.value.find(i => i.clientTypeId == val)
  254. return e ? e.name : val
  255. }
  256. const storeName = (val) => {
  257. let e = storeData.options.find(i => i.id === val)
  258. return e ? e.name : val
  259. }
  260. </script>
  261. <style lang="scss" scoped>
  262. .timer {
  263. display: flex;
  264. flex-direction: column;
  265. width: calc(100% - 50px);
  266. margin-left: 50px;
  267. overflow-y: auto;
  268. padding: 20px 20px 20px 50px;
  269. .item {
  270. width: 100%;
  271. height: 100px;
  272. line-height: 100px;
  273. position: relative;
  274. border-left: 1px solid #e3e3e3;
  275. display: flex;
  276. align-items: center;
  277. .value {
  278. width: 100px;
  279. margin-left: -50px;
  280. .solid {
  281. border-top: 1px solid #e3e3e3;
  282. width: 100%;
  283. position: absolute;
  284. top: 50px;
  285. left: 0;
  286. }
  287. }
  288. .label_box {
  289. display: flex;
  290. width: 100%;
  291. z-index: 99;
  292. position: absolute;
  293. top: 70px;
  294. .label {
  295. background-color: #ebf1fe;
  296. color: #3979F9;
  297. height: 60px;
  298. display: flex;
  299. justify-content: center;
  300. align-items: center;
  301. border-left: 4px solid #3979F9;
  302. border-radius: 4px;
  303. margin-right: 10px;
  304. font-size: 12px;
  305. padding: 0 20px;
  306. flex: 1;
  307. }
  308. }
  309. }
  310. }
  311. .popper {
  312. .title,
  313. .main {
  314. line-height: 35px;
  315. padding: 20px;
  316. }
  317. .title {
  318. background-color: #337ecc;
  319. color: #FFF;
  320. border-radius: 10px 10px 0 0;
  321. font-size: 16px;
  322. }
  323. .main {
  324. display: flex;
  325. flex-direction: column;
  326. }
  327. }
  328. .search {
  329. padding-left: 70px;
  330. }
  331. </style>