warnset.vue 12 KB

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