MessageWarn.vue 16 KB

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