plan.vue 8.4 KB

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