timing.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. <template>
  2. <view>
  3. <u-navbar :title="title" title-color="#101010">
  4. <view slot="right" v-if="timerSwitchList.length"
  5. @click="deleteShow=!deleteShow">
  6. <img v-if="deleteShow==true" src="@/assets/img/arcoDesign-select-all.svg" alt="" />
  7. <span v-else style="color: red;" >删除</span>
  8. <!-- <img src="@/assets/img/riLine-list-settings-line.svg" alt="" /> -->
  9. </view>
  10. </u-navbar>
  11. <view class="time-group">
  12. <checkbox-group @change="checkboxChange">
  13. <view class="time-item" v-for="(item,i) in timerSwitchList" :key="i" >
  14. <view class="time" @click="clicksheetInfo(item)">
  15. <view class="time-slot">
  16. {{item.startTime}}
  17. {{item.switchStatus==2||item.switchStatus==3?'-'+(showjp2time(item.startTime,item.endTime)?'次日':'')+item.endTime:''}}
  18. </view>
  19. <view class="type">
  20. {{item.switchStatusN}} | {{item.type==1?'执行一次':''}}
  21. <template v-if="item.type!=1">
  22. <template v-if="item.weekdays=='1,2,3,4,5,6,7'">
  23. 每天
  24. </template>
  25. <template v-else>
  26. <template v-for="(item,i) in item.weekdays.split(',')">
  27. <span :key="i">
  28. {{weeklist[item]}}
  29. </span>
  30. <span class="weeklistclassSpan" :key="i+'a'">
  31. ,
  32. </span>
  33. </template>
  34. </template>
  35. </template>
  36. <template v-if="item.switchStatus==3">
  37. <span style="margin-left: 8rpx;">| {{item.maxPower}}kW</span>
  38. </template>
  39. <template v-if="item.switchStatus==0&&item.status">
  40. <span style="margin-left: 8rpx;">| {{gethtml(item.startTime)}}停电</span>
  41. </template>
  42. <template v-if="item.switchStatus==1&&item.status">
  43. <span style="margin-left: 8rpx;">| {{gethtml(item.startTime)}}供电</span>
  44. </template>
  45. </view>
  46. <view class="type" v-if="item.switchStatus==2&&item.status">
  47. <view>{{gethtml(item.startTime)}}供电</view>
  48. <view>{{gethtml(item.endTime)}}停电</view>
  49. </view>
  50. <view class="type" v-if="item.switchStatus==3&&item.status">
  51. <view>{{gethtml(item.startTime)}}开启“智能停电”</view>
  52. <view>{{gethtml(item.endTime)}}关闭“智能停电”</view>
  53. </view>
  54. </view>
  55. <!-- 开关 -->
  56. <view class="switch" v-if="!deleteShow">
  57. <u-switch @change="switchBtn(item,$event)" v-model="item.status" size="40"></u-switch>
  58. </view>
  59. <!-- 单选框 -->
  60. <view class="radio" v-if="deleteShow">
  61. <checkbox :value="item.id"></checkbox>
  62. </view>
  63. </view>
  64. </checkbox-group>
  65. </view>
  66. <u-divider :isnone="timerSwitchList.length==0" nonetext="无记录" border-color="#CFD2D5">已经到底了</u-divider>
  67. <!-- 添加按钮 -->
  68. <view class="add" @click="show=true" v-if="deleteShow==false">
  69. <img src="@/assets/img/riLine-add-line 1.svg" alt="" />
  70. </view>
  71. <!-- 新增弹窗 -->
  72. <view class="add-popup">
  73. <u-action-sheet :list="list" @click="clicksheet" v-model="show" border-radius="16"></u-action-sheet>
  74. </view>
  75. <!-- 删除 -->
  76. <view class="delete" v-if="deleteShow" @click="deletePopupQuery">
  77. <view class="icon">
  78. <img src="@/assets/img/riLine-delete-bin-7-line 1.svg" alt="" />
  79. </view>
  80. <view class="text">
  81. 删除
  82. </view>
  83. </view>
  84. <!-- 删除确认弹框 -->
  85. <u-popup v-model="deletePopup" mode="bottom" border-radius="12">
  86. <view class="popup">
  87. <view class="headline">
  88. 删除定时
  89. </view>
  90. <view class="hint">
  91. 要删除选中的定时吗?
  92. </view>
  93. <view class="btn-box">
  94. <view class="cancel" @click="deletePopup=false">
  95. 取消
  96. </view>
  97. <view class="confirm" @click="deletePopupApi">
  98. 确认删除
  99. </view>
  100. </view>
  101. </view>
  102. </u-popup>
  103. </view>
  104. </template>
  105. <script>
  106. import * as API from '@/apis/pagejs/meterTimer.js'
  107. import {
  108. hourDistanceArr,
  109. parseUnixTime,
  110. newDate
  111. } from '@/apis/utils/index.js'
  112. export default {
  113. data() {
  114. return {
  115. checked: false,
  116. show: false,
  117. popShow: false,
  118. deleteShow: false,
  119. deletePopup: false,
  120. weeklist: [
  121. '', '周一', '周二', '周三', '周四', '周五', '周六', '周日'
  122. ],
  123. list: [{
  124. text: '智能停电',
  125. value: 3,
  126. },
  127. {
  128. text: '供电时间',
  129. value: 0,
  130. }, {
  131. text: '定时供电',
  132. value: 1,
  133. }, {
  134. text: '定时停电',
  135. value: 2,
  136. }
  137. ],
  138. timerSwitchList: [],
  139. getMeterTimerListReady: false,
  140. deleteIds: "",
  141. title: "",
  142. }
  143. },
  144. onLoad(op) {
  145. if (op.id) {
  146. this.title = op.title;
  147. this.meterId = op.id;
  148. this.getMeterTimerList()
  149. }
  150. },
  151. onShow() {
  152. if (this.meterId) {
  153. this.getMeterTimerList()
  154. }
  155. },
  156. methods: {
  157. gethtml(item) {
  158. var str = parseUnixTime(new Date().getTime(), '{y}-{m}-{d}');
  159. var time1 = new Date();
  160. var time2 = newDate(str + ' ' + item + ':00');
  161. var sz = []
  162. if (time1 > time2) {
  163. time2.setDate(time2.getDate() + 1)
  164. sz = hourDistanceArr(time1, time2)
  165. } else {
  166. sz = hourDistanceArr(time1, time2)
  167. }
  168. console.log(sz[0])
  169. return (sz[0] ? sz[0] + '小时' : '') + (sz[1] ? sz[1] + '分钟后' : '0分钟后')
  170. },
  171. switchBtn(node, key) {
  172. uni.showLoading({
  173. title: "加载中",
  174. mask: true,
  175. })
  176. API.changeStatus({
  177. id: node.id,
  178. //enabled:key
  179. }).then((res) => {
  180. uni.hideLoading();
  181. node.status = res.data.status
  182. }).catch(error => {
  183. node.status=!key
  184. uni.showToast({
  185. title: error,
  186. icon: "none"
  187. })
  188. })
  189. },
  190. showjp2time(time1, time2) {
  191. if (time1 && time2) {
  192. var num1 = parseInt(time1.replace(":", ''))
  193. var num2 = parseInt(time2.replace(":", ''))
  194. return num1 >= num2
  195. } else {
  196. return false
  197. }
  198. },
  199. deletePopupQuery() {
  200. if (this.deleteIds != '') {
  201. this.deletePopup = true
  202. } else {
  203. uni.showToast({
  204. title: "请至少勾选一项",
  205. icon: "none"
  206. })
  207. }
  208. },
  209. deletePopupApi() {
  210. uni.showLoading({
  211. title: "加载中",
  212. mask: true,
  213. })
  214. API.deleteSwitch({
  215. ids: this.deleteIds
  216. }).then((response) => {
  217. uni.hideLoading();
  218. this.deletePopup = false
  219. this.deleteShow = false
  220. this.deleteIds = ""
  221. this.getMeterTimerList()
  222. }).catch(error => {
  223. uni.showToast({
  224. title: error,
  225. icon: "none"
  226. })
  227. })
  228. },
  229. checkboxChange(e) {
  230. var sz = e.detail.value;
  231. this.deleteIds = sz.join()
  232. },
  233. clicksheetInfo(item) {
  234. if (!this.deleteShow) {
  235. var url = `/pages/timing/autoOff?id=${item.id}`
  236. uni.navigateTo({
  237. url: url
  238. })
  239. }
  240. },
  241. clicksheet(index) {
  242. var k=this.list[index].value
  243. var url = `/pages/timing/autoOff?meterId=${this.meterId}&type=${index}`
  244. uni.navigateTo({
  245. url: url
  246. })
  247. },
  248. getMeterTimerList() {
  249. uni.showLoading({
  250. title: "加载中",
  251. mask: true,
  252. })
  253. API.meterTimerList({
  254. meterId: this.meterId
  255. }).then((response) => {
  256. uni.hideLoading();
  257. this.getMeterTimerListReady = true
  258. this.timerSwitchList = response.data.timerSwitchList;
  259. }).catch(error => {
  260. uni.showToast({
  261. title: error,
  262. icon: "none"
  263. })
  264. })
  265. }
  266. }
  267. }
  268. </script>
  269. <style lang="scss" scoped>
  270. .weeklistclassSpan:last-child {
  271. display: none;
  272. }
  273. ::v-deep.u-back-wrap{
  274. background-color: #fff;
  275. }
  276. ::v-deep.u-slot-right {
  277. padding-right: 32rpx;
  278. padding-left: 16rpx;
  279. line-height: 30px;
  280. background-color: #fff;
  281. img {
  282. width: 48rpx;
  283. height: 48rpx;
  284. }
  285. }
  286. .time-group {
  287. background-color: #fff;
  288. .time-item {
  289. padding: 24rpx 0;
  290. margin: 0 32rpx;
  291. display: flex;
  292. justify-content: space-between;
  293. align-items: center;
  294. border-bottom: 1px solid rgba(221, 221, 221, 1);
  295. .time {
  296. width: 100%;
  297. .time-slot {
  298. color: rgba(16, 16, 16, 1);
  299. font-size: 32rpx;
  300. }
  301. .type {
  302. color: rgba(119, 119, 119, 1);
  303. }
  304. }
  305. }
  306. .time-item:last-of-type {
  307. border: none;
  308. }
  309. }
  310. // 添加按钮
  311. .add {
  312. z-index: 99;
  313. width: 128rpx;
  314. height: 128rpx;
  315. background-color: rgba(22, 119, 255, 1);
  316. border-radius: 999px;
  317. display: flex;
  318. align-items: center;
  319. justify-content: center;
  320. position: fixed;
  321. bottom: 80rpx;
  322. right: 40rpx;
  323. img {
  324. width: 80rpx;
  325. height: 80rpx;
  326. }
  327. }
  328. .add-popup {
  329. ::v-deep.u-drawer {
  330. left: 24rpx;
  331. right: 24rpx;
  332. bottom: 24rpx;
  333. border-radius: 8px;
  334. }
  335. ::v-deep.u-action-sheet-item {
  336. color: #101010;
  337. }
  338. }
  339. // 删除
  340. .delete {
  341. position: fixed;
  342. left: 0;
  343. right: 0;
  344. bottom: 0;
  345. background-color: #fff;
  346. display: flex;
  347. flex-direction: column;
  348. align-items: center;
  349. justify-content: center;
  350. // padding: 20rpx 0;
  351. height: 120rpx;
  352. img {
  353. width: 48rpx;
  354. height: 48rpx;
  355. }
  356. .text {
  357. color: rgba(51, 51, 51, 1);
  358. font-size: 20rpx;
  359. }
  360. }
  361. // 删除确认弹框
  362. .popup {
  363. padding: 32rpx;
  364. text-align: center;
  365. .headline {
  366. color: rgba(16, 16, 16, 1);
  367. font-size: 36rpx;
  368. font-weight: bold;
  369. }
  370. .hint {
  371. color: rgba(16, 16, 16, 1);
  372. font-size: 32rpx;
  373. margin-top: 40rpx;
  374. }
  375. .btn-box {
  376. margin-top: 82rpx;
  377. display: flex;
  378. justify-content: space-between;
  379. .cancel {
  380. width: 328rpx;
  381. line-height: 80rpx;
  382. border-radius: 4px;
  383. background-color: rgba(222, 225, 228, 1);
  384. color: rgba(51, 51, 51, 1);
  385. font-size: 32rpx;
  386. }
  387. .confirm {
  388. width: 328rpx;
  389. line-height: 80rpx;
  390. border-radius: 4px;
  391. background-color: rgba(255, 68, 68, 1);
  392. color: rgba(255, 255, 255, 1);
  393. font-size: 32rpx;
  394. }
  395. }
  396. }
  397. </style>