业务交流通
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.

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