alarmClockItem.vue 17 KB

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