index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. const util = require('../../utils/util')
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. storeList:[],
  9. selectH: 0,
  10. searchParams:{
  11. storeId: '',
  12. storeName: '',
  13. pageNo: 1,
  14. pageSize: 20,
  15. schemeName: ''
  16. },
  17. loadding: false,
  18. pullUpOn: true,
  19. schemeList:[]
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. this.bindStoreList()
  26. this.bindScheme()
  27. },
  28. onUnload: function () {
  29. wx.reLaunch({
  30. url: '../vendingMachine/index',
  31. })
  32. },
  33. /**
  34. * 页面相关事件处理函数--监听用户下拉动作
  35. */
  36. onPullDownRefresh: function () {
  37. this.setData({
  38. ["searchParams.pageNo"]: 1,
  39. pullUpOn: true,
  40. loadding: false,
  41. schemeList: []
  42. })
  43. this.bindScheme()
  44. setTimeout(() => {
  45. wx.stopPullDownRefresh()
  46. }, 300);
  47. },
  48. /**
  49. * 页面上拉触底事件的处理函数
  50. */
  51. onReachBottom: function () {
  52. var that = this
  53. //只是测试效果,逻辑以实际数据为准
  54. this.setData({
  55. loadding: true,
  56. pullUpOn: true
  57. })
  58. this.setData({
  59. ["searchParams.pageNo"]: that.data.searchParams.pageNo + 1
  60. })
  61. this.bindScheme()
  62. },
  63. bindStorePickerChange: function (e) {
  64. var item = this.data.storeList[e.detail.value]
  65. console.log(item)
  66. this.setData({
  67. ['searchParams.storeId']: item.id,
  68. ['searchParams.storeName']: item.storeName,
  69. ["searchParams.pageNo"]: 1,
  70. pullUpOn: true,
  71. loadding: false,
  72. schemeList: []
  73. })
  74. this.bindScheme()
  75. },
  76. showSearchModel: function() {
  77. this.setData({
  78. selectH: 200
  79. })
  80. },
  81. hideSearchModel: function() {
  82. this.setData({
  83. selectH: 0
  84. })
  85. },
  86. clearSearch(){
  87. },
  88. submitSearch(){
  89. this.setData({
  90. selectH: 0
  91. })
  92. },
  93. toAddScheme(){
  94. wx.navigateTo({
  95. url: '/pages/scheme/form',
  96. })
  97. },
  98. bindStoreList() {
  99. var that = this
  100. util.request(util.api.storeList, {}, "GET", false, true,app.globalData.token).then((res) => {
  101. if (res.code == 200) {
  102. that.setData({
  103. storeList: res.result
  104. })
  105. }
  106. }).catch((res) => {})
  107. },
  108. inputedit: function (e) {
  109. let _this = this;
  110. let dataset = e.currentTarget.dataset;
  111. let value = e.detail.value;
  112. let name = dataset.name;
  113. _this.data[name] = value;
  114. _this.setData({
  115. [name]: _this.data[name]
  116. });
  117. },
  118. bindScheme(){
  119. var that = this
  120. console.log("3333")
  121. console.log(that.data.searchParams)
  122. console.log("4444")
  123. util.request(util.api.schemeListPage, that.data.searchParams, "GET", false, false, app.globalData.token).then((res) => {
  124. if (res.code == 200) {
  125. if (res.result.records.length > 0) {
  126. if (that.data.schemeList.length > 0) {
  127. let list = that.data.schemeList
  128. res.result.records.forEach((e)=>{
  129. list.push(e)
  130. })
  131. that.setData({
  132. schemeList: list
  133. })
  134. } else {
  135. that.setData({
  136. schemeList: res.result.records
  137. })
  138. }
  139. } else {
  140. that.setData({
  141. loadding: false,
  142. pullUpOn: false,
  143. ["searchParams.pageNo"]:that.data.searchParams.pageNo-1
  144. })
  145. }
  146. console.log("555")
  147. console.log(that.data.schemeList)
  148. console.log("666")
  149. }
  150. }).catch((res) => {})
  151. },
  152. toEdit(e){
  153. wx.navigateTo({
  154. url: '/pages/scheme/form?id='+e.currentTarget.dataset.id,
  155. })
  156. },
  157. btnSearch(){
  158. console.log("1111")
  159. console.log(this.data.searchParams)
  160. console.log("2222")
  161. this.setData({
  162. ["searchParams.pageNo"]: 1,
  163. pullUpOn: true,
  164. loadding: false,
  165. schemeList: []
  166. })
  167. this.bindScheme()
  168. }
  169. })