index.js 4.0 KB

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