autoOff.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. <template>
  2. <view>
  3. <u-navbar :title="title" title-color="#101010">
  4. <view slot="right" @click="submitApi">
  5. <img src="@/assets/img/riLine-check-line 1.svg" alt="" />
  6. </view>
  7. </u-navbar>
  8. <view class="time-group">
  9. <view class="time-item" @click="typeShow=true">
  10. <view class="time">
  11. <view class="time-slot">
  12. 重复
  13. </view>
  14. <view class="type weeklistclass" v-if="typeShowIndex==2">
  15. <template v-for="(item,i) in weekdaysList">
  16. <template v-if="item==1">
  17. <span :key="i">
  18. {{weeklist[i]}}
  19. </span>
  20. <span class="weeklistclassSpan" :key="i+'a'" >
  21. ,
  22. </span>
  23. </template>
  24. </template>
  25. </view>
  26. <view class="type" v-else >
  27. {{typeShowIndex==0?'执行一次':''}}
  28. {{typeShowIndex==1?'每天':''}}
  29. </view>
  30. </view>
  31. <view class="more">
  32. <u-icon name="arrow-right" color="#b2b2b2"></u-icon>
  33. </view>
  34. </view>
  35. <view class="time-item" v-show="type==0||type==1||type==3"
  36. @click="pickerShow1=true">
  37. <view class="time">
  38. <view class="time-slot">
  39. 定时开启
  40. </view>
  41. <view class="type">
  42. {{startTime?startTimeStr(startTime):'未设置'}}
  43. </view>
  44. </view>
  45. <view class="more">
  46. <u-icon name="arrow-right" color="#b2b2b2"></u-icon>
  47. </view>
  48. </view>
  49. <view class="time-item" v-show="type==0||type==2||type==3"
  50. @click="pickerShow2=true">
  51. <view class="time">
  52. <view class="time-slot">
  53. 定时关闭
  54. </view>
  55. <view class="type">
  56. {{showjp2time(startTime,endTime)?'次日':''}}{{endTime?startTimeStr(endTime):'未设置'}}
  57. </view>
  58. </view>
  59. <view class="more">
  60. <u-icon name="arrow-right" color="#b2b2b2"></u-icon>
  61. </view>
  62. </view>
  63. <view class="time-item" v-show="type==3"
  64. @click="thresholdsPopup=true" >
  65. <view class="time">
  66. <view class="time-slot">
  67. 最大功率阈值
  68. </view>
  69. <view class="type">
  70. {{formData.maxPower!=''?formData.maxPower+'kW':'未设置'}}
  71. </view>
  72. </view>
  73. <view class="more">
  74. <u-icon name="arrow-right" color="#b2b2b2"></u-icon>
  75. </view>
  76. </view>
  77. </view>
  78. <!-- 重复类型 -->
  79. <view class="repeatType" v-if="typeShow">
  80. <u-popup v-model="typeShow" mode="bottom">
  81. <view>
  82. <view class="headline">
  83. 重复类型
  84. </view>
  85. <view class="type-group">
  86. <view class="item" :class="{
  87. 'item-title-checked':typeShowIndex==0
  88. }" @click="typeShowIndex=0,typeShow=false">
  89. <view class="item-title " >
  90. 执行一次
  91. </view>
  92. <view class="item-icon item-icon1">
  93. <img src="@/assets/img/riLine-check-line.svg" alt="" />
  94. </view>
  95. <view class="item-icon item-icon2">
  96. <img src="" alt="" />
  97. </view>
  98. </view>
  99. <view class="item" :class="{
  100. 'item-title-checked':typeShowIndex==1
  101. }" @click="typeShowIndex=1,typeShow=false">
  102. <view class="item-title " > 每天
  103. </view>
  104. <view class="item-icon item-icon1">
  105. <img src="@/assets/img/riLine-check-line.svg" alt="" />
  106. </view>
  107. <view class="item-icon item-icon2">
  108. <img src="" alt="" />
  109. </view>
  110. </view>
  111. <view class="item" :class="{
  112. 'item-title-checked':typeShowIndex==2
  113. }" @click="customPopup=true,weekdaysListTemp=weekdaysList">
  114. <view class="item-title" >
  115. 自定义
  116. </view>
  117. <view class="item-icon item-icon1">
  118. <img src="@/assets/img/riLine-check-line.svg" alt="" />
  119. </view>
  120. <view class="item-icon item-icon2">
  121. <img src="" alt="" />
  122. </view>
  123. </view>
  124. </view>
  125. </view>
  126. </u-popup>
  127. </view>
  128. <!-- 关闭时间 -->
  129. <ujpPicker mode="time" jp="1" :default-time="startTime?'2024-1-1 '+startTime+':1':''"
  130. v-model="pickerShow1" :params="params" @confirm="pickerShow1confirm" ></ujpPicker>
  131. <ujpPicker mode="time" jp="2" :default-time="endTime?'2024-1-1 '+endTime+':1':''" :defaultStartTime="startTime"
  132. v-model="pickerShow2" :params="params" @confirm="pickerShow2confirm" ></ujpPicker>
  133. <!-- 自定义重复 -->
  134. <u-popup v-model="customPopup" mode="bottom">
  135. <view class="custom">
  136. <view class="headline">
  137. 自定义重复
  138. </view>
  139. <view class="radio-group">
  140. <checkbox-group @change="checkboxChange" >
  141. <view class="radio-item" v-for="(item,i) in weekdaysListTemp" :key="i">
  142. <view class="item-title" >
  143. {{weeklist[i]}}
  144. </view>
  145. <view class="item-value">
  146. <checkbox
  147. :value="''+i"
  148. :checked="item?true:false"
  149. ></checkbox>
  150. </view>
  151. </view>
  152. </checkbox-group>
  153. </view>
  154. <view class="btn-group">
  155. <view class="btn cancel" @click="customPopup=false">
  156. 取消
  157. </view>
  158. <view class="btn confirm" @click="customPopupApi" >
  159. 确认
  160. </view>
  161. </view>
  162. </view>
  163. </u-popup>
  164. <!-- 最大功率阈值 -->
  165. <u-popup v-model="thresholdsPopup" mode="bottom">
  166. <view class="thresholds">
  167. <view class="headline">
  168. 最大功率阈值(kW)
  169. </view>
  170. <view class="input" style=" padding: 0 24rpx;">
  171. <u-input type="digit" min="1"
  172. v-model="maxPower" placeholder="填写触发自动关闭的功率数值" />
  173. </view>
  174. <view class="btn-group">
  175. <view class="btn cancel" @click="thresholdsPopup=false" >
  176. 取消
  177. </view>
  178. <view class="btn confirm" @click="thresholdsPopupApi">
  179. 确认
  180. </view>
  181. </view>
  182. </view>
  183. </u-popup>
  184. </view>
  185. </template>
  186. <script>
  187. import ujpPicker from '@/components/u-picker.vue'
  188. import * as API from '@/apis/pagejs/meterTimer.js'
  189. export default {
  190. components: {
  191. ujpPicker
  192. },
  193. data() {
  194. return {
  195. typeShow: true,
  196. pickerShow1: false,
  197. pickerShow2: false,
  198. typeShow: false,
  199. customPopup: false,
  200. thresholdsPopup: false,
  201. listtemp: [2,1,0,3],
  202. list: [{
  203. text: '时间段定时',
  204. value:2
  205. }, {
  206. text: '定时开启',
  207. value:1
  208. }, {
  209. text: '定时关闭' ,
  210. value:0
  211. },{
  212. text:'自动关闭',
  213. value:3
  214. }],
  215. params: {
  216. year: false,
  217. month: false,
  218. day: false,
  219. hour: true,
  220. minute: true,
  221. second: false,
  222. },
  223. id:"",
  224. type:"",
  225. meterId:"",
  226. title:"",
  227. weekdaysListTemp:[0,0,0,0,0,0,0],
  228. weekdaysList:[0,0,0,0,0,0,0],
  229. weeklist:[
  230. '周一','周二','周三','周四','周五','周六','周日'
  231. ],
  232. typeShowIndex:0,
  233. startTime:"",
  234. endTime:"",
  235. maxPower:"",
  236. timerSwitch:{},
  237. formData:{
  238. meterId:"",
  239. weekdays:"",
  240. startTime:"",
  241. type:"",
  242. switchStatus:"",
  243. status:true,
  244. id:"",
  245. endTime:"",
  246. maxPower:"",
  247. }
  248. }
  249. },
  250. onLoad(op) {
  251. if(op.meterId){
  252. this.meterId=op.meterId;
  253. this.formData.meterId=this.meterId
  254. }
  255. if(op.type){
  256. this.type=op.type;
  257. this.title=this.list[this.type].text
  258. }
  259. if(op.id){
  260. this.id=op.id;
  261. this.getMeterTimerDetails()
  262. }
  263. },
  264. methods: {
  265. showjp2time(time1,time2){
  266. if(time1&&time2){
  267. var num1=parseInt(time1.replace(":",''))
  268. var num2=parseInt(time2.replace(":",''))
  269. return num1>=num2
  270. }else{
  271. return false
  272. }
  273. },
  274. getMeterTimerDetails(){
  275. uni.showLoading({
  276. title: "加载中",
  277. mask: true,
  278. })
  279. API.meterTimerDetails({
  280. id:this.id
  281. }).then((response) => {
  282. uni.hideLoading();
  283. var timerSwitch=response.data.timerSwitch;
  284. this.formData=timerSwitch
  285. this.meterId=timerSwitch.meterId
  286. this.type=this.listtemp[timerSwitch.switchStatus]
  287. this.title=this.list[this.type].text
  288. if(timerSwitch.type==1){
  289. this.typeShowIndex=0;
  290. }else{
  291. if(timerSwitch.weekdays=="1,2,3,4,5,6,7"){
  292. this.typeShowIndex=1;
  293. }else{
  294. this.typeShowIndex=2;
  295. var sz=timerSwitch.weekdays.split(',');
  296. for(var i in sz){
  297. var num= parseInt(sz[i])-1
  298. this.weekdaysListTemp[num]=1
  299. }
  300. this.weekdaysList=this.weekdaysListTemp
  301. }
  302. }
  303. this.startTime=timerSwitch.startTime
  304. this.endTime=timerSwitch.endTime
  305. if(this.type==2){
  306. this.endTime=timerSwitch.startTime
  307. }
  308. this.maxPower=this.formData.maxPower
  309. }).catch(error => {
  310. uni.showToast({
  311. title: error,
  312. icon: "none"
  313. })
  314. })
  315. },
  316. thresholdsPopupApi(){
  317. if(this.maxPower!=''){
  318. if(this.maxPower<=0){
  319. uni.showToast({
  320. title: "请输入大于0的功率阈值(kw)",
  321. icon: "none"
  322. })
  323. }else{
  324. this.thresholdsPopup=false
  325. this.formData.maxPower=this.maxPower
  326. }
  327. }else{
  328. uni.showToast({
  329. title: "请填写最大功率阈值(kw)",
  330. icon: "none"
  331. })
  332. }
  333. },
  334. pickerShow1confirm(e){
  335. this.startTime=e.hour+":"+e.minute+""
  336. //this.startTimeStr=e.hour+"时"+e.minute+"分"
  337. },
  338. startTimeStr(str){
  339. if(str){
  340. return str.replace(":","时")+"分"
  341. }else{
  342. return ''
  343. }
  344. },
  345. pickerShow2confirm(e){
  346. this.endTime=e.hour+":"+e.minute+""
  347. //this.endTimeStr=e.hour+"时"+e.minute+"分"
  348. },
  349. customPopupApi(){
  350. var str1=[0,0,0,0,0,0,0].join()
  351. var str2=this.weekdaysListTemp.join()
  352. if(str1!=str2){
  353. this.typeShowIndex=2;
  354. this.customPopup=false
  355. this.typeShow=false;
  356. this.weekdaysList=this.weekdaysListTemp;
  357. }else{
  358. uni.showToast({
  359. title: "请至少勾选一项",
  360. icon: "none"
  361. })
  362. }
  363. },
  364. checkboxChange(e){
  365. var sz=e.detail.value;
  366. this.weekdaysListTemp=[0,0,0,0,0,0,0]
  367. for(var i in sz){
  368. var k=sz[i]
  369. this.weekdaysListTemp[k]=1
  370. }
  371. console.log(this.weekdaysListTemp)
  372. },
  373. submitApi(){
  374. this.formData.weekdays=""
  375. this.formData.switchStatus=this.list[this.type].value
  376. if(!this.startTime){
  377. var br=false
  378. if(this.formData.switchStatus==1){
  379. br=true
  380. }
  381. if(this.formData.switchStatus==2){
  382. br=true
  383. }
  384. if(this.formData.switchStatus==3){
  385. br=true
  386. }
  387. if(br){
  388. uni.showToast({
  389. title: "请设置定时开启",
  390. icon: "none"
  391. })
  392. return
  393. }
  394. }
  395. if(!this.endTime){
  396. var br=false
  397. if(this.formData.switchStatus==0){
  398. br=true
  399. }
  400. if(this.formData.switchStatus==2){
  401. br=true
  402. }
  403. if(this.formData.switchStatus==3){
  404. br=true
  405. }
  406. if(br){
  407. uni.showToast({
  408. title: "请设置定时关闭",
  409. icon: "none"
  410. })
  411. return
  412. }
  413. }
  414. if(this.formData.switchStatus==0){
  415. this.formData.startTime=this.endTime
  416. }else{
  417. this.formData.startTime=this.startTime
  418. this.formData.endTime=this.endTime
  419. }
  420. if(!this.formData.endTime){
  421. this.formData.endTime=""
  422. }
  423. if(this.typeShowIndex==0){
  424. this.formData.type="1"
  425. }else{
  426. this.formData.type="2"
  427. var weekdaysList=this.weekdaysList
  428. if(this.typeShowIndex==1){
  429. this.formData.weekdays='1,2,3,4,5,6,7'
  430. }
  431. if(this.typeShowIndex==2){
  432. for(var i in weekdaysList){
  433. var day=weekdaysList[i]
  434. if(day==1){
  435. if(this.formData.weekdays!=""){
  436. this.formData.weekdays+=","
  437. }
  438. this.formData.weekdays+=(parseInt(i)+1)
  439. }
  440. }
  441. }
  442. }
  443. if(this.formData.switchStatus==3&&this.maxPower==''){
  444. uni.showToast({
  445. title: "请填写最大功率阈值(kw)",
  446. icon: "none"
  447. })
  448. return
  449. }else{
  450. this.formData.maxPower=this.maxPower;
  451. if(!this.formData.maxPower){
  452. this.formData.maxPower=''
  453. }
  454. }
  455. uni.showLoading({
  456. title: "加载中",
  457. mask: true,
  458. })
  459. API.saveSwitch(this.formData).then((response) => {
  460. //uni.hideLoading();
  461. //this.getMeterTimerListReady=true
  462. //this.timerSwitchList=response.data.timerSwitchList;
  463. uni.navigateBack();
  464. }).catch(error => {
  465. uni.showToast({
  466. title: error,
  467. icon: "none"
  468. })
  469. })
  470. }
  471. }
  472. }
  473. </script>
  474. <style lang="scss" scoped>
  475. /deep/.u-slot-right {
  476. margin-right: 32rpx;
  477. img {
  478. width: 48rpx;
  479. height: 48rpx;
  480. }
  481. }
  482. .time-group {
  483. background-color: #fff;
  484. .time-item {
  485. padding: 24rpx 0;
  486. margin: 0 32rpx;
  487. display: flex;
  488. justify-content: space-between;
  489. align-items: center;
  490. border-bottom: 1px solid rgba(221, 221, 221, 1);
  491. .time {
  492. .time-slot {
  493. color: rgba(16, 16, 16, 1);
  494. font-size: 32rpx;
  495. }
  496. .type {
  497. color: rgba(119, 119, 119, 1);
  498. }
  499. }
  500. }
  501. .time-item:last-of-type {
  502. border: none;
  503. }
  504. }
  505. .weeklistclassSpan:last-child{
  506. display: none;
  507. }
  508. // 重复类型
  509. .repeatType {
  510. .headline {
  511. color: rgba(16, 16, 16, 1);
  512. font-size: 36rpx;
  513. margin-top: 32rpx;
  514. font-weight: bold;
  515. text-align: center;
  516. }
  517. .type-group {
  518. margin-top: 24rpx;
  519. .item {
  520. display: flex;
  521. align-items: center;
  522. justify-content: space-between;
  523. height: 96rpx;
  524. line-height: 96rpx;
  525. border-bottom: 1px solid rgba(245,245,245,1);
  526. padding: 0 32rpx;
  527. }
  528. .time-item:last-of-type{
  529. border: none;
  530. }
  531. .item-title {
  532. color: rgb(16, 16, 16);
  533. font-size: 32rpx;
  534. }
  535. .item-icon1{
  536. display: none;
  537. }
  538. .item-icon2{
  539. display: block;
  540. }
  541. .item-title-checked {
  542. color: rgba(22, 119, 255, 1);
  543. .item-title {
  544. color: rgba(22, 119, 255, 1);
  545. font-size: 32rpx;
  546. }
  547. .item-icon1{
  548. display: block;
  549. }
  550. .item-icon2{
  551. display: none;
  552. }
  553. }
  554. }
  555. }
  556. // 自定义重复
  557. .custom,
  558. .thresholds {
  559. padding: 32rpx 0;
  560. .headline {
  561. color: rgba(16, 16, 16, 1);
  562. font-size: 36rpx;
  563. margin-bottom: 32rpx;
  564. font-weight: bold;
  565. text-align: center;
  566. }
  567. .radio-group {
  568. .radio-item {
  569. padding: 0 32rpx;
  570. display: flex;
  571. align-items: center;
  572. justify-content: space-between;
  573. height: 96rpx;
  574. line-height: 96rpx;
  575. border-bottom: 1px solid rgba(245,245,245,1);
  576. .item-title {
  577. color: rgba(16, 16, 16, 1);
  578. font-size: 32rpx;
  579. }
  580. }
  581. }
  582. .btn-group {
  583. display: flex;
  584. align-items: center;
  585. justify-content: space-between;
  586. padding: 0 32rpx;
  587. .btn {
  588. width: 328rpx;
  589. height: 80rpx;
  590. line-height: 80rpx;
  591. font-size: 32rpx;
  592. border-radius: 4px;
  593. text-align: center;
  594. margin-top: 24rpx;
  595. }
  596. .cancel {
  597. background-color: rgba(222, 225, 228, 1);
  598. color: rgba(51, 51, 51, 1);
  599. }
  600. .confirm {
  601. background-color: rgba(22, 119, 255, 1);
  602. color: rgba(255, 255, 255, 1);
  603. }
  604. }
  605. }
  606. /deep/.u-drawer-content-visible {
  607. border-radius: 12px 12px 0 0;
  608. }
  609. /deep/uni-input{
  610. background-color: rgba(241,242,245,1);
  611. color: rgba(119,119,119,1);
  612. font-size: 36rpx;
  613. height: 80rpx;
  614. padding-left: 16rpx;
  615. }
  616. </style>