Преглед изворни кода

促销活动创建方式修改

xiaohaizhao пре 2 година
родитељ
комит
2f66df5d24

+ 45 - 5
packageA/activity/detail.js

@@ -173,6 +173,27 @@ Page({
 	},
 	/* 去下单 */
 	clickBut() {
+		wx.navigateTo({
+			url: '/packageA/activity/selectProduct/index?params=' + JSON.stringify({
+				"id": 20230116094803,
+				"version": 1,
+				"content": {
+					nocache: true,
+					sa_promotionid: this.data.sa_promotionid,
+					sa_promotion_itemgroupid: this.data.active,
+					"where": {
+						"condition": ""
+					}
+				}
+			}),
+		});
+		getApp().globalData.handleSelect = this.creadedOrderForm.bind(this);
+	},
+
+	creadedOrderForm({
+		list
+	}) {
+		console.log(list)
 		let that = this;
 		wx.showModal({
 			title: '提示',
@@ -191,6 +212,7 @@ Page({
 						"sa_brandid": that.data.detail.sa_brandid, //品牌ID
 						"type": "促销订单", //订单类型
 						"tradefield": that.data.detail.tradefield, //必选
+
 					}
 				}).then(res => {
 					console.log("创建促销订单", res);
@@ -198,11 +220,29 @@ Page({
 						title: res.msg != '成功' ? res.msg : '创建成功',
 						icon: "none"
 					});
-					if (res.msg == '成功') setTimeout(() => {
-						wx.navigateTo({
-							url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
-						});
-					}, 500)
+					/* 绑定产品 */
+					_Http.basic({
+						"id": 20221109093602,
+						"content": {
+							"sa_orderid": res.data.sa_orderid,
+							"sa_contractid": res.data.sa_contractid,
+							"sys_enterpriseid": res.data.sys_enterpriseid,
+							"type": "促销订单",
+							"items": list.map(v => {
+								return {
+									"sa_orderitemsid": 0,
+									"itemid": v.itemid,
+									"qty": v.qty
+								}
+							})
+						}
+					}).then(s => {
+						if (s.msg == '成功') setTimeout(() => {
+							wx.redirectTo({
+								url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
+							});
+						}, 500)
+					})
 				})
 			}
 		})

+ 1 - 0
packageA/activity/index.wxml

@@ -5,6 +5,7 @@
 <!-- 产品列表 -->
 <view class="division" />
 <Yl_ListBox id='ListBox' bind:getlist='getList'>
+	<view style="height: 10rpx;" />
 	<List list="{{list}}" />
 </Yl_ListBox>
 <!-- 筛选条件 -->

+ 185 - 0
packageA/activity/selectProduct/index.js

@@ -0,0 +1,185 @@
+import currency from "../../../utils/currency";
+const _Http = getApp().globalData.http,
+  file = require("../../../utils/FormatTheAttachment");
+Page({
+  data: {
+    loading: true,
+    params: {}, //请求体
+    result: [], //返回结果
+    idname: "itemid", //idkey
+    showName: "itemname",
+    newPrice: "price",
+    oldPrice: "oldprice",
+  },
+  onLoad(options) {
+    if (options.params) {
+      let params = JSON.parse(options.params);
+      if (!params.content.pageNumber || !params.content.pageTotal) {
+        params.content.pageNumber = 1;
+        params.content.pageTotal = 1;
+      }
+      this.setData({
+        params
+      });
+    };
+    this.setData({
+      idname: options.idname || this.data.idname
+    });
+    this.getList()
+  },
+  getList(init = false) {
+    //init 用于初始化分页
+    if (init.detail != undefined) init = init.detail;
+    let params = this.data.params;
+    if (init) params.content.pageNumber = 1
+    if (params.content.pageNumber > params.content.pageTotal) return;
+    _Http.basic(params).then(res => {
+      console.log("选择产品列表", res)
+      this.selectComponent('#ListBox').RefreshToComplete();
+      if (res.msg != '成功') return wx.showToast({
+        title: res.msg,
+        icon: "none"
+      })
+      const CNY = num => currency(num, {
+        symbol: "¥",
+        precision: 2
+      }).format();
+      let newPrice = this.data.newPrice,
+        oldPrice = this.data.oldPrice;
+      res.data = res.data.map(value => {
+        if (value.attinfos.length != 0) {
+          value.attinfos = file.fileList(value.attinfos)
+          let image = value.attinfos.find(v => v.fileType == "image");
+          value.cover = image ? image.cover : "";
+        }
+        if (newPrice) value.newPrice = CNY(value[newPrice] || 0);
+        if (oldPrice) value.oldPrice = CNY(value[oldPrice] || 0);
+        value.qty = value.orderminqty;
+        return value;
+      })
+      this.setData({
+        'params.content.pageNumber': res.pageNumber + 1,
+        'params.content.pageTotal': res.pageTotal,
+        'params.content.total': res.total,
+        list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
+        loading: false
+      })
+    })
+  },
+  /* 选中 */
+  changeResult(e) {
+    if (e.target.dataset.iscatch) return;
+    let {
+      id
+    } = e.currentTarget.dataset, result = this.data.result;
+    console.log(e)
+    result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
+    this.setData({
+      result
+    });
+  },
+  /* 提交 */
+  submit() {
+    let result = this.data.result,
+      obj = {
+        result,
+        list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
+        value: [result.map(v => {
+          let data = this.data.list.find(value => value[this.data.idname] == v);
+          return data ? data[this.data.showName] : ""
+        }), result]
+      }
+    getApp().globalData.handleSelect && getApp().globalData.handleSelect(obj)
+  },
+  /* 预览图片 */
+  viewImage(e) {
+    const {
+      file
+    } = e.currentTarget.dataset;
+    if (file.length) wx.previewMedia({
+      sources: file.filter(value => ['image', 'vadio'].includes(value.fileType)).map(v => {
+        return {
+          url: v.url,
+          type: v.fileType
+        }
+      }),
+      current: 0,
+      showmenu: true
+    })
+  },
+  /* 开始搜索 */
+  startSearch({
+    detail
+  }) {
+    let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
+    if (detail == condition) return;
+    this.setData({
+      'content.where.condition': detail,
+      'params.content.where.condition': detail
+    });
+    this.getList(true);
+  },
+  /* 取消搜索 */
+  onClear() {
+    this.setData({
+      'content.where.condition': "",
+      'params.content.where.condition': ""
+    });
+    this.getList(true);
+  },
+  onReady() {
+    this.selectComponent("#ListBox").setHeight(".total", this);
+  },
+  /* 步进器输入框失去焦点 */
+  inputBlur(e) {
+    const {
+      index
+    } = e.currentTarget.dataset;
+    let item = this.data.list[index];
+    let qty = 0;
+    if (item.orderminqty > e.detail.value) {
+      wx.showToast({
+        title: '输入数量低于最低起订量!',
+        icon: "none"
+      })
+      qty = item.orderminqty;
+    } else if (item.orderminqty < e.detail.value) {
+      var currencyRounding = value => currency(value, {
+        increment: item.orderaddqty
+      });
+      qty = currency(currencyRounding(currency(e.detail.value).subtract(item.orderminqty)).format()).add(item.orderminqty).value;
+
+    } else {
+      qty = e.detail.value;
+    }
+    this.setData({
+      [`list[${index}].qty`]: 0
+    });
+    this.setData({
+      [`list[${index}].qty`]: qty
+    });
+  },
+  stepperChange(e) {
+    const {
+      index
+    } = e.currentTarget.dataset;
+    let item = this.data.list[index];
+    console.log(item)
+    console.log(item.qty)
+    console.log(item.orderaddqty)
+    if (e.type == 'plus') {
+      item.qty += (item.orderaddqty) - 0
+    } else {
+      item.qty -= item.orderaddqty
+    }
+    console.log(item.qty)
+    this.setData({
+      [`list[${index}]`]: item
+    })
+  },
+  onUnload() {
+    //回收数据
+    getApp().globalData.handleSelect = null;
+
+  }
+})

+ 6 - 0
packageA/activity/selectProduct/index.json

@@ -0,0 +1,6 @@
+{
+  "usingComponents": {
+    "van-checkbox": "@vant/weapp/checkbox/index",
+    "van-stepper": "@vant/weapp/stepper/index"
+  }
+}

+ 135 - 0
packageA/activity/selectProduct/index.scss

@@ -0,0 +1,135 @@
+page {
+	height: 100vh;
+	overflow: hidden;
+}
+
+.total {
+	height: 60rpx;
+	line-height: 60rpx;
+	font-size: 24rpx;
+	font-family: PingFang SC-Regular, PingFang SC;
+	color: #666666;
+	padding-left: 30rpx;
+}
+
+.item-box {
+	position: relative;
+	width: 100vw;
+	background-color: #fff;
+	margin-bottom: 20rpx;
+	padding-bottom: 20rpx;
+	box-sizing: border-box;
+
+	.top {
+		display: flex;
+		padding: 20rpx 30rpx 10rpx;
+		box-sizing: border-box;
+
+
+		.image {
+			width: 128rpx;
+			height: 128rpx;
+			border-radius: 16rpx;
+			overflow: hidden;
+			margin-right: 20rpx;
+			flex-shrink: 0;
+		}
+
+		.content {
+			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;
+					right: 0;
+					top: 20rpx;
+					flex-shrink: 0;
+				}
+			}
+
+			.exp {
+				line-height: 34rpx;
+				font-size: 24rpx;
+				font-family: PingFang SC-Regular, PingFang SC;
+				color: #999999;
+				margin-top: 8rpx;
+			}
+
+		}
+
+	}
+
+	.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;
+
+			.label-class {
+				font-size: 24rpx;
+				font-family: PingFang SC-Regular, PingFang SC;
+				color: #999999;
+				margin-left: -6rpx;
+			}
+		}
+
+		.input-class {
+			width: 120rpx;
+		}
+	}
+}
+
+.footer {
+	width: 100vw;
+	min-height: 130rpx;
+	position: fixed;
+	bottom: 0;
+	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;
+		font-size: 28rpx;
+		line-height: 106rpx;
+	}
+
+	.but {
+		width: 230rpx;
+		height: 90rpx;
+		background: #3874F6;
+		border-radius: 16rpx;
+		font-size: 28rpx;
+		font-weight: 600;
+		color: #FFFFFF;
+		margin-top: 10rpx;
+	}
+}

+ 60 - 0
packageA/activity/selectProduct/index.wxml

@@ -0,0 +1,60 @@
+<van-search class="search" value="{{ params.content.where.condition }}" shape="round" placeholder="请输入搜索关键词" bind:search='startSearch' bind:clear='onClear' />
+<view class="total">共{{params.content.total}}个</view>
+
+<Yl_ListBox id='ListBox' bind:getlist='getList'>
+	<navigator url="#" wx:for="{{list}}" wx:key="itemid" class="item-box" data-id="{{item[idname]}}" bindtap="changeResult">
+
+		<view class="top" bindtap="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 custom-class="iconfont" shape='square' icon-size='24rpx' value="{{ decide.checked(item.itemid,result) }}" />
+				</view>
+				<view class="exp">编号:{{item.itemno}}</view>
+				<view class="exp">规格:{{item.spec ||" --"}}</view>
+				<view class="exp">型号:{{item.model ||" --"}}</view>
+				<view class="exp"><text style="font-size: 24rpx;font-weight: 600;color: #FF3B30;">{{item.newPrice}}</text><text style="font-size: 20rpx; text-decoration:line-through; margin-left: 6rpx;">¥{{item.oldprice}}</text></view>
+			</view>
+		</view>
+		<view class="bottom">
+			<view class="check" bindtap="changeResults" data-item="{{item}}">
+				<view class="label-class">
+					起订量:{{item.orderminqty}},增减量:{{item.orderaddqty}}
+				</view>
+			</view>
+			<van-stepper value="{{ item.qty }}" min="{{item.orderminqty}}" step="{{item.orderaddqty}}" input-class='input-class' data-index="{{index}}" data-iscatch="catch" catch:minus='stepperChange' catch:plus='stepperChange' catch:blur='inputBlur' />
+		</view>
+	</navigator>
+
+	<Yl_Empty wx:if="{{list.length==0}}" />
+</Yl_ListBox>
+
+<!-- 底部 -->
+<view style="height: 130rpx;" />
+<view class="footer">
+	<view class="left">
+		已选{{result.length}}个
+	</view>
+	<van-button custom-class='but' disabled='{{!result.length}}' bind:click="submit">生成订单</van-button>
+</view>
+
+<wxs module="decide">
+	module.exports = {
+		checked: function (id, list) {
+			return list.some(function (v) {
+				return v == id
+			});
+		}
+	}
+</wxs>
+<wxs module="gap">
+	module.exports.price = function (figure, defaultamount) {
+		return (figure - defaultamount).toFixed(2)
+	}
+</wxs>