| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- //获取应用实例
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- //设置初始值
- aa: [],
- arrayA: [],
- dexData: [], //添加的所有害虫名称数组
- dexNum: [], //添加的所有害虫数量数组
- Index: 0,
- typeNum: '', //害虫种类数量input
- insectNum: '', //害虫数量inputs
- sumNum: '', //害虫数量总和input
- phone: '', //信息接收手机号input
- switch1Checked: false, //目标种类预警swicth开关
- switch2Checked: false, //指定害虫数量预警swicth开关
- switch3Checked: false, //害虫数量综合预警swicth开关
- switch4Checked: false, //综合预警swicth开关
- swit1: '', //目标种类预警
- swit2: '', //指定害虫数量预警
- swit3: '', //害虫数量综合预警
- swit4: '', //综合预警
- swit5: '', //信息接收
- arrayb: [], //测试
- insectName: '', //测试选中害虫的name
- //按钮大小
- Size: '15',
- windowHeight: app.globalData.windowHeight
- },
- //指定害虫数量
- watchPassWord: function (event) {
- var dexNum = this.data.dexNum
- var num = event.detail.value
- if (dexNum.length >= 5) {
- console.log('最多添加五条数据')
- } else if (dexNum.length < 6) {
- dexNum.push(num + '#')
- }
- this.setData({
- dexNum: dexNum
- })
- this.data.dexNum = dexNum
- },
- //指定害虫数量预警添加input
- addInsect: function () {
- var old = this.data.arrayA; //大数组
- var aa = this.data.aa
- var a = {index: 0, array: aa}
- if (old.length >= 5) {
- console.log('最多添加五条数据')
- } else if (old.length < 6) {
- old.push(a)
- }
- this.setData({
- arrayA: old
- })
- },
- //目标种类预警swicth开关
- switch1Change: function (e) {
- console.log('switch1 发生 change 事件,携带值为' + e.detail.value)
- },
- //指定害虫数量预警swicth开关
- switch2Change: function (e) {
- console.log('switch2 发生 change 事件,携带值为' + e.detail.value)
- },
- //害虫数量综合预警swicth开关
- switch3Change: function (e) {
- console.log('switch3 发生 change 事件,携带值为' + e.detail.value)
- },
- //综合预警swicth开关
- switch4Change: function (e) {
- console.log('switch4 发生 change 事件,携带值为' + e.detail.value)
- },
- //指定害虫数量-害虫种类选择事件
- bindPickerChange: function (e) {
- var that = this;
- // 定义一个变量curindex 储存触发事件的数组对象的下标
- const curindex = e.target.dataset.current
- //根据下标 改变该数组对象中的index值
- that.data.arrayA[curindex].index = e.detail.value
- //把改变某个数组对象index值之后的全新objArray重新 赋值给objArray
- this.setData({
- arrayA: this.data.arrayA,
- Index: e.detail.value, //数组的下标
- insectName: that.data.arrayb[e.detail.value]
- })
- // console.log(that.data.arrayb[e.detail.value].vauls) //获取到选中害虫的ID
-
- var dex = that.data.arrayb[e.detail.value].vauls
- var dexData = that.data.dexData;
- if (dexData.length >= 5) {
- console.log('最多添加五条数据')
- } else if (dexData.length < 6) {
- dexData.push(dex + '#')
- }
- // that.setData({
- // dexData: dexData
- // })
- that.data.dexData = dexData
- // console.log(dexData)
- console.log(that.data.dexData)
- },
- //提交按钮事件
- formSubmit: function (e) {
- var that = this;
- //测试提交事件
- wx.getStorage({
- key: 'warningID',
- success(res) {
- var insectID = that.data.dexData //选中害虫种类的vauls
- var typeNum1 = e.detail.value.typeNum //害虫种类数量设置input
- var insectNum1 = that.data.dexNum //害虫数量input
- var sumNum1 = e.detail.value.sumNum //害虫数量总和设置input
- var phone1 = e.detail.value.phone //信息接收手机号input
- let swit1 = e.detail.value.swit1
- let swit2 = e.detail.value.swit2
- let swit3 = e.detail.value.swit3
- let swit4 = e.detail.value.swit4
- //变换开关值
- if (swit1 == true) {
- var swi1 = 'on' //开启
- } else if (swit1 == false) {
- var swi1 = 'off' //关闭
- }
- if (swit2 == true) {
- var swi2 = 'on' //开启
- } else if (swit2 == false) {
- var swi2 = 'off' //关闭
- }
- if (swit3 == true) {
- var swi3 = 'on' //开启
- } else if (swit3 == false) {
- console.log('222')
- var swi3 = 'off' //关闭
- }
- if (swit4 == true) {
- var swi4 = 'on' //开启
- } else if (swit4 == false) {
- var swi4 = 'off' //关闭
- }
- wx.request({
- url: 'https://wx.yfzhwlw.com/wechat_pest',
- header: {
- "Content-Type": "application/x-www-form-urlencoded"
- // 'content-type': 'application/json'
- },
- method: 'post',
- dataType: 'json',
- data: {
- pestCategory: swi1, //目标种类预警
- pestCategoryNum: typeNum1, //害虫种类数量设置
- appointPest: swi2, //指定害虫数量预警
- appointPestName1: insectID, //选中害虫种类vauls
- appointPestNum1: insectNum1, //害虫数量
- pestTotal: swi3, //害虫数量总和预警
- pestTotalNum: sumNum1, //害虫数量总和设置
- pestWarn: swi4, //综合预警
- phone: phone1, //手机号
- equip_id: res.data, //设备号
- },
- success: function (res) {
- if (res.statusCode != 200) {
- wx.showToast({ //这里提示失败原因
- title: res.data.message,
- icon: 'loading',
- duration: 1500
- })
- } else {
- console.log(res.data)
- if (res.data == 0) {
- wx.showToast({
- title: '提交成功',
- icon: 'success',
- duration: 2000
- })
- } else if (res.data == 1) {
- wx.showToast({
- title: '提交失败,请重试',
- icon: 'none',
- duration: 2000
- })
- }
- console.log('成功了')
- }
- },
- fail: function (err) {
- console.log(err)
- wx.showToast({
- title: '请求失败',
- icon: 'none',
- duration: 1500
- })
- }
- })
- }
- })
- },
- //重置按钮事件
- Reset: function () {
- console.log('重置')
- },
- //获取害虫种类事件
- getInsect: function () {
- var that = this;
- wx.request({
- url: 'https://wx.yfzhwlw.com/wechat_pest',
- header: {
- "Content-Type": "application/x-www-form-urlencoded"
- },
- success: function (res) {
- if (res.statusCode != 200) {
- wx.showToast({ //这里提示失败原因
- title: res.data.message,
- icon: 'loading',
- duration: 1500
- })
- } else {
- var aa = that.data.aa
- for (let i = 0; i < res.data.length; i++) {
- aa.push(res.data[i].name)
- }
- that.setData({
- arrayb: res.data
- })
- }
- },
- fail: function (err) {
- wx.showToast({
- title: '请求失败',
- icon: 'none',
- duration: 1500
- })
- }
- })
- },
- //获取到返显数据进行判断和取值
- judge: function (res) {
- var that = this
- // 种类预警
- if (res.pestCategory == 'on') {
- that.setData({
- switch1Checked: true
- })
- } else if (res.pestCategory == 'off') {
- that.setData({
- switch1Checked: false
- })
- }
- //指定害虫数量
- if (res.appointPest == 'on') {
- that.setData({
- switch2Checked: true
- })
- } else if (res.appointPest == 'off') {
- that.setData({
- switch2Checked: false
- })
- }
- //害虫数量综合预警
- if (res.pestTotal == 'on') {
- that.setData({
- switch3Checked: true
- })
- } else if (res.pestTotal == 'off') {
- that.setData({
- switch3Checked: false
- })
- }
- //综合防治预警
- if (res.pestWarn == 'on') {
- that.setData({
- switch4Checked: true
- })
- } else if (res.pestWarn == 'off') {
- that.setData({
- switch4Checked: false
- })
- }
- console.log(res.appointPestName)
- console.log(res.appointPestNum)
- var insect = res.appointPestName
- if (insect[0] == '0') {
- console.log('没数据')
- } else if (insect[0] !== '0') {
- console.log('有数据')
- var old = this.data.arrayA; //大数组
- var aa = this.data.aa
- var a = {index: 0, array: aa}
- //指定害虫数量
- for (var i = 0; i < insect.length; i++) {
- old.push(a)
- }
- that.setData({
- arrayA: old
- })
- console.log(old)
- }
-
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- var that = this;
- that.getInsect();
- //获取页面初始值
- wx.getStorage({
- key: 'warningID',
- success: function (res) {
- //回显在短信预警页面的设备ID
- that.setData({
- name: res.data
- })
- wx.request({
- url: 'https://wx.yfzhwlw.com/wechat_pest_list',
- method: 'post',
- header: {
- "Content-Type": "application/x-www-form-urlencoded"
- },
- data: {
- equip_id: res.data
- },
- success: function (res) {
- if (res.statusCode != 200) {
- wx.showToast({ //这里提示失败原因
- title: res.data.message,
- icon: 'loading',
- duration: 1500
- })
- } else {
- that.setData({
- redata: res.data,
- })
- var res = res.data
- that.judge(res)
- }
- },
- fail: function (err) {
- console.log(err)
- wx.showToast({
- title: '请求失败',
- icon: 'none',
- duration: 1500
- })
- }
- })
- }
- })
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|