| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791 |
- <template>
- <view class="pay-container">
- <!-- 支付金额区域 -->
- <view class="amount-section">
- <view class="amount-label">支付金额</view>
- <view class="amount-display">
- <text class="currency">¥</text>
- <text class="amount">{{ displayAmount }}</text>
- </view>
- <button class="clear-amount-btn" @click="changeAmount(0)">清空金额</button>
- </view>
- <!-- 客户信息卡片 -->
- <view class="customer-info-card">
- <view class="card-header">
- <view class="customer-avatar">
- <text class="avatar-text">{{ customInfo.name ? customInfo.name.charAt(0) : '客' }}</text>
- </view>
- <view class="customer-details">
- <text class="customer-name">{{ customInfo.name || '客户' }}</text>
- <text class="customer-status has-debt" @click="goGathering">
- 查看待结订单
- </text>
- </view>
- </view>
- <view class="debt-info" v-if="Number(customInfo.remainDebtAmount) > 0">
- <view class="debt-amount" @click="changeAmount(customInfo.remainDebtAmount)">
- <text class="debt-label">待结金额</text>
- <text class="debt-value">¥{{ customInfo.remainDebtAmount }}</text>
- </view>
- </view>
- </view>
- <!-- 数字键盘 - 使用直接事件绑定,确保兼容性 -->
- <view class="keyboard-section">
- <view class="keyboard">
- <view class="keyboard-row" v-for="(row, rowIndex) in keyboardKeys" :key="rowIndex">
- <view
- class="key-item"
- v-for="(key, keyIndex) in row"
- :key="`${rowIndex}-${keyIndex}`"
- :class="{
- 'key-number': key.type === 'number',
- 'key-delete': key.type === 'delete',
- 'key-dot': key.type === 'dot',
- 'key-confirm': key.type === 'confirm'
- }"
- @click="handleKeyPress(key)"
- @touchstart="handleTouchStart"
- @touchend="handleTouchEnd"
- >
- <text v-if="key.type === 'delete'" class="iconfont icon-delete"></text>
- <text v-else-if="key.type === 'confirm'">确认</text>
- <text v-else>{{ key.value }}</text>
- </view>
- </view>
- </view>
- </view>
- <!-- 支付按钮 -->
- <view class="pay-button-section">
- <button
- class="pay-button"
- :class="{ disabled: !canPay }"
- :disabled="!canPay"
- @click="handlePay"
- >
- <text class="button-text">支付宝支付</text>
- </button>
- </view>
- </view>
- </template>
- <script>
- import { getGhsData } from '@/api/ghs';
- import { rechargeFn } from '@/api/custom-recharge'
- // 优化:使用常量避免重复创建
- const KEY_TYPES = {
- NUMBER: 'number',
- DELETE: 'delete',
- DOT: 'dot',
- CONFIRM: 'confirm'
- };
- const MAX_INTEGER_LENGTH = 8;
- const MAX_DECIMAL_LENGTH = 2;
- export default {
- name: 'pay',
- data() {
- return {
- currentAmount: '0',
- displayAmount: '0',
- // 优化:使用静态数据,避免重复创建
- keyboardKeys: [
- [
- { type: KEY_TYPES.NUMBER, value: '1' },
- { type: KEY_TYPES.NUMBER, value: '2' },
- { type: KEY_TYPES.NUMBER, value: '3' }
- ],
- [
- { type: KEY_TYPES.NUMBER, value: '4' },
- { type: KEY_TYPES.NUMBER, value: '5' },
- { type: KEY_TYPES.NUMBER, value: '6' }
- ],
- [
- { type: KEY_TYPES.NUMBER, value: '7' },
- { type: KEY_TYPES.NUMBER, value: '8' },
- { type: KEY_TYPES.NUMBER, value: '9' }
- ],
- [
- { type: KEY_TYPES.DOT, value: '.' },
- { type: KEY_TYPES.NUMBER, value: '0' },
- { type: KEY_TYPES.DELETE, value: '' }
- ]
- ],
- // 优化:使用更高效的状态管理
- amountBuffer: '0',
- updateScheduled: false,
- updateTimer: null,
- id:0,
- salt:'',
- ghsInfo:[],
- customInfo:{},
- payWay:1
- }
- },
- computed: {
- // 简化支付按钮判断逻辑:只要大于0就能支付
- canPay() {
- const amount = parseFloat(this.currentAmount);
- return amount > 0;
- }
- },
- onLoad(options) {
- if (options.id) {
- this.id = options.id;
- }
- if (options.salt) {
- this.salt = options.salt;
- }
- let that = this
- if (this.id && this.salt) {
- getGhsData({id:this.id,salt:this.salt}).then(res => {
- if (res.data && res.data.ghs){
- that.ghsInfo = res.data.ghs
- that.customInfo = res.data.custom?res.data.custom:[]
- if(that.customInfo.remainDebtAmount && Number(that.customInfo.remainDebtAmount)>0){
- that.currentAmount = parseFloat(that.customInfo.remainDebtAmount).toString()
- that.updateDisplay()
- }
- }
- })
- }
-
- },
- methods: {
- changeAmount(amount){
- this.currentAmount = amount
- this.updateDisplay()
- },
- // 优化:添加触摸反馈
- handleTouchStart(e) {
- const target = e.currentTarget;
- if (target && target.style) {
- target.style.transform = 'scale(0.95)';
- }
- },
-
- handleTouchEnd(e) {
- const target = e.currentTarget;
- if (target && target.style) {
- setTimeout(() => {
- target.style.transform = 'scale(1)';
- }, 100);
- }
- },
- // 优化:简化的键盘处理逻辑
- handleKeyPress(key) {
- // 防抖处理
- if (this.updateTimer) {
- clearTimeout(this.updateTimer);
- }
-
- if (key.type === KEY_TYPES.NUMBER) {
- this.addNumber(key.value);
- } else if (key.type === KEY_TYPES.DELETE) {
- this.deleteNumber();
- } else if (key.type === KEY_TYPES.DOT) {
- this.addDecimal();
- }
-
- // 使用 requestAnimationFrame 优化更新
- this.scheduleUpdate();
- },
- // 优化:使用 requestAnimationFrame 调度更新
- scheduleUpdate() {
- if (!this.updateScheduled) {
- this.updateScheduled = true;
- requestAnimationFrame(() => {
- this.updateDisplay();
- this.updateScheduled = false;
- });
- }
- },
- // 优化:更高效的数字添加逻辑
- addNumber(num) {
- const buffer = this.amountBuffer;
-
- // 快速路径:如果当前是0且输入的不是小数点,直接替换
- if (buffer === '0' && num !== '.') {
- this.amountBuffer = num;
- this.currentAmount = num;
- return;
- }
- // 检查长度限制
- const parts = buffer.split('.');
- const integerPart = parts[0];
- const decimalPart = parts[1];
- // 整数部分限制
- if (!decimalPart && integerPart.length >= MAX_INTEGER_LENGTH) {
- uni.showToast({
- title: '金额不能超过8位数',
- icon: 'none',
- duration: 1500
- })
- return;
- }
- // 小数部分限制
- if (decimalPart && decimalPart.length >= MAX_DECIMAL_LENGTH) {
- uni.showToast({
- title: '最多支持2位小数',
- icon: 'none',
- duration: 1500
- })
- return;
- }
- // 添加数字
- this.amountBuffer = buffer + num;
- this.currentAmount = this.amountBuffer;
- },
- // 优化:更高效的小数点添加逻辑
- addDecimal() {
- if (!this.amountBuffer.includes('.')) {
- this.amountBuffer += '.';
- this.currentAmount = this.amountBuffer;
- }
- },
- // 优化:更高效的删除逻辑
- deleteNumber() {
- const buffer = this.amountBuffer;
- if (buffer.length > 1) {
- this.amountBuffer = buffer.slice(0, -1);
- } else {
- this.amountBuffer = '0';
- }
- this.currentAmount = this.amountBuffer;
- },
- // 优化:更高效的显示更新逻辑
- updateDisplay() {
- let amount = this.currentAmount;
-
- // 确保 amount 是字符串类型
- if (typeof amount !== 'string') {
- amount = amount.toString();
- }
-
- // 快速路径:如果是0,直接显示
- if (amount === '0') {
- this.displayAmount = '0';
- return;
- }
- // 检查是否包含小数点
- if (amount.includes('.')) {
- const numAmount = parseFloat(amount) || 0;
- this.displayAmount = numAmount.toFixed(2);
- } else {
- // 整数显示
- this.displayAmount = amount;
- }
- },
- // 优化:更高效的金额设置
- setAmount(amount) {
- const numAmount = parseFloat(amount);
- if (!isNaN(numAmount) && numAmount > 0) {
- const amountStr = numAmount.toString();
- this.amountBuffer = amountStr;
- this.currentAmount = amountStr;
- this.updateDisplay();
- }
- },
- // 处理支付
- handlePay() {
- if (!this.canPay) return;
- const amount = parseFloat(this.currentAmount);
- // 简化验证:只要大于0就能支付
- if (amount <= 0) {
- uni.showToast({
- title: '请输入金额!',
- icon: 'none',
- duration: 2000
- })
- return false
- }
- let params = {}
- params = {
- actPrice: amount,
- payWay: this.payWay,
- }
- params.ghsId = this.id
- params.salt = this.salt
- rechargeFn(params).then(res => {
- //错误返回判断
- if(res.code == 0){
- uni.hideLoading()
- uni.showToast({
- title: res.msg,
- icon: 'none',
- duration: 2000
- })
- return false
- }
- // 隐藏加载提示
- uni.hideLoading()
- // 显示成功提示
- uni.showToast({
- title: '正在跳转支付...',
- icon: 'success',
- duration: 1500
- })
- // 延迟跳转到支付页面
- setTimeout(() => {
- window.location.href = res.data.url;
- }, 300)
- }).catch(err => {
- // 隐藏加载提示
- uni.hideLoading()
- // 显示错误提示
- uni.showToast({
- title: '请求失败,请重试',
- icon: 'none',
- duration: 2000
- })
- })
- },
- // 返回上一页
- goBack() {
- uni.navigateBack({
- delta: 1
- });
- },
- // 跳转到待结订单页面
- goGathering() {
- if (!this.id) {
- uni.showToast({
- title: '供货商信息加载中,请稍后再试',
- icon: 'none'
- });
- return;
- }
- uni.navigateTo({
- url: `/pagesPurchase/gathering?id=${this.id}&salt=${this.salt}`
- });
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- .pay-container {
- min-height: 100vh;
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
- position: relative;
- }
- .nav-bar {
- display: flex;
- align-items: center;
- justify-content: center; /* Changed to center the title */
- padding: 20upx 30upx;
- background: rgba(255, 255, 255, 0.1);
- backdrop-filter: blur(10px);
-
- .nav-back {
- width: 80upx;
- height: 80upx;
- display: flex;
- align-items: center;
- justify-content: center;
- border-radius: 50%;
- background: rgba(255, 255, 255, 0.2);
- cursor: pointer;
- transition: all 0.2s ease;
-
- &:active {
- background: rgba(255, 255, 255, 0.3);
- transform: scale(0.9);
- }
-
- .iconfont {
- font-size: 40upx;
- color: #fff;
- font-weight: bold;
- }
- }
-
- .nav-title {
- color: #fff;
- font-size: 36upx;
- font-weight: 600;
- }
-
- .nav-placeholder {
- width: 80upx; /* Placeholder for back button */
- }
- }
- .amount-section {
- padding: 60upx 40upx;
- text-align: center;
-
- .amount-label {
- color: rgba(255, 255, 255, 0.8);
- font-size: 34upx;
- margin-bottom: 20upx;
- }
-
- .amount-display {
- display: flex;
- align-items: baseline;
- justify-content: center;
- margin-bottom: 20upx;
-
- .currency {
- color: #fff;
- font-size: 48upx;
- font-weight: 600;
- margin-right: 10upx;
- }
-
- .amount {
- color: #fff;
- font-size: 80upx;
- font-weight: 700;
- font-family: 'Arial', sans-serif;
- }
- }
-
- .clear-amount-btn {
- color: rgb(226, 219, 219);
- font-size: 22upx;
- margin-top: 20upx;
- background: transparent;
- border: 1upx solid rgb(226, 219, 219);
- border-radius: 12upx;
- padding: 6upx 12upx;
- transition: all 0.3s ease;
- cursor: pointer;
- width: auto;
- display: inline-block;
- }
- }
- .customer-info-card {
- background: #fff; /* Changed to white */
- margin: 0 30upx 20upx;
- border-radius: 20upx;
- padding: 30upx;
- box-shadow: 0 8upx 30upx rgba(0, 0, 0, 0.08);
- position: relative;
- overflow: hidden;
-
- &::before {
- content: '';
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- height: 8upx;
- background: #fff; /* Changed to white */
- box-shadow: 0 2upx 8upx rgba(0, 0, 0, 0.1);
- }
-
- .card-header {
- display: flex;
- align-items: center;
- margin-bottom: 20upx;
- margin-top: 8upx;
-
- .customer-avatar {
- width: 90upx;
- height: 90upx;
- border-radius: 50%;
- background: linear-gradient(135deg, #1677ff 0%, #4096ff 100%);
- display: flex;
- align-items: center;
- justify-content: center;
- margin-right: 25upx;
- box-shadow: 0 6upx 20upx rgba(22, 119, 255, 0.3);
- position: relative;
-
- &::after {
- content: '';
- position: absolute;
- top: -2upx;
- left: -2upx;
- right: -2upx;
- bottom: -2upx;
- border-radius: 50%;
- background: linear-gradient(135deg, #1677ff 0%, #4096ff 100%);
- z-index: -1;
- opacity: 0.3;
- }
-
- .avatar-text {
- color: #fff;
- font-size: 44upx;
- font-weight: 600;
- }
- }
-
- .customer-details {
- flex: 1;
- display: flex;
- align-items: center;
- justify-content: space-between;
-
- .customer-name {
- display: block;
- font-size: 34upx;
- font-weight: 600;
- color: #333;
- }
-
- .customer-status {
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 24upx;
- color: #999;
- padding: 0 24upx;
- height: 70upx;
- line-height: 70upx;
- border-radius: 36upx;
- background: #f8f9fa;
- border: 1upx solid #e9ecef;
- box-sizing: border-box;
-
- &.has-debt {
- color: #fff;
- background: linear-gradient(135deg, #ff6b6b 0%, #ff5252 100%);
- border-color: #ff6b6b;
- box-shadow: 0 2upx 10upx rgba(255, 107, 107, 0.3);
- }
- }
- }
- }
-
- .debt-info {
- background: linear-gradient(135deg, #fff5f5 0%, #fef2f2 100%);
- border-radius: 15upx;
- padding: 20upx 25upx;
- margin-top: 20upx;
- border: 1upx solid rgba(255, 107, 107, 0.2);
- position: relative;
-
- &::before {
- content: '';
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background: linear-gradient(135deg, rgba(255, 107, 107, 0.05) 0%, rgba(255, 107, 107, 0.02) 100%);
- border-radius: 15upx;
- }
-
- .debt-amount {
- display: flex;
- align-items: baseline;
- justify-content: space-between;
- margin-bottom: 10upx;
- position: relative;
- z-index: 1;
-
- .debt-label {
- font-size: 28upx;
- color: #666;
- font-weight: 500;
- }
-
- .debt-value {
- font-size: 40upx;
- font-weight: 700;
- color: #ff6b6b;
- font-family: 'Arial', sans-serif;
- text-shadow: 0 2upx 10upx rgba(255, 107, 107, 0.2);
- }
- }
-
- .debt-tip {
- font-size: 22upx;
- color: #999;
- text-align: right;
- position: relative;
- z-index: 1;
- font-style: italic;
- }
- }
- }
- .keyboard-section {
- position: fixed;
- bottom: 160upx;
- left: 0;
- right: 0;
- background: rgba(255, 255, 255, 0.98);
- backdrop-filter: blur(20px);
- padding: 30upx;
- border-top: 1upx solid rgba(0, 0, 0, 0.05);
-
- .keyboard {
- .keyboard-row {
- display: flex;
- margin-bottom: 20upx;
-
- &:last-child {
- margin-bottom: 0;
- }
-
- .key-item {
- flex: 1;
- height: 120upx;
- margin: 0 10upx;
- border-radius: 20upx;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 40upx;
- font-weight: 600;
- transition: all 0.15s ease;
- user-select: none;
- -webkit-user-select: none;
- cursor: pointer;
- will-change: transform;
- position: relative;
- overflow: hidden;
-
- &::before {
- content: '';
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);
- opacity: 0;
- transition: opacity 0.15s ease;
- }
-
- &:active::before {
- opacity: 1;
- }
-
- &.key-number {
- background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
- color: #333;
- box-shadow: 0 4upx 20upx rgba(0, 0, 0, 0.08);
- border: 1upx solid rgba(0, 0, 0, 0.05);
- }
-
- &.key-delete {
- background: linear-gradient(135deg, #ff6b6b 0%, #ff5252 100%);
- color: #fff;
- box-shadow: 0 4upx 20upx rgba(255, 107, 107, 0.3);
- }
-
- &.key-dot {
- background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
- color: #333;
- box-shadow: 0 4upx 20upx rgba(0, 0, 0, 0.08);
- border: 1upx solid rgba(0, 0, 0, 0.05);
- }
-
- &.key-confirm {
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
- color: #fff;
- box-shadow: 0 4upx 20upx rgba(102, 126, 234, 0.3);
- }
- }
- }
- }
- }
- .pay-button-section {
- position: fixed;
- bottom: 0;
- left: 0;
- right: 0;
- padding: 30upx;
- background: rgba(255, 255, 255, 0.98);
- backdrop-filter: blur(20px);
- border-top: 1upx solid rgba(0, 0, 0, 0.05);
-
- .pay-button {
- width: 100%;
- height: 100upx;
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
- color: #fff;
- font-size: 36upx;
- font-weight: 600;
- border-radius: 50upx;
- border: none;
- transition: all 0.3s ease;
- position: relative;
- overflow: hidden;
-
- &::before {
- content: '';
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);
- opacity: 0;
- transition: opacity 0.3s ease;
- }
-
- &:active::before {
- opacity: 1;
- }
-
- &.disabled {
- background: linear-gradient(135deg, #e9ecef 0%, #dee2e6 100%);
- color: #adb5bd;
- box-shadow: none;
- }
-
- &:not(.disabled):active {
- transform: scale(0.98);
- }
-
- .button-text {
- position: absolute;
- left: 50%;
- transform: translateX(-50%);
- font-size: 36upx;
- font-weight: 600;
- color: #fff;
- }
-
- .button-amount {
- position: absolute;
- right: 30upx;
- font-size: 36upx;
- font-weight: 700;
- color: #fff;
- font-family: 'Arial', sans-serif;
- }
- }
- }
- </style>
|