warnset.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. <template>
  2. <view>
  3. <view class="basesel">
  4. <view class="basesel_list">
  5. <view class="">
  6. <view class=""> 预警名称 </view>
  7. <view class="">
  8. <u-input v-model="title" />
  9. </view>
  10. </view>
  11. <view class="basesel_list_tilte"> 预警设备选择: </view>
  12. <view class="basesel_list_sel" @click="baseshow = true">
  13. <view class="basesel_list_sel_left" v-show="selbaselist == ''">
  14. 请选择预警
  15. </view>
  16. <view class="basesel_list_sel_left" v-show="selbaselist != ''">
  17. {{ selbaselist }}
  18. </view>
  19. <u-icon name="arrow-down" class="icon" color="#999999"></u-icon>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="usersel">
  24. <view class="warmissue_itemone">
  25. <view class="warmissue_itemone_title"> 短信接受人: </view>
  26. <view class="" style="color: #14a478" @click="tobook">
  27. 预警通讯录编辑
  28. </view>
  29. </view>
  30. <view class="warmissue_itemtwo" @click="accServiceShowphone = true">
  31. <view class="itemtwo_left" v-show="!userphone.length">
  32. 请选择短信接收人
  33. </view>
  34. <view class="itemtwo_left" v-show="userphone.length">
  35. <view
  36. class=""
  37. style="margin-right: 20rpx"
  38. v-for="item in userphone"
  39. :key="item"
  40. >
  41. {{ item }}
  42. </view>
  43. </view>
  44. <u-icon name="arrow-down" class="icon" color="#999999"></u-icon>
  45. </view>
  46. </view>
  47. <view class="tongdao" v-for="(item, index) in tongdaolist" :key="index">
  48. <view class="tongdao_title">
  49. <view class="">
  50. {{ item.key }}
  51. </view>
  52. <view class="">
  53. <u-switch
  54. v-model="item.type"
  55. size="40"
  56. style="margin-top: 13rpx"
  57. ></u-switch>
  58. </view>
  59. </view>
  60. <view class="tongdao_item">
  61. <view class=""> 通道名称 </view>
  62. <view class="">
  63. {{ item.name }}
  64. </view>
  65. </view>
  66. <view class="tongdao_item">
  67. <view class=""> 运算符 </view>
  68. <view
  69. class="target_text_item_sel"
  70. @click="
  71. selindex = index;
  72. operationshow = true;
  73. "
  74. >
  75. <view class="itemtwo_left" v-show="item.value == ''">
  76. 请选择运算符
  77. </view>
  78. <view class="itemtwo_left" v-show="item.value != ''">
  79. {{ item.value }}
  80. </view>
  81. <u-icon name="arrow-down" class="icon" color="#999999"></u-icon>
  82. </view>
  83. </view>
  84. <view class="tongdao_item">
  85. <view class=""> 阈值 </view>
  86. <view class="" style="display: flex">
  87. <u-input
  88. v-model="item.num[0]"
  89. type="number"
  90. @blur="numyanzheng(index)"
  91. />
  92. <view
  93. class=""
  94. style="width: 60rpx; text-align: center"
  95. v-show="item.valuenum == 2"
  96. >
  97. -
  98. </view>
  99. <u-input
  100. v-model="item.num[1]"
  101. type="number"
  102. v-show="item.valuenum == 2"
  103. @blur="numyanzheng(index)"
  104. />
  105. </view>
  106. </view>
  107. </view>
  108. <view class="sendbox" @click="send"> 保存预警设置 </view>
  109. <view class="">
  110. <u-mask :show="accServiceShowphone" z-index="998"></u-mask>
  111. <u-select
  112. v-model="baseshow"
  113. :list="baselist"
  114. @confirm="selconfirm"
  115. ></u-select>
  116. <u-select
  117. v-model="operationshow"
  118. :list="operationlist"
  119. @confirm="operationconfirm"
  120. ></u-select>
  121. <multiple-select
  122. v-model="accServiceShowphone"
  123. :value="accServiceShowphone"
  124. :data="serviceListphone"
  125. :default-selected="defaultSelectedphone"
  126. @confirm="accServiceConfirmphone"
  127. ></multiple-select>
  128. </view>
  129. </view>
  130. </template>
  131. <script>
  132. import multipleSelect from '../../components/multiple-select.vue';
  133. export default {
  134. components: {
  135. multipleSelect,
  136. },
  137. data() {
  138. return {
  139. title: '',
  140. device_type: '',
  141. fanxianid: '',
  142. fanxianconf: '',
  143. warning_id: '',
  144. accServiceShowphone: false,
  145. userphone: [],
  146. send_user: [],
  147. defaultSelectedphone: [],
  148. serviceListphone: [],
  149. selbaselist: [],
  150. baselist: [],
  151. baseshow: false,
  152. statustf: false,
  153. operationshow: false,
  154. operationlist: [
  155. {
  156. value: 0,
  157. label: '小于',
  158. },
  159. {
  160. value: 1,
  161. label: '大于',
  162. },
  163. {
  164. value: 2,
  165. label: '介于',
  166. },
  167. ],
  168. tongdaolist: [],
  169. selindex: 0,
  170. };
  171. },
  172. methods: {
  173. tobook() {
  174. uni.navigateTo({
  175. url: '../cbqxyj/addressbook',
  176. });
  177. },
  178. accServiceConfirmphone(e) {
  179. this.userphone = [];
  180. this.send_user = [];
  181. for (var i = 0; i < e.length; i++) {
  182. this.userphone.push(e[i].name);
  183. this.send_user.push(e[i].value);
  184. }
  185. },
  186. async getuseriphonelist() {
  187. const res = await this.$myRequest({
  188. url: '/api/api_gateway?method=device.device_sms_alert.user_warning_liaisons_list',
  189. data: {
  190. page: 1,
  191. page_size: 9999999,
  192. device_type: this.device_type,
  193. },
  194. });
  195. // console.log(res)
  196. this.serviceListphone = [];
  197. for (var i = 0; i < res.data.length; i++) {
  198. var obj = {
  199. value: res.data[i].d_id,
  200. name: res.data[i].liaisons + '/' + res.data[i].phone,
  201. };
  202. this.serviceListphone.push(obj);
  203. }
  204. },
  205. async getbaselist() {
  206. const res = await this.$myRequest({
  207. url: '/api/api_gateway?method=device.device_sms_alert.user_warning_device_list',
  208. data: {
  209. device_type_id: this.device_type,
  210. device_type: this.device_type,
  211. page: '1',
  212. page_size: '999999999',
  213. },
  214. });
  215. // console.log(res.data)
  216. for (var i = 0; i < res.data.length; i++) {
  217. var obj = {
  218. value: res.data[i].d_id,
  219. label: res.data[i].device_id,
  220. };
  221. this.baselist.push(obj);
  222. }
  223. },
  224. selconfirm(e) {
  225. console.log(e);
  226. this.selbaselist = e[0].label;
  227. this.getbasetongdao(e[0].label);
  228. },
  229. operationconfirm(e) {
  230. console.log(e);
  231. console.log(this.selindex);
  232. this.tongdaolist[this.selindex].value = e[0].label;
  233. this.tongdaolist[this.selindex].valuenum = e[0].value;
  234. },
  235. async getbasetongdao(device_id) {
  236. uni.showLoading({
  237. title: '加载中',
  238. });
  239. const res = await this.$myRequest({
  240. url: '/api/api_gateway?method=weather.weather.qxz_early_warning',
  241. data: {
  242. device_id: device_id,
  243. device_type: this.device_type,
  244. status: 'see',
  245. },
  246. });
  247. uni.hideLoading();
  248. console.log(res.conf);
  249. this.tongdaolist = [];
  250. for (var key in res.conf) {
  251. var obj = {
  252. key: key,
  253. name: res.conf[key],
  254. type: false,
  255. value: '',
  256. valuenum: '',
  257. num: [],
  258. };
  259. if (this.fanxianid == device_id) {
  260. console.log(this.fanxianconf);
  261. for (var i = 0; i < this.fanxianconf.length; i++) {
  262. if (Object.keys(this.fanxianconf[i]) == key) {
  263. obj.type = true;
  264. var arr = this.fanxianconf[i][key].split('|')[0].split('#');
  265. if (arr[1].indexOf('&')) {
  266. arr[1] = arr[1].split('&');
  267. obj.num[1] = arr[1][1];
  268. obj.num[0] = arr[1][0];
  269. }
  270. obj.value = this.operationlist[arr[0]].label;
  271. obj.valuenum = arr[0];
  272. }
  273. }
  274. }
  275. this.tongdaolist.push(obj);
  276. }
  277. // console.log(this.tongdaolist)
  278. },
  279. yanzheng() {
  280. for (var i = 0; i < this.tongdaolist.length; i++) {
  281. if (this.tongdaolist[i].type) {
  282. return false;
  283. }
  284. }
  285. return true;
  286. },
  287. yanzheng2() {
  288. for (var i = 0; i < this.tongdaolist.length; i++) {
  289. if (this.tongdaolist[i].type) {
  290. if (!this.tongdaolist[i].value || !this.tongdaolist[i].num[0]) {
  291. return true;
  292. } else if (
  293. this.tongdaolist[i].value == '介于' &&
  294. !this.tongdaolist[i].num[1]
  295. ) {
  296. return true;
  297. }
  298. }
  299. }
  300. return false;
  301. },
  302. numyanzheng(index) {
  303. if (this.tongdaolist[index].num[1]) {
  304. // console.log(Number(this.tongdaolist[index].num[0]) > Number(this.tongdaolist[index].num[1]))
  305. if (
  306. Number(this.tongdaolist[index].num[0]) >=
  307. Number(this.tongdaolist[index].num[1])
  308. ) {
  309. this.tongdaolist[index].num = [this.tongdaolist[index].num[0], ''];
  310. }
  311. }
  312. },
  313. async send() {
  314. console.log(this.selbaselist);
  315. if (this.selbaselist == '') {
  316. uni.showToast({
  317. title: '请选择预警设备',
  318. icon: 'none',
  319. });
  320. } else if (this.userphone.length == 0) {
  321. uni.showToast({
  322. title: '请选择预警短信接收人',
  323. icon: 'none',
  324. });
  325. } else if (this.yanzheng()) {
  326. // console.log(this.tongdaolist)
  327. uni.showToast({
  328. title: '请开启至少一个通道预警',
  329. icon: 'none',
  330. });
  331. } else if (this.yanzheng2()) {
  332. uni.showToast({
  333. title: '请将开启的通道信息填写完成',
  334. icon: 'none',
  335. });
  336. } else {
  337. if (this.title.length > 32 || this.title == '') {
  338. uni.showToast({
  339. title: '标题不能为空且长度不大于32个字符',
  340. icon: 'none',
  341. });
  342. return;
  343. }
  344. var conf = [];
  345. for (var i = 0; i < this.tongdaolist.length; i++) {
  346. if (this.tongdaolist[i].type) {
  347. var obj = {};
  348. obj[this.tongdaolist[i].key] =
  349. this.tongdaolist[i].valuenum +
  350. '#' +
  351. this.tongdaolist[i].num.join('&') +
  352. '|' +
  353. this.tongdaolist[i].name;
  354. conf.push(obj);
  355. }
  356. }
  357. // console.log(conf)
  358. const res = await this.$myRequest({
  359. url: '/api/api_gateway?method=device.device_sms_alert.create_qxz_warning_config',
  360. data: {
  361. conf: JSON.stringify(conf),
  362. device_id: this.selbaselist,
  363. send_user_id: this.send_user.join(','),
  364. warning_id: this.warning_id,
  365. device_type: this.device_type,
  366. title: this.title,
  367. },
  368. });
  369. if (res) {
  370. uni.showToast({
  371. title: '预警配置成功',
  372. icon: 'none',
  373. complete: () => {
  374. uni.navigateBack({
  375. delta: 1,
  376. });
  377. },
  378. });
  379. }
  380. // console.log(res)
  381. }
  382. },
  383. //返现
  384. async getstatsu() {
  385. const res = await this.$myRequest({
  386. url: '/api/api_gateway?method=device.device_sms_alert.user_qxz_warning_statsu',
  387. data: {
  388. warning_id: this.warning_id,
  389. },
  390. });
  391. console.log(res);
  392. this.selbaselist = res.device_ids;
  393. this.fanxianid = res.device_ids;
  394. this.defaultSelectedphone = [];
  395. this.userphone = [];
  396. this.send_user = [];
  397. this.fanxianconf = res.conf;
  398. this.title = res.warning_name;
  399. for (var key in res.send_user) {
  400. this.defaultSelectedphone.push(Number(key));
  401. this.userphone.push(
  402. res.send_user[key][0] + '/' + res.send_user[key][1]
  403. );
  404. this.send_user.push(Number(key));
  405. }
  406. this.getbasetongdao(res.device_ids);
  407. },
  408. },
  409. onLoad(option) {
  410. this.device_type = option.typeId;
  411. this.getbaselist();
  412. this.getuseriphonelist();
  413. if (option.id) {
  414. this.warning_id = option.id;
  415. this.getstatsu();
  416. }
  417. },
  418. };
  419. </script>
  420. <style lang="less">
  421. page {
  422. background-color: #f6f6fb;
  423. }
  424. .basesel {
  425. width: 95%;
  426. margin: 20rpx auto;
  427. padding: 30rpx 20rpx;
  428. box-sizing: border-box;
  429. background-color: #fff;
  430. border-radius: 10rpx;
  431. .basesel_list {
  432. width: 100%;
  433. .basesel_list_tilte {
  434. margin-bottom: 60rpx;
  435. font-size: 32rpx;
  436. }
  437. .basesel_list_sel {
  438. display: flex;
  439. margin-bottom: 60rpx;
  440. .basesel_list_sel_left {
  441. width: calc(100% - 40rpx);
  442. display: flex;
  443. flex-wrap: wrap;
  444. color: #999999;
  445. }
  446. .icon {
  447. width: 40rpx;
  448. }
  449. }
  450. }
  451. }
  452. .usersel {
  453. width: 95%;
  454. margin: 20rpx auto;
  455. padding: 30rpx 20rpx;
  456. box-sizing: border-box;
  457. background-color: #fff;
  458. border-radius: 10rpx;
  459. .warmissue_itemone {
  460. margin-bottom: 60rpx;
  461. display: flex;
  462. justify-content: space-between;
  463. .warmissue_itemone_title {
  464. font-size: 32rpx;
  465. }
  466. }
  467. .warmissue_item {
  468. margin-bottom: 60rpx;
  469. display: flex;
  470. .warmissue_item_title {
  471. width: 160rpx;
  472. }
  473. .warmissue_item_text {
  474. width: calc(100% - 160rpx);
  475. }
  476. }
  477. .warmissue_itemtwo {
  478. display: flex;
  479. .itemtwo_left {
  480. width: calc(100% - 40rpx);
  481. display: flex;
  482. flex-wrap: wrap;
  483. color: #999999;
  484. }
  485. .icon {
  486. width: 40rpx;
  487. }
  488. }
  489. }
  490. .tongdao {
  491. width: 95%;
  492. margin: 20rpx auto;
  493. padding: 30rpx 0rpx;
  494. box-sizing: border-box;
  495. background-color: #fff;
  496. border-radius: 10rpx;
  497. .tongdao_title {
  498. padding: 0 20rpx;
  499. display: flex;
  500. line-height: 60rpx;
  501. justify-content: space-between;
  502. height: 60rpx;
  503. border-left: 8rpx solid #14a478;
  504. }
  505. .tongdao_item {
  506. padding: 0 20rpx;
  507. display: flex;
  508. justify-content: space-between;
  509. margin-top: 30rpx;
  510. line-height: 70rpx;
  511. .target_text_item_sel {
  512. display: flex;
  513. border-bottom: 1px solid #aaaaad;
  514. height: 70rpx;
  515. line-height: 70rpx;
  516. .itemtwo_left {
  517. color: #999999;
  518. }
  519. }
  520. ::v-deep .uni-input-input {
  521. border-bottom: 1px solid #aaaaad;
  522. text-align: right;
  523. width: 200rpx;
  524. }
  525. ::v-deep .u-input__right-icon {
  526. line-height: 35px;
  527. }
  528. }
  529. }
  530. .sendbox {
  531. margin: 40rpx auto;
  532. width: 80%;
  533. background-color: #14a478;
  534. padding: 20rpx 0;
  535. border-radius: 59px;
  536. text-align: center;
  537. color: #fff;
  538. }
  539. </style>