123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- // index.js
- // 获取应用实例
- const app = getApp()
- const { axios } = app.globalData;
- Page({
- data: {
- // 商品列表
- shoplist: [],
- // 广告
- datalist: []
- },
- // 点击商品查看详情
- ShopSuccess (e) {
- let { id } = e.currentTarget.dataset;
- wx.navigateTo({
- url: `/pages/detail/detail?data=${JSON.stringify({ id })}`,
- })
- },
- // 请求广告
- hotrequest () {
- let that = this;
- axios({
- url: '/notices/wx_notices/',
- method: 'get',
- success (res) {
- let { data } = res.data, datalist = [];
- data.forEach(item => {
- datalist.push({
- name: item.title,
- url: `/pages/hot/hot?data=${JSON.stringify({ hot: item })}`
- })
- })
- that.setData({
- datalist
- })
- }
- }).then(res => {
- wx.lxd.NoticeBar({
- datalist: that.data.datalist
- })
- if (app.globalData.hot) {
- this.hot();
- app.globalData.hot = false;
- }
- })
- },
- //加载商品数据 模拟5条
- PageCount: 1,//总页数
- Page: 1,//当前页数
- ShopRequest () {
- if (this.Page > this.PageCount) return false;
- let that = this, { shoplist } = this.data;
- axios({
- url: "/commodity/wx_commodity/",
- method: "get",
- data: {
- page: that.Page,
- limit: 10,
- },
- success (res) {
- let { data, totalPage } = res.data;
- that.PageCount = totalPage;
- that.Page++;
- data.forEach(item => {
- shoplist.push({
- id: item.id,
- price: item.amount,
- desc: item.introduce,
- imgurl: item.list_image,
- title: item.name
- })
- })
- wx.stopPullDownRefresh();
- that.setData({
- shoplist
- })
- }
- })
- },
- // 广告
- hot () {
- let { datalist } = this.data;
- if (datalist.length == 0) return false;
- wx.showModal({
- title: '通知',
- content: datalist[0]['name'],
- confirmText: '查看',
- success (res) {
- if (res.confirm) {
- wx.navigateTo({
- url: datalist[0]["url"],
- })
- }
- }
- })
- },
- onLoad () {
- wx.lxd.Ctr({
- // nav
- title: "我要订餐", //标题
- back: false,//返回按钮,tabber必须false(除非会改)
- bgc: false,//使用更改后的颜色;配合json使用
- // tabber
- tabber: true, // 显示
- active: 0,//活动值
- })
- this.hotrequest();
- },
- onReady: function () {
- },
- onShow () {
- this.ShopRequest();
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- this.PageCount = 1;
- this.Page = 1;
- this.setData({ shoplist: [] })
- this.ShopRequest();
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- this.ShopRequest();
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- onShareTimeline: function (res) {
- }
- })
|