业务交流通
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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