123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- const app = getApp();
- import productApi from '../../api/product'
- import storeApi from '../../api/store'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- peopleNum: 1,
- activeTab: 0,
- productInfo: {
-
- },
- shopInfo: {},
- tabs: [],
- orderTime: "",
- orderTimeHeight: 0
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: async function (options) {
- var shopId = options.shopId;
- var productId = options.productId
- var productInfo = await productApi.getProductById(productId);
- var shopInfo = await storeApi.getStoreById(shopId);
- this.setData({
- productInfo: productInfo.info,
- shopInfo:shopInfo.info
- })
- var tabs = await this.createTimeList(268);
- this.setData({
- tabs
- });
- this.getOrderHeight();
- this.checkedTime()
- },
- checkAuth: async function () {
- console.log(this)
- const isAuth = await app.isAuth()
- if (!isAuth) {
- wx.redirectTo({
- url: '/pages/prompt/prompt?page=' + this.route,
- })
- }
- },
- onSlideChangeEnd: function (e) {
- var that = this;
- that.setData({
- activeTab: e.detail.index
- })
- },
- //动态生成产品的父盒子高度
- getOrderHeight: function () {
- var activeTab = this.data.activeTab;
- var orderTimeHeight = (this.data.tabs[activeTab].list.length) / 5 * 130;
- this.setData({
- orderTimeHeight
- })
- },
- createTimeList: async function (price) {
- var titles = ["今天", "明天", "12-23", "12-24", "12-25", "12-26", "12-27"];
- var day = ["12-21", "12-22", "12-23", "12-24", "12-25", "12-26", "12-27"];
- const tabs = [];
- let list = [{
- id: "1",
- time: "8:00",
- price: price,
- },
- {
- id: "2",
- time: "8:30",
- price: price,
- },
- {
- id: "3",
- time: "9:00",
- price: price,
- },
- {
- id: "4",
- time: "9:30",
- price: price,
- },
- {
- id: "5",
- time: "10:00",
- price: price,
- },
- {
- id: "6",
- time: "10:30",
- price: price,
- },
- {
- id: "7",
- time: "11:00",
- price: price,
- },
- {
- id: "8",
- time: "11:30",
- price: price,
- }, {
- id: "9",
- time: "12:00",
- price: price,
- },
- {
- id: "10",
- time: "12:30",
- price: price,
- },
- {
- id: "11",
- time: "13:00",
- price: price,
- },
- {
- id: "12",
- time: "13:30",
- price: price,
- },
- {
- id: "13",
- time: "14:00",
- price: price,
- },
- {
- id: "14",
- time: "14:30",
- price: price,
- },
- {
- id: "15",
- time: "15:00",
- price: price,
- },
- {
- id: "16",
- time: "15:30",
- price: price,
- }, {
- id: "17",
- time: "16:00",
- price: price,
- },
- {
- id: "18",
- time: "16:30",
- price: price,
- },
- {
- id: "19",
- time: "17:00",
- price: price,
- },
- {
- id: "20",
- time: "17:30",
- price: price,
- },
- {
- id: "21",
- time: "18:00",
- price: price,
- },
- {
- id: "22",
- time: "18:30",
- price: price,
- },
- {
- id: "23",
- time: "19:00",
- price: price,
- },
- {
- id: "24",
- time: "19:30",
- price: price,
- },
- {
- id: "25",
- time: "20:00",
- price: price,
- }
- ];
- titles.forEach(function (item, i, array) {
- list.forEach(function (item, i, array) {
- array[i].timeId = i;
- array[i].inTime = true;
- array[i].checked = false;
- })
- tabs.push({
- title: titles[i],
- day: day[i],
- list
- })
- })
- // tabs[2].list.splice(7,7)
- return tabs;
- },
- //判断产品是否过时间
- checkedTime: function (e) {
- // 设置一小时内订单不能购买
- var timeLimit = 1;
- var nowTime = new Date(2020, 11, 21, 18, 29, 0);
- var hour = nowTime.getHours();
- var tabs = this.data.tabs[0];
- var list = firstTabs.list;
- // console.log(tabs[5].list)
- list.forEach(function (item, i, array) {
- var orderHour = item.time.split(":")[0];
- if (parseInt(orderHour) <= parseInt(hour)) {
- item.inTime = false;
- }
- })
- this.setData({
- tabs: nowTabs
- })
- },
- getOrderTime: function (e) {
- // var date = document.getElementById("orderDate");
- // console.log(date.target)
- // console.log(e.currentTarget)
- //选中日期的下标
- var i = this.data.activeTab;
- //选中时间的下标
- var index = e.currentTarget.dataset.i;
- //获取选中的日期
- var date = this.data.tabs[i].day;
- var time = e.currentTarget.dataset.time;
- var oTime = date + '/' + time;
- //设置选中的样式
- var tabs = this.data.tabs;
- var list = tabs[i].list;
- //先清空其他选中的样式
- list.forEach(function (item, i, array) {
- item.checked = false;
- })
- if (list[index].inTime) {
- list[index].checked = true;
- this.data.tabs[i].list = list;
- }
- this.setData({
- orderTime: oTime,
- tabs
- })
- },
- addPeopleNum: function (e) {
- var num = e.currentTarget.dataset.num;
- var maxNum = 9;
- if (num < maxNum) {
- num++;
- }
- this.setData({
- peopleNum: num
- })
- },
- reducePeopleNum: function (e) {
- var num = e.currentTarget.dataset.num;
- if (num > 1) {
- num--;
- }
- this.setData({
- peopleNum: num
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|