alarmClockItem.vue 16 KB

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