123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- // pages/market_buy/detail.js
- import WxValidate from '../../utils/wxValidate';
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- frameStyle: { useTop: true, name: '信息管理', leftArrow: true, useBar: false },
- // 主体高度
- infoHeight: '',
- userInfo: {},
- // 上架的商品
- marketList: [],
- // 类型
- typeList: [],
- // 详细信息
- info: {},
- // 弹框
- dialog: { title: '详细信息', show: false, type: '1' },
- // 选购
- formList: [],
- list: [],
- // 收货信息
- receiveForm: {}
- },
- initValidate() {
- const rules = { receive_user_name: { required: true, }, receive_user_phone: { required: true, }, receive_address: { required: true, } }
- // 验证字段的提示信息,若不传则调用默认的信息
- const messages = { receive_user_name: { required: '请输入收货人', }, receive_user_phone: { required: '请输入收货电话', }, receive_address: { required: '请输入收货地址', } };
- this.WxValidate = new WxValidate(rules, messages)
- },
- back: function () {
- wx.navigateBack({ url: '/pages/home/index' })
- },
- // 详细信息
- toView: function (e) {
- let item = e.currentTarget.dataset.item;
- this.setData({ info: item })
- this.setData({ dialog: { title: '详细信息', show: true, type: '1' } })
- },
- // 添加
- toPlus: function (e) {
- let p1 = this.data.formList;
- // 商品
- let { item } = e.currentTarget.dataset;
- let data = { user_id: this.data.userInfo.id, user_name: this.data.userInfo.name, user_phone: this.data.userInfo.phone, order: [] };
- // 查询是否已有订单
- if (p1.length > 0) {
- // 查询供货单位是否已经加入商品
- let p2 = p1.find(i => i.mech_id == item.mech_id);
- if (p2) {
- // 查找该商品是否已经加入订单
- let p3 = p2.order.find(i => i.id == item.id);
- if (p3) {
- p3.num = p3.num + 1;
- p2.money = Number(p2.money) + Number(p3.money);
- }
- else {
- item.num = 1;
- p2.money = Number(p2.money) + Number(item.money); p2.order.push(item);
- }
- } else {
- item.num = 1; data.mech_id = item.mech_id; data.mech_name = item.mech_name; data.money = item.money * item.num; data.order.push(item); p1.push(data);
- }
- } else {
- item.num = 1; data.mech_id = item.mech_id; data.mech_name = item.mech_name; data.money = item.money * item.num; data.order.push(item); p1.push(data);
- }
- },
- // 減少
- toMinus: function (e) {
- let p1 = this.data.formList;
- // 商品
- let { item } = e.currentTarget.dataset;
- let p2 = p1.find(i => i.mech_id == item.mech_id);
- if (p2) {
- p2.money = p2.money - item.money;
- if (p2 && p2.money === 0) {
- // 获取索引值,删除指定无商品商家信息
- var key = p1.indexOf(p2.mech_id);
- p1.splice(key, 1);
- } else {
- let p3 = p2.order.find(i => i.id == item.id);
- if (p3) p3.num = p3.num - 1;
- if (p3 && p3.num === 0) p3 = {};
- }
- }
- },
- // 查看选购
- toBuy: function () {
- this.setData({ list: this.data.formList })
- this.setData({ dialog: { title: '查看选购', show: true, type: '2' } })
- },
- // 确认选购
- toConfirm: function () {
- this.setData({ dialog: { title: '收货信息', show: true, type: '3' } })
- },
- // 提交订单
- onSubmit: function (e) {
- const params = e.detail.value;
- if (!this.WxValidate.checkForm(params)) {
- const error = this.WxValidate.errorList[0];
- wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
- return false
- } else {
- wx.showModal({
- title: '是否确认提交订单',
- success(res) {
- if (res.confirm) {
- wx.showToast({ title: `提交订单成功`, icon: 'success', duration: 2000 });
- } else if (res.cancel) {
- }
- }
- })
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- //验证规则函数
- this.initValidate();
- this.watchLogin();
- // 计算高度
- this.searchHeight();
- },
- // 监听用户是否登录
- watchLogin: function () {
- let data = [
- { id: '001', name: '喜羊羊', money: '20', type_name: '羊肉', type_id: '111', brief: '一份', mech_id: '000000001', mech_name: '羊村', img_one: '', img_url: [], status: '1' },
- { id: '002', name: '美羊羊', money: '30', type_name: '羊肉', type_id: '222', brief: '一份', mech_id: '000000001', mech_name: '羊村' },
- { id: '003', name: '懒羊羊', money: '15', type_name: '羊肉', type_id: '333', brief: '一份', mech_id: '000000001', mech_name: '羊村' },
- { id: '004', name: '沸羊羊', money: '25', type_name: '羊肉', type_id: '444', brief: '一份', mech_id: '000000001', mech_name: '羊村' },
- { id: '005', name: '慢羊羊', money: '26', type_name: '羊肉', type_id: '555', brief: '一份', mech_id: '000000001', mech_name: '羊村' },
- { id: '006', name: '暖羊羊', money: '27', type_name: '羊肉', type_id: '666', brief: '一份', mech_id: '000000001', mech_name: '羊村' }
- ]
- let info = { id: '00038494480001', user_id: '00038494480001', name: '法外狂徒张三', phone: '1239999999' };
- this.setData({ marketList: data })
- this.setData({ userInfo: info })
- this.setData({ 'receiveForm.receive_user_name': info.name, 'receiveForm.receive_user_id': info.user_id, 'receiveForm.receive_user_phone': info.phone, })
- // wx.getStorage({
- // key: 'user',
- // success: res => {
- // if (res.data) {
- // // 查询菜单
- // if (res.data) this.searchRouter(res.data);
- // res.data.type = type.find((i) => i.value == res.data.type).label;
- // if (res.data) this.setData({ userInfo: res.data });
- // if (res.data && res.data.avatarUrl) this.setData({ avatarUrl: res.data.avatarUrl });
- // } else {
- // wx.redirectTo({ url: '/pages/login/index', })
- // }
- // }
- // })
- },
- // 计算高度
- searchHeight: function () {
- let frameStyle = this.data.frameStyle;
- let client = app.globalData.client;
- // 减去状态栏
- let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
- // 是否减去底部菜单
- if (frameStyle.useBar) infoHeight = infoHeight - 50;
- if (infoHeight) this.setData({ infoHeight: infoHeight })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|