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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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: "my1"
  19. },
  20. ],
  21. currentTab: "all",
  22. // 更多tab
  23. moreTabOption: [],
  24. moreTab: "gengduo",
  25. moreTitle: "更多",
  26. // list数据加载
  27. // list块加载
  28. listLoading: false,
  29. // item行加载
  30. itemLoading: false,
  31. // 数据是否加载完成
  32. isFinished: false,
  33. listData: [],
  34. page: 1,
  35. size: 10,
  36. total: 0,
  37. // 是否加载数据,true加载,false不加载
  38. onRefresh: true,
  39. },
  40. onLoad() {
  41. this.setData({
  42. listLoading: true,
  43. })
  44. // 获取分类
  45. this.getAllType();
  46. },
  47. toggleMore() {
  48. this.selectComponent('#item').toggle();
  49. },
  50. // 搜索框输入同步值
  51. bindKeyInput: function (e) {
  52. this.setData({
  53. keyword: e.detail.value
  54. })
  55. },
  56. // 点击搜索
  57. toSearch(e) {
  58. console.log(this.data.keyword)
  59. this.setData({
  60. listData: [],
  61. onRefresh: true,
  62. isFinished: false,
  63. listLoading: true,
  64. page: 1,
  65. })
  66. this.getListData();
  67. },
  68. // tab切换
  69. tabChange(e) {
  70. let dataset = e.currentTarget.dataset;
  71. // if(dataset.value == 'my1'){
  72. // console.log(this.selectComponent('#shouquan'));
  73. // return
  74. // }
  75. // 如果实在加载中点击无效
  76. if (this.data.listLoading) {
  77. return
  78. }
  79. // 如果当前tab是选中直接点击无效
  80. if (this.data.currentTab == dataset.value) {
  81. return
  82. }
  83. this.setData({
  84. currentTab: dataset.value,
  85. moreTitle: "更多",
  86. moreTab: "gengduo"
  87. })
  88. this.toSearch();
  89. },
  90. // 更多tab切换
  91. moreTabChange(e) {
  92. // 如果实在加载中点击无效
  93. if (this.data.listLoading) {
  94. return
  95. }
  96. // 如果当前tab是选中直接点击无效
  97. if (this.data.moreTab == e.detail) {
  98. return
  99. }
  100. let moreTitle = "";
  101. this.data.moreTabOption.forEach(el => {
  102. if (el.value == e.detail) {
  103. moreTitle = el.text;
  104. }
  105. })
  106. this.setData({
  107. currentTab: "more",
  108. moreTab: e.detail,
  109. moreTitle
  110. })
  111. this.toSearch();
  112. },
  113. // 进入详情
  114. goDetails(e) {
  115. wx.navigateTo({
  116. url: '/pages/index/components/listDetails/Details',
  117. success: function (res) {
  118. // 通过eventChannel向被打开页面传送数据
  119. res.eventChannel.emit('acceptDataFromOpenerPage', { listDetail: e.detail })
  120. }
  121. })
  122. },
  123. // 获取tab数据
  124. getAllType() {
  125. $request.get('/businessCommunicationType/getAllType.action').then(res => {
  126. if (res.status == 0) {
  127. let { tabData, moreTabOption } = this.data;
  128. let datas = res.data;
  129. datas.forEach(el => {
  130. if (tabData.length < 5) {
  131. tabData.push({
  132. text: el.typeName,
  133. value: el.typeName
  134. })
  135. } else {
  136. moreTabOption.push({
  137. text: el.typeName,
  138. value: el.typeName
  139. })
  140. }
  141. })
  142. this.setData({
  143. tabData,
  144. moreTabOption
  145. })
  146. this.getListData();
  147. }
  148. }).catch(error => {
  149. console.log(error, 'error appletLogin')
  150. })
  151. },
  152. // 获取list数据
  153. getListData() {
  154. let { page, size, keyword, currentTab, onRefresh, total, moreTab } = this.data;
  155. console.log(currentTab, moreTab)
  156. let type = currentTab;
  157. if (currentTab == 'more') {
  158. type = moreTab;
  159. }
  160. if (type == 'all') {
  161. type = "";
  162. }
  163. $request.get('/businessCommunicationDemand/getDemandByKeywordOrType.action',
  164. { page, size, keyword, type,isInterest:0 }
  165. ).then(res => {
  166. // console.log(res);
  167. this.setData({
  168. listLoading: false
  169. })
  170. let tempListData = this.data.listData;
  171. if (res.status == 0) {
  172. let datas = res.data;
  173. // 先push数据
  174. tempListData.push(...datas.demandList);
  175. tempListData.forEach(el => {
  176. el.createdOn = $util.formatTime(new Date(el.createdOn),true);
  177. if (typeof el.type == 'string') {
  178. el.type = el.type.split(',');
  179. }
  180. })
  181. // 设置总数
  182. this.setData({
  183. listData: tempListData,
  184. total: res.data.total,
  185. })
  186. // 如果数据大于了返回的总数
  187. if (tempListData.length >= this.data.total) {
  188. // 停止累加数据
  189. this.setData({
  190. onRefresh: false,
  191. itemLoading: false,
  192. isFinished: true,
  193. })
  194. } else {
  195. this.setData({
  196. onRefresh: true,
  197. itemLoading: false,
  198. isFinished: false,
  199. page: page + 1
  200. })
  201. }
  202. console.log('-------------首页 beg-------------------')
  203. console.log(this.data.listData);
  204. console.log('-------------首页 end-------------------')
  205. }
  206. }).catch(error => {
  207. console.log(error, 'error appletLogin')
  208. })
  209. },
  210. /**
  211. * 页面上拉触底事件的处理函数
  212. */
  213. onReachBottom() {
  214. if (this.data.onRefresh) {
  215. this.setData({
  216. itemLoading: true
  217. })
  218. this.getListData();
  219. }
  220. },
  221. /**
  222. * 授权获取加密信息
  223. */
  224. getPhoneNumber(e) {
  225. if (!!e.detail.iv && !!e.detail.encryptedData) {
  226. const iv = e.detail.iv
  227. const encryptedData = e.detail.encryptedData
  228. this.appletLogin(iv, encryptedData)
  229. } else {
  230. wx.showToast({
  231. title: '请允许授权,获得更好的服务哦',
  232. icon: "none",
  233. duration: 3000
  234. })
  235. }
  236. },
  237. /**
  238. * 用户授权信息存储
  239. */
  240. appletLogin(iv, encrypted) {
  241. $request.get('/com/appletLogin.action', {
  242. // openid: app.globalData.openid,
  243. iv: iv,
  244. encryptedData: encrypted,
  245. sessionKey: app.globalData.sessionKey,
  246. loginState: "业务交流通",
  247. }).then(res => {
  248. this.getUserSession()
  249. }).catch(error => {
  250. console.log(error, 'error appletLogin')
  251. })
  252. },
  253. /**
  254. * 获取用户身份信息
  255. */
  256. getUserSession() {
  257. let that = this
  258. wx.showLoading({
  259. title: '加载中',
  260. mask: true
  261. })
  262. $request.post('/script/getSession.action', {}).then(res => {
  263. // 如果有传入的urlcustomer
  264. // 跳转到传入地址页面
  265. wx.setStorageSync('customerId', res.data.customer.customerId) //存储用户customerId到本地
  266. that.setData({
  267. isLogin: true
  268. })
  269. app.globalData.customerId = res.data.customer.customerId
  270. wx.hideLoading()
  271. that.checkIsFinish(res.data.customer.customerId, 1)
  272. }).catch(error => {
  273. console.log(error, "获取error")
  274. })
  275. },
  276. })