123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- const util = require('../../utils/util')
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- storeList:[],
- schemeList:[],
- deviceList:[],
- selectList:[],
- values:{
- storeId: '',
- storeName: '',
- schemeId: '',
- schemeName: ''
- },
- sync:false
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.bindStoreList()
- this.bindSchemeList()
- },
- bindStorePickerChange: function (e) {
- var item = this.data.storeList[e.detail.value]
-
- console.log(item)
- this.setData({
- ['values.storeId']: item.id,
- ['values.storeName']: item.storeName
- })
- this.binddeviceListByStoreId()
- },
- bindSchemePickerChange: function (e) {
- var item = this.data.schemeList[e.detail.value]
- console.log(item)
- this.setData({
- ['values.schemeId']: item.id,
- ['values.schemeName']: item.schemeName
- })
- },
- syncSwitchChange(e){
- var that =this
- if(e.detail.value){
- that.data.deviceList.forEach((e)=>{
- e.checkout = true
- })
- }else{
- that.data.deviceList.forEach((e)=>{
- e.checkout = false
- })
- }
- var list = that.data.deviceList.filter((e)=>e.checkout == true)
- console.log(list)
- that.setData({
- sync:e.detail.value,
- deviceList:that.data.deviceList,
- selectList: list
- })
- },
- bindStoreList() {
- var that = this
- util.request(util.api.storeList, {}, "GET", false, true, app.globalData.token).then((res) => {
- if (res.code == 200) {
- that.setData({
- storeList: res.result
- })
- }
- }).catch((res) => {})
- },
- bindSchemeList() {
- var that = this
- util.request(util.api.schemeList, {}, "GET", false, true, app.globalData.token).then((res) => {
- if (res.code == 200) {
- that.setData({
- schemeList: res.result
- })
- }
- }).catch((res) => {})
- },
- binddeviceListByStoreId(){
- var that = this
- util.request(util.api.deviceListByStoreId, {storeId:that.data.values.storeId}, "GET", false, true, app.globalData.token).then((res) => {
- console.log(res)
- if (res.code == 200) {
- res.result.forEach((e)=>{
- e.checkout = false
- })
- that.setData({
- deviceList: res.result
- })
- }
- }).catch((res) => {})
- },
- syncChecked(e){
- let that = this;
- let dataset = e.currentTarget.dataset;
- var list = that.data.deviceList
- var index = dataset.index;
- var itemDevice = dataset.item
- itemDevice.checkout = !itemDevice.checkout
- list.splice(index,1,itemDevice)
- var selectList = that.data.deviceList.filter((e)=>e.checkout == true)
- that.setData({
- deviceList:list,
- selectList:selectList
- })
- },
- saveInfo(){
- var that = this;
- var storeId = this.data.values.storeId
- var schemeId = this.data.values.schemeId
- var selectList = this.data.selectList
- var selectList1 = [];
- for (let i = 0; i < selectList.length; i++) {
- selectList1.push(selectList[i].deviceSn)
- }
- if(storeId==null||storeId==""){
- wx.showToast({
- icon: "none",
- title: "门店不能为空"
- });
- return;
- }
- if(schemeId==null||schemeId==""){
- wx.showToast({
- icon: "none",
- title: "方案不能为空"
- });
- return;
- }
- if(selectList1==null||selectList1.length==0){
- wx.showToast({
- icon: "none",
- title: "请选择客房"
- });
- return;
- }
- util.request(util.api.upDevice, {storeId:storeId,schemeId:schemeId,selectList:selectList1}, "POST", true, true,app.globalData.token).then((res)=>{
- console.log(res)
- if (res.code == 200) {
- util.toast('保存成功')
- }
- }).catch((res) => {})
- }
- })
|