timing.vue 9.6 KB

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