healthAlarm.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <template>
  2. <view class="home-warpTwo">
  3. <view class="airbody">
  4. <view class="module">
  5. <view class="device-bottom">
  6. <view
  7. class="info-box"
  8. v-for="(item, index) in selectedPlan"
  9. :key="index"
  10. >
  11. <view class="info-text">
  12. <text>{{ item.name }}</text>
  13. </view>
  14. <view class="edit_del">
  15. <image
  16. @click="deleteItem(item)"
  17. src="../../static/delete.png"
  18. alt=""
  19. ></image>
  20. <image
  21. @click="editItem(item)"
  22. style="margin-left: 10rpx"
  23. src="../../static/edit.png"
  24. alt=""
  25. ></image>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="bottomTwo">
  32. <view class="addNewAlarm" @click="addNewAlarm">新增守护计划</view>
  33. </view>
  34. <!-- 选择守护计划遮罩层 -->
  35. <view v-if="showPopup" class="mask" @click="showPopup = false"></view>
  36. <view v-if="showPopup" class="popup">
  37. <view class="popup-body">
  38. <picker
  39. mode="selector"
  40. :range="planListName"
  41. @change="bindPickerChange"
  42. :value="selectedIndex"
  43. >
  44. <view class="picker-text">
  45. {{
  46. planListName[selectedIndex] ||
  47. "点击此处选择守护计划"
  48. }}
  49. </view>
  50. </picker>
  51. </view>
  52. <view class="popup-footer">
  53. <view class="cancel-btn" @click="showPopup = false">
  54. 取消
  55. </view>
  56. <view type="primary" @click="confirmSelect" class="sure-btn">
  57. 确定
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. </template>
  63. <script>
  64. export default {
  65. data() {
  66. return {
  67. devInfo: {},
  68. showPopup: false,
  69. planList: [],
  70. planListName: [],
  71. selectedIndex: null,
  72. // 已经新增的守护计划
  73. selectedPlan: [],
  74. };
  75. },
  76. computed: {},
  77. methods: {
  78. getPlanList() {
  79. this.$http
  80. .post("wap/alarm/plan/queryTpl", {
  81. eventVal: "",
  82. name: "",
  83. })
  84. .then((res) => {
  85. if (res.data.code == 200) {
  86. if (res.data.data.length > 0) {
  87. this.planList = res.data.data;
  88. this.planListName = res.data.data.map(
  89. (ele) => ele.name
  90. );
  91. console.log(this.planList, 99999);
  92. }
  93. }
  94. });
  95. },
  96. confirmSelect() {
  97. if (this.selectedIndex !== null) {
  98. let selectedPlan = this.planList.find(
  99. (plan) => plan.name == this.planListName[this.selectedIndex]
  100. );
  101. selectedPlan.clientId = this.devInfo.clientId;
  102. if (!selectedPlan.alarmTimePlan) {
  103. this.$set(selectedPlan, "alarmTimePlan", {});
  104. }
  105. selectedPlan.alarmTimePlan.startDate = this.$time(
  106. new Date(),
  107. 1
  108. );
  109. selectedPlan.alarmTimePlan.stopDate = this.$time(
  110. new Date(
  111. new Date().setFullYear(new Date().getFullYear() + 1)
  112. ),
  113. 1
  114. );
  115. this.$http
  116. .post(
  117. "wap/alarm/plan/save",
  118. {
  119. ...selectedPlan,
  120. },
  121. {
  122. header: {
  123. "Content-Type":
  124. "application/json;charset=UTF-8",
  125. token: uni.getStorageSync("tokenValue") || "",
  126. },
  127. }
  128. )
  129. .then((res) => {
  130. if (res.data.code == 200) {
  131. uni.showToast({
  132. title: "添加计划成功",
  133. icon: "success",
  134. duration: 1500,
  135. });
  136. } else {
  137. uni.showToast({
  138. title: res.data.message,
  139. icon: "none",
  140. duration: 1500,
  141. });
  142. }
  143. this.getSelectPlan();
  144. });
  145. this.showPopup = false;
  146. }
  147. },
  148. bindPickerChange(e) {
  149. this.selectedIndex = e.detail.value;
  150. },
  151. addNewAlarm() {
  152. this.showPopup = true;
  153. },
  154. getSelectPlan() {
  155. this.$http
  156. .post(
  157. "wap/alarm/plan/query",
  158. {
  159. clientId: this.devInfo.clientId,
  160. },
  161. {
  162. header: {
  163. "Content-Type": "application/json;charset=UTF-8",
  164. token: uni.getStorageSync("tokenValue") || "",
  165. },
  166. }
  167. )
  168. .then((res) => {
  169. if (res.data.code == 200) {
  170. if (res.data.data.length > 0) {
  171. this.selectedPlan = res.data.data;
  172. }
  173. }
  174. });
  175. },
  176. deleteItem(item) {
  177. uni.showModal({
  178. content: "是否删除该计划",
  179. complete: (res) => {
  180. if (res.confirm) {
  181. this.$http
  182. .post(
  183. "wap/alarm/plan/del",
  184. {
  185. id: item.id,
  186. },
  187. {
  188. header: {
  189. "Content-Type":
  190. "application/json;charset=UTF-8",
  191. token:
  192. uni.getStorageSync("tokenValue") ||
  193. "",
  194. },
  195. }
  196. )
  197. .then((res) => {
  198. if (res.data.code == 200) {
  199. uni.showToast({
  200. title: "守护计划删除成功",
  201. icon: "success",
  202. duration: 1500,
  203. });
  204. } else {
  205. uni.showToast({
  206. title: res.data.message,
  207. icon: "none",
  208. duration: 1500,
  209. });
  210. }
  211. this.getSelectPlan();
  212. });
  213. }
  214. if (res.cancel) {
  215. }
  216. return;
  217. },
  218. });
  219. },
  220. editItem(item) {
  221. console.log(item, 88888);
  222. },
  223. },
  224. onLoad(options) {
  225. this.devInfo = JSON.parse(options.devInfo);
  226. this.getSelectPlan();
  227. },
  228. onShow() {
  229. this.getPlanList();
  230. },
  231. };
  232. </script>
  233. <style lang="less" scoped>
  234. .home-warpTwo {
  235. position: relative;
  236. height: 100vh;
  237. background: linear-gradient(180deg, #ffdfdf 0%, #ffffff 30.3%);
  238. box-sizing: border-box;
  239. width: 750rpx;
  240. border-bottom-left-radius: 35rpx;
  241. border-bottom-right-radius: 35rpx;
  242. background: linear-gradient(180deg, #faede2 0%, #ffffff 100%);
  243. .airCantInfo {
  244. margin: 30rpx auto 0 auto;
  245. border: 18rpx solid #1f1f1f;
  246. position: relative;
  247. }
  248. .airbody {
  249. background: #ffffff;
  250. box-sizing: border-box;
  251. .header_top {
  252. // padding: 0rpx 40rpx;
  253. display: flex;
  254. justify-content: space-between;
  255. align-items: center;
  256. .airTitle {
  257. font-weight: 500;
  258. color: #784c41;
  259. font-size: 32rpx;
  260. padding-left: 20rpx;
  261. padding-top: 20rpx;
  262. }
  263. .addfnt {
  264. display: flex;
  265. align-items: center;
  266. image {
  267. margin-top: 7rpx;
  268. width: 25rpx;
  269. height: 25rpx;
  270. }
  271. .add_btn {
  272. margin-left: 10rpx;
  273. font-size: 32rpx;
  274. }
  275. }
  276. }
  277. .module {
  278. bottom: 0;
  279. box-sizing: border-box;
  280. width: 100%;
  281. background: #ffffff;
  282. border-radius: 20rpx 20rpx 20rpx 20rpx;
  283. .device-bottom {
  284. .no-data {
  285. text-align: center;
  286. }
  287. .info-box {
  288. display: flex;
  289. align-items: center;
  290. // width: 620rpx;
  291. padding: 0 30rpx;
  292. height: 110rpx;
  293. background: #f8f8f8;
  294. border-radius: 38rpx;
  295. border-radius: 20rpx 20rpx 20rpx 20rpx;
  296. font-family: PingFang SC, PingFang SC;
  297. font-weight: 400;
  298. font-size: 26rpx;
  299. .info-text {
  300. display: flex;
  301. flex-direction: column;
  302. margin-left: 20rpx;
  303. }
  304. image {
  305. margin-bottom: 10rpx;
  306. width: 75rpx;
  307. height: 75rpx;
  308. }
  309. .edit_del {
  310. margin-left: auto;
  311. image {
  312. width: 40rpx;
  313. height: 40rpx;
  314. }
  315. }
  316. }
  317. .info-box:not(:first-child) {
  318. margin-top: 20rpx;
  319. }
  320. }
  321. }
  322. }
  323. .bottomTwo {
  324. display: flex;
  325. align-items: center;
  326. justify-content: space-between;
  327. position: fixed;
  328. bottom: 0;
  329. left: 0;
  330. width: 750rpx;
  331. height: 120rpx;
  332. background: #f3e2dd;
  333. .addNewAlarm {
  334. margin: 0 auto;
  335. display: flex;
  336. align-items: center;
  337. justify-content: center;
  338. width: 700rpx;
  339. height: 94rpx;
  340. background: #ffebe4;
  341. border-radius: 28rpx;
  342. font-weight: 500;
  343. color: #111111;
  344. font-size: 32rpx;
  345. text-align: center;
  346. }
  347. }
  348. .mask {
  349. position: fixed;
  350. top: 0;
  351. left: 0;
  352. right: 0;
  353. bottom: 0;
  354. background: rgba(0, 0, 0, 0.4);
  355. z-index: 99;
  356. }
  357. .popup {
  358. position: fixed;
  359. left: 50%;
  360. top: 50%;
  361. transform: translate(-50%, -50%);
  362. width: 500rpx;
  363. background: #fff;
  364. border-radius: 16rpx;
  365. padding: 20rpx;
  366. z-index: 100;
  367. .popup-body {
  368. text-align: center;
  369. margin-bottom: 20rpx;
  370. .picker-text {
  371. padding: 20rpx;
  372. border-radius: 8rpx;
  373. }
  374. }
  375. .popup-footer {
  376. display: flex;
  377. justify-content: space-around;
  378. margin-top: 40rpx;
  379. .cancel-btn {
  380. width: 200rpx;
  381. height: 75rpx;
  382. background: #ffebe4;
  383. line-height: 75rpx;
  384. border-radius: 28rpx;
  385. font-weight: 500;
  386. color: #111111;
  387. font-size: 32rpx;
  388. text-align: center;
  389. }
  390. .sure-btn {
  391. width: 200rpx;
  392. height: 75rpx;
  393. background: #4f372e;
  394. line-height: 75rpx;
  395. border-radius: 28rpx;
  396. font-weight: 500;
  397. color: #ffffff;
  398. font-size: 32rpx;
  399. text-align: center;
  400. }
  401. }
  402. }
  403. }
  404. </style>