warnset.vue 18 KB

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