warnset.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  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-if="selbaselist.length==0">
  10. 请选择预警设备
  11. </view>
  12. <view class="basesel_list_sel_left" v-if="selbaselist.length!=0">
  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">
  26. 逐台预警
  27. </u-radio>
  28. <u-radio name="1" :disabled="disabled">
  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-if="item.appointPestName==''">
  78. 请选择害虫
  79. </view>
  80. <view class="itemtwo_left" v-if="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-if="!userphone.length">
  144. 请选择短信接收人
  145. </view>
  146. <view class="itemtwo_left" v-if="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. // disabled:false,
  179. warnjihe: "0",
  180. accServiceShow: false,
  181. serviceList: [],
  182. defaultSelected: [],
  183. userphone: [],
  184. accServiceShowphone: false,
  185. serviceListphone: [],
  186. defaultSelectedphone: [],
  187. //预警配置
  188. conf: {
  189. pestCategory: false,
  190. pestCategoryNum: "",
  191. appointPest: false,
  192. pestTotalNum: "",
  193. pestTotal: false,
  194. pestWarn: false
  195. },
  196. confnum: [{
  197. appointPestName: "",
  198. appointPestNum: "",
  199. appointPestNameid: ""
  200. }],
  201. device_ids: [],
  202. send_user: [],
  203. wormshow: false,
  204. wormlist: [],
  205. selwormindex: 0
  206. }
  207. },
  208. computed: {
  209. disabled(){
  210. return this.selbaselist.length<=1?true:false
  211. }
  212. },
  213. methods: {
  214. accServiceConfirm(e) {
  215. this.selbaselist = []
  216. this.device_ids = []
  217. for (var i = 0; i < e.length; i++) {
  218. this.selbaselist.push(e[i].name)
  219. this.device_ids.push(e[i].value)
  220. }
  221. console.log(e)
  222. },
  223. accServiceConfirmphone(e) {
  224. this.userphone = []
  225. this.send_user = []
  226. for (var i = 0; i < e.length; i++) {
  227. this.userphone.push(e[i].name)
  228. this.send_user.push(e[i].value)
  229. }
  230. },
  231. async getpeizhi(id) {
  232. const res = await this.$myRequest({
  233. url: '/api/api_gateway?method=device.device_sms_alert.user_pest_warning_statsu',
  234. data: {
  235. warning_id: id
  236. }
  237. })
  238. console.log(res)
  239. this.confnum = []
  240. this.conf.pestCategory = res.conf.pestCategory == "on" ? true : false
  241. this.conf.appointPest = res.conf.appointPest == "on" ? true : false
  242. this.conf.pestTotal = res.conf.pestTotal == "on" ? true : false
  243. this.conf.pestWarn = res.conf.pestWarn == "on" ? true : false
  244. this.conf.pestCategoryNum = res.conf.pestCategoryNum
  245. this.conf.pestTotalNum = res.conf.pestTotalNum
  246. for (var key in res.device_ids) {
  247. this.selbaselist.push(res.device_ids[key]);
  248. this.defaultSelected.push(Number(key));
  249. this.device_ids.push(Number(key));
  250. }
  251. console.log(this.defaultSelected)
  252. for (var key in res.send_user) {
  253. this.userphone.push(res.send_user[key][0] + "/" + res.send_user[key][1]);
  254. this.defaultSelectedphone.push(Number(key))
  255. this.send_user.push(Number(key));
  256. }
  257. var flag = 0
  258. for (var key in res.conf) {
  259. if (key.indexOf("appointPestName") != -1) {
  260. flag++
  261. }
  262. }
  263. for (var i = 0; i < flag; i++) {
  264. // console.log(i)
  265. if (i == 0) {
  266. var obj = {
  267. appointPestName: dict[Number(res.conf["appointPestName"])],
  268. appointPestNum: res.conf["appointPestNum"],
  269. appointPestNameid: res.conf["appointPestName"]
  270. };
  271. } else {
  272. var obj = {
  273. appointPestName: dict[Number(res.conf["appointPestName" + i])],
  274. appointPestNum: res.conf["appointPestNum" + i],
  275. appointPestNameid: res.conf["appointPestName" + i]
  276. };
  277. }
  278. this.confnum.push(obj);
  279. }
  280. },
  281. async getbaselist() {
  282. const res = await this.$myRequest({
  283. url: '/api/api_gateway?method=device.device_sms_alert.user_warning_device_list',
  284. data: {
  285. device_type_id: "3",
  286. page: "1",
  287. page_size: "999999999"
  288. }
  289. })
  290. // console.log(res.data)
  291. for (var i = 0; i < res.data.length; i++) {
  292. var obj = {
  293. value: res.data[i].d_id,
  294. name: res.data[i].device_id,
  295. }
  296. this.serviceList.push(obj)
  297. }
  298. },
  299. async getuseriphonelist() {
  300. const res = await this.$myRequest({
  301. url: '/api/api_gateway?method=device.device_sms_alert.user_warning_liaisons_list',
  302. data: {
  303. page: 1,
  304. page_size: 9999999,
  305. }
  306. })
  307. // console.log(res)
  308. this.serviceListphone = []
  309. for (var i = 0; i < res.data.length; i++) {
  310. var obj = {
  311. value: res.data[i].d_id,
  312. name: res.data[i].liaisons + "/" + res.data[i].phone,
  313. }
  314. this.serviceListphone.push(obj)
  315. }
  316. },
  317. tobook() {
  318. uni.navigateTo({
  319. url: "./addressbook"
  320. })
  321. },
  322. selconfirm(e) {
  323. console.log(e, this.selwormindex)
  324. this.confnum[this.selwormindex].appointPestName = e[0].label
  325. this.confnum[this.selwormindex].appointPestNameid = e[0].value
  326. },
  327. addconfitem() {
  328. for (var i = 0; i < this.confnum.length; i++) {
  329. if (this.confnum[i].appointPestName == "" ||
  330. this.confnum[i].appointPestNum == "") {
  331. uni.showToast({
  332. title: "请先将信息填写完成后添加",
  333. icon: "none"
  334. })
  335. return
  336. }
  337. }
  338. var obj = {
  339. appointPestName: "",
  340. appointPestNum: "",
  341. }
  342. this.confnum.push(obj)
  343. },
  344. delconfitem(index) {
  345. this.confnum.splice(index, 1)
  346. },
  347. yanzheng() {
  348. for (var i = 0; i < this.confnum.length; i++) {
  349. if (this.confnum[i].appointPestName == "" || this.confnum[i].appointPestNum == "") {
  350. return true
  351. }
  352. }
  353. return false
  354. },
  355. async send() {
  356. if (this.selbaselist.length == 0) {
  357. uni.showToast({
  358. title: "请选择预警设备",
  359. icon: "none"
  360. })
  361. } else if (this.conf.pestCategory == false &&
  362. this.conf.appointPest == false &&
  363. this.conf.pestTotal == false &&
  364. this.conf.pestWarn == false) {
  365. uni.showToast({
  366. title: "请开启至少一种预警",
  367. icon: "none"
  368. })
  369. } else if (this.conf.pestCategory && this.conf.pestCategoryNum == "") {
  370. uni.showToast({
  371. title: "请将目标种类预警信息填写完整",
  372. icon: "none"
  373. })
  374. } else if (this.conf.appointPest && this.yanzheng()) {
  375. uni.showToast({
  376. title: "请将数量预警信息填写完整",
  377. icon: "none"
  378. })
  379. } else if (this.conf.pestTotal && this.conf.pestTotalNum == "") {
  380. uni.showToast({
  381. title: "请将总数预警信息填写完整",
  382. icon: "none"
  383. })
  384. } else if (this.userphone.length == 0) {
  385. uni.showToast({
  386. title: "请选择短信接收人",
  387. icon: "none"
  388. })
  389. } else {
  390. console.log(this.device_ids)
  391. console.log(this.send_user)
  392. var obj = {
  393. }
  394. // console.log(this.confnum)
  395. for (var i = 0; i < this.confnum.length; i++) {
  396. if (i == 0) {
  397. obj['appointPestName'] = this.confnum[i].appointPestNameid
  398. obj['appointPestNum'] = this.confnum[i].appointPestNum
  399. } else {
  400. obj['appointPestName' + i] = this.confnum[i].appointPestNameid
  401. obj['appointPestNum' + i] = this.confnum[i].appointPestNum
  402. }
  403. }
  404. for (var key in this.conf) {
  405. if (key == "pestCategory" ||
  406. key == "appointPest" ||
  407. key == "pestTotal" ||
  408. key == "pestWarn") {
  409. obj[key] = this.conf[key] ? "on" : "off"
  410. } else {
  411. obj[key] = this.conf[key]
  412. }
  413. }
  414. console.log(obj)
  415. const res = await this.$myRequest({
  416. url: '/api/api_gateway?method=device.device_sms_alert.create_user_pest_warning',
  417. data: {
  418. conf: JSON.stringify(obj),
  419. device_ids: this.device_ids.join(","),
  420. send_user: this.send_user.join(","),
  421. warning_id: this.warning_id,
  422. warning_type: this.warnjihe
  423. }
  424. })
  425. console.log(res)
  426. uni.showToast({
  427. title: "预警配置成功",
  428. icon: "none"
  429. })
  430. uni.navigateBack({
  431. delta: 1
  432. })
  433. }
  434. }
  435. },
  436. onLoad(option) {
  437. // console.log(dict)
  438. this.wormlist = []
  439. for (var key in dict) {
  440. var obj = {
  441. value: key,
  442. label: dict[key]
  443. }
  444. this.wormlist.push(obj)
  445. }
  446. this.getbaselist()
  447. this.getuseriphonelist()
  448. this.getpeizhi(option.id)
  449. this.warning_id = option.id
  450. }
  451. }
  452. </script>
  453. <style lang="less">
  454. page {
  455. background-color: #F6F6FB;
  456. }
  457. .basesel {
  458. width: 95%;
  459. margin: 20rpx auto;
  460. padding: 30rpx 20rpx;
  461. box-sizing: border-box;
  462. background-color: #fff;
  463. border-radius: 10rpx;
  464. .basesel_list {
  465. width: 100%;
  466. .basesel_list_tilte {
  467. margin-bottom: 60rpx;
  468. font-size: 32rpx;
  469. }
  470. .basesel_list_sel {
  471. display: flex;
  472. margin-bottom: 60rpx;
  473. .basesel_list_sel_left {
  474. width: calc(100% - 40rpx);
  475. display: flex;
  476. flex-wrap: wrap;
  477. color: #999999;
  478. }
  479. .icon {
  480. width: 40rpx;
  481. }
  482. }
  483. }
  484. .basesel_calculate {
  485. margin-top: 30rpx;
  486. display: flex;
  487. }
  488. }
  489. .usersel {
  490. width: 95%;
  491. margin: 20rpx auto;
  492. padding: 30rpx 20rpx;
  493. box-sizing: border-box;
  494. background-color: #fff;
  495. border-radius: 10rpx;
  496. .warmissue_itemone {
  497. margin-bottom: 60rpx;
  498. display: flex;
  499. justify-content: space-between;
  500. .warmissue_itemone_title {
  501. font-size: 32rpx;
  502. }
  503. }
  504. .warmissue_item {
  505. margin-bottom: 60rpx;
  506. display: flex;
  507. .warmissue_item_title {
  508. width: 160rpx;
  509. }
  510. .warmissue_item_text {
  511. width: calc(100% - 160rpx);
  512. }
  513. }
  514. .warmissue_itemtwo {
  515. display: flex;
  516. .itemtwo_left {
  517. width: calc(100% - 40rpx);
  518. display: flex;
  519. flex-wrap: wrap;
  520. color: #999999;
  521. }
  522. .icon {
  523. width: 40rpx;
  524. }
  525. }
  526. }
  527. .target {
  528. width: 95%;
  529. margin: 20rpx auto;
  530. padding: 30rpx 20rpx;
  531. box-sizing: border-box;
  532. background-color: #fff;
  533. border-radius: 10rpx;
  534. .target_title {
  535. margin-bottom: 40rpx;
  536. display: flex;
  537. justify-content: space-between;
  538. .target_title_left {
  539. font-size: 24rpx;
  540. color: #999999;
  541. .target_title_left_title {
  542. font-size: 32rpx;
  543. color: #2F2F30;
  544. }
  545. }
  546. }
  547. .target_text {
  548. width: 100%;
  549. .target_text_item {
  550. width: 100%;
  551. margin-top: 30rpx;
  552. display: flex;
  553. justify-content: space-between;
  554. .target_text_item_sel {
  555. width: 40%;
  556. display: flex;
  557. justify-content: space-between;
  558. line-height: 70rpx;
  559. height: 70rpx;
  560. border-bottom: 1px solid #aaaaad;
  561. .itemtwo_left {
  562. color: #999999;
  563. }
  564. }
  565. .target_text_item_ipt {
  566. width: 40%;
  567. /deep/.u-input__right-icon {
  568. line-height: 35px;
  569. }
  570. /deep/.uni-input-input {
  571. border-bottom: 1px solid #aaaaad;
  572. }
  573. /deep/.u-input__input {
  574. border-bottom: 1px solid #aaaaad;
  575. }
  576. }
  577. .addordel {
  578. width: 10%;
  579. line-height: 35px;
  580. }
  581. }
  582. }
  583. /deep/.uni-input-input {
  584. border-bottom: 1px solid #aaaaad;
  585. }
  586. }
  587. .sendbox {
  588. margin: 40rpx auto;
  589. width: 80%;
  590. background-color: #14A478;
  591. padding: 20rpx 0;
  592. border-radius: 59px;
  593. text-align: center;
  594. color: #fff;
  595. }
  596. </style>