|
@@ -1,170 +1,194 @@
|
|
|
// 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: { user_id: '00038494480001', name: '123', phone: '1239999999' },
|
|
|
- // 上架的商品
|
|
|
- marketList: [
|
|
|
- { id: '001', name: '喜羊羊', money: '22', type_name: '羊肉', type_id: '111', brief: '一份', mech_id: '000000001', mech_name: '羊村' },
|
|
|
- { id: '002', name: '美羊羊', money: '23', type_name: '羊肉', type_id: '222', brief: '一份', mech_id: '000000001', mech_name: '羊村' },
|
|
|
- { id: '003', name: '懒羊羊', money: '24', 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: '羊村' }
|
|
|
- ],
|
|
|
- // 类型
|
|
|
- typeList: [],
|
|
|
- // 详细信息
|
|
|
- info: {},
|
|
|
- // 弹框
|
|
|
- dialog: { title: '详细信息', show: false, type: '1' },
|
|
|
- // 选购
|
|
|
- formList: [],
|
|
|
- list: [],
|
|
|
- // 收货信息
|
|
|
- receiveForm: {}
|
|
|
- },
|
|
|
- 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;
|
|
|
- // console.log(this.data.formList);
|
|
|
- // 商品
|
|
|
- let { item } = e.currentTarget.dataset;
|
|
|
- // console.log(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 = p2.money + p3.money;
|
|
|
- }
|
|
|
- else {
|
|
|
- item.num = 1; p2.money = p2.money + 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) {
|
|
|
- wx.showToast({ title: `采买发布成功`, icon: 'error', duration: 2000 });
|
|
|
- },
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面加载
|
|
|
- */
|
|
|
- onLoad: function (options) {
|
|
|
- // 计算高度
|
|
|
- this.searchHeight();
|
|
|
- },
|
|
|
- // 计算高度
|
|
|
- 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 })
|
|
|
- },
|
|
|
+ /**
|
|
|
+ * 页面的初始数据
|
|
|
+ */
|
|
|
+ data: {
|
|
|
+ frameStyle: { useTop: true, name: '信息管理', leftArrow: true, useBar: false },
|
|
|
+ // 主体高度
|
|
|
+ infoHeight: '',
|
|
|
+ userInfo: { id: '00038494480001', user_id: '00038494480001', name: '法外狂徒张三', phone: '1239999999' },
|
|
|
+ // 上架的商品
|
|
|
+ marketList: [
|
|
|
+ { 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: '羊村' }
|
|
|
+ ],
|
|
|
+ // 类型
|
|
|
+ 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.setData({ 'receiveForm.receive_user_name': this.data.userInfo.name, 'receiveForm.receive_user_id': this.data.userInfo.user_id, 'receiveForm.receive_user_phone': this.data.userInfo.phone, })
|
|
|
+ //验证规则函数
|
|
|
+ this.initValidate();
|
|
|
+ // 计算高度
|
|
|
+ this.searchHeight();
|
|
|
+ },
|
|
|
+ // 计算高度
|
|
|
+ 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 () {
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面初次渲染完成
|
|
|
+ */
|
|
|
+ onReady: function () {
|
|
|
|
|
|
- },
|
|
|
+ },
|
|
|
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面显示
|
|
|
- */
|
|
|
- onShow: function () {
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面显示
|
|
|
+ */
|
|
|
+ onShow: function () {
|
|
|
|
|
|
- },
|
|
|
+ },
|
|
|
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面隐藏
|
|
|
- */
|
|
|
- onHide: function () {
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面隐藏
|
|
|
+ */
|
|
|
+ onHide: function () {
|
|
|
|
|
|
- },
|
|
|
+ },
|
|
|
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面卸载
|
|
|
- */
|
|
|
- onUnload: function () {
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面卸载
|
|
|
+ */
|
|
|
+ onUnload: function () {
|
|
|
|
|
|
- },
|
|
|
+ },
|
|
|
|
|
|
- /**
|
|
|
- * 页面相关事件处理函数--监听用户下拉动作
|
|
|
- */
|
|
|
- onPullDownRefresh: function () {
|
|
|
+ /**
|
|
|
+ * 页面相关事件处理函数--监听用户下拉动作
|
|
|
+ */
|
|
|
+ onPullDownRefresh: function () {
|
|
|
|
|
|
- },
|
|
|
+ },
|
|
|
|
|
|
- /**
|
|
|
- * 页面上拉触底事件的处理函数
|
|
|
- */
|
|
|
- onReachBottom: function () {
|
|
|
+ /**
|
|
|
+ * 页面上拉触底事件的处理函数
|
|
|
+ */
|
|
|
+ onReachBottom: function () {
|
|
|
|
|
|
- },
|
|
|
+ },
|
|
|
|
|
|
- /**
|
|
|
- * 用户点击右上角分享
|
|
|
- */
|
|
|
- onShareAppMessage: function () {
|
|
|
+ /**
|
|
|
+ * 用户点击右上角分享
|
|
|
+ */
|
|
|
+ onShareAppMessage: function () {
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
})
|