playSetting.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <template>
  2. <view class="container">
  3. <!-- 计划名称输入框 -->
  4. <view class="input-container">
  5. <text class="input-label">计划名称:</text>
  6. <input
  7. class="input-field"
  8. type="text"
  9. v-model="planInfo.name"
  10. placeholder="请输入计划名称"
  11. />
  12. </view>
  13. <!-- <view class="input-container">
  14. <text class="input-label">触发阈值:</text>
  15. <input
  16. class="input-field"
  17. type="number"
  18. v-model="thresholdTime"
  19. placeholder="请输入触发阈值"
  20. />
  21. </view>
  22. <view class="input-container">
  23. <text class="input-label">归并时间:</text>
  24. <input
  25. class="input-field"
  26. type="number"
  27. v-model="mergeTime"
  28. placeholder="请输入归并时间"
  29. />
  30. </view> -->
  31. <!-- 事件类型选择 -->
  32. <view class="select-container">
  33. <text class="input-label">事件类型:</text>
  34. <input
  35. class="input-field"
  36. type="text"
  37. v-model="eventType.eventDesc"
  38. placeholder="请选择计划类型"
  39. disabled="true"
  40. />
  41. </view>
  42. <!-- 计划时间 -->
  43. <view class="time-container" style="margin-bottom: 20rpx">
  44. <text class="input-label">计划时间:</text>
  45. <view class="time-picker-container">
  46. <picker
  47. mode="date"
  48. v-model="startDate"
  49. start="2000-01-01"
  50. end="2099-12-31"
  51. @change="bindStartChange"
  52. >
  53. <view class="picker-content">{{ startDate }}</view>
  54. </picker>
  55. ~
  56. <picker
  57. mode="date"
  58. v-model="stopDate"
  59. start="2000-01-01"
  60. end="2099-12-31"
  61. @change="bindEndChange"
  62. >
  63. <view class="picker-content">{{ stopDate }}</view>
  64. </picker>
  65. </view>
  66. </view>
  67. <!-- 生效时段 -->
  68. <view class="time-container" v-if="judgeFlage != 'noneFlag'">
  69. <text class="input-label">生效时段:</text>
  70. <view class="time-picker-container">
  71. <picker
  72. mode="time"
  73. v-model="effectiveStart"
  74. @change="bindEffectiveStartChange"
  75. >
  76. <view class="picker-content" style="width: 170rpx">{{
  77. effectiveStart
  78. }}</view>
  79. </picker>
  80. ~
  81. <picker
  82. mode="time"
  83. v-model="effectiveEnd"
  84. @change="bindEffectiveEndChange"
  85. >
  86. <view class="picker-content" style="width: 170rpx">{{
  87. effectiveEnd
  88. }}</view>
  89. </picker>
  90. </view>
  91. </view>
  92. <view class="time-range-wrapper" v-if="timeRange.length > 0">
  93. <view
  94. class="time-item"
  95. v-for="(item, index) in timeRange"
  96. :key="index"
  97. >
  98. <text class="time-text"
  99. >{{ item.start_time }} - {{ item.end_time }}</text
  100. >
  101. <text class="delete-btn" @click="removeTime(index)">×</text>
  102. </view>
  103. </view>
  104. <!-- 告警提醒 -->
  105. <view class="switch-container" style="margin-top: 20rpx">
  106. <text class="input-label">告警联动(服务号推送):</text>
  107. <switch
  108. :checked="linkagePushWechatService == 1"
  109. @change="onChangeLian"
  110. :active-value="1"
  111. :inactive-value="0"
  112. size="24px"
  113. active-color="#07c160"
  114. inactive-color="#eeeff1"
  115. style="transform: scale(0.8)"
  116. />
  117. </view>
  118. <!-- 是否启用 -->
  119. <view class="switch-container">
  120. <text class="input-label">是否启用:</text>
  121. <switch
  122. :checked="enable == 1"
  123. @change="onChangeQi"
  124. :active-value="1"
  125. :inactive-value="0"
  126. size="24px"
  127. active-color="#07c160"
  128. inactive-color="#eeeff1"
  129. style="transform: scale(0.8)"
  130. />
  131. </view>
  132. <!-- 保存按钮 -->
  133. <view class="save-button" @click="saveTemplate">
  134. <text class="save-button-text">保存</text>
  135. </view>
  136. </view>
  137. </template>
  138. <script>
  139. export default {
  140. data() {
  141. return {
  142. planName: "",
  143. selectedEventType: 0,
  144. startDate: "2025-01-01",
  145. stopDate: "2025-11-01",
  146. effectiveStart: "00:00",
  147. effectiveEnd: "23:59",
  148. isAlarmActive: true,
  149. isEnabled: true,
  150. planInfo: {},
  151. warmTypeList: [],
  152. eventType: "",
  153. linkagePushWechatService: 1,
  154. enable: 1,
  155. timeRange: [],
  156. thresholdTime: 300,
  157. mergeTime: 30,
  158. judgeFlage: "",
  159. remark: "",
  160. };
  161. },
  162. methods: {
  163. saveTemplate() {
  164. // 1 2 3 9
  165. // 允许多个时间
  166. // 5 7
  167. // 只有一个时间
  168. // 4 6 8
  169. // 不配生效时间
  170. if (this.judgeFlage == "noneFlag") {
  171. this.timeRange = [
  172. {
  173. start_time: "00:00",
  174. end_time: "23:59",
  175. },
  176. ];
  177. } else if (this.judgeFlage == "one" && this.timeRange.length > 1) {
  178. uni.showModal({
  179. title: "提示",
  180. content: "此事件类型只能选择一个生效时段",
  181. showCancel: false,
  182. });
  183. return;
  184. }
  185. if (this.enable == true) {
  186. this.enable = 1;
  187. } else {
  188. this.enable = 0;
  189. }
  190. if (this.linkagePushWechatService == true) {
  191. this.linkagePushWechatService = 1;
  192. } else {
  193. this.linkagePushWechatService = 0;
  194. }
  195. let planInfo = {
  196. alarmPlanId: this.planInfo.id,
  197. name: this.planInfo.name,
  198. clientId: this.planInfo.clientId,
  199. eventVal: this.planInfo.eventVal,
  200. thresholdTime: this.thresholdTime,
  201. mergeTime: this.mergeTime,
  202. linkagePushWechatService: this.linkagePushWechatService,
  203. enable: this.enable,
  204. alarmTimePlan: {
  205. id: this.planInfo.alarmTimePlan.id,
  206. startDate: this.startDate,
  207. stopDate: this.stopDate,
  208. timeRange: JSON.stringify(this.timeRange),
  209. monthDays: this.planInfo.alarmTimePlan.monthDays,
  210. weekdays: this.planInfo.alarmTimePlan.weekdays,
  211. },
  212. };
  213. if (
  214. this.planInfo.eventVal == 5 ||
  215. this.planInfo.eventVal == 4 ||
  216. this.planInfo.eventVal == 8
  217. ) {
  218. planInfo.param = JSON.stringify(this.timeRange);
  219. }
  220. console.log(planInfo, 9999);
  221. this.$http
  222. .post(
  223. "wap/alarm/plan/save",
  224. { ...planInfo },
  225. {
  226. header: {
  227. "Content-Type": "application/json",
  228. token: uni.getStorageSync("tokenValue") || "",
  229. },
  230. }
  231. )
  232. .then((res) => {
  233. if (res.data.code == 200) {
  234. uni.showToast({
  235. title: "修改成功",
  236. icon: "success",
  237. });
  238. setTimeout(() => {
  239. uni.navigateBack({
  240. delta: 1,
  241. });
  242. }, 1000);
  243. } else {
  244. uni.showToast({
  245. title: res.data.message,
  246. icon: "none",
  247. duration: 1500,
  248. });
  249. }
  250. });
  251. },
  252. handlePlanInfo() {
  253. console.log(this.planInfo, 9999999);
  254. },
  255. getWarnType() {
  256. this.$http.get("wap/stats/queryEventType").then((res) => {
  257. if (res.data.data) {
  258. this.warmTypeList = res.data.data;
  259. this.eventType = this.warmTypeList.find(
  260. (item) => item.eventVal == this.planInfo.eventVal
  261. );
  262. }
  263. });
  264. },
  265. bindStartChange(val) {
  266. this.startDate = val.detail.value;
  267. this.planInfo.startDate = this.startDate + " 00:00:00";
  268. },
  269. bindEndChange(val) {
  270. this.stopDate = val.detail.value;
  271. this.planInfo.stopDate = this.stopDate + " 23:59:59";
  272. },
  273. bindEffectiveStartChange(val) {
  274. this.effectiveStart = val.detail.value;
  275. console.log(this.effectiveStart, val.detail.value, 88887);
  276. },
  277. bindEffectiveEndChange(val) {
  278. this.effectiveEnd = val.detail.value;
  279. console.log(this.effectiveEnd, 9999);
  280. this.timeRange.push({
  281. start_time: this.effectiveStart,
  282. end_time: this.effectiveEnd,
  283. });
  284. },
  285. removeTime(index) {
  286. this.timeRange.splice(index, 1);
  287. },
  288. onChangeLian(e) {
  289. let newValue = e.detail.value == true ? 1 : 0;
  290. this.linkagePushWechatService = newValue.toString();
  291. },
  292. onChangeQi(e) {
  293. let newValue = e.detail.value == true ? 1 : 0;
  294. this.enable = newValue.toString();
  295. },
  296. },
  297. onLoad(options) {
  298. this.planInfo = JSON.parse(options.planInfo);
  299. console.log(this.planInfo, 9999999);
  300. this.startDate =
  301. this.planInfo?.alarmTimePlan.startDate?.slice(0, 10) || "";
  302. this.stopDate =
  303. this.planInfo?.alarmTimePlan.stopDate?.slice(0, 10) || "";
  304. if (this.planInfo.alarmTimePlan.timeRange) {
  305. this.timeRange = JSON.parse(this.planInfo.alarmTimePlan.timeRange);
  306. }
  307. this.eventType = this.planInfo.eventVal;
  308. this.linkagePushWechatService = this.planInfo.linkagePushWechatService;
  309. this.enable = this.planInfo.enable;
  310. if (this.eventType == 4 || this.eventType == 6 || this.eventType == 8) {
  311. this.judgeFlage = "noneFlag";
  312. } else if (this.eventType == 5 || this.eventType == 7) {
  313. this.judgeFlage = "one";
  314. } else if (
  315. this.eventType == 1 ||
  316. this.eventType == 2 ||
  317. this.eventType == 3 ||
  318. this.eventType == 9
  319. ) {
  320. this.judgeFlage = "more";
  321. }
  322. },
  323. onShow() {
  324. this.linkagePushWechatService =
  325. this.planInfo.linkagePushWechatService == 1 ? true : false;
  326. this.enable = this.planInfo.enable == 1 ? true : false;
  327. this.getWarnType();
  328. },
  329. };
  330. </script>
  331. <style scoped>
  332. .container {
  333. padding: 20px;
  334. height: 100vh;
  335. background-color: #f9eee3;
  336. border-radius: 12px;
  337. }
  338. .input-container {
  339. margin-bottom: 25px;
  340. }
  341. .input-label {
  342. font-size: 16px;
  343. color: #333;
  344. margin-bottom: 8px;
  345. font-weight: 600;
  346. }
  347. .time-picker-container {
  348. margin-top: 20rpx;
  349. align-items: center;
  350. display: flex;
  351. justify-content: space-between;
  352. }
  353. .input-field {
  354. width: 92%;
  355. padding: 14px;
  356. margin-top: 20rpx;
  357. border: 1px solid #ccc;
  358. border-radius: 10px;
  359. font-size: 16px;
  360. background-color: #fff;
  361. }
  362. .input-counter {
  363. font-size: 12px;
  364. color: #999;
  365. text-align: right;
  366. margin-top: 4px;
  367. }
  368. .select-container {
  369. margin-bottom: 25px;
  370. }
  371. .picker-content {
  372. padding: 14px;
  373. border: 1px solid #ccc;
  374. border-radius: 10px;
  375. font-size: 16px;
  376. color: #333;
  377. background-color: #fff;
  378. }
  379. .time-range-wrapper {
  380. margin-top: 20rpx;
  381. display: flex;
  382. flex-wrap: wrap; /* 多行换行显示 */
  383. gap: 10rpx; /* 间距 */
  384. padding: 10rpx;
  385. }
  386. .time-item {
  387. position: relative;
  388. display: flex;
  389. align-items: center;
  390. padding: 10rpx 20rpx;
  391. background-color: #f5f5f5;
  392. border-radius: 12rpx;
  393. }
  394. .time-text {
  395. font-size: 28rpx;
  396. color: #333;
  397. }
  398. .delete-btn {
  399. position: absolute;
  400. top: -6rpx;
  401. right: -6rpx;
  402. width: 30rpx;
  403. height: 30rpx;
  404. line-height: 30rpx;
  405. text-align: center;
  406. background-color: #ff4d4f;
  407. color: #fff;
  408. border-radius: 50%;
  409. font-weight: bold;
  410. font-size: 20rpx;
  411. }
  412. .switch-container {
  413. margin-bottom: 25px;
  414. display: flex;
  415. justify-content: space-between;
  416. align-items: center;
  417. }
  418. /* 新的保存按钮样式 */
  419. .save-button {
  420. width: 750rpx;
  421. height: 120rpx;
  422. position: fixed;
  423. display: flex;
  424. justify-content: center;
  425. align-items: center;
  426. bottom: 0;
  427. left: 0;
  428. line-height: 120rpx;
  429. background: #f3e2dd;
  430. border-radius: 12px;
  431. }
  432. .save-button-text {
  433. font-size: 18px;
  434. /* font-weight: bold; */
  435. }
  436. </style>