warnset.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  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. const res = await this.$myRequest({
  210. url: '/api/api_gateway?method=weather.weather.qxz_early_warning',
  211. data: {
  212. device_id: device_id,
  213. device_type: this.device_type,
  214. status: "see"
  215. }
  216. })
  217. console.log(res.conf)
  218. this.tongdaolist = []
  219. for (var key in res.conf) {
  220. var obj = {
  221. key: key,
  222. name: res.conf[key],
  223. type: false,
  224. value: "",
  225. valuenum: "",
  226. num: []
  227. }
  228. if (this.fanxianid == device_id) {
  229. console.log(this.fanxianconf)
  230. for (var i = 0; i < this.fanxianconf.length; i++) {
  231. if (Object.keys(this.fanxianconf[i]) == key) {
  232. obj.type = true;
  233. var arr = this.fanxianconf[i][key].split('|')[0].split('#');
  234. if (arr[1].indexOf('&')) {
  235. arr[1] = arr[1].split('&');
  236. obj.num[1] = arr[1][1];
  237. obj.num[0] = arr[1][0];
  238. }
  239. obj.value = this.operationlist[arr[0]].label;
  240. obj.valuenum = arr[0];
  241. }
  242. }
  243. }
  244. this.tongdaolist.push(obj)
  245. }
  246. // console.log(this.tongdaolist)
  247. },
  248. yanzheng() {
  249. for (var i = 0; i < this.tongdaolist.length; i++) {
  250. if (this.tongdaolist[i].type) {
  251. return false
  252. }
  253. }
  254. return true
  255. },
  256. yanzheng2() {
  257. for (var i = 0; i < this.tongdaolist.length; i++) {
  258. if (this.tongdaolist[i].type) {
  259. if (!this.tongdaolist[i].value || !this.tongdaolist[i].num[0]) {
  260. return true
  261. } else if (this.tongdaolist[i].value == "介于" && !this.tongdaolist[i].num[1]) {
  262. return true
  263. }
  264. }
  265. }
  266. return false
  267. },
  268. numyanzheng(index) {
  269. if (this.tongdaolist[index].num[1]) {
  270. // console.log(Number(this.tongdaolist[index].num[0]) > Number(this.tongdaolist[index].num[1]))
  271. if (Number(this.tongdaolist[index].num[0]) >= Number(this.tongdaolist[index].num[1])) {
  272. this.tongdaolist[index].num = [this.tongdaolist[index].num[0], ""]
  273. }
  274. }
  275. },
  276. async send() {
  277. console.log(this.selbaselist)
  278. if (this.selbaselist == '') {
  279. uni.showToast({
  280. title: "请选择预警设备",
  281. icon: "none"
  282. })
  283. } else if (this.userphone.length == 0) {
  284. uni.showToast({
  285. title: "请选择预警短信接收人",
  286. icon: "none"
  287. })
  288. } else if (this.yanzheng()) {
  289. // console.log(this.tongdaolist)
  290. uni.showToast({
  291. title: "请开启至少一个通道预警",
  292. icon: "none"
  293. })
  294. } else if (this.yanzheng2()) {
  295. uni.showToast({
  296. title: "请将开启的通道信息填写完成",
  297. icon: "none"
  298. })
  299. } else {
  300. if(this.title.length > 32 || this.title == '') {
  301. uni.showToast({
  302. title: "标题不能为空且长度不大于32个字符",
  303. icon: "none"
  304. })
  305. return
  306. }
  307. var conf = [
  308. ]
  309. for (var i = 0; i < this.tongdaolist.length; i++) {
  310. if (this.tongdaolist[i].type) {
  311. var obj = {}
  312. obj[this.tongdaolist[i].key] = this.tongdaolist[i].valuenum + "#" + this.tongdaolist[i].num
  313. .join("&") + '|' + this.tongdaolist[i].name
  314. conf.push(obj)
  315. }
  316. }
  317. // console.log(conf)
  318. const res = await this.$myRequest({
  319. url: '/api/api_gateway?method=device.device_sms_alert.create_qxz_warning_config',
  320. data: {
  321. conf: JSON.stringify(conf),
  322. device_id: this.selbaselist,
  323. send_user_id: this.send_user.join(","),
  324. warning_id: this.warning_id,
  325. device_type: this.device_type,
  326. title: this.title ,
  327. }
  328. })
  329. if(res) {
  330. uni.showToast({
  331. title: "预警配置成功",
  332. icon: "none",
  333. complete: () => {
  334. uni.navigateBack({
  335. delta:1
  336. })
  337. }
  338. })
  339. }
  340. // console.log(res)
  341. }
  342. },
  343. //返现
  344. async getstatsu() {
  345. const res = await this.$myRequest({
  346. url: '/api/api_gateway?method=device.device_sms_alert.user_qxz_warning_statsu',
  347. data: {
  348. warning_id: this.warning_id,
  349. }
  350. })
  351. console.log(res)
  352. this.selbaselist = res.device_ids
  353. this.fanxianid = res.device_ids
  354. this.defaultSelectedphone = []
  355. this.userphone = []
  356. this.send_user = []
  357. this.fanxianconf = res.conf;
  358. this.title = res.warning_name;
  359. for (var key in res.send_user) {
  360. this.defaultSelectedphone.push(Number(key))
  361. this.userphone.push(res.send_user[key][0] + "/" + res.send_user[key][1])
  362. this.send_user.push(Number(key))
  363. }
  364. this.getbasetongdao(res.device_ids)
  365. }
  366. },
  367. onLoad(option) {
  368. this.device_type = option.typeId;
  369. this.getbaselist()
  370. this.getuseriphonelist()
  371. if(option.id) {
  372. this.warning_id = option.id;
  373. this.getstatsu()
  374. }
  375. }
  376. }
  377. </script>
  378. <style lang="less">
  379. page {
  380. background-color: #F6F6FB;
  381. }
  382. .basesel {
  383. width: 95%;
  384. margin: 20rpx auto;
  385. padding: 30rpx 20rpx;
  386. box-sizing: border-box;
  387. background-color: #fff;
  388. border-radius: 10rpx;
  389. .basesel_list {
  390. width: 100%;
  391. .basesel_list_tilte {
  392. margin-bottom: 60rpx;
  393. font-size: 32rpx;
  394. }
  395. .basesel_list_sel {
  396. display: flex;
  397. margin-bottom: 60rpx;
  398. .basesel_list_sel_left {
  399. width: calc(100% - 40rpx);
  400. display: flex;
  401. flex-wrap: wrap;
  402. color: #999999;
  403. }
  404. .icon {
  405. width: 40rpx;
  406. }
  407. }
  408. }
  409. }
  410. .usersel {
  411. width: 95%;
  412. margin: 20rpx auto;
  413. padding: 30rpx 20rpx;
  414. box-sizing: border-box;
  415. background-color: #fff;
  416. border-radius: 10rpx;
  417. .warmissue_itemone {
  418. margin-bottom: 60rpx;
  419. display: flex;
  420. justify-content: space-between;
  421. .warmissue_itemone_title {
  422. font-size: 32rpx;
  423. }
  424. }
  425. .warmissue_item {
  426. margin-bottom: 60rpx;
  427. display: flex;
  428. .warmissue_item_title {
  429. width: 160rpx;
  430. }
  431. .warmissue_item_text {
  432. width: calc(100% - 160rpx);
  433. }
  434. }
  435. .warmissue_itemtwo {
  436. display: flex;
  437. .itemtwo_left {
  438. width: calc(100% - 40rpx);
  439. display: flex;
  440. flex-wrap: wrap;
  441. color: #999999;
  442. }
  443. .icon {
  444. width: 40rpx;
  445. }
  446. }
  447. }
  448. .tongdao {
  449. width: 95%;
  450. margin: 20rpx auto;
  451. padding: 30rpx 0rpx;
  452. box-sizing: border-box;
  453. background-color: #fff;
  454. border-radius: 10rpx;
  455. .tongdao_title {
  456. padding: 0 20rpx;
  457. display: flex;
  458. line-height: 60rpx;
  459. justify-content: space-between;
  460. height: 60rpx;
  461. border-left: 8rpx solid #14A478;
  462. }
  463. .tongdao_item {
  464. padding: 0 20rpx;
  465. display: flex;
  466. justify-content: space-between;
  467. margin-top: 30rpx;
  468. line-height: 70rpx;
  469. .target_text_item_sel {
  470. display: flex;
  471. border-bottom: 1px solid #aaaaad;
  472. height: 70rpx;
  473. line-height: 70rpx;
  474. .itemtwo_left {
  475. color: #999999;
  476. }
  477. }
  478. /deep/.uni-input-input {
  479. border-bottom: 1px solid #aaaaad;
  480. text-align: right;
  481. width: 200rpx;
  482. }
  483. /deep/.u-input__right-icon {
  484. line-height: 35px;
  485. }
  486. }
  487. }
  488. .sendbox {
  489. margin: 40rpx auto;
  490. width: 80%;
  491. background-color: #14A478;
  492. padding: 20rpx 0;
  493. border-radius: 59px;
  494. text-align: center;
  495. color: #fff;
  496. }
  497. </style>