warning_message.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. //获取应用实例
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. //设置初始值
  9. aa: [],
  10. arrayA: [],
  11. dexData: [], //添加的所有害虫名称数组
  12. dexNum: [], //添加的所有害虫数量数组
  13. Index: 0,
  14. typeNum: '', //害虫种类数量input
  15. insectNum: '', //害虫数量inputs
  16. sumNum: '', //害虫数量总和input
  17. phone: '', //信息接收手机号input
  18. switch1Checked: false, //目标种类预警swicth开关
  19. switch2Checked: false, //指定害虫数量预警swicth开关
  20. switch3Checked: false, //害虫数量综合预警swicth开关
  21. switch4Checked: false, //综合预警swicth开关
  22. swit1: '', //目标种类预警
  23. swit2: '', //指定害虫数量预警
  24. swit3: '', //害虫数量综合预警
  25. swit4: '', //综合预警
  26. swit5: '', //信息接收
  27. arrayb: [], //测试
  28. insectName: '', //测试选中害虫的name
  29. //按钮大小
  30. Size: '15',
  31. windowHeight: app.globalData.windowHeight
  32. },
  33. //指定害虫数量
  34. watchPassWord: function (event) {
  35. var dexNum = this.data.dexNum
  36. var num = event.detail.value
  37. if (dexNum.length >= 5) {
  38. console.log('最多添加五条数据')
  39. } else if (dexNum.length < 6) {
  40. dexNum.push(num + '#')
  41. }
  42. this.setData({
  43. dexNum: dexNum
  44. })
  45. this.data.dexNum = dexNum
  46. },
  47. //指定害虫数量预警添加input
  48. addInsect: function () {
  49. var old = this.data.arrayA; //大数组
  50. var aa = this.data.aa
  51. var a = {index: 0, array: aa}
  52. if (old.length >= 5) {
  53. console.log('最多添加五条数据')
  54. } else if (old.length < 6) {
  55. old.push(a)
  56. }
  57. this.setData({
  58. arrayA: old
  59. })
  60. },
  61. //目标种类预警swicth开关
  62. switch1Change: function (e) {
  63. console.log('switch1 发生 change 事件,携带值为' + e.detail.value)
  64. },
  65. //指定害虫数量预警swicth开关
  66. switch2Change: function (e) {
  67. console.log('switch2 发生 change 事件,携带值为' + e.detail.value)
  68. },
  69. //害虫数量综合预警swicth开关
  70. switch3Change: function (e) {
  71. console.log('switch3 发生 change 事件,携带值为' + e.detail.value)
  72. },
  73. //综合预警swicth开关
  74. switch4Change: function (e) {
  75. console.log('switch4 发生 change 事件,携带值为' + e.detail.value)
  76. },
  77. //指定害虫数量-害虫种类选择事件
  78. bindPickerChange: function (e) {
  79. var that = this;
  80. // 定义一个变量curindex 储存触发事件的数组对象的下标
  81. const curindex = e.target.dataset.current
  82. //根据下标 改变该数组对象中的index值
  83. that.data.arrayA[curindex].index = e.detail.value
  84. //把改变某个数组对象index值之后的全新objArray重新 赋值给objArray
  85. this.setData({
  86. arrayA: this.data.arrayA,
  87. Index: e.detail.value, //数组的下标
  88. insectName: that.data.arrayb[e.detail.value]
  89. })
  90. // console.log(that.data.arrayb[e.detail.value].vauls) //获取到选中害虫的ID
  91. var dex = that.data.arrayb[e.detail.value].vauls
  92. var dexData = that.data.dexData;
  93. if (dexData.length >= 5) {
  94. console.log('最多添加五条数据')
  95. } else if (dexData.length < 6) {
  96. dexData.push(dex + '#')
  97. }
  98. // that.setData({
  99. // dexData: dexData
  100. // })
  101. that.data.dexData = dexData
  102. // console.log(dexData)
  103. console.log(that.data.dexData)
  104. },
  105. //提交按钮事件
  106. formSubmit: function (e) {
  107. var that = this;
  108. //测试提交事件
  109. wx.getStorage({
  110. key: 'warningID',
  111. success(res) {
  112. var insectID = that.data.dexData //选中害虫种类的vauls
  113. var typeNum1 = e.detail.value.typeNum //害虫种类数量设置input
  114. var insectNum1 = that.data.dexNum //害虫数量input
  115. var sumNum1 = e.detail.value.sumNum //害虫数量总和设置input
  116. var phone1 = e.detail.value.phone //信息接收手机号input
  117. let swit1 = e.detail.value.swit1
  118. let swit2 = e.detail.value.swit2
  119. let swit3 = e.detail.value.swit3
  120. let swit4 = e.detail.value.swit4
  121. //变换开关值
  122. if (swit1 == true) {
  123. var swi1 = 'on' //开启
  124. } else if (swit1 == false) {
  125. var swi1 = 'off' //关闭
  126. }
  127. if (swit2 == true) {
  128. var swi2 = 'on' //开启
  129. } else if (swit2 == false) {
  130. var swi2 = 'off' //关闭
  131. }
  132. if (swit3 == true) {
  133. var swi3 = 'on' //开启
  134. } else if (swit3 == false) {
  135. console.log('222')
  136. var swi3 = 'off' //关闭
  137. }
  138. if (swit4 == true) {
  139. var swi4 = 'on' //开启
  140. } else if (swit4 == false) {
  141. var swi4 = 'off' //关闭
  142. }
  143. wx.request({
  144. url: 'https://wx.yfzhwlw.com/wechat_pest',
  145. header: {
  146. "Content-Type": "application/x-www-form-urlencoded"
  147. // 'content-type': 'application/json'
  148. },
  149. method: 'post',
  150. dataType: 'json',
  151. data: {
  152. pestCategory: swi1, //目标种类预警
  153. pestCategoryNum: typeNum1, //害虫种类数量设置
  154. appointPest: swi2, //指定害虫数量预警
  155. appointPestName1: insectID, //选中害虫种类vauls
  156. appointPestNum1: insectNum1, //害虫数量
  157. pestTotal: swi3, //害虫数量总和预警
  158. pestTotalNum: sumNum1, //害虫数量总和设置
  159. pestWarn: swi4, //综合预警
  160. phone: phone1, //手机号
  161. equip_id: res.data, //设备号
  162. },
  163. success: function (res) {
  164. if (res.statusCode != 200) {
  165. wx.showToast({ //这里提示失败原因
  166. title: res.data.message,
  167. icon: 'loading',
  168. duration: 1500
  169. })
  170. } else {
  171. console.log(res.data)
  172. if (res.data == 0) {
  173. wx.showToast({
  174. title: '提交成功',
  175. icon: 'success',
  176. duration: 2000
  177. })
  178. } else if (res.data == 1) {
  179. wx.showToast({
  180. title: '提交失败,请重试',
  181. icon: 'none',
  182. duration: 2000
  183. })
  184. }
  185. console.log('成功了')
  186. }
  187. },
  188. fail: function (err) {
  189. console.log(err)
  190. wx.showToast({
  191. title: '请求失败',
  192. icon: 'none',
  193. duration: 1500
  194. })
  195. }
  196. })
  197. }
  198. })
  199. },
  200. //重置按钮事件
  201. Reset: function () {
  202. console.log('重置')
  203. },
  204. //获取害虫种类事件
  205. getInsect: function () {
  206. var that = this;
  207. wx.request({
  208. url: 'https://wx.yfzhwlw.com/wechat_pest',
  209. header: {
  210. "Content-Type": "application/x-www-form-urlencoded"
  211. },
  212. success: function (res) {
  213. if (res.statusCode != 200) {
  214. wx.showToast({ //这里提示失败原因
  215. title: res.data.message,
  216. icon: 'loading',
  217. duration: 1500
  218. })
  219. } else {
  220. var aa = that.data.aa
  221. for (let i = 0; i < res.data.length; i++) {
  222. aa.push(res.data[i].name)
  223. }
  224. that.setData({
  225. arrayb: res.data
  226. })
  227. }
  228. },
  229. fail: function (err) {
  230. wx.showToast({
  231. title: '请求失败',
  232. icon: 'none',
  233. duration: 1500
  234. })
  235. }
  236. })
  237. },
  238. //获取到返显数据进行判断和取值
  239. judge: function (res) {
  240. var that = this
  241. // 种类预警
  242. if (res.pestCategory == 'on') {
  243. that.setData({
  244. switch1Checked: true
  245. })
  246. } else if (res.pestCategory == 'off') {
  247. that.setData({
  248. switch1Checked: false
  249. })
  250. }
  251. //指定害虫数量
  252. if (res.appointPest == 'on') {
  253. that.setData({
  254. switch2Checked: true
  255. })
  256. } else if (res.appointPest == 'off') {
  257. that.setData({
  258. switch2Checked: false
  259. })
  260. }
  261. //害虫数量综合预警
  262. if (res.pestTotal == 'on') {
  263. that.setData({
  264. switch3Checked: true
  265. })
  266. } else if (res.pestTotal == 'off') {
  267. that.setData({
  268. switch3Checked: false
  269. })
  270. }
  271. //综合防治预警
  272. if (res.pestWarn == 'on') {
  273. that.setData({
  274. switch4Checked: true
  275. })
  276. } else if (res.pestWarn == 'off') {
  277. that.setData({
  278. switch4Checked: false
  279. })
  280. }
  281. console.log(res.appointPestName)
  282. console.log(res.appointPestNum)
  283. var insect = res.appointPestName
  284. if (insect[0] == '0') {
  285. console.log('没数据')
  286. } else if (insect[0] !== '0') {
  287. console.log('有数据')
  288. var old = this.data.arrayA; //大数组
  289. var aa = this.data.aa
  290. var a = {index: 0, array: aa}
  291. //指定害虫数量
  292. for (var i = 0; i < insect.length; i++) {
  293. old.push(a)
  294. }
  295. that.setData({
  296. arrayA: old
  297. })
  298. console.log(old)
  299. }
  300. },
  301. /**
  302. * 生命周期函数--监听页面加载
  303. */
  304. onLoad: function (options) {
  305. },
  306. /**
  307. * 生命周期函数--监听页面初次渲染完成
  308. */
  309. onReady: function () {
  310. var that = this;
  311. that.getInsect();
  312. //获取页面初始值
  313. wx.getStorage({
  314. key: 'warningID',
  315. success: function (res) {
  316. //回显在短信预警页面的设备ID
  317. that.setData({
  318. name: res.data
  319. })
  320. wx.request({
  321. url: 'https://wx.yfzhwlw.com/wechat_pest_list',
  322. method: 'post',
  323. header: {
  324. "Content-Type": "application/x-www-form-urlencoded"
  325. },
  326. data: {
  327. equip_id: res.data
  328. },
  329. success: function (res) {
  330. if (res.statusCode != 200) {
  331. wx.showToast({ //这里提示失败原因
  332. title: res.data.message,
  333. icon: 'loading',
  334. duration: 1500
  335. })
  336. } else {
  337. that.setData({
  338. redata: res.data,
  339. })
  340. var res = res.data
  341. that.judge(res)
  342. }
  343. },
  344. fail: function (err) {
  345. console.log(err)
  346. wx.showToast({
  347. title: '请求失败',
  348. icon: 'none',
  349. duration: 1500
  350. })
  351. }
  352. })
  353. }
  354. })
  355. },
  356. /**
  357. * 生命周期函数--监听页面显示
  358. */
  359. onShow: function () {
  360. },
  361. /**
  362. * 生命周期函数--监听页面隐藏
  363. */
  364. onHide: function () {
  365. },
  366. /**
  367. * 生命周期函数--监听页面卸载
  368. */
  369. onUnload: function () {
  370. },
  371. /**
  372. * 页面相关事件处理函数--监听用户下拉动作
  373. */
  374. onPullDownRefresh: function () {
  375. },
  376. /**
  377. * 页面上拉触底事件的处理函数
  378. */
  379. onReachBottom: function () {
  380. },
  381. /**
  382. * 用户点击右上角分享
  383. */
  384. onShareAppMessage: function () {
  385. }
  386. })