业务交流通
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

index.js 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. attentionTypeIds: "",
  74. // 用来判断关注显示按钮
  75. paramIsInterest: 0,
  76. customerId: null,
  77. },
  78. onLoad() {
  79. this.setData({
  80. currentIndex: 0
  81. })
  82. this.toSearch();
  83. const businessCommunicationCustomer = wx.getStorageSync('businessCommunicationCustomer') || null;
  84. if (businessCommunicationCustomer) {
  85. let attentionTypeIds = businessCommunicationCustomer.attentionTypeIds;
  86. if (attentionTypeIds) {
  87. attentionTypeIds = attentionTypeIds.split(',');
  88. }else{
  89. attentionTypeIds = [];
  90. }
  91. this.setData({
  92. attentionTypeIds,
  93. customerId: businessCommunicationCustomer.customerId
  94. })
  95. }
  96. },
  97. onShow() {
  98. },
  99. toggleMore() {
  100. this.selectComponent('#item').toggle();
  101. },
  102. // 搜索框输入同步值
  103. bindKeyInput: function (e) {
  104. this.setData({
  105. keyword: e.detail.value
  106. })
  107. },
  108. // 点击搜索
  109. toSearch(e) {
  110. this.setData({
  111. listData: [],
  112. onRefresh: true,
  113. isFinished: false,
  114. listLoading: true,
  115. page: 1,
  116. })
  117. this.getListData();
  118. },
  119. // tab切换
  120. tabChange(e) {
  121. let dataset = e.currentTarget.dataset;
  122. // 如果实在加载中点击无效
  123. if (this.data.listLoading) {
  124. return
  125. }
  126. // 如果当前tab是选中直接点击无效
  127. if (this.data.currentTab == dataset.value) {
  128. return
  129. }
  130. this.setData({
  131. currentTab: dataset.value,
  132. moreTitle: "更多",
  133. moreTab: "gengduo"
  134. })
  135. this.toSearch();
  136. },
  137. // 更多tab切换
  138. moreTabChange(e) {
  139. // 如果实在加载中点击无效
  140. if (this.data.listLoading) {
  141. return
  142. }
  143. // 如果当前tab是选中直接点击无效
  144. if (this.data.moreTab == e.detail) {
  145. return
  146. }
  147. let moreTitle = "";
  148. this.data.moreTabOption.forEach(el => {
  149. if (el.value == e.detail) {
  150. moreTitle = el.text;
  151. }
  152. })
  153. this.setData({
  154. currentTab: "more",
  155. moreTab: e.detail,
  156. moreTitle
  157. })
  158. this.toSearch();
  159. },
  160. // 进入详情
  161. goDetails(e) {
  162. wx.navigateTo({
  163. url: '/pages/index/components/listDetails/Details?businessCommunicationDemandId=' + e.detail,
  164. })
  165. },
  166. // 获取tab数据
  167. getAllType() {
  168. $request.get('/businessCommunicationType/getAllType.action').then(res => {
  169. if (res.status == 0) {
  170. let { tabData, moreTabOption } = this.data;
  171. let datas = res.data;
  172. datas.forEach(el => {
  173. if (tabData.length < 5) {
  174. tabData.push({
  175. text: el.typeName,
  176. value: el.typeName
  177. })
  178. } else {
  179. moreTabOption.push({
  180. text: el.typeName,
  181. value: el.typeName
  182. })
  183. }
  184. })
  185. this.setData({
  186. tabData,
  187. moreTabOption
  188. })
  189. this.getListData();
  190. }
  191. }).catch(error => {
  192. console.log(error, 'error appletLogin')
  193. })
  194. },
  195. // 获取list数据
  196. getListData(isInterest) {
  197. let { page, size, keyword, currentTab, moreTab } = this.data;
  198. let type = currentTab;
  199. if (currentTab == 'more') {
  200. type = moreTab;
  201. }
  202. if (type == 'all') {
  203. type = "";
  204. }
  205. if (currentTab == 'my') {
  206. if (app.globalData.businessCommunicationCustomer) {
  207. type = app.globalData.businessCommunicationCustomer.attentionTypeIds;
  208. if(!type){
  209. this.setData({
  210. listLoading: false
  211. })
  212. return
  213. }
  214. }
  215. }
  216. let paramIsInterest = 0;
  217. if (isInterest) {
  218. paramIsInterest = isInterest;
  219. }
  220. this.setData({
  221. paramIsInterest
  222. })
  223. $request.get('/businessCommunicationDemand/getDemandByKeywordOrType.action',
  224. { page, size, keyword, type, isInterest: paramIsInterest }
  225. ).then(res => {
  226. // console.log(res);
  227. let tempListData = this.data.listData;
  228. if (res.status == 0) {
  229. let datas = res.data;
  230. // 先push数据
  231. tempListData.push(...datas.demandList);
  232. tempListData.forEach(el => {
  233. el.createdOn = $util.formatTime(new Date(el.createdOn), true);
  234. el.createdOn = el.createdOn.replaceAll('/', '-');
  235. if (typeof el.type == 'string') {
  236. el.type = el.type.split(',');
  237. }
  238. })
  239. // 设置总数
  240. this.setData({
  241. listData: tempListData,
  242. total: res.data.total,
  243. })
  244. // 如果数据大于了返回的总数
  245. if (tempListData.length >= this.data.total) {
  246. // 停止累加数据
  247. this.setData({
  248. onRefresh: false,
  249. itemLoading: false,
  250. isFinished: true,
  251. })
  252. } else {
  253. this.setData({
  254. onRefresh: true,
  255. itemLoading: false,
  256. isFinished: false,
  257. page: page + 1
  258. })
  259. }
  260. }
  261. this.setData({
  262. listLoading: false
  263. })
  264. if (this.data.attentionTypeIds && this.data.currentTab == 'my') {
  265. if (this.data.attentionTypeIds.length > 0 && this.data.total == 0) {
  266. this.getListData(2);
  267. }
  268. }
  269. }).catch(error => {
  270. console.log(error, 'error appletLogin')
  271. })
  272. },
  273. /**
  274. * 页面上拉触底事件的处理函数
  275. */
  276. onReachBottom() {
  277. if (this.data.onRefresh) {
  278. this.setData({
  279. itemLoading: true
  280. })
  281. this.getListData();
  282. }
  283. },
  284. // 设置关注类型喜好
  285. setAttention() {
  286. if (!app.globalData.customerId) {
  287. app.goLogin();
  288. return
  289. }
  290. this.setData({
  291. currentTab: 'my',
  292. moreTitle: "更多",
  293. moreTab: "gengduo"
  294. })
  295. let customerid = app.globalData.customerId;
  296. wx.navigateTo({
  297. url: "/pages/myModule/components/myAttention/myAttention",
  298. success: function (res) {
  299. // 通过eventChannel向被打开页面传送数据
  300. res.eventChannel.emit('customerid', { customerid })
  301. }
  302. })
  303. },
  304. /**
  305. * 用户点击右上角分享给朋友
  306. */
  307. onShareAppMessage() {
  308. return {
  309. title: "分享你一个需求交流平台!推荐你一起来关注~",
  310. imageUrl: '/images/home/ShareApp-index.png',
  311. path: 'pages/index/index'
  312. }
  313. },
  314. })