alarmClockItem.vue 18 KB

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