當前位置:編程學習大全網 - 編程語言 - 微信小程序的index.js怎麽寫?詳細代碼見下方↓

微信小程序的index.js怎麽寫?詳細代碼見下方↓

微信小程序實例index.js代碼如下:

可以搜索小程序名稱: 快遞最後壹公裏

實例index.js代碼

var app = getApp();

Page({

/**

* 頁面的初始數據

*/

data: {

//三張圖片輪播

imgUrls: [

{

imageUrl: '/images/weicha/timg1.jpg',

},

{

imageUrl: '/images/weicha/timg2.jpg',

},

{

imageUrl: '/images/weicha/timg3.jpg',

}

],

indicatorDots: false,

autoplay: false,

interval: 5000,

duration: 800,

},

onSwiperTab: function (e) {

/*var postId = e.target.dataset.postId;

wx.navigateTo({

url: postId,

});*/

},

/**

* 生命周期函數--監聽頁面加載

*/

onLoad: function (options) {

app.loginWinCha(this.initPageData);

},

//初始化登錄才能查看的數據

initPageData: function () {

this.setData({

componentList: [

{

id: 1,

url: '../weicha/express/courier/index',

imageUrl: '/images/weicha/timg1_1.jpg',

title: '快遞小哥(送快遞)',

queryType: 'courier'

},

{

id: 2,

url: '../weicha/express/seller/index',

imageUrl: '/images/weicha/timg1_2.jpg',

title: '合作商家(代收快遞)',

queryType: 'seller'

},

{

id: 3,

url: '../weicha/express/personal/index',

imageUrl: '/images/weicha/timg1_3.jpg',

title: '收件人(簽收快遞)'

},

{

id: 4,

url: '../weicha/express/logistics/index',

imageUrl: '/images/weicha/timg1_4.jpg',

title: '快遞物流查詢'

}

]

});

},

onItemClick: function (e) {

var targetUrl = e.currentTarget.dataset.pay;

var targetQueryType = e.currentTarget.dataset.index;

if (targetQueryType == "seller") {

var reqData = {

seller_openId: app.globalData.openid,

status: '2'

};

this.queryDBUtil("sellerInfo", reqData, targetQueryType, targetUrl,

"親,您暫未申請商家,請提交商家申請!");

} else if (targetQueryType == "courier") {

var reqData = {

courier_openId: app.globalData.openid,

status: '2'

};

this.queryDBUtil("courierInfo", reqData, targetQueryType, targetUrl,

"親,您暫未申請快遞員,請提交快遞員申請!");;

} else {

wx.navigateTo({

url: targetUrl

});

}

},

queryDBUtil: function (reqCollectionName, reqData,queryType, retUrl,retMgs){

wx.cloud.callFunction({

name: "utilsDB",

data: {

collectionName: reqCollectionName,

collectionWhere: reqData

},

complete: res => {

let retStatus = '1';

if (res.result.data.length >= 1) {

retStatus = res.result.data[0].status;

}

if (retStatus == '2') {

if (queryType == "seller"){

app.globalData.seller = res.result.data[0];

} else if (queryType == "courier"){

app.globalData.courier = res.result.data[0];

}

wx.navigateTo({

url: retUrl

});

} else {

wx.showToast({

icon: 'none',

title: retMgs

});

}

},

fail: err => {

wx.showToast({

icon: 'none',

title: retMgs

});

}

});

}

})

  • 上一篇:機器人程序設計
  • 下一篇:手工制作用英語怎麽說
  • copyright 2024編程學習大全網