业务交流通
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

index.js 8.8KB

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