plan.vue 8.0 KB

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