123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- // index.js
- // 获取应用实例
- const app = getApp()
- const $request = require('../../utils/request.js');
- const $util = require('../../utils/util.js');
- Page({
- data: {
- currentIndex: 0,
- keyword: "",
- // tab
- tabData: [
- {
- text: "全部",
- value: "all"
- },
- {
- text: "我关注的",
- value: "my1"
- },
- ],
- currentTab: "all",
- // 更多tab
- moreTabOption: [],
- moreTab: "gengduo",
- moreTitle: "更多",
- // list数据加载
- // list块加载
- listLoading: false,
- // item行加载
- itemLoading: false,
- // 数据是否加载完成
- isFinished: false,
- listData: [],
- page: 1,
- size: 10,
- total: 0,
- // 是否加载数据,true加载,false不加载
- onRefresh: true,
- },
- onLoad() {
- this.setData({
- listLoading: true,
- })
- // 获取分类
- this.getAllType();
- },
- toggleMore() {
- this.selectComponent('#item').toggle();
- },
- // 搜索框输入同步值
- bindKeyInput: function (e) {
- this.setData({
- keyword: e.detail.value
- })
- },
- // 点击搜索
- toSearch(e) {
- console.log(this.data.keyword)
- this.setData({
- listData: [],
- onRefresh: true,
- isFinished: false,
- listLoading: true,
- page: 1,
- })
- this.getListData();
- },
- // tab切换
- tabChange(e) {
- let dataset = e.currentTarget.dataset;
- // if(dataset.value == 'my1'){
- // console.log(this.selectComponent('#shouquan'));
- // return
- // }
- // 如果实在加载中点击无效
- if (this.data.listLoading) {
- return
- }
- // 如果当前tab是选中直接点击无效
- if (this.data.currentTab == dataset.value) {
- return
- }
- this.setData({
- currentTab: dataset.value,
- moreTitle: "更多",
- moreTab: "gengduo"
- })
- this.toSearch();
- },
- // 更多tab切换
- moreTabChange(e) {
- // 如果实在加载中点击无效
- if (this.data.listLoading) {
- return
- }
- // 如果当前tab是选中直接点击无效
- if (this.data.moreTab == e.detail) {
- return
- }
- let moreTitle = "";
- this.data.moreTabOption.forEach(el => {
- if (el.value == e.detail) {
- moreTitle = el.text;
- }
- })
- this.setData({
- currentTab: "more",
- moreTab: e.detail,
- moreTitle
- })
- this.toSearch();
- },
- // 进入详情
- goDetails(e) {
- wx.navigateTo({
- url: '/pages/index/components/listDetails/Details',
- success: function (res) {
- // 通过eventChannel向被打开页面传送数据
- res.eventChannel.emit('acceptDataFromOpenerPage', { listDetail: e.detail })
- }
- })
- },
- // 获取tab数据
- getAllType() {
- $request.get('/businessCommunicationType/getAllType.action').then(res => {
- if (res.status == 0) {
- let { tabData, moreTabOption } = this.data;
- let datas = res.data;
- datas.forEach(el => {
- if (tabData.length < 5) {
- tabData.push({
- text: el.typeName,
- value: el.typeName
- })
- } else {
- moreTabOption.push({
- text: el.typeName,
- value: el.typeName
- })
- }
- })
- this.setData({
- tabData,
- moreTabOption
- })
- this.getListData();
- }
- }).catch(error => {
- console.log(error, 'error appletLogin')
- })
- },
- // 获取list数据
- getListData() {
- let { page, size, keyword, currentTab, moreTab } = this.data;
- let type = currentTab;
- if (currentTab == 'more') {
- type = moreTab;
- }
- if (type == 'all') {
- type = "";
- }
- $request.get('/businessCommunicationDemand/getDemandByKeywordOrType.action',
- { page, size, keyword, type,isInterest:0 }
- ).then(res => {
- // console.log(res);
- this.setData({
- listLoading: false
- })
- let tempListData = this.data.listData;
- if (res.status == 0) {
- let datas = res.data;
- // 先push数据
- tempListData.push(...datas.demandList);
- tempListData.forEach(el => {
- el.createdOn = $util.formatTime(new Date(el.createdOn),true);
- if (typeof el.type == 'string') {
- el.type = el.type.split(',');
- }
- })
- // 设置总数
- this.setData({
- listData: tempListData,
- total: res.data.total,
- })
- // 如果数据大于了返回的总数
- if (tempListData.length >= this.data.total) {
- // 停止累加数据
- this.setData({
- onRefresh: false,
- itemLoading: false,
- isFinished: true,
- })
- } else {
- this.setData({
- onRefresh: true,
- itemLoading: false,
- isFinished: false,
- page: page + 1
- })
- }
- }
- }).catch(error => {
- console.log(error, 'error appletLogin')
- })
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- if (this.data.onRefresh) {
- this.setData({
- itemLoading: true
- })
- this.getListData();
- }
- },
- /**
- * 授权获取加密信息
- */
- getPhoneNumber(e) {
- if (!!e.detail.iv && !!e.detail.encryptedData) {
- const iv = e.detail.iv
- const encryptedData = e.detail.encryptedData
- this.appletLogin(iv, encryptedData)
- } else {
- wx.showToast({
- title: '请允许授权,获得更好的服务哦',
- icon: "none",
- duration: 3000
- })
- }
- },
- /**
- * 用户授权信息存储
- */
- appletLogin(iv, encrypted) {
- $request.get('/com/appletLogin.action', {
- // openid: app.globalData.openid,
- iv: iv,
- encryptedData: encrypted,
- sessionKey: app.globalData.sessionKey,
- loginState: "业务交流通",
- }).then(res => {
- this.getUserSession()
- }).catch(error => {
- console.log(error, 'error appletLogin')
- })
- },
- /**
- * 获取用户身份信息
- */
- getUserSession() {
- let that = this
- wx.showLoading({
- title: '加载中',
- mask: true
- })
- $request.post('/script/getSession.action', {}).then(res => {
- // 如果有传入的urlcustomer
- // 跳转到传入地址页面
- wx.setStorageSync('customerId', res.data.customer.customerId) //存储用户customerId到本地
- that.setData({
- isLogin: true
- })
- app.globalData.customerId = res.data.customer.customerId
- wx.hideLoading()
- that.checkIsFinish(res.data.customer.customerId, 1)
- }).catch(error => {
- console.log(error, "获取error")
- })
- },
- })
|