页面中
<view class="container">
<view class="list-tab flexR" catchtap='toggleView'>
<view class="{{nowRole==0?'checked-item':''}}" data-index="0">项目</view>
</view>
<!--列表展示 -->
<swiper bindchange="toggleSwiper" current='{{currentIndex}}'>
<swiper-item>
<scroll-view scroll-y="true" style="height:calc(100vh - 252px);" bindscrolltolower="bindDownLoad" id="gn" class="investment-people-list flexC">
<view class="item flexR" wx:for="{{contentlistn}}" bindtap='toDetail' data-type="gn" data-id="{{item.id}}">
<view class="people-info flexC">
<view>{{item.title}}</view>
<view>所在地区:{{item.address}}</view>
<view>所属行业:{{item.industry}}</view>
</view>
</view>
</scroll-view>
</swiper-item>
</swiper>
</view>
js 中
//获取应用实例
const app = getApp();
// 引入 js
var xtrequest = require('../../utils/xtrequest.js')
Page({
data: {
pagen: 1,
pagey: 1,
totalpage: '',
nowRole: 0,
currentIndex: 0,
app_parameter: '',
contentlistn: [], // 页面分配数据,在这定义空数据,下面方法中分配数据
loadMoreData: '',
hideBottom: true,
refreshTime: '', // 刷新的时间
},
// 加载页面时 触发的操作
onLoad: function () {
this.setData({
app_parameter: wx.getStorageSync('app_parameter')
})
var that = this;
wx.request({
url: 'https://...com/Wapi/Index/index', // 请求接口返回列表数据
header: {
'content-type': 'application/json' // 默认值
},
success: function (res) {
that.setData({
contentlistn: res.data.guonei, // 页面分配数据
});
}
})
},
onshow: function () {
},
//toggleView
toggleView: function (event) {
let that = this;
let currentIndex = that.data;
currentIndex = event.target.dataset.index;
that.setData({
currentIndex
})
},
//swiper切换
toggleSwiper: function (event) {
let that = this;
let nowRole = that.data;
nowRole = event.detail.current;
that.setData({
nowRole
})
},
//跳转到详情页
toDetail: (event) => {
let type = event.currentTarget.dataset.type;
var id = event.currentTarget.dataset.id;
let url;
if (type == "gn") {
url = "/pages/detail/detail?id=" + id + "&type=" + type;
} else {
url = "/pages/detail/detail?id=" + id + "&type=" + type;
}
wx.navigateTo({
url: url,
})
},
// tab切换
toTabPage: function (e) {
toTabPage(e)
},
launchAppError: function (e) {
console.log(e.detail.errMsg)
},
toApp: function () {
app.toApp();
},
bindDownLoad: function (options) {
var that = this;
// console.log(options);
var id = options.currentTarget.id
if (id == 'gn') {
var page = this.data.pagen
var content = this.data.contentlistn
xtrequest.xtrequest.getItemList({
page: page,
id: id,
content: content,
success: function (res, shuju) {
if (shuju.status == 0) {
that.setData({
loadMoreData: shuju.error,
hideBottom: false
})
setTimeout(function () {
that.setData({
hideBottom: true
})
}, 3000)
return false
}
that.setData({
contentlistn: shuju.item,
pagen: shuju.page
})
}
})
}
},
})
控制器
public function index() {
$id=I("get.id",0,'intval');
$project_model=M("project");
$project=$project_model->where('status=1')->limit(6)->select();
// 返回 列表数据
$info=array(
"guonei"=>$project
);
if(empty($info)){
$data=array(
"status"=>0,
"message"=>"数据异常",
);
$data=json_encode($data,true);
}
$this->ajaxReturn($info,'JSON');
}