业务交流通
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

index.js 8.0KB

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