timing.vue 9.8 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. uni.showToast({
  184. title: error,
  185. icon: "none"
  186. })
  187. })
  188. },
  189. showjp2time(time1, time2) {
  190. if (time1 && time2) {
  191. var num1 = parseInt(time1.replace(":", ''))
  192. var num2 = parseInt(time2.replace(":", ''))
  193. return num1 >= num2
  194. } else {
  195. return false
  196. }
  197. },
  198. deletePopupQuery() {
  199. if (this.deleteIds != '') {
  200. this.deletePopup = true
  201. } else {
  202. uni.showToast({
  203. title: "请至少勾选一项",
  204. icon: "none"
  205. })
  206. }
  207. },
  208. deletePopupApi() {
  209. uni.showLoading({
  210. title: "加载中",
  211. mask: true,
  212. })
  213. API.deleteSwitch({
  214. ids: this.deleteIds
  215. }).then((response) => {
  216. uni.hideLoading();
  217. this.deletePopup = false
  218. this.deleteShow = false
  219. this.deleteIds = ""
  220. this.getMeterTimerList()
  221. }).catch(error => {
  222. uni.showToast({
  223. title: error,
  224. icon: "none"
  225. })
  226. })
  227. },
  228. checkboxChange(e) {
  229. var sz = e.detail.value;
  230. this.deleteIds = sz.join()
  231. },
  232. clicksheetInfo(item) {
  233. if (!this.deleteShow) {
  234. var url = `/pages/timing/autoOff?id=${item.id}`
  235. uni.navigateTo({
  236. url: url
  237. })
  238. }
  239. },
  240. clicksheet(index) {
  241. var k=this.list[index].value
  242. var url = `/pages/timing/autoOff?meterId=${this.meterId}&type=${index}`
  243. uni.navigateTo({
  244. url: url
  245. })
  246. },
  247. getMeterTimerList() {
  248. uni.showLoading({
  249. title: "加载中",
  250. mask: true,
  251. })
  252. API.meterTimerList({
  253. meterId: this.meterId
  254. }).then((response) => {
  255. uni.hideLoading();
  256. this.getMeterTimerListReady = true
  257. this.timerSwitchList = response.data.timerSwitchList;
  258. }).catch(error => {
  259. uni.showToast({
  260. title: error,
  261. icon: "none"
  262. })
  263. })
  264. }
  265. }
  266. }
  267. </script>
  268. <style lang="scss" scoped>
  269. .weeklistclassSpan:last-child {
  270. display: none;
  271. }
  272. /deep/.u-back-wrap{
  273. background-color: #fff;
  274. }
  275. /deep/.u-slot-right {
  276. padding-right: 32rpx;
  277. padding-left: 16rpx;
  278. line-height: 30px;
  279. background-color: #fff;
  280. img {
  281. width: 48rpx;
  282. height: 48rpx;
  283. }
  284. }
  285. .time-group {
  286. background-color: #fff;
  287. .time-item {
  288. padding: 24rpx 0;
  289. margin: 0 32rpx;
  290. display: flex;
  291. justify-content: space-between;
  292. align-items: center;
  293. border-bottom: 1px solid rgba(221, 221, 221, 1);
  294. .time {
  295. width: 100%;
  296. .time-slot {
  297. color: rgba(16, 16, 16, 1);
  298. font-size: 32rpx;
  299. }
  300. .type {
  301. color: rgba(119, 119, 119, 1);
  302. }
  303. }
  304. }
  305. .time-item:last-of-type {
  306. border: none;
  307. }
  308. }
  309. // 添加按钮
  310. .add {
  311. z-index: 99;
  312. width: 128rpx;
  313. height: 128rpx;
  314. background-color: rgba(22, 119, 255, 1);
  315. border-radius: 999px;
  316. display: flex;
  317. align-items: center;
  318. justify-content: center;
  319. position: fixed;
  320. bottom: 80rpx;
  321. right: 40rpx;
  322. img {
  323. width: 80rpx;
  324. height: 80rpx;
  325. }
  326. }
  327. .add-popup {
  328. /deep/.u-drawer {
  329. left: 24rpx;
  330. right: 24rpx;
  331. bottom: 24rpx;
  332. border-radius: 8px;
  333. }
  334. /deep/.u-action-sheet-item {
  335. color: #101010;
  336. }
  337. }
  338. // 删除
  339. .delete {
  340. position: fixed;
  341. left: 0;
  342. right: 0;
  343. bottom: 0;
  344. background-color: #fff;
  345. display: flex;
  346. flex-direction: column;
  347. align-items: center;
  348. justify-content: center;
  349. // padding: 20rpx 0;
  350. height: 120rpx;
  351. img {
  352. width: 48rpx;
  353. height: 48rpx;
  354. }
  355. .text {
  356. color: rgba(51, 51, 51, 1);
  357. font-size: 20rpx;
  358. }
  359. }
  360. // 删除确认弹框
  361. .popup {
  362. padding: 32rpx;
  363. text-align: center;
  364. .headline {
  365. color: rgba(16, 16, 16, 1);
  366. font-size: 36rpx;
  367. font-weight: bold;
  368. }
  369. .hint {
  370. color: rgba(16, 16, 16, 1);
  371. font-size: 32rpx;
  372. margin-top: 40rpx;
  373. }
  374. .btn-box {
  375. margin-top: 82rpx;
  376. display: flex;
  377. justify-content: space-between;
  378. .cancel {
  379. width: 328rpx;
  380. line-height: 80rpx;
  381. border-radius: 4px;
  382. background-color: rgba(222, 225, 228, 1);
  383. color: rgba(51, 51, 51, 1);
  384. font-size: 32rpx;
  385. }
  386. .confirm {
  387. width: 328rpx;
  388. line-height: 80rpx;
  389. border-radius: 4px;
  390. background-color: rgba(255, 68, 68, 1);
  391. color: rgba(255, 255, 255, 1);
  392. font-size: 32rpx;
  393. }
  394. }
  395. }
  396. </style>