plan.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <view class="container">
  3. <view class="header-image">
  4. <image style="width: 100%" :src="imgUrl+'/precharge/precharge.png'"/>
  5. </view>
  6. <view class="charge-type">
  7. <view class="charge-type-container">
  8. <view @click="changeType(0)" class="type-left" :class="chargeType == 0?'type-choose':''">单次</view>
  9. <view @click="changeType(1)" class="type-right" :class="chargeType == 1?'type-choose':''">自定义</view>
  10. </view>
  11. </view>
  12. <view class="time-area" v-if="chargeType == 0">
  13. <!-- <view class="one-date">{{ oneTime.date }}</view>-->
  14. <view class="one-time">{{ oneTime.time }}</view>
  15. <view class="one-setting"><uni-datetime-picker @change="changeDate" v-model="oneTime.time" :hide-second ="true">选择时间</uni-datetime-picker></view>
  16. </view>
  17. <view class="time-area" style="padding-left:0px;padding-right: 0px" v-if="chargeType == 1">
  18. <view style=";text-align: center;">
  19. <view class="one-date" style="display:inline-block;font-size: 12px;padding:0 2px" v-for="item in array">{{ item.name }}</view>
  20. </view>
  21. <view class="one-setting" @click="showChoose">选择重复日期</view>
  22. <view class="one-time">{{time}}</view>
  23. <picker mode="time" start="00:00" end="23:59" @change="bindTimeChange">
  24. <view class="one-setting">选择时间</view>
  25. </picker>
  26. </view>
  27. <view style="margin:5vh 7vw;">
  28. <button @click="saveConfig" style="background: #0E9F9B;color: white;" type="default" >确认</button>
  29. </view>
  30. <uni-popup ref="popup" type="bottom">
  31. <view class="uni-list">
  32. <checkbox-group @change="checkboxChange">
  33. <label class="uni-list-cell uni-list-cell-pd" v-for="item in items" :key="item.value">
  34. <view style="width: 90%">{{item.name}}</view>
  35. <view>
  36. <checkbox :value="item.value" :checked="item.checked" />
  37. </view>
  38. </label>
  39. </checkbox-group>
  40. <view style="text-align: center">
  41. <button size="mini" @click="chooseDay" style="background: #1cbbb4;color: white;" type="default" >确认</button>
  42. </view>
  43. </view>
  44. </uni-popup>
  45. </view>
  46. </template>
  47. <script>
  48. import {save} from '@/api/device/plan.js'
  49. export default {
  50. data() {
  51. return {
  52. deviceId: "",
  53. ccid:"",
  54. repeatTime: '',
  55. cb:"",
  56. chargeType:0,
  57. oneTime:{
  58. time:"",
  59. },
  60. time:"",
  61. index:0,
  62. array: [],
  63. items: [{
  64. value: '7',
  65. name: '周日'
  66. },
  67. {
  68. value: '1',
  69. name: '周一',
  70. },
  71. {
  72. value: '2',
  73. name: '周二'
  74. },
  75. {
  76. value: '3',
  77. name: '周三'
  78. },
  79. {
  80. value: '4',
  81. name: '周四'
  82. },
  83. {
  84. value: '5',
  85. name: '周五'
  86. },
  87. {
  88. value: '6',
  89. name: '周六'
  90. }
  91. ]
  92. }
  93. },
  94. computed: {
  95. imgUrl: function () {
  96. return getApp().globalData.config.imgUrl;
  97. }
  98. },
  99. onLoad(opt){
  100. this.deviceId = opt.id;
  101. this.ccid = opt.ccid;
  102. },
  103. methods: {
  104. chooseDay(){
  105. this.array = [];
  106. let items = this.items;
  107. for (var i = 0, lenI = items.length; i < lenI; ++i) {
  108. const item = items[i]
  109. if(item.checked){
  110. this.array.push(item)
  111. }
  112. }
  113. this.$refs.popup.close();
  114. },
  115. checkboxChange: function (e) {
  116. var items = this.items,
  117. values = e.detail.value;
  118. for (var i = 0, lenI = items.length; i < lenI; ++i) {
  119. const item = items[i]
  120. if(values.includes(item.value)){
  121. this.$set(item,'checked',true)
  122. }else{
  123. this.$set(item,'checked',false)
  124. }
  125. }
  126. },
  127. showChoose(){
  128. this.$refs.popup.open("center");
  129. var items = this.items;
  130. let values = [];
  131. for (let i = 0; i < this.array.length; i++) {
  132. let curItem = this.array[i];
  133. values.push(curItem.value);
  134. }
  135. for (var i = 0, lenI = items.length; i < lenI; ++i) {
  136. const item = items[i]
  137. if(values.includes(item.value)){
  138. this.$set(item,'checked',true)
  139. }else{
  140. this.$set(item,'checked',false)
  141. }
  142. }
  143. },
  144. bindTimeChange(e){
  145. let time = e.detail;
  146. this.time = time.value;
  147. this.repeatTime = time.value;
  148. },
  149. open(){
  150. // 通过组件定义的ref调用uni-popup方法 ,如果传入参数 ,type 属性将失效 ,仅支持 ['top','left','bottom','right','center']
  151. this.$refs.popup.open('top')
  152. },
  153. changeDate(date){
  154. let hasMin = date.split(":")
  155. let self = this;
  156. if(hasMin.length == 1){
  157. setTimeout(function(){
  158. date = date.trim();
  159. self.oneTime.time = date+" 00:00";
  160. },100);
  161. }
  162. },
  163. changeType(type){
  164. if(this.chargeType == type){
  165. return;
  166. }
  167. this.chargeType = type;
  168. this.array = [];
  169. this.time = "";
  170. this.oneTime.time = "";
  171. },
  172. async saveConfig() {
  173. // debugger
  174. // const time = new Date(this.chargeType === 0 ? this.oneTime.time : this.time);
  175. // const minute = time.getMinutes();
  176. // time.setMinutes(minute + 1, 0, 0); // 将时间的秒数和毫秒数设置为 0,并将分钟数加 1。
  177. // const repeatTime = time.toISOString(); // 将时间对象转换成 ISO 格式的字符串。
  178. // const repeatTimeString = repeatTime.substring(0, repeatTime.length - 1); // 去除字符串末尾的 "Z" 字符。
  179. let runTime = null;
  180. if (this.chargeType === 0) {
  181. runTime = this.oneTime.time;
  182. if(!runTime){
  183. this.$modal.showToast("请设置时间");
  184. return;
  185. }
  186. }else{
  187. if(!this.repeatTime || this.array.length == 0){
  188. this.$modal.showToast("请设置重复时间");
  189. return;
  190. }
  191. }
  192. const params = {
  193. // createTime: new Date().toLocaleTimeString(),
  194. planType: this.chargeType === 0 ? 1 : 2, // 计划类型(单次或自定义)
  195. status: 1, // 状态(默认为未完成)
  196. runTime: runTime,
  197. repeatDays: this.chargeType === 1 ? this.array.map(item => item.value).join(',') : '',
  198. repeatTime: this.chargeType === 1 ? this.repeatTime : '',
  199. deviceId: this.deviceId, // 设备 ID
  200. ccid:this.ccid
  201. };
  202. console.log(params);
  203. save(params).then(res => {
  204. this.$modal.loading("预约成功");
  205. setTimeout(()=>{
  206. uni.navigateBack();
  207. },1000)
  208. })
  209. },
  210. }
  211. }
  212. </script>
  213. <style>
  214. .container{
  215. position: absolute;
  216. inset:0;
  217. background: rgb(249, 252, 255);
  218. }
  219. .header-image{
  220. width: 100%;
  221. }
  222. .charge-type{
  223. text-align: center;
  224. width: 100%;
  225. margin-top:2vh;
  226. }
  227. .charge-type-container{
  228. margin:0 20vw;
  229. border:1px solid #0E9F9B;
  230. border-radius: 2px;
  231. }
  232. .charge-type-container view{
  233. display: inline-block;
  234. padding:2vw;
  235. width: 50%;
  236. border-radius: 2px;
  237. }
  238. .type-left{
  239. }
  240. .type-choose{
  241. background: #0E9F9B;
  242. color:white;
  243. }
  244. .type-right{
  245. }
  246. .time-area{
  247. border: 1px solid #E6E6E6;
  248. border-radius: 10px;
  249. margin:0 11vh;
  250. margin-top:5vh;
  251. height: 25vh;
  252. text-align: center;
  253. padding: 8vw;
  254. line-height: 5vh;
  255. }
  256. .one-date{
  257. text-align: center;
  258. color: #0E9F9B;
  259. }
  260. .one-time{
  261. font-weight: bold;
  262. color: #0E9F9B;
  263. font-size: 24px;
  264. }
  265. .one-setting{
  266. font-weight: 400;
  267. color: #B2B2B2;
  268. }
  269. .uni-list-cell {
  270. justify-content: flex-start
  271. }
  272. .uni-list-cell{
  273. display: flex;
  274. flex-direction: row;
  275. padding:10px 10px
  276. }
  277. .uni-list{
  278. background: rgb(249, 252, 255);
  279. width: 300px;
  280. }
  281. </style>