业务交流通
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.

index.js 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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: "my"
  19. },
  20. {
  21. text: "工商类",
  22. value: "工商类"
  23. },
  24. {
  25. text: "财税类",
  26. value: "财税类"
  27. },
  28. {
  29. text: "资质类",
  30. value: "资质类"
  31. },
  32. ],
  33. currentTab: "all",
  34. // 更多tab
  35. moreTabOption: [
  36. {
  37. text: "公司转让",
  38. value: "公司转让"
  39. },
  40. {
  41. text: "知识产权",
  42. value: "知识产权"
  43. },
  44. {
  45. text: "银行服务",
  46. value: "银行服务"
  47. },
  48. {
  49. text: "法律服务",
  50. value: "法律服务"
  51. },
  52. {
  53. text: "其他",
  54. value: "其他"
  55. },
  56. ],
  57. moreTab: "gengduo",
  58. moreTitle: "更多",
  59. // list数据加载
  60. // list块加载
  61. listLoading: true,
  62. // item行加载
  63. itemLoading: false,
  64. // 数据是否加载完成
  65. isFinished: false,
  66. listData: [],
  67. page: 1,
  68. size: 10,
  69. total: 0,
  70. // 是否加载数据,true加载,false不加载
  71. onRefresh: true,
  72. },
  73. onLoad() {
  74. },
  75. onShow(){
  76. // console.log(`会触发吗?`)
  77. this.toSearch();
  78. },
  79. toggleMore() {
  80. this.selectComponent('#item').toggle();
  81. },
  82. // 搜索框输入同步值
  83. bindKeyInput: function (e) {
  84. this.setData({
  85. keyword: e.detail.value
  86. })
  87. },
  88. // 点击搜索
  89. toSearch(e) {
  90. this.setData({
  91. listData: [],
  92. onRefresh: true,
  93. isFinished: false,
  94. listLoading: true,
  95. page: 1,
  96. })
  97. this.getListData();
  98. },
  99. // tab切换
  100. tabChange(e) {
  101. let dataset = e.currentTarget.dataset;
  102. // 如果实在加载中点击无效
  103. if (this.data.listLoading) {
  104. return
  105. }
  106. // 如果当前tab是选中直接点击无效
  107. if (this.data.currentTab == dataset.value) {
  108. return
  109. }
  110. this.setData({
  111. currentTab: dataset.value,
  112. moreTitle: "更多",
  113. moreTab: "gengduo"
  114. })
  115. this.toSearch();
  116. },
  117. // 更多tab切换
  118. moreTabChange(e) {
  119. // 如果实在加载中点击无效
  120. if (this.data.listLoading) {
  121. return
  122. }
  123. // 如果当前tab是选中直接点击无效
  124. if (this.data.moreTab == e.detail) {
  125. return
  126. }
  127. let moreTitle = "";
  128. this.data.moreTabOption.forEach(el => {
  129. if (el.value == e.detail) {
  130. moreTitle = el.text;
  131. }
  132. })
  133. this.setData({
  134. currentTab: "more",
  135. moreTab: e.detail,
  136. moreTitle
  137. })
  138. this.toSearch();
  139. },
  140. // 进入详情
  141. goDetails(e) {
  142. wx.setStorageSync('listDetail', e.detail)
  143. wx.navigateTo({
  144. url: '/pages/index/components/listDetails/Details',
  145. })
  146. },
  147. // 获取tab数据
  148. getAllType() {
  149. $request.get('/businessCommunicationType/getAllType.action').then(res => {
  150. if (res.status == 0) {
  151. let { tabData, moreTabOption } = this.data;
  152. let datas = res.data;
  153. datas.forEach(el => {
  154. if (tabData.length < 5) {
  155. tabData.push({
  156. text: el.typeName,
  157. value: el.typeName
  158. })
  159. } else {
  160. moreTabOption.push({
  161. text: el.typeName,
  162. value: el.typeName
  163. })
  164. }
  165. })
  166. this.setData({
  167. tabData,
  168. moreTabOption
  169. })
  170. this.getListData();
  171. }
  172. }).catch(error => {
  173. console.log(error, 'error appletLogin')
  174. })
  175. },
  176. // 获取list数据
  177. getListData() {
  178. let { page, size, keyword, currentTab, moreTab } = this.data;
  179. let type = currentTab;
  180. if (currentTab == 'more') {
  181. type = moreTab;
  182. }
  183. if (type == 'all') {
  184. type = "";
  185. }
  186. if(currentTab == 'my' ){
  187. type = app.globalData.businessCommunicationCustomer.attentionTypeIds;
  188. }
  189. $request.get('/businessCommunicationDemand/getDemandByKeywordOrType.action',
  190. { page, size, keyword, type, isInterest: 0 }
  191. ).then(res => {
  192. // console.log(res);
  193. let tempListData = this.data.listData;
  194. if (res.status == 0) {
  195. let datas = res.data;
  196. // 先push数据
  197. tempListData.push(...datas.demandList);
  198. tempListData.forEach(el => {
  199. el.createdOn = $util.formatTime(new Date(el.createdOn), true);
  200. if (typeof el.type == 'string') {
  201. el.type = el.type.split(',');
  202. }
  203. })
  204. // 设置总数
  205. this.setData({
  206. listData: tempListData,
  207. total: res.data.total,
  208. })
  209. // 如果数据大于了返回的总数
  210. if (tempListData.length >= this.data.total) {
  211. // 停止累加数据
  212. this.setData({
  213. onRefresh: false,
  214. itemLoading: false,
  215. isFinished: true,
  216. })
  217. } else {
  218. this.setData({
  219. onRefresh: true,
  220. itemLoading: false,
  221. isFinished: false,
  222. page: page + 1
  223. })
  224. }
  225. }
  226. this.setData({
  227. listLoading: false
  228. })
  229. }).catch(error => {
  230. console.log(error, 'error appletLogin')
  231. })
  232. },
  233. /**
  234. * 页面上拉触底事件的处理函数
  235. */
  236. onReachBottom() {
  237. if (this.data.onRefresh) {
  238. this.setData({
  239. itemLoading: true
  240. })
  241. this.getListData();
  242. }
  243. },
  244. setAttention() {
  245. if(!app.globalData.customerId){
  246. app.goLogin();
  247. return
  248. }
  249. let customerid = app.globalData.customerId;
  250. wx.navigateTo({
  251. url:"/pages/myModule/components/myAttention/myAttention",
  252. success: function (res) {
  253. // 通过eventChannel向被打开页面传送数据
  254. res.eventChannel.emit('customerid', { customerid })
  255. }
  256. })
  257. },
  258. })