业务交流通
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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