warnset.vue 15 KB

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