warnset.vue 16 KB

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