Browse Source

收藏夹

xiaohaizhao 1 year ago
parent
commit
22426a61fb

+ 2 - 1
app.json

@@ -54,7 +54,8 @@
         "dispatchBill/rows",
         "dispatchBill/sentandback",
         "activity/selectProduct/cart/index",
-        "target/index"
+        "target/index",
+        "favorites/index"
       ]
     },
     {

+ 344 - 0
packageA/favorites/index.js

@@ -0,0 +1,344 @@
+const _Http = getApp().globalData.http,
+  currency = require("../../utils/currency"),
+  CNY = sum => currency(sum, {
+    symbol: "¥",
+    precision: 2
+  }).format();
+let downCount = {};
+Page({
+  data: {
+    list: [],
+    results: [], //选中结果
+    classList: [], //生成订单时所选
+    sum: 0, //价格合
+    hidePrice: wx.getStorageSync('hidePrice')
+  },
+  onLoad() {
+    this.getList()
+  },
+  /* 打开设置定制项 */
+  customization(e) {
+    const {
+      item
+    } = e.target.dataset;
+    if (item) this.selectComponent("#Custom").onClick(item)
+  },
+  onShow() {
+    //修改定制项产品
+    getApp().globalData.customizedProduct = item => {
+      return new Promise((resolve) => {
+        _Http.basic({
+          "id": 20231121143403,
+          "content": {
+            "itemid": item.itemid,
+            "sa_favoritesid": item.sa_favoritesid,
+            "favoritesqty": item.favoritesqty,
+            "qty": item.favoritesqty,
+            "width": item.width || 0,
+            "length": item.length || 0,
+            "iscollection": true
+          },
+        }).then(res => {
+          console.log("修改定制", res)
+          wx.showToast({
+            title: res.msg != '成功' ? res.msg : '修改成功',
+            icon: "none"
+          });
+          this.getList()
+          resolve(true)
+        })
+      })
+    }
+  },
+  /* 获取列表 */
+  getList() {
+    _Http.basic({
+      "id": 20231121145103,
+      "content": {
+        nocache: true,
+        istool: 0,
+        "pageNumber": 1,
+        "pageSize": getApp().globalData.favoriteCount + 5,
+        "where": {
+          "condition": ""
+        }
+      }
+    }).then(res => {
+      console.log('收藏夹列表', res)
+      this.selectComponent('#ListBox').RefreshToComplete();
+      this.selectComponent("#ListBox").setHeight(".head", this);
+      if (res.msg != '成功') return wx.showToast({
+        title: res.msg,
+        icon: "none"
+      })
+      this.setData({
+        list: res.data.map(v => {
+          v.showPrice = CNY(v.gradeprice)
+          return v
+        })
+      });
+      if (wx.getStorageSync('favorites')) {
+        this.setData({
+          ...wx.getStorageSync('favorites')
+        });
+        this.computeSum();
+      }
+    })
+  },
+  /* 选中单品 */
+  clickBut(e) {
+    this.data.classList.length >= 2 ? wx.showToast({
+      title: '请选择订单领域(订单只允许同领域的商品)',
+      icon: "none",
+      duration: 3000
+    }) : this[e.target.id](0);
+  },
+  /* 是否选择全部 */
+  setIsAll() {
+    let isAll = this.data.isAll;
+    this.setData({
+      results: isAll ? [] : this.data.list.map(v => v.sa_favoritesid),
+      isAll: !isAll
+    })
+    this.computeSum();
+  },
+  /* 计算总价/产品领域分类 */
+  computeSum() {
+    let results = this.data.results,
+      sum = 0,
+      classList = [];
+    if (results.length) results = results.filter(v => {
+      let item = this.data.list.find(va => va.sa_favoritesid == v);
+      if (item) {
+        sum = currency(sum).add(currency(item.favoritesqty).multiply(item.gradeprice)).value;
+        /* 领域分类 */
+        let index = classList.findIndex(value => value.type == item.tradefield[0].tradefield);
+        if (index == -1) {
+          classList.push({
+            type: item.tradefield[0].tradefield,
+            list: [item],
+            name: item.tradefield[0].tradefield + "(1件商品)"
+          })
+        } else {
+          classList[index].list.push(item)
+          classList[index].name = classList[index].type + `(${classList[index].list.length}件商品)`
+        }
+      };
+      return item
+    });
+    wx.setStorageSync('shopping', {
+      results
+    })
+    console.log("计算价格results", results)
+    this.setData({
+      sum: CNY(sum),
+      isAll: results.length == this.data.list.length,
+      results,
+      classList
+    });
+  },
+  /* 提交 */
+  submit(e) {
+    this[e.target.id](e.detail.value)
+  },
+  /* 处理生成订单 */
+  handleSubmit(index) {
+    let data = this.data.classList[index];
+    wx.showLoading({
+      title: '生成中...',
+    })
+    _Http.basic({
+      "id": 20221128183202,
+      "content": {
+        istool: 0,
+        type: "标准订单",
+        "tradefield": data.type, //必选
+        "items": data.list.map(v => {
+          return {
+            "sa_orderitemsid": 0,
+            "itemid": v.itemid,
+            "qty": v.favoritesqty,
+            width: v.width || 0,
+            length: v.length || 0,
+          }
+        })
+      }
+    }).then(res => {
+      wx.hideLoading()
+      console.log("转化订单", res)
+      if (res.msg != '成功') return wx.showToast({
+        title: res.msg,
+        icon: "none"
+      });
+      this.setData({
+        results: [],
+        isAll: false
+      })
+      wx.showModal({
+        title: '提示',
+        content: '生成成功!是否立即前往',
+        complete: (s) => {
+          if (s.confirm) wx.navigateTo({
+            url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
+          })
+        }
+      });
+    })
+  },
+  addToShoppingCart(index) {
+    let data = this.data.classList[index];
+    wx.showLoading({
+      title: '处理中...',
+    })
+    _Http.basic({
+      "id": 20231024110003,
+      "content": {
+        "items": data.list.map(v => {
+          return {
+            "sa_brandid": v.brand.length ? v.brand[0].sa_brandid : 0,
+            "itemid": v.itemid,
+            "qty": v.favoritesqty,
+            "itemno": v.itemno,
+            "tradefield": data.type,
+            "length": v.length || 0,
+            "width": v.width || 0
+          }
+        })
+      }
+    }).then(res => {
+      wx.hideLoading()
+      console.log("加入购物车", res)
+      wx.showToast({
+        title: res.msg != '成功' ? res.msg : "加入成功",
+        icon: "none"
+      });
+      if (res.msg != '成功') return;
+      this.setData({
+        results: [],
+        isAll: false
+      })
+    })
+  },
+  /* 切换选中项 */
+  changeResults(e, my = false) {
+    const {
+      item
+    } = my ? e : e.currentTarget.dataset;
+    let results = this.data.results,
+      sa_brandid = this.data.sa_brandid;
+    if (sa_brandid && sa_brandid != item.sa_brandid) return;
+    if (results.length == 0) {
+      results.push(item.sa_favoritesid);
+      sa_brandid = item.sa_brandid;
+    } else {
+      let index = results.findIndex(v => v == item.sa_favoritesid)
+      if (index == -1) {
+        results.push(item.sa_favoritesid);
+      } else {
+        results.splice(index, 1);
+        if (results.length == 0) sa_brandid = null;
+      }
+    };
+    this.setData({
+      results,
+      sa_brandid
+    })
+    this.computeSum();
+  },
+  /* 删除产品 */
+  deteleItem(e) {
+    const {
+      item
+    } = e.currentTarget.dataset;
+    wx.showModal({
+      title: '提示',
+      content: `是否确认删除${item.itemname}?`,
+      complete: ({
+        confirm
+      }) => {
+        e.detail.instance.close();
+        if (confirm) _Http.basic({
+          "id": 20231121143403,
+          "content": {
+            "itemid": item.itemid,
+            "iscollection": false
+          }
+        }).then(res => {
+          wx.showToast({
+            title: res.msg != '成功' ? res.msg : "删除成功",
+            icon: "none"
+          });
+          if (res.msg != '成功') return;
+          this.getList(true)
+          getApp().globalData.getFavoriteCount()
+        })
+      }
+    })
+  },
+  /* 输入框失去焦点调整数量 */
+  inputBlur(e) {
+    const {
+      index
+    } = e.currentTarget.dataset;
+    let item = this.data.list[index];
+    let favoritesqty = 0;
+    if (item.orderminqty > e.detail.value) {
+      wx.showToast({
+        title: '输入数量低于最低起订量!',
+        icon: "none"
+      })
+      favoritesqty = item.orderminqty;
+    } else if (item.orderminqty < e.detail.value) {
+      var currencyRounding = value => currency(value, {
+        increment: item.orderaddqty
+      });
+      favoritesqty = currency(currencyRounding(currency(e.detail.value).subtract(item.orderminqty)).format()).add(item.orderminqty).value;
+
+    } else {
+      favoritesqty = e.detail.value;
+    }
+    this.setData({
+      [`list[${index}].favoritesqty`]: 0
+    });
+    this.setData({
+      [`list[${index}].favoritesqty`]: favoritesqty
+    });
+    this.handleChangeQty(item, index)
+  },
+  /* 步进器调整数量 */
+  stepperChange(e) {
+    const {
+      index
+    } = e.currentTarget.dataset;
+    let item = this.data.list[index];
+    if (e.type == 'plus') {
+      item.favoritesqty += item.orderaddqty
+    } else {
+      item.favoritesqty -= item.orderaddqty
+    }
+    this.setData({
+      [`list[${index}]`]: item
+    })
+    this.handleChangeQty(item, index)
+  },
+  handleChangeQty(item, index) {
+    this.computeSum();
+    clearTimeout(downCount['count' + index])
+    downCount['count' + index] = setTimeout(() => {
+      _Http.basic({
+        "id": 20231121143403,
+        "content": {
+          "sa_favoritesid": item.sa_favoritesid,
+          "itemid": item.itemid,
+          "favoritesqty": item.favoritesqty,
+          "qty": item.favoritesqty,
+          "width": item.width || 0,
+          "length": item.length || 0,
+          "iscollection": true
+        },
+      }, false).then(res => {
+        console.log("修改数量", res)
+      })
+    }, 1000)
+  }
+})

+ 9 - 0
packageA/favorites/index.json

@@ -0,0 +1,9 @@
+{
+  "component": true,
+  "usingComponents": {
+    "van-checkbox": "@vant/weapp/checkbox/index",
+    "van-stepper": "@vant/weapp/stepper/index",
+    "van-swipe-cell": "@vant/weapp/swipe-cell/index",
+    "custom": "../../pages/index/collect/modules/custom"
+  }
+}

+ 180 - 0
packageA/favorites/index.scss

@@ -0,0 +1,180 @@
+.item-box {
+	position: relative;
+	width: 100vw;
+	background-color: #fff;
+	margin-bottom: 20rpx;
+	padding-bottom: 16rpx;
+	box-sizing: border-box;
+
+	.top {
+		display: flex;
+		padding: 20rpx 30rpx 0rpx;
+		box-sizing: border-box;
+
+
+		.image {
+			width: 128rpx;
+			height: 128rpx;
+			border-radius: 16rpx;
+			overflow: hidden;
+			margin-right: 20rpx;
+			flex-shrink: 0;
+		}
+
+		.content {
+			position: relative;
+			flex: 1;
+
+			.title {
+				display: flex;
+				align-items: center;
+				justify-content: space-between;
+				height: 40rpx;
+
+				.line-1 {
+					display: block;
+					width: 500rpx;
+					font-size: 28rpx;
+					font-family: PingFang SC-Semibold, PingFang SC;
+					font-weight: 600;
+					color: #333333;
+				}
+
+				.iconfont {
+					position: absolute;
+					width: 60rpx;
+					height: 60rpx;
+					line-height: 60rpx;
+					right: 0;
+					flex-shrink: 0;
+				}
+			}
+
+			.exp {
+				line-height: 34rpx;
+				font-size: 24rpx;
+				font-family: PingFang SC-Regular, PingFang SC;
+				color: #999999;
+				margin-top: 8rpx;
+			}
+
+			.price {
+				position: absolute;
+				font-size: 28rpx;
+				font-weight: 600;
+				color: #FF3B30;
+				right: 10rpx;
+			}
+		}
+
+	}
+
+	.bottom {
+		display: flex;
+		justify-content: space-between;
+		align-items: center;
+		height: 58rpx;
+		padding: 0 30rpx;
+		box-sizing: border-box;
+		margin-top: 12rpx;
+
+		.check {
+			display: flex;
+			align-items: center;
+			height: 100%;
+			width: 380rpx;
+			font-size: 24rpx;
+			font-family: PingFang SC-Regular, PingFang SC;
+			color: #999999;
+		}
+
+		.input-class {
+			width: 120rpx;
+		}
+	}
+}
+
+.cell-right {
+	background-color: #E54D42;
+	display: flex;
+	align-items: center;
+	justify-content: center;
+	color: #fff;
+	font-weight: 700;
+	font-size: 28rpx;
+	width: 65px;
+	height: 100%;
+}
+
+.footer-box {
+	position: fixed;
+	bottom: 0;
+	padding: 0;
+	z-index: 99;
+
+	.footer {
+		width: 100vw;
+		min-height: 130rpx;
+		z-index: 999;
+		display: flex;
+		justify-content: space-between;
+		padding: 0 30rpx;
+		box-sizing: border-box;
+		background-color: #fff;
+		box-shadow: rgba(0, 0, 0, 0.15) 0px 5rpx 15rpx 0px;
+
+
+		.left {
+			flex: 1;
+			color: #333333;
+
+			.selected {
+				font-size: 24rpx;
+				color: #999;
+			}
+
+			.sum {
+				height: 40rpx;
+				line-height: 40rpx;
+				font-size: 28rpx;
+				font-family: PingFang SC-Medium, PingFang SC;
+				font-weight: 500;
+				margin-top: 10rpx;
+
+				text {
+					color: #FF3B30;
+				}
+			}
+
+			.transport {
+				height: 34rpx;
+				line-height: 34rpx;
+				font-size: 24rpx;
+				font-family: PingFang SC-Regular, PingFang SC;
+				margin-top: 8rpx;
+
+				text {
+					color: #FF3B30;
+				}
+			}
+		}
+
+		.but {
+			width: 200rpx;
+			height: 90rpx;
+			background: #3874F6;
+			border-radius: 0 16rpx 16rpx 0;
+			font-size: 28rpx;
+			font-weight: 600;
+			color: #FFFFFF;
+			margin-top: 10rpx;
+
+		}
+
+		.shopping {
+			background: #FA8C16 !important;
+			border-radius: 16rpx 0 0 16rpx;
+		}
+	}
+
+}

+ 74 - 0
packageA/favorites/index.wxml

@@ -0,0 +1,74 @@
+<view class="head" />
+<custom id="Custom" />
+<Yl_ListBox id='ListBox' bind:getlist='getList'>
+	<van-swipe-cell wx:for="{{list}}" wx:key="itemid" id="swipe-cell" right-width="{{ 65 }}" async-close data-item="{{item}}" bind:close="deteleItem">
+		<view url="#" class="item-box">
+			<view class="top" catch:tap="changeResults" data-item="{{item}}">
+				<view class="image">
+					<van-image width="100%" height="100%" fit="cover" src="{{item.attinfos[0].subfiles[0].url||item.attinfos[0].url||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>
+				</view>
+				<view class="content">
+					<view class="title">
+						<text class="line-1">{{item.itemname}}</text>
+						<van-checkbox shape='square' icon-size='24rpx' value="{{ decide.checked(item.sa_favoritesid,results) }}" />
+					</view>
+					<view class="exp">编号:{{item.itemno}}</view>
+					<view class="exp">型号:{{item.model ||" --"}}</view>
+					<view class="exp">品牌:{{item.brandname ||" --"}}</view>
+					<view class="exp">领域:{{item.tradefield_shoppingcart ||" --"}}</view>
+					<view class="exp" wx:if="{{item.iscustomsize}}" data-item="{{item}}" catch:tap="customization" style="color:#085CDF;">
+						长:{{item.favoriteslength}} / 宽:{{item.favoriteswidth}}
+						<van-icon name="arrow-down" />
+					</view>
+					<view class="price" style="bottom: {{item.iscustomsize?'40rpx':'0rpx'}};">{{handleHide.query(item.showPrice,hidePrice)}}/{{item.unitname}}</view>
+				</view>
+			</view>
+			<view class="bottom">
+				<view class="check label-class">
+					起订量:{{item.orderminqty}},增减量:{{item.orderaddqty}}
+				</view>
+				<van-stepper value="{{ item.favoritesqty }}" min="{{item.orderminqty}}" step="{{item.orderaddqty||1}}" input-class='input-class' data-index="{{index}}" bind:minus='stepperChange' bind:plus='stepperChange' bind:blur='inputBlur' />
+			</view>
+		</view>
+		<view slot="right" class="cell-right">移 除</view>
+	</van-swipe-cell>
+	<Yl_Empty wx:if="{{list.length === 0}}" />
+	<view style="height: 120rpx;" />
+</Yl_ListBox>
+<view class="footer-box">
+	<view class="footer">
+		<view class="left">
+			<view style="margin-top: 8rpx;">
+				<van-checkbox icon-size="26rpx" shape='square' value="{{ isAll }}" bind:change="setIsAll">全选 <text class="selected">已选{{results.length}}件</text></van-checkbox>
+			</view>
+			<view class="sum">
+				合计:<text>{{handleHide.query(sum,hidePrice)}}</text>
+			</view>
+			<view class="transport">
+				{{logistics}}
+			</view>
+		</view>
+		<picker wx:if="{{classList.length>=2}}" id='addToShoppingCart' range='{{classList}}' range-key='name' disabled='{{!results.length}}' bindchange="submit">
+			<van-button custom-class='but shopping' id='addToShoppingCart' disabled='{{!results.length}}' bind:click="clickBut">加入购物车</van-button>
+		</picker>
+		<van-button wx:else custom-class='but shopping' id='addToShoppingCart' disabled='{{!results.length}}' bind:click="clickBut">加入购物车</van-button>
+
+		<picker wx:if="{{classList.length>=2}}" id='handleSubmit' range='{{classList}}' range-key='name' disabled='{{!results.length}}' bindchange="submit">
+			<van-button custom-class='but' disabled='{{!results.length}}' id='handleSubmit' bind:click="clickBut">生成订单</van-button>
+		</picker>
+		<van-button wx:else custom-class='but' id='handleSubmit' disabled='{{!results.length}}' bind:click="clickBut">生成订单</van-button>
+	</view>
+</view>
+<wxs module="decide">
+	module.exports = {
+		checked: function (id, list) {
+			return list.some(function (v) {
+				return v == id
+			});
+		}
+	}
+</wxs>
+<wxs src="/utils/hidePrice.wxs" module="handleHide" />

+ 17 - 1
packageA/market/detail.js

@@ -301,11 +301,27 @@ Page({
 	},
 	/* 加入收藏夹 */
 	addToFavorites() {
-		let iscollection = this.data.detail.iscollection == 1 ? false : true
+		let detail = this.data.detail,
+			content = this.data.content,
+			iscollection = this.data.detail.iscollection == 1 ? false : true
+
+		if (iscollection && detail.iscustomsize == 1) {
+			if (detail.widthschemeid != 0 && content.dwidth == 0) return wx.showToast({
+				title: '请完成定制宽选项',
+				icon: "none"
+			})
+			if (detail.lengthschemeid != 0 && content.dlength == 0) return wx.showToast({
+				title: '请完成定制长选项',
+				icon: "none"
+			})
+		}
 		_Http.basic({
 			"id": 20231121143403,
 			"content": {
 				"itemid": this.data.detail.itemid, //货品id
+				"qty": detail.orderminqty, //数量
+				width: content.dwidth || 0,
+				length: content.dlength || 0,
 				iscollection
 			},
 		}).then(res => {

+ 1 - 1
packageA/market/detail.wxml

@@ -153,7 +153,7 @@
         </view>
         购物车
     </navigator>
-    <navigator url="#" class="action" style="height: 100%;display: flex; flex-direction: column; align-items: center;" bindtap="toCollect">
+    <navigator url="/packageA/favorites/index" class="action" style="height: 100%;display: flex; flex-direction: column; align-items: center;">
         <view class="{{detail.iscollection?'cuIcon-favorfill':'cuIcon-favor'}}" style="color:{{detail.iscollection?'#FADB14':''}}">
             <view class="cu-tag badge">{{favoriteCount}}</view>
         </view>