sync.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. const util = require('../../utils/util')
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. storeList:[],
  9. schemeList:[],
  10. deviceList:[],
  11. selectList:[],
  12. values:{
  13. storeId: '',
  14. storeName: '',
  15. schemeId: '',
  16. schemeName: ''
  17. },
  18. sync:false
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function (options) {
  24. this.bindStoreList()
  25. this.bindSchemeList()
  26. },
  27. bindStorePickerChange: function (e) {
  28. var item = this.data.storeList[e.detail.value]
  29. console.log(item)
  30. this.setData({
  31. ['values.storeId']: item.id,
  32. ['values.storeName']: item.storeName
  33. })
  34. this.binddeviceListByStoreId()
  35. },
  36. bindSchemePickerChange: function (e) {
  37. var item = this.data.schemeList[e.detail.value]
  38. console.log(item)
  39. this.setData({
  40. ['values.schemeId']: item.id,
  41. ['values.schemeName']: item.schemeName
  42. })
  43. },
  44. syncSwitchChange(e){
  45. var that =this
  46. if(e.detail.value){
  47. that.data.deviceList.forEach((e)=>{
  48. e.checkout = true
  49. })
  50. }else{
  51. that.data.deviceList.forEach((e)=>{
  52. e.checkout = false
  53. })
  54. }
  55. var list = that.data.deviceList.filter((e)=>e.checkout == true)
  56. console.log(list)
  57. that.setData({
  58. sync:e.detail.value,
  59. deviceList:that.data.deviceList,
  60. selectList: list
  61. })
  62. },
  63. bindStoreList() {
  64. var that = this
  65. util.request(util.api.storeList, {}, "GET", false, true, app.globalData.token).then((res) => {
  66. if (res.code == 200) {
  67. that.setData({
  68. storeList: res.result
  69. })
  70. }
  71. }).catch((res) => {})
  72. },
  73. bindSchemeList() {
  74. var that = this
  75. util.request(util.api.schemeList, {}, "GET", false, true, app.globalData.token).then((res) => {
  76. if (res.code == 200) {
  77. that.setData({
  78. schemeList: res.result
  79. })
  80. }
  81. }).catch((res) => {})
  82. },
  83. binddeviceListByStoreId(){
  84. var that = this
  85. util.request(util.api.deviceListByStoreId, {storeId:that.data.values.storeId}, "GET", false, true, app.globalData.token).then((res) => {
  86. console.log(res)
  87. if (res.code == 200) {
  88. res.result.forEach((e)=>{
  89. e.checkout = false
  90. })
  91. that.setData({
  92. deviceList: res.result
  93. })
  94. }
  95. }).catch((res) => {})
  96. },
  97. syncChecked(e){
  98. let that = this;
  99. let dataset = e.currentTarget.dataset;
  100. var list = that.data.deviceList
  101. var index = dataset.index;
  102. var itemDevice = dataset.item
  103. itemDevice.checkout = !itemDevice.checkout
  104. list.splice(index,1,itemDevice)
  105. var selectList = that.data.deviceList.filter((e)=>e.checkout == true)
  106. that.setData({
  107. deviceList:list,
  108. selectList:selectList
  109. })
  110. },
  111. saveInfo(){
  112. var that = this;
  113. var storeId = this.data.values.storeId
  114. var schemeId = this.data.values.schemeId
  115. var selectList = this.data.selectList
  116. var selectList1 = [];
  117. for (let i = 0; i < selectList.length; i++) {
  118. selectList1.push(selectList[i].deviceSn)
  119. }
  120. if(storeId==null||storeId==""){
  121. wx.showToast({
  122. icon: "none",
  123. title: "门店不能为空"
  124. });
  125. return;
  126. }
  127. if(schemeId==null||schemeId==""){
  128. wx.showToast({
  129. icon: "none",
  130. title: "方案不能为空"
  131. });
  132. return;
  133. }
  134. if(selectList1==null||selectList1.length==0){
  135. wx.showToast({
  136. icon: "none",
  137. title: "请选择客房"
  138. });
  139. return;
  140. }
  141. util.request(util.api.upDevice, {storeId:storeId,schemeId:schemeId,selectList:selectList1}, "POST", true, true,app.globalData.token).then((res)=>{
  142. console.log(res)
  143. if (res.code == 200) {
  144. util.toast('保存成功')
  145. }
  146. }).catch((res) => {})
  147. }
  148. })