Ver código fonte

添加快速进入购物车按钮

xiaohaizhao 2 anos atrás
pai
commit
f392eec015
2 arquivos alterados com 298 adições e 278 exclusões
  1. 203 195
      packageA/market/detail.js
  2. 95 83
      packageA/market/detail.wxml

+ 203 - 195
packageA/market/detail.js

@@ -1,203 +1,211 @@
 const _Http = getApp().globalData.http;
 let sa_brandid = null,
-  sys_enterpriseid = null;
+	sys_enterpriseid = null;
 import {
-  fileList
+	fileList
 } from "../../utils/FormatTheAttachment";
 import currency from "../../utils/currency";
 
 Page({
-  data: {
-    loading: true,
-    content: {
-      sa_itemgroupid: null,
-      spec: "", //规格
-      color: "", //颜色
-      material: "", //材质
-      cheek: "", //边框
-    }
-  },
-  onLoad(options) {
-    let data = JSON.parse(options.params);
-    sa_brandid = data.sa_brandid;
-    if (wx.getStorageSync('userrole') == '业务员') sys_enterpriseid = data.sys_enterpriseid
-    this.data.content.sa_itemgroupid = data.sa_itemgroupid;
-    this.setData({
-      userrole: wx.getStorageSync('userrole')
-    })
-    this.getDetail(true);
-  },
-  /* 获取详情 */
-  getDetail(init = false) {
-    let content = this.data.content;
-    if (sys_enterpriseid) content.sys_enterpriseid = sys_enterpriseid;
-    _Http.basic({
-      "id": "20221223165503",
-      content
-    }).then(res => {
-      wx.hideLoading();
-      console.log("商品详情", res)
-      if (res.msg != '成功') return wx.showToast({
-        title: res.msg,
-        icon: "none"
-      })
-      if (res.data.item.length == 0) return wx.showToast({
-        title: '未查询到商品',
-        icon: "none",
-        mask: true
-      })
-      this.handleFiles(res.data.item[0].attinfos)
-      const CNY = sum => currency(sum, {
-        symbol: "¥",
-        precision: 2
-      }).format();
-      res.data.item[0].gradeprice = CNY(res.data.item[0].gradeprice);
-      res.data.item[0].marketprice = CNY(res.data.item[0].marketprice);
-      this.setData({
-        content,
-        detail: res.data.item[0],
-        specRows: res.data.specRows,
-        cheekRows: res.data.cheekRows,
-        materialRows: res.data.materialRows,
-        colorRows: res.data.colorRows,
-        loading: false
-      });
-    })
-  },
-  /* 预览媒体 */
-  viewMedias(e) {
-    const {
-      index,
-      type
-    } = e.currentTarget.dataset;
-    wx.previewMedia({
-      current: index,
-      sources: type == 'image' ? this.data.files.viewImages : this.data.files.viewVideos,
-    })
-  },
-  /* 处理附件 */
-  handleFiles(arr) {
-    let files = {
-        images: [],
-        viewImages: [],
-        videos: [],
-        viewVideos: [],
-        files: []
-      },
-      list = fileList(arr);
-    list.forEach(v => {
-      switch (v.fileType) {
-        case "video":
-          files.videos.push(v)
-          files.viewVideos.push({
-            url: v.url,
-            type: "video",
-            poster: v.subfiles[0].url
-          })
-          break;
-        case "image":
-          files.images.push(v)
-          files.viewImages.push({
-            url: v.url,
-            type: "image"
-          })
-          break;
-        default:
-          files.files.push(v)
-          break;
-      }
-    });
-    this.setData({
-      files
-    })
-  },
-  /* 切换产品 */
-  changeItemno(e) {
-    console.log("切换产品", e.currentTarget.dataset)
-    const {
-      value,
-      valuename
-    } = e.currentTarget.dataset,
-      content = this.data.content;
-    if (!value.flag) return;
-    wx.showLoading({
-      title: '加载中...',
-      mask: true
-    })
-    content[valuename] = (content[valuename] == value.parm) ? "" : value.parm;
-    this.getDetail()
-  },
-  clickBut() {
-    this.data.detail.tradefield.length >= 2 ? wx.showToast({
-      title: '请选择加入产品领域',
-      icon: "none",
-      duration: 3000
-    }) : this.handleStorage(0);
-  },
-  /* 打开文档 */
-  openDocument(e) {
-    const {
-      item
-    } = e.currentTarget.dataset;
-    console.log(item)
-    wx.showLoading({
-      title: '加载中...',
-      mask: true,
-    })
-    wx.downloadFile({
-      url: item.url,
-      success: function (res) {
-        const filePath = res.tempFilePath
-        wx.openDocument({
-          filePath: filePath,
-          showMenu: true,
-          fileType: item.postfix,
-          success: function (res) {
-            wx.hideLoading();
-            console.log('打开文档成功')
-          },
-          fail(e) {
-            console.log(e)
-            wx.showToast({
-              title: '打开失败',
-              icon: "error",
-              mask: true
-            })
-          }
-        })
-      },
-      fail(e) {
-        console.log(e)
-        wx.showToast({
-          title: '打开失败',
-          icon: "error",
-          mask: true
-        })
-      }
-    })
-  },
-  /* 选择领域 */
-  storage(e) {
-    this.handleStorage(e.detail.value)
-  },
-  handleStorage(index) {
-    let detail = this.data.detail;
-    _Http.basic({
-      "id": 20220924095102,
-      "content": {
-        sa_brandid,
-        "itemid": detail.itemid, //货品id
-        "qty": detail.orderminqty, //数量
-        itemno: detail.itemno, //货品编号
-        tradefield: detail.tradefield[index].tradefield
-      },
-    }).then(res => {
-      console.log("加入购物车", res)
-      wx.showToast({
-        title: res.msg == '成功' ? '加入成功' : res.msg,
-        icon: "none"
-      });
-      if (res.msg == '成功') getApp().globalData.getCollectCount()
-    })
-  }
+	data: {
+		badge: getApp().globalData.collectCount,
+		loading: true,
+		content: {
+			sa_itemgroupid: null,
+			spec: "", //规格
+			color: "", //颜色
+			material: "", //材质
+			cheek: "", //边框
+		}
+	},
+	onLoad(options) {
+		let data = JSON.parse(options.params);
+		sa_brandid = data.sa_brandid;
+		if (wx.getStorageSync('userrole') == '业务员') sys_enterpriseid = data.sys_enterpriseid
+		this.data.content.sa_itemgroupid = data.sa_itemgroupid;
+		this.setData({
+			userrole: wx.getStorageSync('userrole')
+		})
+		this.getDetail(true);
+	},
+	/* 获取详情 */
+	getDetail(init = false) {
+		let content = this.data.content;
+		if (sys_enterpriseid) content.sys_enterpriseid = sys_enterpriseid;
+		_Http.basic({
+			"id": "20221223165503",
+			content
+		}).then(res => {
+			wx.hideLoading();
+			console.log("商品详情", res)
+			if (res.msg != '成功') return wx.showToast({
+				title: res.msg,
+				icon: "none"
+			})
+			if (res.data.item.length == 0) return wx.showToast({
+				title: '未查询到商品',
+				icon: "none",
+				mask: true
+			})
+			this.handleFiles(res.data.item[0].attinfos)
+			const CNY = sum => currency(sum, {
+				symbol: "¥",
+				precision: 2
+			}).format();
+			res.data.item[0].gradeprice = CNY(res.data.item[0].gradeprice);
+			res.data.item[0].marketprice = CNY(res.data.item[0].marketprice);
+			this.setData({
+				content,
+				detail: res.data.item[0],
+				specRows: res.data.specRows,
+				cheekRows: res.data.cheekRows,
+				materialRows: res.data.materialRows,
+				colorRows: res.data.colorRows,
+				loading: false
+			});
+		})
+	},
+	/* 预览媒体 */
+	viewMedias(e) {
+		const {
+			index,
+			type
+		} = e.currentTarget.dataset;
+		wx.previewMedia({
+			current: index,
+			sources: type == 'image' ? this.data.files.viewImages : this.data.files.viewVideos,
+		})
+	},
+	/* 处理附件 */
+	handleFiles(arr) {
+		let files = {
+				images: [],
+				viewImages: [],
+				videos: [],
+				viewVideos: [],
+				files: []
+			},
+			list = fileList(arr);
+		list.forEach(v => {
+			switch (v.fileType) {
+				case "video":
+					files.videos.push(v)
+					files.viewVideos.push({
+						url: v.url,
+						type: "video",
+						poster: v.subfiles[0].url
+					})
+					break;
+				case "image":
+					files.images.push(v)
+					files.viewImages.push({
+						url: v.url,
+						type: "image"
+					})
+					break;
+				default:
+					files.files.push(v)
+					break;
+			}
+		});
+		this.setData({
+			files
+		})
+	},
+	/* 切换产品 */
+	changeItemno(e) {
+		console.log("切换产品", e.currentTarget.dataset)
+		const {
+			value,
+			valuename
+		} = e.currentTarget.dataset,
+			content = this.data.content;
+		if (!value.flag) return;
+		wx.showLoading({
+			title: '加载中...',
+			mask: true
+		})
+		content[valuename] = (content[valuename] == value.parm) ? "" : value.parm;
+		this.getDetail()
+	},
+	clickBut() {
+		this.data.detail.tradefield.length >= 2 ? wx.showToast({
+			title: '请选择加入产品领域',
+			icon: "none",
+			duration: 3000
+		}) : this.handleStorage(0);
+	},
+	/* 打开文档 */
+	openDocument(e) {
+		const {
+			item
+		} = e.currentTarget.dataset;
+		console.log(item)
+		wx.showLoading({
+			title: '加载中...',
+			mask: true,
+		})
+		wx.downloadFile({
+			url: item.url,
+			success: function (res) {
+				const filePath = res.tempFilePath
+				wx.openDocument({
+					filePath: filePath,
+					showMenu: true,
+					fileType: item.postfix,
+					success: function (res) {
+						wx.hideLoading();
+						console.log('打开文档成功')
+					},
+					fail(e) {
+						console.log(e)
+						wx.showToast({
+							title: '打开失败',
+							icon: "error",
+							mask: true
+						})
+					}
+				})
+			},
+			fail(e) {
+				console.log(e)
+				wx.showToast({
+					title: '打开失败',
+					icon: "error",
+					mask: true
+				})
+			}
+		})
+	},
+	/* 选择领域 */
+	storage(e) {
+		this.handleStorage(e.detail.value)
+	},
+	handleStorage(index) {
+		let detail = this.data.detail;
+		_Http.basic({
+			"id": 20220924095102,
+			"content": {
+				sa_brandid,
+				"itemid": detail.itemid, //货品id
+				"qty": detail.orderminqty, //数量
+				itemno: detail.itemno, //货品编号
+				tradefield: detail.tradefield[index].tradefield
+			},
+		}).then(res => {
+			console.log("加入购物车", res)
+			wx.showToast({
+				title: res.msg == '成功' ? '加入成功' : res.msg,
+				icon: "none"
+			});
+			if (res.msg == '成功') getApp().globalData.getCollectCount().then(badge => this.setData({
+				badge
+			}))
+		})
+	},
+	/* 前往购物车 */
+	toCollect(e) {
+		getApp().globalData.changeBar({detail:"Collect"})
+		wx.navigateBack();
+	}
 })

+ 95 - 83
packageA/market/detail.wxml

@@ -3,98 +3,110 @@
 <template is="skeleton" wx:if="{{loading}}" />
 <!-- 轮播图 -->
 <swiper indicator-dots circular indicator-active-color='#333'>
-  <swiper-item wx:for="{{files.images}}" wx:key="attachmentid" data-index="{{index}}" data-type='image' bindtap="viewMedias">
-    <van-image width="100vw" height="464rpx" fit="contain" src="{{item.cover}}" use-loading-slot use-error-slot lazy-load>
-      <van-loading slot="loading" type="spinner" size="20" vertical />
-      <text slot="error">加载失败</text>
-    </van-image>
-  </swiper-item>
+	<swiper-item wx:for="{{files.images}}" wx:key="attachmentid" data-index="{{index}}" data-type='image' bindtap="viewMedias">
+		<van-image width="100vw" height="464rpx" fit="contain" src="{{item.cover}}" use-loading-slot use-error-slot lazy-load>
+			<van-loading slot="loading" type="spinner" size="20" vertical />
+			<text slot="error">加载失败</text>
+		</van-image>
+	</swiper-item>
 </swiper>
 <!-- 产品介绍 -->
 <view class="intr">
-  <view class="title">
-    {{detail.itemname}}
-  </view>
-  <view class="tags">
-    <text wx:for="{{detail.brand}}" wx:key="sa_brandid">{{item.brandname}}</text>
-    <text wx:for="{{detail.tradefield}}" wx:key="index">{{item.tradefield}}</text>
-  </view>
-  <view class="offer">
-    <view>
-      <text class="price">{{detail.gradeprice}}</text>
-      <text class="old-price">{{detail.marketprice}}</text>
-    </view>
-    <text class="unit">单位/{{detail.unitname}}</text>
-  </view>
-  <view class="else">
-    <text>起订量:{{detail.orderminqty}}({{detail.unitname}})</text>
-    <text>库存:{{userrole=='经销商'?detail.stockstatus:detail.cansaleqty}}</text>
-  </view>
+	<view class="title">
+		{{detail.itemname}}
+	</view>
+	<view class="tags">
+		<text wx:for="{{detail.brand}}" wx:key="sa_brandid">{{item.brandname}}</text>
+		<text wx:for="{{detail.tradefield}}" wx:key="index">{{item.tradefield}}</text>
+	</view>
+	<view class="offer">
+		<view>
+			<text class="price">{{detail.gradeprice}}</text>
+			<text class="old-price">{{detail.marketprice}}</text>
+		</view>
+		<text class="unit">单位/{{detail.unitname}}</text>
+	</view>
+	<view class="else">
+		<text>起订量:{{detail.orderminqty}}({{detail.unitname}})</text>
+		<text>库存:{{userrole=='经销商'?detail.stockstatus:detail.cansaleqty}}</text>
+	</view>
 </view>
 <!-- 选择规格 -->
 <view class="model">
-  <block wx:if="{{specRows.length}}">
-    <view class="label">
-      规格
-    </view>
-    <view class="product-box">
-      <navigator url="#" class="product {{content.spec===item.parm?'active':''}} {{item.flag?'':'disabled'}}" wx:for="{{specRows}}" wx:key="index" bindtap="changeItemno" data-valuename="spec" data-value="{{item}}">{{item.parm}}</navigator>
-    </view>
-  </block>
+	<block wx:if="{{specRows.length}}">
+		<view class="label">
+			规格
+		</view>
+		<view class="product-box">
+			<navigator url="#" class="product {{content.spec===item.parm?'active':''}} {{item.flag?'':'disabled'}}" wx:for="{{specRows}}" wx:key="index" bindtap="changeItemno" data-valuename="spec" data-value="{{item}}">{{item.parm}}</navigator>
+		</view>
+	</block>
 
-  <block wx:if="{{colorRows.length}}">
-    <view class="label">
-      颜色
-    </view>
-    <view class="product-box">
-      <navigator url="#" class="product {{content.color===item.parm?'active':''}} {{item.flag?'':'disabled'}}" wx:for="{{colorRows}}" wx:key="index" bindtap="changeItemno" data-valuename="color" data-value="{{item}}">{{item.parm}}</navigator>
-    </view>
-  </block>
+	<block wx:if="{{colorRows.length}}">
+		<view class="label">
+			颜色
+		</view>
+		<view class="product-box">
+			<navigator url="#" class="product {{content.color===item.parm?'active':''}} {{item.flag?'':'disabled'}}" wx:for="{{colorRows}}" wx:key="index" bindtap="changeItemno" data-valuename="color" data-value="{{item}}">{{item.parm}}</navigator>
+		</view>
+	</block>
 
-  <block wx:if="{{materialRows.length}}">
-    <view class="label">
-      材质
-    </view>
-    <view class="product-box">
-      <navigator url="#" class="product {{content.material===item.parm?'active':''}} {{item.flag?'':'disabled'}}" wx:for="{{materialRows}}" wx:key="index" bindtap="changeItemno" data-valuename="material" data-value="{{item}}">{{item.parm}}</navigator>
-    </view>
-  </block>
+	<block wx:if="{{materialRows.length}}">
+		<view class="label">
+			材质
+		</view>
+		<view class="product-box">
+			<navigator url="#" class="product {{content.material===item.parm?'active':''}} {{item.flag?'':'disabled'}}" wx:for="{{materialRows}}" wx:key="index" bindtap="changeItemno" data-valuename="material" data-value="{{item}}">{{item.parm}}</navigator>
+		</view>
+	</block>
 
-  <block wx:if="{{cheekRows.length}}">
-    <view class="label">
-      边框
-    </view>
-    <view class="product-box">
-      <navigator url="#" class="product {{content.cheek===item.parm?'active':''}}  {{item.flag?'':'disabled'}}" wx:for="{{cheekRows}}" wx:key="index" bindtap="changeItemno" data-valuename="cheek" data-value="{{item}}">{{item.parm}}</navigator>
-    </view>
-  </block>
+	<block wx:if="{{cheekRows.length}}">
+		<view class="label">
+			边框
+		</view>
+		<view class="product-box">
+			<navigator url="#" class="product {{content.cheek===item.parm?'active':''}}  {{item.flag?'':'disabled'}}" wx:for="{{cheekRows}}" wx:key="index" bindtap="changeItemno" data-valuename="cheek" data-value="{{item}}">{{item.parm}}</navigator>
+		</view>
+	</block>
 </view>
 <van-tabs custom-class='tabs' title-active-color='var(--assist)' color='var(--assist)'>
-  <van-tab title="商品简介">
-    <view class="tab-box">
-      <view class="row">
-        品号:{{detail.itemno}}
-      </view>
-      <view class="row">
-        型号:{{detail.model || ' --'}}
-      </view>
-    </view>
-  </van-tab>
-  <van-tab title="产品资料">
-    <Yl_Empty wx:if="{{detail.technicalinfo.length==0}}" />
-    <view wx:else class="document-box">
-      <navigator class="document" url="#" wx:for="{{detail.technicalinfo}}" wx:key="index" bindtap="openDocument" data-item="{{item}}">{{item.document}}</navigator>
-    </view>
-  </van-tab>
+	<van-tab title="商品简介">
+		<view class="tab-box">
+			<view class="row">
+				品号:{{detail.itemno}}
+			</view>
+			<view class="row">
+				型号:{{detail.model || ' --'}}
+			</view>
+		</view>
+	</van-tab>
+	<van-tab title="产品资料">
+		<Yl_Empty wx:if="{{detail.technicalinfo.length==0}}" />
+		<view wx:else class="document-box">
+			<navigator class="document" url="#" wx:for="{{detail.technicalinfo}}" wx:key="index" bindtap="openDocument" data-item="{{item}}">{{item.document}}</navigator>
+		</view>
+	</van-tab>
 </van-tabs>
-<block wx:if="{{userrole!='业务员'}}">
-  <!-- 底部 -->
-  <view style="height: 150rpx;" />
-  <view class="footer">
-    <picker wx:if="{{detail.tradefield.length>=2}}" range='{{detail.tradefield}}' range-key='tradefield' bindchange='storage'>
-      <van-button custom-class='but' bindtap="clickBut">加入购物车</van-button>
-    </picker>
-    <van-button wx:else custom-class='but' bindtap="clickBut">加入购物车
-    </van-button>
-  </view>
-</block>
+<!-- 底部 -->
+<!-- <view style=" height: 150rpx;" />
+<view class="footer">
+  <picker wx:if="{{detail.tradefield.length>=2}}" range='{{detail.tradefield}}' range-key='tradefield' bindchange='storage'>
+    <van-button custom-class='but' bindtap="clickBut">加入购物车</van-button>
+  </picker>
+  <van-button wx:else custom-class='but' bindtap="clickBut">加入购物车
+  </van-button>
+</view> -->
+
+<view class="cu-bar bg-white tabbar border shop footer">
+	<navigator url="#" class="action" style="height: 100%;display: flex; flex-direction: column; align-items: center;" bindtap="toCollect">
+		<view class="cuIcon-cart">
+			<view class="cu-tag badge">{{badge}}</view>
+		</view>
+		购物车
+	</navigator>
+
+	<picker wx:if="{{detail.tradefield.length>=2}}" range='{{detail.tradefield}}' range-key='tradefield' bindchange='storage'>
+		<view class="bg-orange submit" bindtap="clickBut">加入购物车</view>
+	</picker>
+	<view wx:else class="bg-orange submit" bindtap="clickBut">加入购物车</view>
+</view>