业务交流通
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. // index.js
  2. // 获取应用实例
  3. const app = getApp()
  4. const $request = require('../../utils/request.js');
  5. const $util = require('../../utils/util.js');
  6. Page({
  7. data: {
  8. currentIndex: 0,
  9. keyword: "",
  10. // tab
  11. tabData: [
  12. {
  13. text: "全部",
  14. value: "all"
  15. },
  16. {
  17. text: "我关注的",
  18. value: "my1"
  19. },
  20. ],
  21. currentTab: "all",
  22. // 更多tab
  23. moreTabOption: [],
  24. moreTab: "gengduo",
  25. moreTitle: "更多",
  26. // list数据加载
  27. // list块加载
  28. listLoading: false,
  29. // item行加载
  30. itemLoading: false,
  31. // 数据是否加载完成
  32. isFinished: false,
  33. listData: [],
  34. page: 1,
  35. size: 10,
  36. total: 0,
  37. // 是否加载数据,true加载,false不加载
  38. onRefresh: true,
  39. },
  40. onLoad() {
  41. this.setData({
  42. listLoading: true,
  43. })
  44. // 获取分类
  45. this.getAllType();
  46. },
  47. toggleMore() {
  48. this.selectComponent('#item').toggle();
  49. },
  50. // 搜索框输入同步值
  51. bindKeyInput: function (e) {
  52. this.setData({
  53. keyword: e.detail.value
  54. })
  55. },
  56. // 点击搜索
  57. toSearch(e) {
  58. console.log(this.data.keyword)
  59. this.setData({
  60. listData: [],
  61. onRefresh: true,
  62. isFinished: false,
  63. listLoading: true,
  64. page: 1,
  65. })
  66. this.getListData();
  67. },
  68. // tab切换
  69. tabChange(e) {
  70. let dataset = e.currentTarget.dataset;
  71. // if(dataset.value == 'my1'){
  72. // console.log(this.selectComponent('#shouquan'));
  73. // return
  74. // }
  75. // 如果实在加载中点击无效
  76. if (this.data.listLoading) {
  77. return
  78. }
  79. // 如果当前tab是选中直接点击无效
  80. if (this.data.currentTab == dataset.value) {
  81. return
  82. }
  83. this.setData({
  84. currentTab: dataset.value,
  85. moreTitle: "更多",
  86. moreTab: "gengduo"
  87. })
  88. this.toSearch();
  89. },
  90. // 更多tab切换
  91. moreTabChange(e) {
  92. // 如果实在加载中点击无效
  93. if (this.data.listLoading) {
  94. return
  95. }
  96. // 如果当前tab是选中直接点击无效
  97. if (this.data.moreTab == e.detail) {
  98. return
  99. }
  100. let moreTitle = "";
  101. this.data.moreTabOption.forEach(el => {
  102. if (el.value == e.detail) {
  103. moreTitle = el.text;
  104. }
  105. })
  106. this.setData({
  107. currentTab: "more",
  108. moreTab: e.detail,
  109. moreTitle
  110. })
  111. this.toSearch();
  112. },
  113. // 进入详情
  114. goDetails(e) {
  115. wx.navigateTo({
  116. url: '/pages/index/components/listDetails/Details',
  117. success: function (res) {
  118. // 通过eventChannel向被打开页面传送数据
  119. res.eventChannel.emit('acceptDataFromOpenerPage', { listDetail: e.detail })
  120. }
  121. })
  122. },
  123. // 获取tab数据
  124. getAllType() {
  125. $request.get('/businessCommunicationType/getAllType.action').then(res => {
  126. if (res.status == 0) {
  127. let { tabData, moreTabOption } = this.data;
  128. let datas = res.data;
  129. datas.forEach(el => {
  130. if (tabData.length < 5) {
  131. tabData.push({
  132. text: el.typeName,
  133. value: el.typeName
  134. })
  135. } else {
  136. moreTabOption.push({
  137. text: el.typeName,
  138. value: el.typeName
  139. })
  140. }
  141. })
  142. this.setData({
  143. tabData,
  144. moreTabOption
  145. })
  146. this.getListData();
  147. }
  148. }).catch(error => {
  149. console.log(error, 'error appletLogin')
  150. })
  151. },
  152. // 获取list数据
  153. getListData() {
  154. let { page, size, keyword, currentTab, moreTab } = this.data;
  155. let type = currentTab;
  156. if (currentTab == 'more') {
  157. type = moreTab;
  158. }
  159. if (type == 'all') {
  160. type = "";
  161. }
  162. $request.get('/businessCommunicationDemand/getDemandByKeywordOrType.action',
  163. { page, size, keyword, type, isInterest: 0 }
  164. ).then(res => {
  165. // console.log(res);
  166. this.setData({
  167. listLoading: false
  168. })
  169. let tempListData = this.data.listData;
  170. if (res.status == 0) {
  171. let datas = res.data;
  172. // 先push数据
  173. tempListData.push(...datas.demandList);
  174. tempListData.forEach(el => {
  175. el.createdOn = $util.formatTime(new Date(el.createdOn), true);
  176. if (typeof el.type == 'string') {
  177. el.type = el.type.split(',');
  178. }
  179. })
  180. // 设置总数
  181. this.setData({
  182. listData: tempListData,
  183. total: res.data.total,
  184. })
  185. // 如果数据大于了返回的总数
  186. if (tempListData.length >= this.data.total) {
  187. // 停止累加数据
  188. this.setData({
  189. onRefresh: false,
  190. itemLoading: false,
  191. isFinished: true,
  192. })
  193. } else {
  194. this.setData({
  195. onRefresh: true,
  196. itemLoading: false,
  197. isFinished: false,
  198. page: page + 1
  199. })
  200. }
  201. }
  202. }).catch(error => {
  203. console.log(error, 'error appletLogin')
  204. })
  205. },
  206. /**
  207. * 页面上拉触底事件的处理函数
  208. */
  209. onReachBottom() {
  210. if (this.data.onRefresh) {
  211. this.setData({
  212. itemLoading: true
  213. })
  214. this.getListData();
  215. }
  216. },
  217. goLogin() {
  218. app.goLogin();
  219. },
  220. })