index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import {
  2. ApiModel
  3. } from "../../utils/api";
  4. const _Http = new ApiModel();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. active: 0, //tabs选中下标
  11. pageNumber: 1, //请求页号
  12. pageTotal: 1, //总页码
  13. productList: [], //产品列表
  14. loadMore: true, //加载更多
  15. fisadministrator: false, //是否主账号
  16. searchContent: "", //模糊搜索字段
  17. onShowFlush: false, //是否触发onShow刷新
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. this.gettingData(this.data.active);
  24. this.setData({
  25. fisadministrator: (wx.getStorageSync('userData').fisadministrator == 1) ? true : false
  26. })
  27. },
  28. /* 搜索查询 */
  29. searchQuery(value) {
  30. if (value.detail == this.data.searchContent) return;
  31. this.gettingData(this.data.active, value.detail)
  32. this.setData({
  33. searchContent: value.detail
  34. })
  35. },
  36. /* 滑动区域上拉触底 */
  37. scrolltolower() {
  38. if (this.data.loadMore) {
  39. if (this.data.pageNumber < this.data.pageTotal) {
  40. this.setData({
  41. pageNumber: this.data.pageNumber + 1
  42. })
  43. this.gettingData(this.data.active)
  44. }
  45. this.setData({
  46. loadMore: false
  47. })
  48. }
  49. },
  50. /* tabs 切换事件 */
  51. tabsChange(e) {
  52. const {
  53. index
  54. } = e.detail;
  55. this.setData({
  56. active: e.detail.index,
  57. pageNumber: 1, //请求页号
  58. pageTotal: 1, //总页码
  59. loadMore: true, //加载更多
  60. productList: [],
  61. })
  62. this.gettingData(index, this.data.searchContent)
  63. },
  64. /* 获取数据 */
  65. gettingData(index, value) {
  66. let where = {
  67. "condition": "",
  68. "fisonsale": ""
  69. };
  70. //请求类型
  71. if (index == 1) {
  72. where.fisonsale = 1;
  73. } else if (index == 2) {
  74. where.fisonsale = 0;
  75. }
  76. //模糊搜索
  77. if (value) {
  78. where.condition = value
  79. };
  80. /* 发送请求 */
  81. _Http.basic({
  82. "accesstoken": wx.getStorageSync('userData').token,
  83. "classname": "customer.products.products",
  84. "method": "query_productsList",
  85. "content": {
  86. "getdatafromdbanyway": true,
  87. "pageNumber": this.data.pageNumber,
  88. "pageSize": 8,
  89. "where": where
  90. }
  91. }).then(res => {
  92. if (res.msg != '成功') return wx.showToast({
  93. title: res.data,
  94. icon: "none"
  95. })
  96. /* 拼接列表 */
  97. let productList = [];
  98. if (this.data.pageNumber != 1) {
  99. productList = this.data.productList.concat(res.data);
  100. } else {
  101. productList = res.data;
  102. }
  103. this.setData({
  104. productList,
  105. loadMore: true, //加载更多
  106. pageTotal: res.pageTotal
  107. })
  108. })
  109. },
  110. /* 产品信息修改 */
  111. changeProductMessage(e) {
  112. const {
  113. index
  114. } = e.currentTarget.dataset;
  115. const data = JSON.stringify(this.data.productList[index])
  116. //刷新页面
  117. this.isOnShow();
  118. wx.navigateTo({
  119. url: '/pages/productManagement/change?data=' + data,
  120. })
  121. },
  122. /**
  123. * 生命周期函数--监听页面初次渲染完成
  124. */
  125. onReady: function () {
  126. },
  127. //允许onshow刷新
  128. isOnShow() {
  129. console.log("调用")
  130. this.setData({
  131. onShowFlush: true
  132. })
  133. },
  134. /**
  135. * 生命周期函数--监听页面显示
  136. */
  137. onShow: function () {
  138. //重新获取数据列表
  139. if (this.data.onShowFlush) {
  140. this.gettingData(this.data.active)
  141. this.setData({
  142. onShowFlush: false
  143. })
  144. }
  145. },
  146. /**
  147. * 生命周期函数--监听页面隐藏
  148. */
  149. onHide: function () {
  150. },
  151. /**
  152. * 生命周期函数--监听页面卸载
  153. */
  154. onUnload: function () {
  155. },
  156. /**
  157. * 页面相关事件处理函数--监听用户下拉动作
  158. */
  159. onPullDownRefresh: function () {
  160. },
  161. /**
  162. * 页面上拉触底事件的处理函数
  163. */
  164. onReachBottom: function () {
  165. },
  166. /**
  167. * 用户点击右上角分享
  168. */
  169. onShareAppMessage: function () {
  170. }
  171. })