warnset.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. <template>
  2. <view style="padding-bottom: 30rpx;">
  3. <view class="basesel">
  4. <view class="">
  5. <view class="">
  6. 预警名称
  7. </view>
  8. <view class="">
  9. <u-input v-model="warning_name" placeholder="请输入预警名称" maxlength="24" />
  10. </view>
  11. </view>
  12. <view class="basesel_list">
  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_name:'',
  185. warning_id: "",
  186. selbaselist: [],
  187. warnjihe: "0",
  188. accServiceShow: false,
  189. serviceList: [],
  190. defaultSelected: [],
  191. userphone: [],
  192. accServiceShowphone: false,
  193. serviceListphone: [],
  194. defaultSelectedphone: [],
  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.warning_name = res.warning_name;
  243. this.confnum = []
  244. this.conf.pestCategory = res.conf.pestCategory == "on" ? true : false
  245. this.conf.appointPest = res.conf.appointPest == "on" ? true : false
  246. this.conf.pestTotal = res.conf.pestTotal == "on" ? true : false
  247. this.conf.pestWarn = res.conf.pestWarn == "on" ? true : false
  248. this.conf.pestCategoryNum = res.conf.pestCategoryNum
  249. this.conf.pestTotalNum = res.conf.pestTotalNum
  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. var obj = {
  397. }
  398. // console.log(this.confnum)
  399. for (var i = 0; i < this.confnum.length; i++) {
  400. if (i == 0) {
  401. obj['appointPestName'] = this.confnum[i].appointPestNameid
  402. obj['appointPestNum'] = this.confnum[i].appointPestNum
  403. } else {
  404. obj['appointPestName' + i] = this.confnum[i].appointPestNameid
  405. obj['appointPestNum' + i] = this.confnum[i].appointPestNum
  406. }
  407. }
  408. for (var key in this.conf) {
  409. if (key == "pestCategory" ||
  410. key == "appointPest" ||
  411. key == "pestTotal" ||
  412. key == "pestWarn") {
  413. obj[key] = this.conf[key] ? "on" : "off"
  414. } else {
  415. obj[key] = this.conf[key]
  416. }
  417. }
  418. console.log(obj)
  419. let res = Promise.resolve();
  420. if(this.warning_id){
  421. res = await this.$myRequest({
  422. url: '/api/api_gateway?method=device.device_sms_alert.create_user_pest_warning',
  423. data: {
  424. conf: JSON.stringify(obj),
  425. device_ids: this.device_ids.join(","),
  426. send_user: this.send_user.join(","),
  427. warning_id: this.warning_id,
  428. warning_type: this.warnjihe
  429. }
  430. })
  431. }else{
  432. res = await this.$myRequest({
  433. url: '/api/api_gateway?method=device.device_sms_alert.create_user_warning_config',
  434. data: {
  435. title: this.warning_name,
  436. device_type_id: 3,
  437. conf: JSON.stringify(obj),
  438. device_ids: this.device_ids.join(","),
  439. send_user: this.send_user.join(","),
  440. warning_type: this.warnjihe
  441. }
  442. })
  443. }
  444. console.log(res)
  445. if(res){
  446. uni.showToast({
  447. title: "预警配置成功",
  448. icon: "none"
  449. })
  450. uni.navigateBack({
  451. delta: 1
  452. })
  453. }else{
  454. uni.showToast({
  455. title: "预警配置失败,请稍后再试",
  456. icon: "none"
  457. })
  458. }
  459. }
  460. }
  461. },
  462. onLoad(option) {
  463. // console.log(dict)
  464. console.warn(option.id, 'onload warn set ', option)
  465. this.wormlist = []
  466. for (var key in dict) {
  467. var obj = {
  468. value: key,
  469. label: dict[key]
  470. }
  471. this.wormlist.push(obj)
  472. }
  473. this.getbaselist()
  474. this.getuseriphonelist()
  475. if (option.id) {
  476. this.getpeizhi(option.id)
  477. this.warning_id = option.id
  478. }
  479. }
  480. }
  481. </script>
  482. <style lang="less">
  483. page {
  484. background-color: #F6F6FB;
  485. }
  486. .basesel {
  487. width: 95%;
  488. margin: 20rpx auto;
  489. padding: 30rpx 20rpx;
  490. box-sizing: border-box;
  491. background-color: #fff;
  492. border-radius: 10rpx;
  493. .basesel_list {
  494. width: 100%;
  495. .basesel_list_tilte {
  496. margin-bottom: 60rpx;
  497. font-size: 32rpx;
  498. }
  499. .basesel_list_sel {
  500. display: flex;
  501. margin-bottom: 60rpx;
  502. .basesel_list_sel_left {
  503. width: calc(100% - 40rpx);
  504. display: flex;
  505. flex-wrap: wrap;
  506. color: #999999;
  507. }
  508. .icon {
  509. width: 40rpx;
  510. }
  511. }
  512. }
  513. .basesel_calculate {
  514. margin-top: 30rpx;
  515. display: flex;
  516. }
  517. }
  518. .usersel {
  519. width: 95%;
  520. margin: 20rpx auto;
  521. padding: 30rpx 20rpx;
  522. box-sizing: border-box;
  523. background-color: #fff;
  524. border-radius: 10rpx;
  525. .warmissue_itemone {
  526. margin-bottom: 60rpx;
  527. display: flex;
  528. justify-content: space-between;
  529. .warmissue_itemone_title {
  530. font-size: 32rpx;
  531. }
  532. }
  533. .warmissue_item {
  534. margin-bottom: 60rpx;
  535. display: flex;
  536. .warmissue_item_title {
  537. width: 160rpx;
  538. }
  539. .warmissue_item_text {
  540. width: calc(100% - 160rpx);
  541. }
  542. }
  543. .warmissue_itemtwo {
  544. display: flex;
  545. .itemtwo_left {
  546. width: calc(100% - 40rpx);
  547. display: flex;
  548. flex-wrap: wrap;
  549. color: #999999;
  550. }
  551. .icon {
  552. width: 40rpx;
  553. }
  554. }
  555. }
  556. .target {
  557. width: 95%;
  558. margin: 20rpx auto;
  559. padding: 30rpx 20rpx;
  560. box-sizing: border-box;
  561. background-color: #fff;
  562. border-radius: 10rpx;
  563. .target_title {
  564. margin-bottom: 40rpx;
  565. display: flex;
  566. justify-content: space-between;
  567. .target_title_left {
  568. font-size: 24rpx;
  569. color: #999999;
  570. .target_title_left_title {
  571. font-size: 32rpx;
  572. color: #2F2F30;
  573. }
  574. }
  575. }
  576. .target_text {
  577. width: 100%;
  578. .target_text_item {
  579. width: 100%;
  580. margin-top: 30rpx;
  581. display: flex;
  582. justify-content: space-between;
  583. .target_text_item_sel {
  584. width: 40%;
  585. display: flex;
  586. justify-content: space-between;
  587. line-height: 70rpx;
  588. height: 70rpx;
  589. border-bottom: 1px solid #aaaaad;
  590. .itemtwo_left {
  591. color: #999999;
  592. }
  593. }
  594. .target_text_item_ipt {
  595. width: 40%;
  596. /deep/.u-input__right-icon {
  597. line-height: 35px;
  598. }
  599. }
  600. .addordel {
  601. width: 10%;
  602. }
  603. }
  604. }
  605. /deep/.uni-input-input {
  606. border-bottom: 1px solid #aaaaad;
  607. }
  608. }
  609. .sendbox {
  610. margin: 40rpx auto;
  611. width: 80%;
  612. background-color: #14A478;
  613. padding: 20rpx 0;
  614. border-radius: 59px;
  615. text-align: center;
  616. color: #fff;
  617. }
  618. </style>