// pages/books/books.js
var page=1;
const app=getApp();
Page({网络
/**
* 页面的初始数据
*/
data: {
},
kd:function(e){
let id=e.currentTarget.dataset.id
wx.navigateTo({
url: '/pages/show/show?id='+id,
})
},
dzan:function(e){
let that=this
let id=e.currentTarget.dataset.id
let stor=e.currentTarget.dataset.stor
let sta = e.currentTarget.dataset.stasession
wx.request({
url: 'http://www.month.com/cop/zan',
data: {
id:id,
stor:stor,
sta:sta
},
success: function(res) {
console.log(res)
that.setData({
shop:res.data.data
})
if(res.data.code==200){
wx.showToast({
title: '取消成功',app
})
}
if (res.data.code == 300) {
wx.showToast({
title: '点同意功',ide
})
}
},
})
},
formSubmit:function(e){
let sear=e.detail.value.sear;
let that=this;
wx.request({
url: 'http://www.month.com/cop/lis',
data: {
sear:sear
},函数
success: function (res) {
that.setData({
shop: res.data
})
},this
})url
},code
click:function(e){
let index=e.currentTarget.dataset.index;
let id=e.currentTarget.dataset.id;
app.globalData.cid=id
this.setData({
sel:index
})
let that=this
wx.getStorage({
key: 'shop'+ e.currentTarget.dataset.id,
success(res) {
that.setData({
shop: res.data,
aa: 1
})
},
fail(res){
wx.request({
url: 'http://www.month.com/cop/lis',
data: {
id: id
},orm
success: function (res) {
that.setData({xml
shop: res.data,
aa: 1
})
wx.setStorage({
key: 'shop' +e.currentTarget.dataset.id,
data: res.data
})
},
})
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.clic()
this.dh()
wx.checkSession({
success() {
// session_key 未过时,而且在本生命周期一直有效
},
fail() {
// session_key 已经失效,须要从新执行登陆流程
wx.login() // 从新登陆
}
})
// wx.login({
// success(res) {
// if (res.code) {
// // 发起网络请求
// wx.request({
// url: 'http://www.month.com/cop/ace',
// data: {
// code: res.code
// },
// success:function(data){
// console.log(data)
// }
// })
// } else {
// console.log('登陆失败!' + res.errMsg)
// }
// }
// })
},
onReachBottom:function(){
let that = this;
page++;
console.log(page)
wx.request({
url: 'http://www.month.com/cop/lis',
data: {
page: page,
id: app.globalData.cid
},
success: function (res) {
console.log(res);
that.setData({
shop: res.data
})
page--
},
})
},
tub:function(){
wx.pageScrollTo({
scrollTop: 0,
duration: 300
})
},
clic:function(){
let that=this;
wx.request({
url: 'http://www.month.com/book/show',
data:{
page:page
},
success: function(res) {
that.setData({
list:res.data
})
},
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
cli:function(e){
let id=e.currentTarget.dataset.id
let that=this
wx.navigateTo({
url: '/pages/shbook/shbook?id='+id,
})
},
dh:function(){
let that=this
wx.request({
url: 'http://www.month.com/cop/show',
success: function(res) {
that.setData({
inno:res.data
})
},
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动做
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
//wxml
<!--pages/books/books.wxml-->
<form bindsubmit="formSubmit" bindreset="formReset">
<view class="section">
<input name="sear" placeholder="please input here" class='wb' />
<view class="btn-area">
<button form-type="submit" style='100rpx;height:70rpx;font-size:34rpx;'>搜索</button>
</view>
</view>
<view class='tou'>
<view wx:for="{{inno}}" data-id='{{item.id}}' class="{{sel==index?'wei':'heq'}}" data-index='{{index}}' bindtap='click'>
<text>{{item.cname}}</text>
</view>
</view>
<view wx:if="{{aa ==1}}">
<view wx:for="{{shop}}" >
<image src='{{item.imgurl}}' catchtap='kd' data-id="{{item.id}}" class="tw" ></image>
<view class='wzx'>
<view class='zt'><text>{{item.gname}}</text></view>
<view><text style='color:red' catchtap='dz'>价格:{{item.price}}</text></view>
</view>
<view wx:if="{{item.static==0}}"> <view data-sta="{{item.static}}" data-id="{{item.id}}" data-stor='{{item.store}}' catchtap='dzan' >
<image src='/image/dz1.png' style='width:70rpx;height:70rpx;' ></image></view> </view>
<view wx:else> <view data-sta="{{item.static}}" data-id="{{item.id}}" data-stor='{{item.store}}' catchtap='dzan' >
<image src='/image/dian.png' style='width:70rpx;height:70rpx;' ></image></view> </view>
</view>
</view>
<view wx:else><view class='top'>
<view wx:for="{{list}}" class='tp'>
<view catchtap='cli' data-id='{{item.id}}'>
<image src='{{item.img}}'style="width:330rpx;height:430rpx;"></image>
<view>{{item.name}}</view>
<view style='color:red'>{{item.price}}</view>
</view>
</view></view><view><image src='/image/zhiding.png' class='tb'catchtap='tub'></image></view></view></form>