alarmClockItem.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. <template>
  2. <view>
  3. <view class="test">
  4. <view>{{$t('alarmClock.title')}}</view>
  5. <p class="time">{{time}}</p>
  6. <button class="btime" type="primary" @click="onShowDatePicker('time')">{{$t('alarmClock.chooseTime')}}</button>
  7. </view>
  8. <mx-date-picker :show="showPicker" :type="type" :value="value" :show-tips="true" :begin-text="'1'"
  9. :end-text="'2'" :show-seconds="true" @confirm="onSelected" @cancel="onSelected" />
  10. <view class="example-body">
  11. <uni-badge class="uni-badge-left-margin" :inverted="Sunday" :text="$t('alarmClock.qi')" type="primary" @click="wek(7)" />
  12. <uni-badge class="uni-badge-left-margin" :inverted="Monday" :text="$t('alarmClock.yi')" type="primary" @click="wek(1)" />
  13. <uni-badge class="uni-badge-left-margin" :inverted="Tuesday" :text="$t('alarmClock.er')" type="primary" @click="wek(2)" />
  14. <uni-badge class="uni-badge-left-margin" :inverted="Wednesday" :text="$t('alarmClock.san')" type="primary" @click="wek(3)" />
  15. <uni-badge class="uni-badge-left-margin" :inverted="Thursday" :text="$t('alarmClock.si')" type="primary" @click="wek(4)" />
  16. <uni-badge class="uni-badge-left-margin" :inverted="Friday" :text="$t('alarmClock.wu')" type="primary" @click="wek(5)" />
  17. <uni-badge class="uni-badge-left-margin" :inverted="Saturday" :text="$t('alarmClock.liu')" type="primary" @click="wek(6)" />
  18. </view>
  19. <view class="line"></view>
  20. <view class="uni-list-cell">
  21. <view class="uni-list-cell-left">
  22. {{$t('alarmClock.type')}}:
  23. </view>
  24. <view class="uni-list-cell-db">
  25. <picker @change="bindPickerChange" :value="indexType" :range="array">
  26. <view class="uni-input">{{array[indexType]}}</view>
  27. </picker>
  28. </view>
  29. </view>
  30. <!-- //查找 -->
  31. <view class="search">
  32. <view class="search-title">
  33. {{$t('dosugar.equipmentClientID')}}
  34. </view>
  35. <view class="search-input">
  36. <input type="text" :placeholder="$t('dosugar.placeholder')" v-model="searchClientId" />
  37. </view>
  38. <view class="search-button">
  39. <button type="primary" class="" @click="search()">
  40. <p class="">{{$t('alarmClock.add')}}</P>
  41. </button>
  42. </view>
  43. </view>
  44. <!-- //多选下拉框 -->
  45. <view class="select-item">
  46. <ld-select :multiple="true" :list="equipmentNameList" label-key="label" value-key="value"
  47. :cancel-text="$t('common.cancel')" :confirm-text="$t('common.ok')"
  48. :placeholder="$t('alarmClock.placeholder')" clearable v-model="equipmentIds" @change="selectChange2"></ld-select>
  49. </view>
  50. <view class="uni-list">
  51. <view class="uni-list-cell uni-list-cell-pd">
  52. <view class="uni-list-cell-db">{{$t('alarmClock.switchChange')}}</view>
  53. <switch :checked="status" @change="switchChange" />
  54. </view>
  55. </view>
  56. <view class="search">
  57. <view class="search-title">
  58. {{$t('alarmClock.name')}}:
  59. </view>
  60. <view class="search-input2">
  61. <input type="text" v-model="name" />
  62. </view>
  63. </view>
  64. <view class="line"></view>
  65. <!-- //提交按钮 -->
  66. <view class="tr">
  67. <button v-if="clock=='add'" type="primary" formType="submit" @click="add()" class="button">
  68. <p class="p1">{{$t('alarmClock.add')}}</p>
  69. </button>
  70. <button v-if="clock!='add'" v-show="ushow" type="primary" formType="submit" @click="update()"
  71. class="button">
  72. <p class="p1">{{$t('alarmClock.update')}}</p>
  73. </button>
  74. <button v-if="clock!='add'" v-show="ushow" type="warn" formType="submit" @click="delet()" class="button">
  75. <p class="p1">{{$t('alarmClock.delete')}}</p>
  76. </button>
  77. </view>
  78. </view>
  79. </template>
  80. <script>
  81. import {
  82. mapState,
  83. mapActions,
  84. mapMutations
  85. } from 'vuex'
  86. import MxDatePicker from "../../components/mx-datepicker/mx-datepicker.vue";
  87. // import ldSelect from "../../components/ld-select/ld-select.vue";
  88. import ldSelect from "../../components/ld-select/ld-select.vue"
  89. import likeButton from "../../components/like-button/like-button.vue";
  90. export default {
  91. components: {
  92. MxDatePicker,
  93. ldSelect,
  94. likeButton
  95. },
  96. data() {
  97. return {
  98. showPicker: false,
  99. // date: '2019/01/01',
  100. time: '22:00:00',
  101. // datetime: '2019/01/01 15:00:12',
  102. // range: ['2019/01/01','2019/01/06'],
  103. // rangetime: ['2019/01/08 14:00','2019/01/16 13:59'],
  104. type: 'rangetime',
  105. value: '',
  106. //0:炉头开启,1:炉头关闭,2:开始休眠,3:结束休眠
  107. // array: ['开启炉头', '关闭炉头', '开始休眠', '结束休眠'],
  108. array: [this.$t('alarmClock.kailutou'), this.$t('alarmClock.guanlutou'), this.$t('alarmClock.kaixiumian'), this.$t('alarmClock.guanxiumian')],
  109. indexType: 0,
  110. Sunday: true,
  111. Monday: true,
  112. Tuesday: true,
  113. Wednesday: true,
  114. Thursday: true,
  115. Friday: true,
  116. Saturday: true,
  117. name:'',
  118. week: '1,2,3,4,5,6,7,',
  119. searchClientId: null,
  120. equipmentName: null,
  121. equipmentNameList: [],
  122. globalUser: {},
  123. equipmentIds: [],
  124. clock: null,
  125. status: true,
  126. ushow: false
  127. }
  128. },
  129. onShow() {
  130. this.globalUser = uni.getStorageSync("globalUser");
  131. this.clock = uni.getStorageSync("clock");
  132. uni.setNavigationBarTitle({
  133. title: this.$t('alarmClock.setAlarm')
  134. });
  135. var token = uni.getStorageSync("token");
  136. if (this.clock == "add") {
  137. this.Sunday = false;
  138. this.Monday = false;
  139. this.Tuesday = false;
  140. this.Wednesday = false;
  141. this.Thursday = false;
  142. this.Friday = false;
  143. this.Saturday = false;
  144. }
  145. if (token.length > 1) {
  146. this.getEquipmentListData();
  147. } else {
  148. uni.reLaunch({
  149. url: '../../../pages/Login/Login',
  150. });
  151. }
  152. },
  153. onLoad() {
  154. let that = this
  155. // if (that.clock == "add") {
  156. // this.Sunday = false;
  157. // this.Monday = false;
  158. // this.Tuesday = false;
  159. // this.Wednesday = false;
  160. // this.Thursday = false;
  161. // this.Friday = false;
  162. // this.Saturday = false;
  163. // }
  164. // 回显
  165. setTimeout(function() {
  166. if (that.clock != "add") {
  167. that.selectOne();
  168. }
  169. }, 2000)
  170. // 回显
  171. setTimeout(function() {
  172. if (that.clock != "add") {
  173. that.ushow = true;
  174. }
  175. }, 4000)
  176. },
  177. methods: {
  178. ...mapActions('chart', ['getEquipmentListByUser', 'addAlarmClock', 'addAlarmClockItem', 'updateAlarmClock']),
  179. getEquipmentListData() {
  180. this.getEquipmentListByUser(this.globalUser)
  181. .then(data => {
  182. // this.merchantList = data;
  183. // console.log("1223");
  184. var listName = data[0].equipmentList;
  185. var equipmentNameList = this.equipmentNameList;
  186. var co = {};
  187. co["value"] = 'all';
  188. co["label"] = this.$t('common.allDevice');
  189. equipmentNameList.push(co);
  190. for (var i = 0; i < listName.length; i++) {
  191. var cov = {};
  192. cov["value"] = listName[i].id;
  193. cov["label"] = this.$t('common.name') + listName[i].name + ' , '+ this.$t('common.ID') + listName[i].clientId.substring(
  194. listName[i].clientId.length - 6, listName[i].clientId.length);
  195. equipmentNameList.push(cov);
  196. }
  197. this.equipmentNameList = equipmentNameList;
  198. var listId = data[0].id;
  199. if (listId != null && listId != '1') {
  200. uni.setStorageSync("listName", listName);
  201. }
  202. uni.stopPullDownRefresh();
  203. }, _ => void uni.stopPullDownRefresh());
  204. },
  205. selectOne() {
  206. var token = uni.getStorageSync("token");
  207. var id = this.clock;
  208. var that = this;
  209. uni.request({
  210. url: this.serverurl + '/TAlarmClock/selectOne',
  211. data: {
  212. "id": id
  213. },
  214. header: {
  215. 'token': token
  216. },
  217. method: "POST",
  218. success: (res) => {
  219. if (res.data.code) {
  220. var alarmClock = res.data.data;
  221. // console.log("list");
  222. var status = alarmClock.status;
  223. this.time = alarmClock.hour;
  224. if (status == '0') {
  225. this.status = false;
  226. }
  227. if (status == '1') {
  228. this.status = true;
  229. }
  230. var equipmentIds = alarmClock.equipmentIds;
  231. that.addEids(equipmentIds);
  232. this.name = alarmClock.name;
  233. var week = alarmClock.week;
  234. this.week = week;
  235. if (week != null || week != '') {
  236. var w = week.split(",").sort();
  237. for (var j = 0; j < w.length; j++) {
  238. var t = w[j];
  239. switch (t) {
  240. case "1":
  241. this.Monday = false;
  242. break;
  243. case "2":
  244. this.Tuesday = false;
  245. break;
  246. case "3":
  247. this.Wednesday = false;
  248. break;
  249. case "4":
  250. this.Thursday = false;
  251. break;
  252. case "5":
  253. this.Friday = false;
  254. break;
  255. case "6":
  256. this.Saturday = false;
  257. break;
  258. case "7":
  259. this.Sunday = false;
  260. break;
  261. default:
  262. }
  263. }
  264. var type = alarmClock.type;
  265. switch (type) { //0:炉头开启,1:炉头关闭,2:开始休眠,3:结束休眠
  266. case "0":
  267. this.indexType = 0;
  268. break;
  269. case "1":
  270. this.indexType = 1;
  271. break;
  272. case "2":
  273. this.indexType = 2;
  274. break;
  275. case "3":
  276. this.indexType = 3;
  277. break;
  278. default:
  279. }
  280. }
  281. } else {
  282. uni.showToast({
  283. title: res.data.message,
  284. duration: 2000
  285. });
  286. }
  287. },
  288. });
  289. },
  290. onShowDatePicker(type) { //显示
  291. this.type = type;
  292. this.showPicker = true;
  293. this.value = this[type];
  294. },
  295. onSelected(e) { //选择
  296. this.showPicker = false;
  297. if (e) {
  298. this[this.type] = e.value;
  299. //选择的值
  300. // console.log('value => ' + e.value);
  301. //原始的Date对象
  302. // console.log('date => ' + e.date);
  303. }
  304. },
  305. bindPickerChange: function(e) {
  306. this.indexType = e.target.value
  307. },
  308. wek(num) {
  309. if (num == 1) {
  310. if (this.Monday) {
  311. this.Monday = false;
  312. this.changWeek(1, num);
  313. } else {
  314. this.Monday = true;
  315. this.changWeek(0, num);
  316. }
  317. }
  318. if (num == 2) {
  319. if (this.Tuesday) {
  320. this.Tuesday = false;
  321. this.changWeek(1, num);
  322. } else {
  323. this.Tuesday = true;
  324. this.changWeek(0, num);
  325. }
  326. }
  327. if (num == 3) {
  328. if (this.Wednesday) {
  329. this.Wednesday = false;
  330. this.changWeek(1, num);
  331. } else {
  332. this.Wednesday = true;
  333. this.changWeek(0, num);
  334. }
  335. }
  336. if (num == 4) {
  337. if (this.Thursday) {
  338. this.Thursday = false;
  339. this.changWeek(1, num);
  340. } else {
  341. this.Thursday = true;
  342. this.changWeek(0, num);
  343. }
  344. }
  345. if (num == 5) {
  346. if (this.Friday) {
  347. this.Friday = false;
  348. this.changWeek(1, num);
  349. } else {
  350. this.Friday = true;
  351. this.changWeek(0, num);
  352. }
  353. }
  354. if (num == 6) {
  355. if (this.Saturday) {
  356. this.Saturday = false;
  357. this.changWeek(1, num);
  358. } else {
  359. this.Saturday = true;
  360. this.changWeek(0, num);
  361. }
  362. }
  363. if (num == 7) {
  364. if (this.Sunday) {
  365. this.Sunday = false;
  366. this.changWeek(1, num);
  367. } else {
  368. this.Sunday = true;
  369. this.changWeek(0, num);
  370. }
  371. }
  372. },
  373. changWeek(type, num) {
  374. var week = this.week;
  375. var we = '';
  376. //减
  377. if (type == 0) {
  378. var w = week.split(",").sort();
  379. for (var j = 1; j < w.length; j++) {
  380. var t = w[j];
  381. if (t != num) {
  382. we = we + t + ","
  383. }
  384. }
  385. }
  386. //加
  387. if (type == 1) {
  388. if (week == '' || week == null) {
  389. we = num + ","
  390. } else {
  391. week += num + ",";
  392. var w = week.split(",").sort();
  393. for (var j = 1; j < w.length; j++) {
  394. var t = w[j];
  395. we = we + t + ","
  396. }
  397. }
  398. }
  399. this.week = we;
  400. // console.log('we => ' + this.week);
  401. },
  402. addEids(equipmentIds) {
  403. // console.log('equipmentIds' + equipmentIds);
  404. var eids = equipmentIds.split(",");
  405. var idss = this.equipmentIds;
  406. var is = this.equipmentNameList
  407. for (var k = 0; k < eids.length; k++) {
  408. var id = eids[k];
  409. if (id != "" && id != '') {
  410. this.equipmentIds.push(parseInt(id));
  411. }
  412. }
  413. },
  414. search() {
  415. // console.log("search");
  416. var clientId = this.searchClientId;
  417. var list = uni.getStorageSync("listName");
  418. var n = 0;
  419. for (var i = 0; i < list.length; i++) {
  420. var code = list[i].clientId.substring(list[i].clientId.length - 6, list[i].clientId.length);
  421. if (code == clientId) {
  422. n++;
  423. var id = list[i].id;
  424. this.equipmentIds.push(id);
  425. break;
  426. }
  427. }
  428. if (n == 0) {
  429. uni.showModal({
  430. title: this.$t('common.tip'),
  431. content: this.$t('common.noDevice'),
  432. success: (res) => {
  433. }
  434. })
  435. }
  436. if (n > 0) {
  437. uni.showModal({
  438. title: this.$t('common.tip'),
  439. content: this.$t('common.addDevice'),
  440. success: (res) => {
  441. }
  442. })
  443. }
  444. },
  445. selectChange2(val) {
  446. //有改动文件 import likeButton from "../../components/like-button/like-button.vue";
  447. if (val == "all") {
  448. this.equipmentIds = [];
  449. var list = uni.getStorageSync("listName");
  450. for (var i = 0; i < list.length; i++) {
  451. this.equipmentIds.push(list[i].id);
  452. }
  453. } else {
  454. this.equipmentIds = val
  455. }
  456. // console.log('this.equipmentIds => ' + this.equipmentIds);
  457. },
  458. switchChange: function(e) {
  459. this.status = e.target.value;
  460. },
  461. add() {
  462. const param = {};
  463. param['week'] = this.week;
  464. param['hour'] = this.time;
  465. param['name'] = this.name;
  466. if (this.status) {
  467. param['status'] = "1";
  468. } else {
  469. param['status'] = "0";
  470. }
  471. param['type'] = this.indexType;
  472. var eids = '';
  473. var ids = this.equipmentIds;
  474. for (var j = 0; j < ids.length; j++) {
  475. var t = ids[j];
  476. eids = eids + t + ","
  477. }
  478. param['equipmentIds'] = eids;
  479. param['adminId'] = this.globalUser.id;
  480. // console.log("param =>" + param);
  481. this.addAlarmClock(param)
  482. .then(res => {
  483. if (res.code) {
  484. this.addAlarmClockItems(res.data);
  485. }
  486. // uni.showModal({
  487. // title: "提示",
  488. // content: res.message,
  489. // success: (re) => {
  490. // if (re.confirm) {
  491. // uni.reLaunch({
  492. // url: 'alarmClockList',
  493. // });
  494. // }
  495. // }
  496. // })
  497. uni.stopPullDownRefresh();
  498. }, _ => void uni.stopPullDownRefresh());
  499. },
  500. addAlarmClockItems(alarmClock) {
  501. console.log("alarmClock =>" + alarmClock);
  502. this.addAlarmClockItem(alarmClock)
  503. .then(res => {
  504. uni.showModal({
  505. title: this.$t('common.tip'),
  506. content: res.message,
  507. success: (re) => {
  508. if (re.confirm) {
  509. // uni.navigateTo({
  510. // url: 'alarmClockList',
  511. // });
  512. uni.navigateBack({
  513. url: 'alarmClockList'
  514. });
  515. }
  516. }
  517. })
  518. uni.stopPullDownRefresh();
  519. }, _ => void uni.stopPullDownRefresh());
  520. },
  521. update() {
  522. const param = {};
  523. param['id'] = this.clock;
  524. param['week'] = this.week;
  525. param['name'] = this.name;
  526. param['hour'] = this.time;
  527. if (this.status) {
  528. param['status'] = "1";
  529. } else {
  530. param['status'] = "0";
  531. }
  532. param['type'] = this.indexType;
  533. var eids = '';
  534. var ids = this.equipmentIds;
  535. for (var j = 0; j < ids.length; j++) {
  536. var t = ids[j];
  537. eids = eids + t + ","
  538. }
  539. param['equipmentIds'] = eids;
  540. param['adminId'] = this.globalUser.id;
  541. this.updateAlarmClock(param)
  542. .then(res => {
  543. uni.showToast({
  544. title: res.message,
  545. duration: 2000
  546. });
  547. uni.stopPullDownRefresh();
  548. }, _ => void uni.stopPullDownRefresh());
  549. },
  550. delet() {
  551. uni.showModal({
  552. title: this.$t('common.tip'),
  553. content: this.$t('alarmClock.isDelete'),
  554. success: (res) => {
  555. if (res.confirm) {
  556. var eids = '';
  557. var ids = this.equipmentIds;
  558. for (var j = 0; j < ids.length; j++) {
  559. var t = ids[j];
  560. eids = eids + t + ","
  561. }
  562. var token = uni.getStorageSync("token");
  563. uni.request({
  564. url: this.serverurl + '/TAlarmClock/delete',
  565. data: {
  566. "id": this.clock,
  567. "adminId": this.globalUser.id,
  568. "equipmentIds": eids,
  569. "type": this.indexType
  570. },
  571. header: {
  572. 'token': token
  573. },
  574. method: "POST",
  575. success: (res) => {
  576. uni.showModal({
  577. title: this.$t('common.tip'),
  578. content: res.data.message,
  579. success: (re) => {
  580. if (re.confirm) {
  581. // uni.navigateTo({
  582. // url: 'alarmClockList',
  583. // });
  584. uni.navigateBack({
  585. url: 'alarmClockList'
  586. });
  587. }
  588. }
  589. })
  590. },
  591. });
  592. }
  593. }
  594. });
  595. },
  596. }
  597. }
  598. </script>
  599. <style>
  600. .test {
  601. text-align: center;
  602. padding: 10px 0;
  603. }
  604. .time {
  605. font-size: 78upx;
  606. }
  607. .btime {
  608. margin: 20upx;
  609. font-size: 28upx;
  610. }
  611. /* button {
  612. margin: 20upx;
  613. font-size: 28upx;
  614. } */
  615. /* #ifdef MP-ALIPAY */
  616. .uni-badge {
  617. margin-left: 20rpx;
  618. }
  619. /* #endif */
  620. .uni-badge {
  621. font-size: 40upx;
  622. }
  623. .example-body {
  624. flex-direction: row;
  625. justify-content: flex-start;
  626. padding-bottom: 15upx;
  627. font-size: 40upx;
  628. }
  629. .uni-badge-left-margin {
  630. font-size: 40upx;
  631. margin-left: 50upx;
  632. }
  633. .uni-list-cell {
  634. padding-top: 20upx;
  635. padding-bottom: 10upx;
  636. font-size: 35upx;
  637. }
  638. .line {
  639. height: 2upx;
  640. background: #8C959F;
  641. }
  642. .search {
  643. width: 100%;
  644. padding-top: 15upx;
  645. padding-bottom: 25upx;
  646. display: flex;
  647. align-items: center;
  648. flex-direction: row;
  649. justify-content: flex-start;
  650. }
  651. .search-title {
  652. width: 28%;
  653. text-align: center;
  654. font-size: 26upx;
  655. font-family: "PingFang-SC-Bold";
  656. }
  657. .search-input {
  658. width: 45%;
  659. /* text-align: center; */
  660. font-size: 26upx;
  661. font-family: "PingFang-SC-Bold";
  662. box-shadow: 0upx 0upx 20upx #D3D3D3;
  663. border-radius: 5upx;
  664. }
  665. .search-input2 {
  666. width: 65%;
  667. text-align: center;
  668. font-size: 26upx;
  669. font-family: "PingFang-SC-Bold";
  670. box-shadow: 0upx 0upx 20upx #D3D3D3;
  671. border-radius: 5upx;
  672. }
  673. .search-button {
  674. width: 20%;
  675. padding-left: 20upx;
  676. text-align: center;
  677. }
  678. .select-item {
  679. /* padding-top: 20upx; */
  680. }
  681. .tr {
  682. padding-top: 15upx;
  683. display: flex;
  684. flex-direction: row;
  685. justify-content: flex-start;
  686. font-size: 48upx;
  687. font-family: "PingFang-SC-Bold";
  688. position: fixed;
  689. bottom: 100upx;
  690. width: 100%;
  691. }
  692. .button {
  693. margin: 30px;
  694. width: 50%;
  695. }
  696. .p1 {
  697. font-size: 48upx;
  698. }
  699. </style>