MessageWarn.vue 16 KB

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