123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- // pages/index/components/listDetails/Details.js
- const app = getApp()
- const $request = require('../../../../utils/request.js');
- const $util = require('../../../../utils/util.js');
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- // 页面Loading
- pageLoading: false,
- customerId: "666678",
- // 路由接受的参数
- currentData: {},
- // 感兴趣的需求----
- // item行加载
- itemLoading: false,
- // 数据是否加载完成
- isFinished: false,
- listData: [],
- page: 1,
- size: 10,
- total: 0,
- // 是否加载数据,true加载,false不加载
- onRefresh: true,
- currentIndex: 0,
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(option) {
- const eventChannel = this.getOpenerEventChannel()
- // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
- eventChannel.on('acceptDataFromOpenerPage', data => {
- this.setData({
- currentData: data.listDetail,
- type: data.listDetail.type.join(),
- pageLoading: true,
- })
- this.getIsCollect();
- })
- },
- // 热门详情点击
- goDetails(e) {
- this.setData({
- currentData: e.detail,
- type: e.detail.type.join(),
- pageLoading: true,
- listData: [],
- page: 1,
- onRefresh: true,
- isCollect: false,
- })
- wx.pageScrollTo({
- scrollTop: 0,
- });
- this.getIsCollect();
- },
- // 判断是否收藏
- getIsCollect() {
- let { currentData, customerId } = this.data;
- $request.get('/businessCommunicationCollect/booleanIsCollect.action',
- { customerId, businessCommunicationDemandId: currentData.businessCommunicationDemandId }
- ).then(res => {
- console.log(res);
- if (res.status == 0) {
- this.setData({
- isCollect: res.data == 0 ? false : true
- })
- }
- this.getListData();
- }).catch(err => {
- console.log(error, 'error appletLogin')
- })
- },
- // 切换收藏
- changeCollect() {
- // console.log(this.data.currentData)
- let { currentData, customerId, isCollect } = this.data;
- let url = "";
- let msg = "";
- // 如果已收藏就取消收藏 else 反之
- if (isCollect) {
- url = "/businessCommunicationCollect/deleteCollect.action",
- msg = "取消收藏成功"
- } else {
- url = "/businessCommunicationCollect/saveCollect.action",
- msg = "收藏成功"
- }
- wx.showLoading({
- title: '操作中...',
- mask: true
- })
- $request.post(url,
- { customerId, businessCommunicationDemandId: currentData.businessCommunicationDemandId }
- ).then(res => {
- wx.hideLoading()
- if (res.status == 0) {
- this.setData({
- isCollect: !isCollect
- })
- wx.showToast({
- title: msg,
- icon: 'success',
- duration: 2000
- })
- }
-
- }).catch(err => {
- console.log(error, 'error appletLogin')
- })
- },
- // 获取list数据
- getListData() {
- let { page, size, type, currentData } = this.data;
- $request.get('/businessCommunicationDemand/getDemandByKeywordOrType.action',
- { page, size, type, isInterest: 1, demandId: currentData.businessCommunicationDemandId }
- ).then(res => {
- this.setData({
- pageLoading: 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();
- }
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
-
- }
- })
|