alarmClockItem.vue 17 KB

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