业务交流通
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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