autoOff.vue 17 KB

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