shish пре 2 месеци
родитељ
комит
56e4a3f8ce
2 измењених фајлова са 357 додато и 61 уклоњено
  1. 2 2
      hdApp/src/admin/home/mall.vue
  2. 355 59
      hdApp/src/admin/tools/calculator.vue

+ 2 - 2
hdApp/src/admin/home/mall.vue

@@ -177,11 +177,11 @@
             <view class="header-title">⚙️ 更多功能</view>
           </view>
           <view class="icon-grid">
-            <view class="icon-item" @click="goPage({url: '/admin/order/expend'})">
+            <view class="icon-item" @click="goPage({url: '/admin/tools/calculator'})">
               <view class="icon-wrapper">
                 <view class="icon-emoji">💰</view>
               </view>
-              <view class="icon-text">支出</view>
+              <view class="icon-text">计算器</view>
             </view>
             <view class="icon-item" @click="goPage({url: '/admin/staff/list'})">
               <view class="icon-wrapper">

+ 355 - 59
hdApp/src/admin/tools/calculator.vue

@@ -45,6 +45,13 @@
 						<text class="customer-strip-action">修改客户</text>
 					</view>
 
+					<view v-if="showBalanceRow" class="balance-strip">
+						<text class="balance-strip-label">余额</text>
+						<text class="balance-strip-val">¥{{ formatMoney(customInfo.balance) }}</text>
+						<text v-if="balanceCoversDue && selHasPay === 4" class="balance-strip-hint balance-strip-hint-ok">余额充足</text>
+						<text v-else-if="balanceCoversDue && selHasPay !== 4" class="balance-strip-hint balance-strip-hint-tip">可选用「余额」收款</text>
+					</view>
+
 					<view class="rcv-pay-block">
 						<view class="rcv-pay-title">收款方式</view>
 						<view class="rcv-item-row">
@@ -59,8 +66,17 @@
 								{{ item.name }}
 							</view>
 						</view>
+						<view v-if="selHasPay === 0" class="rcv-pay-hint">
+							<text class="rcv-pay-hint-text">扫码付款、分享小程序付款请选扫码(与开单确认页一致)</text>
+						</view>
+						<view v-if="selHasPay === 2" class="rcv-pay-hint">
+							<text class="rcv-pay-hint-text">客户赊账欠款请选挂账</text>
+						</view>
+						<view v-if="selHasPay === 4" class="rcv-pay-hint">
+							<text class="rcv-pay-hint-text">使用客户余额扣款(与开单确认页一致)</text>
+						</view>
 						<view v-if="selHasPay === 1" class="rcv-sub-block">
-							<view class="rcv-pay-title rcv-pay-title-sub">线下方式</view>
+							<view class="rcv-pay-title rcv-pay-title-sub">线下渠道</view>
 							<view class="rcv-item-row">
 								<view
 									v-for="item in optPayWayList"
@@ -231,18 +247,48 @@
 				</scroll-view>
 			</view>
 		</uni-popup>
+
+		<uni-popup ref="cashShortPopup" type="center" background-color="#ffffff" @change="onCashShortPopupChange">
+			<view class="mob-popup-wrap mob-popup-cash-short">
+				<view class="mob-popup-hd">
+					<text class="mob-popup-title">现金不足</text>
+				</view>
+				<text class="cash-short-desc">实收现金少于应收,可改为线下微信或线下支付宝收款后继续提交(与开单确认页线下渠道一致)。</text>
+				<view class="cash-short-way-row">
+					<view
+						class="cash-short-way-chip"
+						:class="{ 'cash-short-way-chip-on': cashShortPick === 0 }"
+						@tap.stop="setCashShortPick(0)"
+					>
+						微信
+					</view>
+					<view
+						class="cash-short-way-chip"
+						:class="{ 'cash-short-way-chip-on': cashShortPick === 1 }"
+						@tap.stop="setCashShortPick(1)"
+					>
+						支付宝
+					</view>
+				</view>
+				<view class="cash-short-actions">
+					<view class="cash-short-btn cash-short-btn-cancel" @tap.stop="closeCashShortPopupByCancel">取消</view>
+					<view class="cash-short-btn cash-short-btn-ok" @tap.stop="confirmCashShortWay">确认并提交</view>
+				</view>
+			</view>
+		</uni-popup>
 	</view>
 </template>
 
 <script>
 import { createOrder } from '@/api/order/index'
-import { mapGetters } from 'vuex'
+import { getCustomInfo } from '@/api/custom'
+import { mapActions, mapGetters } from 'vuex'
 
-const CALC_HISTORY_STORAGE_KEY = 'ghsApp_calculator_calcHistory'
-const DISCOUNT_CUSTOM_STORAGE_KEY = 'ghsApp_calculator_customDiscountZhe'
-const DISCOUNT_SELECTED_STORAGE_KEY = 'ghsApp_calculator_discountZhe'
+const CALC_HISTORY_STORAGE_KEY = 'hdApp_calculator_calcHistory'
+const DISCOUNT_CUSTOM_STORAGE_KEY = 'hdApp_calculator_customDiscountZhe'
+const DISCOUNT_SELECTED_STORAGE_KEY = 'hdApp_calculator_discountZhe'
 /** 计算器选客回填:对应 selectCustom style=3 */
-const CALCULATOR_PICK_CUSTOMER_KEY = 'ghsApp_calculator_pick_customer'
+const CALCULATOR_PICK_CUSTOMER_KEY = 'hdApp_calculator_pick_customer'
 /** 与首页「快捷开单」一致:取自 loginInfo.skCustomId,界面展示名固定 */
 const SHORTCUT_CUSTOM_DISPLAY_NAME = '快捷开单'
 
@@ -250,7 +296,7 @@ const SETTLE_FORM_DEFAULTS = {
 	sendType: 1,
 	hasPay: 0,
 	payWay: 0,
-	needPrint: 1,
+	needPrint: 2,
 	freight: '',
 	groupName: '',
 	remark: '',
@@ -263,7 +309,8 @@ const SETTLE_FORM_DEFAULTS = {
 	shopAdminId: 0,
 	shopAdminName: '',
 	cash: 0,
-	dealPrice: 0,
+	dealPrice: 1,
+	fromType: 1,
 	reductionRule: 0,
 	callErrand: 0,
 	weight: 1,
@@ -294,19 +341,26 @@ export default {
 			selPayWay: 0,
 			optHasPayList: [
 				{ name: '扫码', id: 0 },
-				{ name: '赊账', id: 2 },
+				{ name: '余额', id: 4 },
 				{ name: '线下', id: 1 },
+				{ name: '挂账', id: 2 },
 			],
 			optPayWayList: [
-				{ name: '微信', id: 0 },
-				{ name: '支付宝', id: 1 },
+				{ name: '线下微信', id: 0 },
+				{ name: '线下支付宝', id: 1 },
 				{ name: '现金', id: 4 },
 				{ name: '银行卡', id: 5 },
 			],
+			customInfo: { discount: 1, balance: 0 },
+			cashShortPick: 0,
+			_cashShortPopupCloseByApi: false,
 		}
 	},
 	computed: {
-		...mapGetters({ loginInfo: 'getLoginInfo' }),
+		...mapGetters({
+			loginInfo: 'getLoginInfo',
+			getMerchantInfo: 'getMerchantInfo',
+		}),
 		/** 工作台「快捷开单」客户 id,与 workbench skKd 使用的 loginInfo.skCustomId 一致 */
 		shortcutCustomerId() {
 			const login = this.loginInfo || {}
@@ -358,6 +412,20 @@ export default {
 		showCashPayCols() {
 			return this.selHasPay === 1 && this.selPayWay === 4
 		},
+		showBalanceRow() {
+			const b = Number(this.customInfo && this.customInfo.balance)
+			return Number.isFinite(b) && b > 0 && Number(this.customId) > 0
+		},
+		balanceCoversDue() {
+			const b = Number(this.customInfo && this.customInfo.balance) || 0
+			const due =
+				this.keyboardTarget === 'calc'
+					? Number(this.stackDiscountedAmount)
+					: Number(this.price)
+			const p = Number(due)
+			if (!Number.isFinite(p) || p <= 0) return false
+			return b + 1e-6 >= p
+		},
 	},
 	watch: {
 		shortcutCustomerId(n) {
@@ -382,16 +450,20 @@ export default {
 			this.customName = decodeURIComponent(String(options.customName))
 		}
 		this.applyDefaultShortcutCustomer()
+		this.refreshCustomerBalance()
 	},
 	onShow() {
 		this.applyPickCustomerFromStorage()
 		this.applyDefaultShortcutCustomer()
+		this.refreshCustomerBalance()
 	},
 	mounted() {
 		this.loadCalcHistoryFromStorage()
 		this.loadDiscountFromStorage()
+		this.initMerchantInfo().catch(() => {})
 	},
 	methods: {
+		...mapActions(['initMerchantInfo']),
 		init(){
 
 		},
@@ -419,6 +491,39 @@ export default {
 			this.customId = skid
 			this.customName = SHORTCUT_CUSTOM_DISPLAY_NAME
 		},
+		/** 对齐 affirm:拉取客户余额;余额大于应收且未手动选收款方式时再自动切换到余额收款 */
+		refreshCustomerBalance() {
+			const cid = Number(this.customId) || 0
+			if (cid <= 0) {
+				this.customInfo = { discount: 1, balance: 0 }
+				return
+			}
+			getCustomInfo({ id: cid })
+				.then((res) => {
+					if (!res || res.code !== 1 || !res.data || !res.data.custom) return
+					const prevHasPay = this.selHasPay
+					this.customInfo = res.data.custom
+					const bal = Number(this.customInfo.balance) || 0
+					const due =
+						this.keyboardTarget === 'calc'
+							? Number(this.stackDiscountedAmount)
+							: Number(this.price)
+					const amt = Number(due)
+					if (
+						prevHasPay !== 4 &&
+						Number.isFinite(amt) &&
+						amt > 0 &&
+						bal > amt + 1e-6
+					) {
+						this.selHasPay = 4
+						this.cash = 0
+						this.selPayWay = 0
+						this.blurCashIfNoColumn()
+					}
+					this.$forceUpdate()
+				})
+				.catch(() => {})
+		},
 		loadCalcHistoryFromStorage() {
 			try {
 				const raw = uni.getStorageSync(CALC_HISTORY_STORAGE_KEY)
@@ -799,6 +904,33 @@ export default {
 		blurCashIfNoColumn() {
 			if (this.keyboardTarget === 'cash' && !this.showCashPayCols) this.focusCalc()
 		},
+		setCashShortPick(v) {
+			this.tapVoice()
+			this.cashShortPick = Number(v) === 1 ? 1 : 0
+		},
+		closeCashShortPopupByCancel() {
+			this.tapVoice()
+			this._cashShortPopupCloseByApi = true
+			this.$refs.cashShortPopup && this.$refs.cashShortPopup.close()
+		},
+		onCashShortPopupChange(e) {
+			if (!e || e.show !== false) return
+			if (this._cashShortPopupCloseByApi) {
+				this._cashShortPopupCloseByApi = false
+				return
+			}
+			this.tapVoice()
+		},
+		confirmCashShortWay() {
+			this.tapVoice()
+			const way = Number(this.cashShortPick) === 1 ? 1 : 0
+			this.applySelPayWay(way)
+			this._cashShortPopupCloseByApi = true
+			this.$refs.cashShortPopup && this.$refs.cashShortPopup.close()
+			this.$nextTick(() => {
+				this._submitCashierPayCore()
+			})
+		},
 		openCalcHistory() {
 			this.tapVoice()
 			this.$refs.calcHistoryPopup && this.$refs.calcHistoryPopup.open()
@@ -1104,6 +1236,17 @@ export default {
 				this.$msg('请先选择客户')
 				return
 			}
+			if (this.selHasPay === 4) {
+				if (!this.customId || Number(this.customId) <= 0) {
+					this.$msg('请先选择客户')
+					return
+				}
+				const bal = Number(this.customInfo.balance) || 0
+				if (bal + 1e-6 < p) {
+					this.$msg('客户余额不足')
+					return
+				}
+			}
 			if (this.showCashPayCols) {
 				const cx = Number(this.cash) || 0
 				if (cx <= 0) {
@@ -1111,7 +1254,8 @@ export default {
 					return
 				}
 				if (Number(this.zl) < 0) {
-					this.$msg('现金不足')
+					this.cashShortPick = 0
+					this.$refs.cashShortPopup && this.$refs.cashShortPopup.open()
 					return
 				}
 			}
@@ -1146,55 +1290,78 @@ export default {
 				dealPrice: 1,
 				getGoods: 1,
 				product: '',
+				orderType: 2,
 				payWay: Number(formPayload.hasPay) === 1 ? (formPayload.payWay != null ? formPayload.payWay : 0) : 0,
 			}
-			uni.showLoading({ mask: true })
-			createOrder(payload)
-				.then((res) => {
-					uni.hideLoading()
-					if (res.code != 1) {
-						return
-					}
-					if (res.data && res.data.diff && !this.$util.isEmpty(res.data.diff)) {
-						this.$msg('存在价差条目,请到开单页处理')
-						return
-					}
-					let navigatedPay = false
-					if (res.data && res.data.status == 1) {
-						const id = res.data.id
-						const orderSn = res.data.orderSn
-						const actPrice = res.data.actPrice != null ? res.data.actPrice : p
-						if (formPayload.hasPay == 0) {
-							navigatedPay = true
-							this.$util.pageTo({
-								url: '/admin/billing/toPay',
-								type: 2,
-								query: { orderId: id, orderSn: orderSn, actPrice: actPrice },
-							})
-						} else {
-							navigatedPay = true
-							this.$util.pageTo({
-								url: '/admin/billing/result',
-								type: 2,
-								query: { orderId: id, orderSn: orderSn, title: '收款成功' },
-							})
+			const sendCreate = () => {
+				if (!this.getMerchantInfo || !this.getMerchantInfo.id) {
+					this.$msg('未获取到店铺信息')
+					return
+				}
+				const shopPayload = {
+					...payload,
+					shopId: this.getMerchantInfo.id,
+				}
+				uni.showLoading({ mask: true })
+				createOrder(shopPayload)
+					.then((res) => {
+						uni.hideLoading()
+						if (res.code != 1) {
+							return
 						}
-					} else if (!navigatedPay) {
-						uni.showToast({ title: '操作成功', icon: 'success' })
-					}
-					this.price = 0
-					this.checkType = 3
-					this.keyboardTarget = 'calc'
-					this.cash = 0
-					this.selHasPay = 0
-					this.selPayWay = 0
-					this.tokens = []
-					this.calcInput = ''
-					this.resetActiveDiscountToNone()
-				})
-				.catch(() => {
-					uni.hideLoading()
-				})
+						if (res.data && res.data.diff && !this.$util.isEmpty(res.data.diff)) {
+							this.$msg('存在价差条目,请到开单页处理')
+							return
+						}
+						let navigatedPay = false
+						if (res.data && res.data.status == 1) {
+							const id = res.data.id
+							const orderSn = res.data.orderSn
+							const actPrice = res.data.actPrice != null ? res.data.actPrice : p
+							if (formPayload.hasPay == 0) {
+								navigatedPay = true
+								this.$util.pageTo({
+									url: '/admin/billing/toPay',
+									type: 2,
+									query: { orderId: id, orderSn: orderSn, actPrice: actPrice },
+								})
+							} else {
+								navigatedPay = true
+								this.$util.pageTo({
+									url: '/admin/billing/result',
+									type: 2,
+									query: { orderId: id, orderSn: orderSn, title: '收款成功' },
+								})
+							}
+						} else if (!navigatedPay) {
+							uni.showToast({ title: '操作成功', icon: 'success' })
+						}
+						this.price = 0
+						this.checkType = 3
+						this.keyboardTarget = 'calc'
+						this.cash = 0
+						this.selHasPay = 0
+						this.selPayWay = 0
+						this.tokens = []
+						this.calcInput = ''
+						this.resetActiveDiscountToNone()
+						this.refreshCustomerBalance()
+					})
+					.catch(() => {
+						uni.hideLoading()
+					})
+			}
+			if (!this.getMerchantInfo || !this.getMerchantInfo.id) {
+				this.initMerchantInfo()
+					.then(() => {
+						sendCreate()
+					})
+					.catch(() => {
+						this.$msg('店铺信息加载失败')
+					})
+				return
+			}
+			sendCreate()
 		},
 	},
 }
@@ -1410,6 +1577,48 @@ export default {
 	margin-left: 12upx;
 }
 
+.balance-strip {
+	display: flex;
+	flex-direction: row;
+	align-items: center;
+	flex-wrap: wrap;
+	background: #fff;
+	border-radius: 14upx;
+	padding: 24upx 28upx;
+	margin-top: 12upx;
+	border: 2upx solid #e5e9ef;
+	box-sizing: border-box;
+}
+
+.balance-strip-label {
+	font-size: 30upx;
+	color: #9aa4b2;
+	flex-shrink: 0;
+	margin-right: 12upx;
+}
+
+.balance-strip-val {
+	font-size: 34upx;
+	font-weight: 700;
+	color: #3385ff;
+}
+
+.balance-strip-hint {
+	margin-left: 16upx;
+	font-size: 24upx;
+	line-height: 1.35;
+	flex: 1;
+	min-width: 200upx;
+}
+
+.balance-strip-hint-ok {
+	color: #09c567;
+}
+
+.balance-strip-hint-tip {
+	color: #876500;
+}
+
 .rcv-pay-block {
 	margin-top: 12upx;
 	padding: 22upx 20upx;
@@ -1431,6 +1640,17 @@ export default {
 	margin-top: 16upx;
 }
 
+.rcv-pay-hint {
+	margin-bottom: 4upx;
+}
+
+.rcv-pay-hint-text {
+	display: block;
+	font-size: 24upx;
+	color: #3385ff;
+	line-height: 1.35;
+}
+
 .rcv-sub-block {
 	margin-top: 4upx;
 }
@@ -1799,6 +2019,82 @@ export default {
 	padding: 0 12upx 12upx;
 }
 
+.mob-popup-cash-short {
+	max-height: none;
+}
+
+.cash-short-desc {
+	display: block;
+	font-size: 26upx;
+	color: #3d4654;
+	line-height: 1.45;
+	padding: 12upx 28upx 8upx;
+	box-sizing: border-box;
+}
+
+.cash-short-way-row {
+	display: flex;
+	flex-direction: row;
+	align-items: center;
+	padding: 12upx 28upx 8upx;
+	box-sizing: border-box;
+}
+
+.cash-short-way-chip {
+	flex: 1;
+	text-align: center;
+	font-size: 28upx;
+	padding: 20upx 12upx;
+	border-radius: 12upx;
+	border: 2upx solid #e8edf3;
+	background: #fafbfc;
+	color: #3d4654;
+	box-sizing: border-box;
+	margin-right: 16upx;
+	font-weight: 500;
+}
+
+.cash-short-way-chip:last-child {
+	margin-right: 0;
+}
+
+.cash-short-way-chip-on {
+	border-color: #09c567;
+	background: #effff4;
+	color: #09c567;
+}
+
+.cash-short-actions {
+	display: flex;
+	flex-direction: row;
+	align-items: center;
+	padding: 22upx 28upx 26upx;
+	border-top: 2upx solid #eef1f6;
+	box-sizing: border-box;
+	margin-top: 8upx;
+}
+
+.cash-short-btn {
+	flex: 1;
+	text-align: center;
+	font-size: 30upx;
+	padding: 22upx 12upx;
+	border-radius: 12upx;
+	box-sizing: border-box;
+	font-weight: 600;
+}
+
+.cash-short-btn-cancel {
+	margin-right: 16upx;
+	background: #f2f4f7;
+	color: #3d4654;
+}
+
+.cash-short-btn-ok {
+	background: #09c567;
+	color: #fff;
+}
+
 .discount-toolbar {
 	flex-shrink: 0;
 	padding: 20upx 24upx 22upx;