alarmClockItem.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  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. this.equipmentNameList = [];
  185. var listName = data[0].equipmentList;
  186. var equipmentNameList = this.equipmentNameList;
  187. var co = {};
  188. co["value"] = 'all';
  189. co["label"] = this.$t('common.allDevice');
  190. equipmentNameList.push(co);
  191. console.log("设备1", equipmentNameList);
  192. for (var i = 0; i < listName.length; i++) {
  193. var cov = {};
  194. cov["value"] = listName[i].id;
  195. cov["label"] = this.$t('common.name') + listName[i].name + ' , '+ this.$t('common.ID') + listName[i].clientId.substring(
  196. listName[i].clientId.length - 6, listName[i].clientId.length);
  197. equipmentNameList.push(cov);
  198. }
  199. this.equipmentNameList = equipmentNameList;
  200. console.log("设备2", equipmentNameList);
  201. var listId = data[0].id;
  202. if (listId != null && listId != '1') {
  203. uni.setStorageSync("listName", listName);
  204. }
  205. uni.stopPullDownRefresh();
  206. }, _ => void uni.stopPullDownRefresh());
  207. },
  208. selectOne() {
  209. var token = uni.getStorageSync("token");
  210. var id = this.clock;
  211. var that = this;
  212. uni.request({
  213. url: this.serverurl + '/TAlarmClock/selectOne',
  214. data: {
  215. "id": id
  216. },
  217. header: {
  218. 'token': token
  219. },
  220. method: "POST",
  221. success: (res) => {
  222. if (res.data.code) {
  223. var alarmClock = res.data.data;
  224. // console.log("list");
  225. var status = alarmClock.status;
  226. this.time = alarmClock.hour;
  227. if (status == '0') {
  228. this.status = false;
  229. }
  230. if (status == '1') {
  231. this.status = true;
  232. }
  233. var equipmentIds = alarmClock.equipmentIds;
  234. that.addEids(equipmentIds);
  235. this.name = alarmClock.name;
  236. var week = alarmClock.week;
  237. this.week = week;
  238. if (week != null || week != '') {
  239. var w = week.split(",").sort();
  240. for (var j = 0; j < w.length; j++) {
  241. var t = w[j];
  242. switch (t) {
  243. case "1":
  244. this.Monday = false;
  245. break;
  246. case "2":
  247. this.Tuesday = false;
  248. break;
  249. case "3":
  250. this.Wednesday = false;
  251. break;
  252. case "4":
  253. this.Thursday = false;
  254. break;
  255. case "5":
  256. this.Friday = false;
  257. break;
  258. case "6":
  259. this.Saturday = false;
  260. break;
  261. case "7":
  262. this.Sunday = false;
  263. break;
  264. default:
  265. }
  266. }
  267. var type = alarmClock.type;
  268. switch (type) { //0:炉头开启,1:炉头关闭,2:开始休眠,3:结束休眠
  269. case "0":
  270. this.indexType = 0;
  271. break;
  272. case "1":
  273. this.indexType = 1;
  274. break;
  275. case "2":
  276. this.indexType = 2;
  277. break;
  278. case "3":
  279. this.indexType = 3;
  280. break;
  281. default:
  282. }
  283. }
  284. } else {
  285. uni.showToast({
  286. title: res.data.message,
  287. duration: 2000
  288. });
  289. }
  290. },
  291. });
  292. },
  293. onShowDatePicker(type) { //显示
  294. this.type = type;
  295. this.showPicker = true;
  296. this.value = this[type];
  297. },
  298. onSelected(e) { //选择
  299. this.showPicker = false;
  300. if (e) {
  301. this[this.type] = e.value;
  302. //选择的值
  303. // console.log('value => ' + e.value);
  304. //原始的Date对象
  305. // console.log('date => ' + e.date);
  306. }
  307. },
  308. bindPickerChange: function(e) {
  309. this.indexType = e.target.value
  310. },
  311. wek(num) {
  312. if (num == 1) {
  313. if (this.Monday) {
  314. this.Monday = false;
  315. this.changWeek(1, num);
  316. } else {
  317. this.Monday = true;
  318. this.changWeek(0, num);
  319. }
  320. }
  321. if (num == 2) {
  322. if (this.Tuesday) {
  323. this.Tuesday = false;
  324. this.changWeek(1, num);
  325. } else {
  326. this.Tuesday = true;
  327. this.changWeek(0, num);
  328. }
  329. }
  330. if (num == 3) {
  331. if (this.Wednesday) {
  332. this.Wednesday = false;
  333. this.changWeek(1, num);
  334. } else {
  335. this.Wednesday = true;
  336. this.changWeek(0, num);
  337. }
  338. }
  339. if (num == 4) {
  340. if (this.Thursday) {
  341. this.Thursday = false;
  342. this.changWeek(1, num);
  343. } else {
  344. this.Thursday = true;
  345. this.changWeek(0, num);
  346. }
  347. }
  348. if (num == 5) {
  349. if (this.Friday) {
  350. this.Friday = false;
  351. this.changWeek(1, num);
  352. } else {
  353. this.Friday = true;
  354. this.changWeek(0, num);
  355. }
  356. }
  357. if (num == 6) {
  358. if (this.Saturday) {
  359. this.Saturday = false;
  360. this.changWeek(1, num);
  361. } else {
  362. this.Saturday = true;
  363. this.changWeek(0, num);
  364. }
  365. }
  366. if (num == 7) {
  367. if (this.Sunday) {
  368. this.Sunday = false;
  369. this.changWeek(1, num);
  370. } else {
  371. this.Sunday = true;
  372. this.changWeek(0, num);
  373. }
  374. }
  375. },
  376. changWeek(type, num) {
  377. var week = this.week;
  378. var we = '';
  379. //减
  380. if (type == 0) {
  381. var w = week.split(",").sort();
  382. for (var j = 1; j < w.length; j++) {
  383. var t = w[j];
  384. if (t != num) {
  385. we = we + t + ","
  386. }
  387. }
  388. }
  389. //加
  390. if (type == 1) {
  391. if (week == '' || week == null) {
  392. we = num + ","
  393. } else {
  394. week += num + ",";
  395. var w = week.split(",").sort();
  396. for (var j = 1; j < w.length; j++) {
  397. var t = w[j];
  398. we = we + t + ","
  399. }
  400. }
  401. }
  402. this.week = we;
  403. // console.log('we => ' + this.week);
  404. },
  405. addEids(equipmentIds) {
  406. // console.log('equipmentIds' + equipmentIds);
  407. var eids = equipmentIds.split(",");
  408. var idss = this.equipmentIds;
  409. var is = this.equipmentNameList
  410. for (var k = 0; k < eids.length; k++) {
  411. var id = eids[k];
  412. if (id != "" && id != '') {
  413. this.equipmentIds.push(parseInt(id));
  414. }
  415. }
  416. },
  417. search() {
  418. // console.log("search");
  419. var clientId = this.searchClientId;
  420. var list = uni.getStorageSync("listName");
  421. var n = 0;
  422. for (var i = 0; i < list.length; i++) {
  423. var code = list[i].clientId.substring(list[i].clientId.length - 6, list[i].clientId.length);
  424. if (code == clientId) {
  425. n++;
  426. var id = list[i].id;
  427. if (!this.equipmentIds.includes(id)) {
  428. this.equipmentIds.push(id);
  429. }
  430. break;
  431. }
  432. }
  433. if (n == 0) {
  434. uni.showModal({
  435. title: this.$t('common.tip'),
  436. content: this.$t('common.noDevice'),
  437. success: (res) => {
  438. }
  439. })
  440. }
  441. if (n > 0) {
  442. uni.showModal({
  443. title: this.$t('common.tip'),
  444. content: this.$t('common.addDevice'),
  445. success: (res) => {
  446. }
  447. })
  448. }
  449. },
  450. selectChange2(val) {
  451. //有改动文件 import likeButton from "../../components/like-button/like-button.vue";
  452. if (val == "all") {
  453. this.equipmentIds = [];
  454. var list = uni.getStorageSync("listName");
  455. for (var i = 0; i < list.length; i++) {
  456. this.equipmentIds.push(list[i].id);
  457. }
  458. } else {
  459. this.equipmentIds = val
  460. }
  461. // console.log('this.equipmentIds => ' + this.equipmentIds);
  462. },
  463. switchChange: function(e) {
  464. this.status = e.target.value;
  465. },
  466. add() {
  467. const param = {};
  468. param['week'] = this.week;
  469. param['hour'] = this.time;
  470. param['name'] = this.name;
  471. if (this.status) {
  472. param['status'] = "1";
  473. } else {
  474. param['status'] = "0";
  475. }
  476. param['type'] = this.indexType;
  477. var eids = '';
  478. var ids = this.equipmentIds;
  479. for (var j = 0; j < ids.length; j++) {
  480. var t = ids[j];
  481. eids = eids + t + ","
  482. }
  483. param['equipmentIds'] = eids;
  484. param['adminId'] = this.globalUser.id;
  485. // console.log("param =>" + param);
  486. this.addAlarmClock(param)
  487. .then(res => {
  488. if (res.code) {
  489. this.addAlarmClockItems(res.data);
  490. }
  491. // uni.showModal({
  492. // title: "提示",
  493. // content: res.message,
  494. // success: (re) => {
  495. // if (re.confirm) {
  496. // uni.reLaunch({
  497. // url: 'alarmClockList',
  498. // });
  499. // }
  500. // }
  501. // })
  502. uni.stopPullDownRefresh();
  503. }, _ => void uni.stopPullDownRefresh());
  504. },
  505. addAlarmClockItems(alarmClock) {
  506. console.log("alarmClock =>" + alarmClock);
  507. this.addAlarmClockItem(alarmClock)
  508. .then(res => {
  509. uni.showModal({
  510. title: this.$t('common.tip'),
  511. content: res.message,
  512. success: (re) => {
  513. if (re.confirm) {
  514. // uni.navigateTo({
  515. // url: 'alarmClockList',
  516. // });
  517. uni.navigateBack({
  518. url: 'alarmClockList'
  519. });
  520. }
  521. }
  522. })
  523. uni.stopPullDownRefresh();
  524. }, _ => void uni.stopPullDownRefresh());
  525. },
  526. update() {
  527. const param = {};
  528. param['id'] = this.clock;
  529. param['week'] = this.week;
  530. param['name'] = this.name;
  531. param['hour'] = this.time;
  532. if (this.status) {
  533. param['status'] = "1";
  534. } else {
  535. param['status'] = "0";
  536. }
  537. param['type'] = this.indexType;
  538. var eids = '';
  539. var ids = this.equipmentIds;
  540. for (var j = 0; j < ids.length; j++) {
  541. var t = ids[j];
  542. eids = eids + t + ","
  543. }
  544. param['equipmentIds'] = eids;
  545. param['adminId'] = this.globalUser.id;
  546. this.updateAlarmClock(param)
  547. .then(res => {
  548. uni.showToast({
  549. title: res.message,
  550. duration: 2000,
  551. success: uni.navigateBack({
  552. url: 'alarmClockList'
  553. }),
  554. });
  555. }, _ => void uni.stopPullDownRefresh());
  556. },
  557. delet() {
  558. uni.showModal({
  559. title: this.$t('common.tip'),
  560. content: this.$t('alarmClock.isDelete'),
  561. success: (res) => {
  562. if (res.confirm) {
  563. var eids = '';
  564. var ids = this.equipmentIds;
  565. for (var j = 0; j < ids.length; j++) {
  566. var t = ids[j];
  567. eids = eids + t + ","
  568. }
  569. var token = uni.getStorageSync("token");
  570. uni.request({
  571. url: this.serverurl + '/TAlarmClock/delete',
  572. data: {
  573. "id": this.clock,
  574. "adminId": this.globalUser.id,
  575. "equipmentIds": eids,
  576. "type": this.indexType
  577. },
  578. header: {
  579. 'token': token
  580. },
  581. method: "POST",
  582. success: (res) => {
  583. uni.showModal({
  584. title: this.$t('common.tip'),
  585. content: res.data.message,
  586. success: (re) => {
  587. if (re.confirm) {
  588. // uni.navigateTo({
  589. // url: 'alarmClockList',
  590. // });
  591. uni.navigateBack({
  592. url: 'alarmClockList'
  593. });
  594. }
  595. }
  596. })
  597. },
  598. });
  599. }
  600. }
  601. });
  602. },
  603. }
  604. }
  605. </script>
  606. <style>
  607. .test {
  608. text-align: center;
  609. padding: 10px 0;
  610. }
  611. .time {
  612. font-size: 78upx;
  613. }
  614. .btime {
  615. margin: 20upx;
  616. font-size: 28upx;
  617. }
  618. /* button {
  619. margin: 20upx;
  620. font-size: 28upx;
  621. } */
  622. /* #ifdef MP-ALIPAY */
  623. .uni-badge {
  624. margin-left: 20rpx;
  625. }
  626. /* #endif */
  627. .uni-badge {
  628. font-size: 40upx;
  629. }
  630. .example-body {
  631. flex-direction: row;
  632. justify-content: flex-start;
  633. padding-bottom: 15upx;
  634. font-size: 40upx;
  635. }
  636. .uni-badge-left-margin {
  637. font-size: 40upx;
  638. margin-left: 50upx;
  639. }
  640. .uni-list-cell {
  641. padding-top: 20upx;
  642. padding-bottom: 10upx;
  643. font-size: 35upx;
  644. }
  645. .line {
  646. height: 2upx;
  647. background: #8C959F;
  648. }
  649. .search {
  650. width: 100%;
  651. padding-top: 15upx;
  652. padding-bottom: 25upx;
  653. display: flex;
  654. align-items: center;
  655. flex-direction: row;
  656. justify-content: flex-start;
  657. }
  658. .search-title {
  659. width: 28%;
  660. text-align: center;
  661. font-size: 26upx;
  662. font-family: "PingFang-SC-Bold";
  663. }
  664. .search-input {
  665. width: 45%;
  666. /* text-align: center; */
  667. font-size: 26upx;
  668. font-family: "PingFang-SC-Bold";
  669. box-shadow: 0upx 0upx 20upx #D3D3D3;
  670. border-radius: 5upx;
  671. }
  672. .search-input2 {
  673. width: 65%;
  674. text-align: center;
  675. font-size: 26upx;
  676. font-family: "PingFang-SC-Bold";
  677. box-shadow: 0upx 0upx 20upx #D3D3D3;
  678. border-radius: 5upx;
  679. }
  680. .search-button {
  681. width: 20%;
  682. padding-left: 20upx;
  683. text-align: center;
  684. }
  685. .select-item {
  686. /* padding-top: 20upx; */
  687. }
  688. .tr {
  689. padding-top: 15upx;
  690. display: flex;
  691. flex-direction: row;
  692. justify-content: flex-start;
  693. font-size: 48upx;
  694. font-family: "PingFang-SC-Bold";
  695. position: fixed;
  696. bottom: 100upx;
  697. width: 100%;
  698. }
  699. .button {
  700. margin: 30px;
  701. width: 50%;
  702. }
  703. .p1 {
  704. font-size: 48upx;
  705. }
  706. </style>