index.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import {
  2. ApiModel
  3. } from "../../../utils/api";
  4. const _Http = new ApiModel();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. searchFocus: false, //我的需求搜索框焦点
  11. searchText: "", //我的需求搜索内容
  12. pageNumber: 1, //获取第几页
  13. pageTotal: 2, //全部分页数量
  14. active: 0, //tabs 选中下标
  15. swiperBannerList: [{
  16. id: "001",
  17. url: "/static/userImage.png",
  18. src: ''
  19. }, {
  20. id: "002",
  21. url: "/static/userImage.png",
  22. src: ''
  23. }, {
  24. id: "003",
  25. url: "/static/userImage.png",
  26. src: ''
  27. }], //轮播图列表
  28. /* 宫格列表 */
  29. gridList: [{
  30. id: '001',
  31. text: '寻找面料',
  32. icon: '/static/login/Phone.png'
  33. }, {
  34. id: '002',
  35. text: '面料设计',
  36. icon: '/static/login/identity.png'
  37. }, {
  38. id: '003',
  39. text: '平面设计',
  40. icon: '/static/login/username.png'
  41. }, {
  42. id: '004',
  43. text: '产品策划',
  44. icon: '/static/login/verificationcode.png'
  45. }, {
  46. id: '005',
  47. text: '寻找主播',
  48. icon: '/static/login/verificationcode.png'
  49. }, {
  50. id: '006',
  51. text: '摄影摄像',
  52. icon: '/static/login/identity.png'
  53. }, {
  54. id: '007',
  55. text: '商业培训',
  56. icon: '/static/login/username.png'
  57. }],
  58. },
  59. /**
  60. * 生命周期函数--监听页面加载
  61. */
  62. onLoad: function (options) {
  63. },
  64. /* 宫格区点击事件 */
  65. gridJumpPage(even) {
  66. const {
  67. name
  68. } = even.target.dataset
  69. console.log(name)
  70. },
  71. /**
  72. * 生命周期函数--监听页面初次渲染完成
  73. */
  74. onReady: function () {
  75. },
  76. /**
  77. * 生命周期函数--监听页面显示
  78. */
  79. onShow: function () {
  80. this.getTabBar().init();
  81. //获取所有信息
  82. this.getSupplyAndDemand();
  83. },
  84. /* 获取供需列表 */
  85. getSupplyAndDemand() {
  86. let ftype = "",
  87. condition = ""
  88. _Http.basic({
  89. "accesstoken": wx.getStorageSync('userData').token,
  90. "classname": "customer.supplyanddemand.supplyanddemand",
  91. "method": "query_supplyanddemandList",
  92. "content": {
  93. "getdatafromdbanyway": true,
  94. "pageNumber": 1,
  95. "pageSize": 20,
  96. "where": {
  97. "condition": condition, //模糊搜索
  98. "ftype": ftype, //数据类型
  99. "fissupply": "" // 0需 1供
  100. }
  101. }
  102. }).then(res => {
  103. console.log(res)
  104. })
  105. },
  106. /* tabs切换 */
  107. tabsChange(even) {
  108. const {
  109. title
  110. } = even.detail;
  111. this.setData({
  112. active: even.detail.index
  113. })
  114. /* 初始化分页 */
  115. this.InitializeDataPaging();
  116. if (title == '我的需求') return this.myNeed();
  117. },
  118. /* 我的需求 */
  119. myNeed() {
  120. //全部加载完成退出请求
  121. if (this.data.pageTotal < this.data.pageNumber) return;
  122. _Http.basic({
  123. "accesstoken": wx.getStorageSync('userData').token,
  124. "classname": "customer.supplyanddemand.supplyanddemand",
  125. "method": "query_mysupplyanddemandList",
  126. "content": {
  127. "getdatafromdbanyway": true,
  128. "pageNumber": this.data.pageNumber,
  129. "pageSize": 20,
  130. "where": {
  131. "condition": this.data.searchText,
  132. "ftype": "",
  133. "fissupply": "0"
  134. }
  135. }
  136. }).then(res => {
  137. console.log(res);
  138. this.PageDemanding(res.pageTotal)
  139. })
  140. },
  141. /* 我的需求搜索框获得焦点 */
  142. needSearchFocus() {
  143. this.setData({
  144. searchFocus: true
  145. })
  146. },
  147. /* 我的需求搜索框失去焦点 */
  148. needSearchBlur(e) {
  149. const {
  150. value
  151. } = e.detail;
  152. //数据比较,防止重复查询
  153. if (value == this.data.searchText) return this.setData({
  154. searchFocus: false,
  155. });
  156. let searchText = "";
  157. if (value != "") searchText = value;
  158. this.setData({
  159. searchFocus: false,
  160. searchText
  161. })
  162. this.InitializeDataPaging();
  163. this.myNeed();
  164. },
  165. /* 初始化分页数据 */
  166. InitializeDataPaging() {
  167. this.setData({
  168. pageTotal: 2,
  169. pageNumber: 1
  170. })
  171. },
  172. /* 分页 */
  173. PageDemanding(pageTotal) {
  174. let pageNumber = this.data.pageNumber + 1;
  175. this.setData({
  176. pageTotal,
  177. pageNumber
  178. })
  179. },
  180. /**
  181. * 生命周期函数--监听页面隐藏
  182. */
  183. onHide: function () {
  184. },
  185. /**
  186. * 生命周期函数--监听页面卸载
  187. */
  188. onUnload: function () {
  189. },
  190. /**
  191. * 页面相关事件处理函数--监听用户下拉动作
  192. */
  193. onPullDownRefresh: function () {
  194. },
  195. /**
  196. * 页面上拉触底事件的处理函数
  197. */
  198. onReachBottom: function () {
  199. if (this.data.active == 2) this.myNeed(); //我的需求
  200. },
  201. /**
  202. * 用户点击右上角分享
  203. */
  204. onShareAppMessage: function () {
  205. }
  206. })