123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- // pages/deliciousList.js
- import {
- imgUrl
- } from "../api/request"
- import {
- request,
- baseUrl
- } from "../api/canteen-request"
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- // 图片前缀
- imgUrl: imgUrl,
- // 服务器地址
- baseUrl: baseUrl + '/',
- // 默认选中
- currentTab: 0,
- // 食堂列表
- canteenList: [],
- isLoading: false
- },
- getDeliciousList() {
- var that = this;
- this.setData({
- isLoading: true
- })
- request({
- url: '/mini/canteen/getDeliciousList',
- method: 'GET'
- }).then(res => {
- if (res.result) {
- let temp = [];
- if (res.data.length < 0) {
- this.setData({
- isLoading: false
- })
- return;
- }
- res.data.forEach(element => {
- if (element.deliciousList.length > 0) {
- temp.push(element);
- }
- })
- temp.forEach(element => {
- element.deliciousList.forEach(item => {
- if (item.dishesPic) {
- wx.getImageInfo({
- src: this.data.baseUrl + item.dishesPic,
- fail() {
- item.dishesPic = '';
- that.setData({
- canteenList: temp
- })
- }
- });
- }
- });
- });
- this.setData({
- isLoading: false,
- canteenList: temp
- })
- } else {
- this.setData({
- isLoading: false
- })
- }
- })
- },
- // 切换食堂
- tabNav(e) {
- let currentTab = e.currentTarget.dataset.index
- this.setData({
- currentTab
- })
- },
- // 切换食堂
- handleSwiper(e) {
- let {
- current,
- source
- } = e.detail
- if (source === 'autoplay' || source === 'touch') {
- const currentTab = current
- this.setData({
- currentTab
- })
- }
- },
- // 查看评论
- toComment: function (e) {
- wx.navigateTo({
- url: '/pages/commentList/commentList?dishesId=' + e.currentTarget.dataset.data.dishesId + '&commentCount=' + e.currentTarget.dataset.data.commentCount + '&compliment=' + e.currentTarget.dataset.data.compliment + '&canteenId=' + this.data.canteenList[this.data.currentTab].id
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.getDeliciousList();
- // 加载字体
- // wx.loadFontFace({
- // family: 'DOUYU',
- // source: 'url("https://www.cqna.gov.cn/mnazw/applet/font/douyu.ttf")',
- // success: function (e) {
- // console.log(e, '动态加载字体成功')
- // },
- // fail: function (e) {
- // console.log(e, '动态加载字体失败')
- // },
- // })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- if (this.data.loginReturnFlag) {
- this.setData({
- loginReturnFlag: false
- })
- this.onLoad()
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- return {
- title: '菜品榜单'
- }
- }
- })
|