业务交流通
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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.setStorageSync('listDetail', e.detail)
  159. wx.navigateTo({
  160. url: '/pages/index/components/listDetails/Details',
  161. })
  162. },
  163. // 获取tab数据
  164. getAllType() {
  165. $request.get('/businessCommunicationType/getAllType.action').then(res => {
  166. if (res.status == 0) {
  167. let { tabData, moreTabOption } = this.data;
  168. let datas = res.data;
  169. datas.forEach(el => {
  170. if (tabData.length < 5) {
  171. tabData.push({
  172. text: el.typeName,
  173. value: el.typeName
  174. })
  175. } else {
  176. moreTabOption.push({
  177. text: el.typeName,
  178. value: el.typeName
  179. })
  180. }
  181. })
  182. this.setData({
  183. tabData,
  184. moreTabOption
  185. })
  186. this.getListData();
  187. }
  188. }).catch(error => {
  189. console.log(error, 'error appletLogin')
  190. })
  191. },
  192. // 获取list数据
  193. getListData(isInterest) {
  194. let { page, size, keyword, currentTab, moreTab } = this.data;
  195. let type = currentTab;
  196. if (currentTab == 'more') {
  197. type = moreTab;
  198. }
  199. if (type == 'all') {
  200. type = "";
  201. }
  202. if (currentTab == 'my') {
  203. type = app.globalData.businessCommunicationCustomer.attentionTypeIds;
  204. }
  205. let paramIsInterest = 0;
  206. if(isInterest){
  207. paramIsInterest = isInterest;
  208. }
  209. this.setData({
  210. paramIsInterest
  211. })
  212. $request.get('/businessCommunicationDemand/getDemandByKeywordOrType.action',
  213. { page, size, keyword, type, isInterest: paramIsInterest }
  214. ).then(res => {
  215. // console.log(res);
  216. let tempListData = this.data.listData;
  217. if (res.status == 0) {
  218. let datas = res.data;
  219. // 先push数据
  220. tempListData.push(...datas.demandList);
  221. tempListData.forEach(el => {
  222. el.createdOn = $util.formatTime(new Date(el.createdOn), true);
  223. el.createdOn = el.createdOn.replaceAll('/', '-');
  224. if (typeof el.type == 'string') {
  225. el.type = el.type.split(',');
  226. }
  227. })
  228. // 设置总数
  229. this.setData({
  230. listData: tempListData,
  231. total: res.data.total,
  232. })
  233. // 如果数据大于了返回的总数
  234. if (tempListData.length >= this.data.total) {
  235. // 停止累加数据
  236. this.setData({
  237. onRefresh: false,
  238. itemLoading: false,
  239. isFinished: true,
  240. })
  241. } else {
  242. this.setData({
  243. onRefresh: true,
  244. itemLoading: false,
  245. isFinished: false,
  246. page: page + 1
  247. })
  248. }
  249. }
  250. this.setData({
  251. listLoading: false
  252. })
  253. if(this.data.attentionTypeIds){
  254. if(this.data.attentionTypeIds.length > 0 && res.data.total == 0){
  255. this.getListData(1);
  256. }
  257. }
  258. }).catch(error => {
  259. console.log(error, 'error appletLogin')
  260. })
  261. },
  262. /**
  263. * 页面上拉触底事件的处理函数
  264. */
  265. onReachBottom() {
  266. if (this.data.onRefresh) {
  267. this.setData({
  268. itemLoading: true
  269. })
  270. this.getListData();
  271. }
  272. },
  273. setAttention() {
  274. if (!app.globalData.customerId) {
  275. app.goLogin();
  276. return
  277. }
  278. let customerid = app.globalData.customerId;
  279. wx.navigateTo({
  280. url: "/pages/myModule/components/myAttention/myAttention",
  281. success: function (res) {
  282. // 通过eventChannel向被打开页面传送数据
  283. res.eventChannel.emit('customerid', { customerid })
  284. }
  285. })
  286. },
  287. })