// 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>