plan.vue 7.8 KB

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