alarmClockItem.vue 18 KB

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