note.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 44px;">
  5. <view style="position: fixed;z-index: 100;">
  6. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" title="短信预警"></uni-nav-bar>
  7. </view>
  8. <view class="earlywarning">
  9. <view class="kind">
  10. <view class="kind_top">
  11. <p class="kind_top_title">目标种类预警</p>
  12. <u-switch v-model="checked1" size="30" style="margin-top: 6rpx;" active-color="#58C876"></u-switch>
  13. </view>
  14. <view class="kind_bot">
  15. <p class="kind_bot_title">害虫种类数量设置:</p>
  16. <input type="number" v-model="form.pestCategoryNum" :disabled="!checked1" />
  17. </view>
  18. <p class="hint">(每天害虫种类数量达到此数量时,短信预警)</p>
  19. </view>
  20. <view class="kind">
  21. <view class="kind_top">
  22. <p class="kind_top_title">指定害虫数量预警</p>
  23. <u-switch v-model="checked2" size="30" style="margin-top: 6rpx;" active-color="#58C876"></u-switch>
  24. </view>
  25. <view class="kind_box" v-for="item,index in kindnum" :key="index" v-if="appointPestNames[index]">
  26. <view class="kind_bot">
  27. <p class="kind_bot_title">害虫种类:</p>
  28. <view class="input" @click="pickerchange(index)">
  29. <input type="text" v-model="selector[Number(appointPestNames[index])]" :disabled="!checked2" />
  30. <u-icon name="arrow-down" class="icon"></u-icon>
  31. </view>
  32. </view>
  33. <view class="kind_bot">
  34. <p class="kind_bot_title">害虫数量:</p>
  35. <input type="number" v-model="appointPestNums[index]" :disabled="!checked2" />
  36. </view>
  37. <u-icon name="plus-circle" class="icons" size="40" color="#28AE4F" @click="addkindnum(index)" v-if="index==0"></u-icon>
  38. <u-icon name="trash" class="icons" size="40" color="#ff0000" @click="jiankindnum(index)" v-else></u-icon>
  39. </view>
  40. <u-picker v-model="pickertf" mode="selector" @confirm="confirmFun2" :default-selector="[Number(appointPestNames[datasindex])]" :range="selector"></u-picker>
  41. <p class="hint">(每天指定害虫数量达到此数量时,短信预警)</p>
  42. </view>
  43. <view class="kind">
  44. <view class="kind_top">
  45. <p class="kind_top_title">害虫数量总和预警</p>
  46. <u-switch v-model="checked3" size="30" style="margin-top: 6rpx;" active-color="#58C876"></u-switch>
  47. </view>
  48. <view class="kind_bot">
  49. <p class="kind_bot_title">害虫总和数量设置:</p>
  50. <input type="number" v-model="form.pestTotalNum" :disabled="!checked3" />
  51. </view>
  52. <p class="hint">(每天害虫数量总和达到此数量时,短信预警)</p>
  53. </view>
  54. <view class="kind">
  55. <view class="kind_top">
  56. <p class="kind_top_title">综合预警</p>
  57. <u-switch v-model="checked4" size="30" style="margin-top: 6rpx;" active-color="#58C876"></u-switch>
  58. </view>
  59. <view class="kind_bot">
  60. <p class="kind_bot_title">每天检测害虫种类及数量,短信预警</p>
  61. </view>
  62. </view>
  63. <view class="kind">
  64. <view class="kind_top">
  65. <p class="kind_top_title">信息接收</p>
  66. </view>
  67. <view class="kind_bot">
  68. <p class="kind_bot_title">信息接受手机号:</p>
  69. <input type="number" v-model="form.phone" @blur="phonereg" />
  70. </view>
  71. <p class="hint" v-if="phonetf">请输入正确的手机号</p>
  72. </view>
  73. <view class="tijiao" @click="btn">
  74. 确 定
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. </template>
  80. <script>
  81. import cbddatas from "../../../../static/data/cbd_pest_library.js"
  82. export default {
  83. data() {
  84. return {
  85. checked1: false,
  86. checked2: false,
  87. checked3: false,
  88. checked4: false,
  89. pickertf: false,
  90. device_id: '',
  91. conf: "",
  92. form: {},
  93. phonetf: false,
  94. selector: [],
  95. kindnum:1,
  96. kindtf:-1,
  97. datasindex:null,
  98. appointPestNames:[-1],//害虫名称
  99. appointPestNums:[],//害虫数量
  100. }
  101. },
  102. methods: {
  103. async notealloc() { //查询短信配置
  104. const res = await this.$myRequest({
  105. url: '/api/api_gateway?method=forecast.forecast_system.cbd_msg_conf',
  106. data: {
  107. device_id: this.device_id,
  108. conf: this.conf
  109. }
  110. })
  111. console.log(res)
  112. this.form = JSON.parse(res)
  113. console.log(this.form)
  114. if(this.conf==""){
  115. this.appointPestNames = this.form.appointPestName.split("#")
  116. this.appointPestNums = this.form.appointPestNum.split("#")
  117. if(this.appointPestNames.length==0){
  118. this.kindnum = 1
  119. }else{
  120. this.kindnum = this.appointPestNames.length
  121. }
  122. if (this.form.pestCategory == "on") {
  123. this.checked1 = true
  124. } else {
  125. this.checked1 = false
  126. }
  127. //pestTotal 总和开关
  128. if (this.form.pestTotal == "on") {
  129. this.checked3 = true
  130. } else {
  131. this.checked3 = false
  132. }
  133. //pestWarn综合预警
  134. if (this.form.pestWarn == "on") {
  135. this.checked4 = true
  136. } else {
  137. this.checked4 = false
  138. }
  139. //appointPest指定害虫
  140. if (this.form.appointPest == "on") {
  141. this.checked2 = true
  142. } else {
  143. this.checked2 = false
  144. }
  145. }else{
  146. if(res){
  147. uni.showToast({
  148. title: '操作成功!',
  149. duration: 2000,
  150. icon:"none"
  151. });
  152. }
  153. }
  154. //种类
  155. },
  156. btn() {
  157. if(this.checked1==true || this.checked2==true || this.checked3==true || this.checked4==true){
  158. if (this.checked1 == true) {
  159. this.form.pestCategory = "on"
  160. } else {
  161. this.form.pestCategory = "off"
  162. }
  163. //pestTotal 总和开关
  164. if (this.checked3 == true) {
  165. this.form.pestTotal = "on"
  166. } else {
  167. this.form.pestTotal = "off"
  168. }
  169. //pestWarn综合预警
  170. if (this.checked4 == true) {
  171. this.form.pestWarn = "on"
  172. } else {
  173. this.form.pestWarn = "off"
  174. }
  175. //appointPest指定害虫
  176. if (this.checked2 == true) {
  177. this.form.appointPest = "on"
  178. } else {
  179. this.form.appointPest = "off"
  180. }
  181. var obj = {}
  182. for(var i=0;i<this.kindnum;i++){
  183. obj["appointPestName"+(i+1)] = this.appointPestNames[i]
  184. obj["appointPestName"] = this.appointPestNames.join("#")
  185. obj["appointPestNum"+(i+1)] = this.appointPestNums[i]
  186. obj["appointPestNum"] = this.appointPestNums.join("#")
  187. }
  188. Object.assign(this.form,obj)
  189. console.log(this.form)
  190. this.conf = JSON.stringify(this.form)
  191. var namesome = this.appointPestNames.some((item)=>{
  192. return item == -1
  193. })
  194. var numsome = false;
  195. if(this.appointPestNums.length != this.appointPestNames.length){
  196. numsome = true
  197. }
  198. var arr = false
  199. if(this.checked1){
  200. if(!this.form.pestCategoryNum){
  201. uni.showToast({
  202. title: '请输入害虫种类数量!',
  203. duration: 2000,
  204. icon:"none"
  205. });
  206. arr=false
  207. }else{
  208. arr=true
  209. }
  210. }
  211. if(this.checked2){
  212. if(namesome){
  213. uni.showToast({
  214. title: '请将指定害虫数量信息填写完全!',
  215. duration: 2000,
  216. icon:"none"
  217. });
  218. arr=false
  219. }else if(numsome){
  220. uni.showToast({
  221. title: '请将指定害虫数量信息填写完全!',
  222. duration: 2000,
  223. icon:"none"
  224. });
  225. arr=false
  226. }else{
  227. arr = true
  228. }
  229. }
  230. if(this.checked3){
  231. if(!this.form.pestTotalNum){
  232. uni.showToast({
  233. title: '请输入害虫种类总和数量!',
  234. duration: 2000,
  235. icon:"none"
  236. });
  237. arr=false
  238. }else{
  239. arr=true
  240. }
  241. }
  242. if(this.form.phone){
  243. if(!this.phonetf && arr){
  244. this.notealloc()
  245. }
  246. }else{
  247. uni.showToast({
  248. title: '请输入手机号码!',
  249. duration: 2000,
  250. icon:"none"
  251. });
  252. }
  253. }else{
  254. uni.showToast({
  255. title: '请在开启预警后点击确定!',
  256. duration: 2000,
  257. icon:"none"
  258. });
  259. }
  260. },
  261. phonereg() {
  262. if (/^1[23456789]\d{9}$/.test(this.form.phone)) {
  263. this.phonetf = false
  264. } else {
  265. this.phonetf = true
  266. }
  267. },
  268. confirmFun2(index) {
  269. this.appointPestNames[this.datasindex] = index[0]
  270. },
  271. clickLeft() {
  272. uni.navigateBack({
  273. delta: 1
  274. })
  275. },
  276. pickerchange(index){
  277. if(this.checked2){
  278. this.pickertf = !this.pickertf
  279. this.datasindex = index
  280. }else{
  281. uni.showToast({
  282. title: '请在开启预警后输入!',
  283. duration: 2000,
  284. icon:"none"
  285. });
  286. }
  287. },
  288. addkindnum(){
  289. this.kindnum++
  290. this.appointPestNames.push(-1)
  291. console.log(this.appointPestNames)
  292. },
  293. jiankindnum(index){
  294. console.log(index)
  295. this.kindnum--
  296. console.log(this.appointPestNames)
  297. this.appointPestNames.splice(index,1)
  298. this.appointPestNums.splice(index,1)
  299. }
  300. },
  301. onLoad(option) {
  302. this.device_id = option.device_id
  303. this.notealloc()
  304. for (var key in cbddatas) {
  305. this.selector[key] = cbddatas[key]
  306. }
  307. }
  308. }
  309. </script>
  310. <style lang="scss">
  311. .earlywarning {
  312. position: absolute;
  313. top: 54px;
  314. width: 100%;
  315. .kind {
  316. width: 90%;
  317. margin: 0 auto 40rpx;
  318. .kind_top {
  319. display: flex;
  320. justify-content: space-between;
  321. .kind_top_title {
  322. border-left: 8rpx solid #28AE4F;
  323. height: 40rpx;
  324. padding-left: 20rpx;
  325. }
  326. }
  327. .kind_box{
  328. position: relative;
  329. .icons{
  330. position: absolute;
  331. top: 40rpx;
  332. right: 50rpx;
  333. }
  334. }
  335. .kind_bot {
  336. display: flex;
  337. padding-left: 28rpx;
  338. margin: 30rpx 0 0;
  339. .kind_bot_title {
  340. font-size: 26rpx;
  341. color: #A7A7A7;
  342. margin-right: 10rpx;
  343. }
  344. input {
  345. border: 2rpx solid #E4E4E4;
  346. font-size: 26rpx;
  347. width: 55%;
  348. padding-left: 10rpx;
  349. }
  350. .input {
  351. position: relative;
  352. width: 55%;
  353. input {
  354. width: 100%;
  355. }
  356. .icon {
  357. position: absolute;
  358. top: 10rpx;
  359. right: 0;
  360. }
  361. }
  362. }
  363. .hint {
  364. font-size: 24rpx;
  365. text-align: right;
  366. color: #ff0000;
  367. margin-top: 10rpx;
  368. }
  369. }
  370. .tijiao {
  371. width: 90%;
  372. text-align: center;
  373. font-size: 34rpx;
  374. height: 60rpx;
  375. line-height: 60rpx;
  376. color: #FFFFFF;
  377. background-color: #28AE4F;
  378. margin: 80rpx auto 0;
  379. border-radius: 30rpx;
  380. }
  381. }
  382. </style>