MessageWarn.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. <template>
  2. <div>
  3. <el-breadcrumb separator-class="el-icon-arrow-right" :class="'el-icon-arrow-right '+ (flag.flag == false ? 'breadcrumb_tab' : '')">
  4. <el-breadcrumb-item :to="{ path: '/index/cbd' }">物联网虫情测报</el-breadcrumb-item>
  5. <el-breadcrumb-item>短信通知</el-breadcrumb-item>
  6. </el-breadcrumb>
  7. <div class="innerBox">
  8. <!-- 1 -->
  9. <div class="category">
  10. <div class="titleNum">
  11. <span>1</span>
  12. </div>
  13. <div class="wormItem">
  14. <h2>目标种类预警</h2>
  15. <div class="previewSwitchBox">
  16. <span>害虫种类数预警</span>
  17. <el-switch
  18. v-model="switch1"
  19. active-color="#13ce66"
  20. inactive-color="#dcdfe6"
  21. @change="switch1Fun"
  22. ></el-switch>
  23. </div>
  24. <div class="limitValBox">
  25. <div>
  26. <el-input
  27. v-model="input1"
  28. type="number"
  29. ref="input"
  30. placeholder="请填写害虫数量"
  31. clearable
  32. @change="input1ChangeFun"
  33. ></el-input>
  34. </div>
  35. <div class="hint">
  36. 每天害虫
  37. <span>种类数量</span>达到此值时,短信预警
  38. </div>
  39. </div>
  40. <div class="previewBox">
  41. <el-button :type="input1!=''?'success':''" @click="previewFun" round size="mini">预览</el-button>
  42. </div>
  43. </div>
  44. </div>
  45. <!-- 2 -->
  46. <div class="category">
  47. <div class="titleNum">
  48. <span>2</span>
  49. </div>
  50. <div class="wormItem">
  51. <h2>数量预警</h2>
  52. <div class="previewSwitchBox">
  53. <span>指定害虫数量预警</span>
  54. <el-switch
  55. v-model="switch2"
  56. active-color="#13ce66"
  57. inactive-color="#dcdfe6"
  58. @change="switch2Fun"
  59. ></el-switch>
  60. </div>
  61. <div class="limitValBox">
  62. <div class="limitWormItem">
  63. <div class="limitWormItemBox" v-for="(item,index) in planKind" :key="index">
  64. <el-select v-model="item.value" placeholder="请选择害虫种类">
  65. <el-option v-for="num in cbdPestNum" :key="num" :label="cbdPest[num]" :value="num"></el-option>
  66. </el-select>
  67. <el-input
  68. v-model="item.nums"
  69. type="number"
  70. placeholder="请填写害虫数量"
  71. clearable
  72. @change="wormNumFun2"
  73. ></el-input>
  74. <i v-if="index==0" class="el-icon-circle-plus-outline" @click="addWormKind"></i>
  75. <i v-if="index!=0" class="el-icon-delete" @click="delWormKind(index)"></i>
  76. </div>
  77. </div>
  78. <div class="hint">
  79. 每天
  80. <span>指定害虫数</span>达到此数量时,短信预警
  81. </div>
  82. </div>
  83. <div class="previewBox">
  84. <el-button :type="reversedMessage?'success':''" @click="previewFun2" round size="mini">预览</el-button>
  85. </div>
  86. </div>
  87. </div>
  88. <!-- 3 -->
  89. <div class="category">
  90. <div class="titleNum">
  91. <span>3</span>
  92. </div>
  93. <div class="wormItem">
  94. <h2>数量预警</h2>
  95. <div class="previewSwitchBox">
  96. <span>害虫数量总和预警</span>
  97. <el-switch
  98. v-model="switch3"
  99. active-color="#13ce66"
  100. inactive-color="#dcdfe6"
  101. @change="switch3Fun"
  102. ></el-switch>
  103. </div>
  104. <div class="limitValBox">
  105. <div>
  106. <el-input
  107. v-model="input3"
  108. type="number"
  109. ref="input3"
  110. placeholder="请填写害虫数量"
  111. clearable
  112. @change="input3ChangeFun"
  113. ></el-input>
  114. </div>
  115. <div class="hint">
  116. 每天害虫
  117. <span>种类数量</span>达到此值时,短信预警
  118. </div>
  119. </div>
  120. <div class="previewBox">
  121. <el-button :type="input3!=''?'success':''" @click="previewFun3" round size="mini">预览</el-button>
  122. </div>
  123. </div>
  124. </div>
  125. <!-- 4 -->
  126. <div class="category">
  127. <div class="titleNum">
  128. <span>4</span>
  129. </div>
  130. <div class="wormItem">
  131. <h2>综合预警</h2>
  132. <div class="previewSwitchBox">
  133. <span>监测每天出现的害虫种类及数量,短信预警</span>
  134. <el-switch v-model="switch4" active-color="#13ce66" inactive-color="#dcdfe6"></el-switch>
  135. </div>
  136. <div class="previewBox">
  137. <el-button type="success" @click="previewFun4" round size="mini">预览</el-button>
  138. </div>
  139. </div>
  140. </div>
  141. <!-- 5 -->
  142. <div class="category">
  143. <div class="titleNum">
  144. <span>5</span>
  145. </div>
  146. <div class="wormItem">
  147. <h2>信息接收</h2>
  148. <div class="limitValBox">
  149. <div class="receptionPhone">
  150. <el-input
  151. v-model="input5"
  152. ref="tel"
  153. type="tel"
  154. placeholder="请填写信息接收手机号"
  155. clearable
  156. @change="telRegular"
  157. ></el-input>
  158. </div>
  159. </div>
  160. </div>
  161. </div>
  162. <div>
  163. <el-button type="primary" @click="submitData()">提交</el-button>
  164. <el-button type="info">重置</el-button>
  165. </div>
  166. </div>
  167. <!-- 预览框 -->
  168. <el-dialog
  169. width="500px"
  170. top="50px"
  171. :visible.sync="dialogVisible"
  172. custom-class="previewDialog"
  173. :close-on-click-modal="false"
  174. :show-close="true"
  175. >
  176. <div class="noteWarnBj">
  177. <div class="noteWarnTxt" ref="txt" v-html="dialogHtml"></div>
  178. <div class="noteWarnTime">上午 8:49</div>
  179. </div>
  180. </el-dialog>
  181. </div>
  182. </template>
  183. <script>
  184. import dict from '../../../../static/js/cbd_pest_library.js'
  185. export default {
  186. props: {
  187. flag: {
  188. flag: Boolean,
  189. siteID: Number
  190. },
  191. },
  192. data() {
  193. return {
  194. switch1: false,
  195. input1: '',
  196. dialogVisible: false,
  197. // 2
  198. switch2: false,
  199. input2: false,
  200. cbdPest: dict,
  201. cbdPestNum: 332,
  202. planKind: [
  203. {
  204. label: '',
  205. value: '',
  206. nums: 0
  207. }
  208. ],
  209. // 3
  210. switch3: false,
  211. input3: '',
  212. // 4
  213. switch4: false,
  214. // 5
  215. input5: '',
  216. dialogHtml: '',
  217. value: true,
  218. input: '',
  219. options: [
  220. {
  221. value: '选项1',
  222. label: '1'
  223. },
  224. {
  225. value: '选项2',
  226. label: '2'
  227. }
  228. ],
  229. value2: ''
  230. // redata: {}, //回显数据
  231. }
  232. },
  233. computed: {
  234. // 计算属性的 getter
  235. reversedMessage: function () {
  236. // `this` 指向 vm 实例
  237. var planKind = this.planKind
  238. var len = this.planKind.length
  239. for (var i = 0; i < len; i++) {
  240. if (!(planKind[i].value && planKind[i].nums != 0)) {
  241. return false
  242. }
  243. if (i == len - 1) {
  244. return true
  245. }
  246. }
  247. }
  248. },
  249. created() {
  250. // this.getHisDataList();
  251. },
  252. mounted() {
  253. // this.echartsFn();
  254. this.warningData()
  255. },
  256. methods: {
  257. switch1Fun() {
  258. console.log(this.switch1)
  259. if (this.switch1 && !this.input1) {
  260. this.$message({
  261. message: '请将数据填写完整,再进行操作',
  262. type: 'warning'
  263. })
  264. this.$refs.input.focus()
  265. this.switch1 = false
  266. }
  267. },
  268. previewFun() {
  269. if (this.input1) {
  270. this.dialogVisible = true
  271. var html =
  272. "尊敬的用户:您的虫情测报设备:868956044830804,于<span>2019-08-31</span>监测到害虫种类数量{'" +
  273. this.input1 +
  274. "'}种,请注意防范(详情请登陆<span>www.yfzhwlw.com</span>查看)"
  275. this.dialogHtml = html
  276. } else {
  277. this.$message({
  278. message: '请将数据填写完整,再进行查看',
  279. type: 'warning'
  280. })
  281. this.$refs.input.focus()
  282. }
  283. },
  284. input1ChangeFun() {
  285. if (!this.input1) {
  286. this.switch1 = false
  287. }
  288. },
  289. // 2
  290. addWormKind() {
  291. var planKind = this.planKind
  292. var len = this.planKind.length
  293. for (var i = 0; i < len; i++) {
  294. if (!(planKind[i].value && planKind[i].nums != 0)) {
  295. this.$message({
  296. message: '请将数据填写完整,再进行添加',
  297. type: 'warning'
  298. })
  299. return false
  300. }
  301. if (i == len - 1) {
  302. planKind.push({
  303. label: '',
  304. value: '',
  305. nums: 0
  306. })
  307. }
  308. }
  309. },
  310. delWormKind(index) {
  311. var planKind = this.planKind
  312. planKind.splice(index, 1)
  313. },
  314. previewFun2() {
  315. if (this.reversedMessage) {
  316. var html =
  317. "尊敬的用户:您的虫情测报设备:865650044512263,于<span>2019-08-31</span>监测到害虫{'" +
  318. this.cbdPest[this.planKind[0].value] +
  319. "'}数量{'" +
  320. this.planKind[0].nums +
  321. "'}种,请注意防范(详情请登陆<span>www.yfzhwlw.com</span>查看)"
  322. this.dialogHtml = html
  323. this.dialogVisible = true
  324. } else {
  325. this.$message({
  326. message: '请将数据填写完整,再进行查看',
  327. type: 'warning'
  328. })
  329. }
  330. },
  331. switch2Fun() {
  332. if (!this.reversedMessage) {
  333. this.$message({
  334. message: '请将数据填写完整,再进行操作',
  335. type: 'warning'
  336. })
  337. this.switch2 = false
  338. }
  339. },
  340. wormNumFun2() {
  341. if (!this.reversedMessage) {
  342. this.switch2 = false
  343. }
  344. },
  345. // 3
  346. switch3Fun() {
  347. console.log(this.switch1)
  348. if (this.switch3 && !this.input3) {
  349. this.$message({
  350. message: '请将数据填写完整,再进行操作',
  351. type: 'warning'
  352. })
  353. this.$refs.input3.focus()
  354. this.switch3 = false
  355. }
  356. },
  357. previewFun3() {
  358. if (this.input3) {
  359. this.dialogVisible = true
  360. var html =
  361. "尊敬的用户:您的虫情测报设备:868956044830804,于<span>2019-08-31</span>监测到害虫数量已达到{'" +
  362. this.input3 +
  363. "'},请注意防范(详情请登陆<span>www.yfzhwlw.com</span>查看)"
  364. this.dialogHtml = html
  365. } else {
  366. this.$message({
  367. message: '请将数据填写完整,再进行查看',
  368. type: 'warning'
  369. })
  370. this.$refs.input3.focus()
  371. }
  372. },
  373. input3ChangeFun() {
  374. if (!this.input3) {
  375. this.switch3 = false
  376. }
  377. },
  378. // 4
  379. previewFun4() {
  380. this.dialogVisible = true
  381. var html =
  382. "尊敬的用户:您的虫情测报设备:868956044830804,于<span>2019-08-31</span>监测到害虫{'暗黑鳃金龟': '5头', '二点委夜蛾': '5头', '玉米螟': '23头', '东方粘虫': '1头', '蝼蛄': '1头'}(详情请登陆<span>www.yfzhwlw.com</span>查看)"
  383. // var html = "尊敬的用户:您的虫情测报设备:868956044830804,于<span>2019-08-31</span>监测到害虫数量已达到{'"+this.input3+"'},请注意防范(详情请登陆<span>www.yfzhwlw.com</span>查看)";
  384. this.dialogHtml = html
  385. },
  386. // 5
  387. telRegular() {
  388. if (this.input5) {
  389. if (!/^1[3456789]\d{9}$/.test(this.input5)) {
  390. this.$message({
  391. message: '手机号码有误,请重填',
  392. type: 'warning'
  393. })
  394. this.$refs.tel.focus()
  395. return false
  396. }
  397. }
  398. },
  399. // 提交数据
  400. submitData() {
  401. let that = this
  402. var pestCategory = that.switch1 == true ? 'on' : 'off' //目标种类预警 pestCategory
  403. var appointPest = that.switch2 == true ? 'on' : 'off' //指定害虫数量预警 appointPest
  404. var pestTotal = that.switch3 == true ? 'on' : 'off' //害虫数量总和预警 pestTotal
  405. var pestWarn = that.switch4 == true ? 'on' : 'off' //综合预警 pestWarn
  406. console.log(that.planKind)
  407. var plantName = []
  408. var plantNums = []
  409. var plantObj = {}
  410. for (var i = 0; i < that.planKind.length; i++) {
  411. plantName.push(that.planKind[i].value)
  412. plantNums.push(that.planKind[i].nums)
  413. plantObj['appointPestNum' + (i + 1)] = that.planKind[i].nums
  414. plantObj['appointPestName' + (i + 1)] = that.planKind[i].value
  415. }
  416. plantObj['pestCategoryNum'] = that.input1 //目标种类预警
  417. plantObj['pestTotalNum'] = that.input3 //害虫数量总和预警
  418. plantObj['phone'] = that.input5 //信息接收
  419. plantObj['appointPestName'] = plantName.join('#') //指定害虫数量预警
  420. plantObj['appointPestNum'] = plantNums.join('#') //指定害虫数量预警
  421. plantObj['pestCategory'] = pestCategory
  422. plantObj['appointPest'] = appointPest
  423. plantObj['pestTotal'] = pestTotal
  424. plantObj['pestWarn'] = pestWarn
  425. let postData = that.qs.stringify({
  426. device_id: that.$route.params.id,
  427. conf: JSON.stringify(plantObj)
  428. })
  429. that
  430. .$axios({
  431. method: 'post',
  432. url: '/api_gateway?method=forecast.forecast_system.cbd_msg_conf',
  433. data: postData
  434. })
  435. .then((res) => {
  436. if (res.data.data == true && res.data.message == '') {
  437. that.$message({
  438. showClose: true,
  439. message: '设置成功',
  440. type: 'success',
  441. duration: 1500
  442. })
  443. } else {
  444. that.$message({
  445. showClose: true,
  446. message: '设置失败',
  447. type: 'error',
  448. duration: 1500
  449. })
  450. }
  451. })
  452. .catch((err) => {
  453. console.log(err)
  454. })
  455. },
  456. // 请求数据返显
  457. warningData() {
  458. let that = this
  459. let postData = that.qs.stringify({
  460. device_id: that.$route.params.id,
  461. conf: ''
  462. })
  463. that
  464. .$axios({
  465. method: 'post',
  466. url: '/api_gateway?method=forecast.forecast_system.cbd_msg_conf',
  467. data: postData
  468. })
  469. .then((res) => {
  470. if (res.data.data !== null || res.data.data !== '') {
  471. var redata = JSON.parse(res.data.data)
  472. that.input1 = redata.pestCategoryNum //目标种类预警
  473. that.input2 = redata.appointPestNum1 //指定害虫数量预警
  474. that.input3 = redata.pestTotalNum //害虫数量总和预警
  475. that.input5 = redata.phone //信息接收
  476. that.planKind[0].nums = redata.appointPestNum1 //数量预警害虫数量
  477. that.planKind[0].value = redata.appointPestName1 //数量预警害虫
  478. that.switch1 = redata.pestCategory == 'on' ? true : false //目标种类预警
  479. that.switch2 = redata.appointPest == 'on' ? true : false //指定害虫数量预警
  480. that.switch3 = redata.pestTotal == 'on' ? true : false //害虫数量总和预警
  481. that.switch4 = redata.pestWarn == 'on' ? true : false //综合预警
  482. var val = redata.appointPestName
  483. var nums = redata.appointPestNum
  484. var arr = val.split('#')
  485. var arrA = nums.split('#')
  486. that.planKind = []
  487. for (let i = 0; i < arr.length; i++) {
  488. var obj = {}
  489. obj['value'] = parseInt(arr[i])
  490. obj['nums'] = arrA[i]
  491. obj['label'] = ''
  492. that.planKind.push(obj)
  493. }
  494. }
  495. })
  496. .catch((err) => {
  497. console.log(err)
  498. })
  499. }
  500. }
  501. }
  502. </script>
  503. <style lang='less' scoped>
  504. .innerBox {
  505. background: #fff;
  506. border-radius: 15px;
  507. padding: 20px;
  508. .category {
  509. margin-top: 20px;
  510. display: flex;
  511. :first-child {
  512. margin-top: 0px;
  513. }
  514. .titleNum {
  515. display: inline-block;
  516. width: 30px;
  517. height: 30px;
  518. line-height: 30px;
  519. text-align: center;
  520. border-radius: 50%;
  521. background: rgba(20, 164, 120, 0.18);
  522. color: #14a478;
  523. margin-right: 20px;
  524. margin-top: 2px;
  525. }
  526. .wormItem {
  527. flex: 1;
  528. h2 {
  529. line-height: 30px;
  530. font-size: 18px;
  531. margin: 0;
  532. }
  533. .previewSwitchBox {
  534. font-size: 14px;
  535. line-height: 50px;
  536. letter-spacing: 2px;
  537. }
  538. .limitValBox {
  539. display: flex;
  540. align-content: center;
  541. .limitWormItem {
  542. > div {
  543. margin-bottom: 10px;
  544. :last-child {
  545. margin: 0;
  546. }
  547. }
  548. }
  549. .receptionPhone {
  550. margin: 10px 0 30px 0;
  551. }
  552. .el-select {
  553. width: 300px;
  554. margin-right: 20px;
  555. }
  556. .el-input {
  557. width: 300px;
  558. margin-right: 20px;
  559. }
  560. i {
  561. line-height: 40px;
  562. font-size: 21px;
  563. cursor: pointer;
  564. color: #35a478;
  565. }
  566. .hint {
  567. margin-left: 15px;
  568. line-height: 40px;
  569. font-size: 14px;
  570. color: #606060;
  571. span {
  572. color: #000;
  573. font-weight: bold;
  574. }
  575. }
  576. }
  577. .previewBox {
  578. margin: 15px 0;
  579. .el-button--success {
  580. background-color: #14a478;
  581. border-color: #14a478;
  582. }
  583. button {
  584. padding: 5px 15px;
  585. }
  586. }
  587. }
  588. }
  589. }
  590. /deep/.previewDialog.el-dialog {
  591. background: transparent;
  592. box-shadow: none;
  593. .el-dialog__headerbtn {
  594. .el-dialog__close {
  595. color: #ffffff;
  596. border: 1px solid #fff;
  597. border-radius: 50%;
  598. padding: 4px;
  599. }
  600. :hover {
  601. color: #14a478;
  602. border: 1px solid #14a478;
  603. }
  604. }
  605. .el-dialog__header {
  606. background: transparent;
  607. border-bottom: 0 solid transparent;
  608. }
  609. .el-dialog__body {
  610. padding: 0;
  611. .noteWarnBj {
  612. width: 500px;
  613. height: 775px;
  614. background: url(~@/assets/images/forecasting/cbd/noteWarnBj.png) no-repeat
  615. center;
  616. background-size: contain;
  617. overflow: hidden;
  618. .noteWarnTxt {
  619. width: 46%;
  620. margin: 136px 0 10px 23%;
  621. background: #f2f2f2;
  622. padding: 10px;
  623. span {
  624. color: #0099f2;
  625. }
  626. }
  627. .noteWarnTime {
  628. width: 46%;
  629. margin: 13px 0 10px 23%;
  630. }
  631. }
  632. }
  633. }
  634. .breadcrumb_tab {
  635. top: 60px !important;
  636. }
  637. </style>