结算逻辑修改完成,起付额判定待处理
This commit is contained in:
@@ -3,6 +3,7 @@ import { getProductById } from '../../utils/productService'
|
||||
import { addToCart } from '../../utils/cartManager'
|
||||
import { getMachineInfo, getPayTypes } from '../../api/products'
|
||||
import { addCart, getGoodsList } from '../../api/shoppingCart'
|
||||
import { truncateAmountByCoin } from '../../utils/amount'
|
||||
|
||||
export default {
|
||||
name: 'ProductDetail',
|
||||
@@ -28,9 +29,21 @@ export default {
|
||||
minPowerDissipation: null,
|
||||
maxPowerDissipation: null
|
||||
},
|
||||
// 排序状态:true 升序,false 降序
|
||||
sortStates: {
|
||||
priceSort: true,
|
||||
powerSort: true,
|
||||
powerDissipationSort: true
|
||||
},
|
||||
// 当前激活的排序字段(仅当用户点击后才会传参)
|
||||
activeSortField: '',
|
||||
// 首次进入时是否已按价格币种设置过支付方式筛选默认值
|
||||
payFilterDefaultApplied: false,
|
||||
params: {
|
||||
id: "",
|
||||
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
|
||||
|
||||
},
|
||||
confirmAddDialog: {
|
||||
@@ -120,13 +133,17 @@ export default {
|
||||
// number:2001,
|
||||
// cost:"1000",//价格
|
||||
// },
|
||||
|
||||
|
||||
],
|
||||
productDetailLoading:false
|
||||
productDetailLoading: false,
|
||||
pageSizes: [10, 20, 50],
|
||||
currentPage: 1,
|
||||
total: 0,
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
console.log(this.$route.params.id, "i叫哦附加费")
|
||||
if (this.$route.params.id) {
|
||||
this.params.id = this.$route.params.id
|
||||
this.product = true
|
||||
@@ -134,7 +151,7 @@ export default {
|
||||
if (this.productListData && this.productListData.length) {
|
||||
this.expandedRowKeys = [this.productListData[0].id]
|
||||
}
|
||||
this.fetchGetMachineInfo(this.params)
|
||||
this.fetchGetMachineInfo(this.params)//priceSort 价格,powerSort 算力,功耗powerDissipationSort 布尔类型,true 升序,false降序
|
||||
this.fetchPayTypes()
|
||||
} else {
|
||||
this.$message.error('商品不存在')
|
||||
@@ -143,9 +160,64 @@ export default {
|
||||
this.fetchGetGoodsList()
|
||||
},
|
||||
methods: {
|
||||
// 行币种:优先行内 payCoin > coin,其次取全局表头币种
|
||||
getRowCoin(row) {
|
||||
try {
|
||||
const c = (row && (row.payCoin || row.coin)) || this.getPriceCoinSymbol() || ''
|
||||
return String(c).toUpperCase()
|
||||
} catch (e) { return '' }
|
||||
},
|
||||
// 金额格式化:不补0、不四舍五入;返回 {text,truncated,full}
|
||||
formatAmount(value, coin) {
|
||||
return truncateAmountByCoin(value, coin)
|
||||
},
|
||||
/**
|
||||
* 首次加载时,将“支付方式筛选”的默认选中值设为与价格列币种一致,
|
||||
* 并同步 filters.chain/filters.coin;仅执行一次,不触发额外查询。
|
||||
*/
|
||||
ensureDefaultPayFilterSelection() {
|
||||
try {
|
||||
if (this.payFilterDefaultApplied) return
|
||||
const payList = Array.isArray(this.paymentMethodList) ? this.paymentMethodList : []
|
||||
if (!payList.length) return
|
||||
const coinSymbol = (this.getPriceCoinSymbol && this.getPriceCoinSymbol()) || ''
|
||||
if (!coinSymbol) return
|
||||
const hit = payList.find(it => String(it && it.payCoin).toUpperCase() === String(coinSymbol).toUpperCase())
|
||||
if (!hit) return
|
||||
const key = `${hit.payChain || ''}|${hit.payCoin || ''}`
|
||||
this.selectedPayKey = key
|
||||
this.filters.chain = String(hit.payChain || '').trim()
|
||||
this.filters.coin = String(hit.payCoin || '').trim()
|
||||
this.payFilterDefaultApplied = true
|
||||
} catch (e) { /* noop */ }
|
||||
},
|
||||
// 切换排序:field in ['priceSort','powerSort','powerDissipationSort']
|
||||
handleToggleSort(field) {
|
||||
try {
|
||||
if (!this.sortStates) this.sortStates = {}
|
||||
if (this.activeSortField !== field) {
|
||||
// 切换到新的字段:默认从升序开始(true)
|
||||
// 先将其它字段复位为升序(▲)
|
||||
Object.keys(this.sortStates).forEach(k => { this.sortStates[k] = true })
|
||||
this.activeSortField = field
|
||||
// 后端默认升序,首次点击应为降序
|
||||
this.sortStates[field] = false
|
||||
} else {
|
||||
// 同一字段:升降序切换
|
||||
this.sortStates[field] = !this.sortStates[field]
|
||||
}
|
||||
const params = this.buildQueryParams()
|
||||
this.fetchGetMachineInfo(params)
|
||||
} catch (e) { /* noop */ }
|
||||
},
|
||||
// 组合查询参数(带上商品 id 与筛选条件)
|
||||
buildQueryParams() {
|
||||
const q = { id: this.params.id }
|
||||
// 分页参数始终透传
|
||||
try {
|
||||
if (this.params && this.params.pageNum != null) q.pageNum = this.params.pageNum
|
||||
if (this.params && this.params.pageSize != null) q.pageSize = this.params.pageSize
|
||||
} catch (e) { /* noop */ }
|
||||
// 仅当用户真实填写(>0)时才传参;默认/空值不传
|
||||
const addNum = (obj, key, name) => {
|
||||
const raw = obj[key]
|
||||
@@ -162,6 +234,13 @@ export default {
|
||||
addNum(this.filters, 'maxPower', 'maxPower')
|
||||
addNum(this.filters, 'minPowerDissipation', 'minPowerDissipation')
|
||||
addNum(this.filters, 'maxPowerDissipation', 'maxPowerDissipation')
|
||||
// 排序参数:仅在用户点击某一列后传当前列
|
||||
try {
|
||||
if (this.activeSortField) {
|
||||
const s = this.sortStates || {}
|
||||
q[this.activeSortField] = !!s[this.activeSortField]
|
||||
}
|
||||
} catch (e) { /* noop */ }
|
||||
return q
|
||||
},
|
||||
// 拉取支付方式
|
||||
@@ -172,6 +251,8 @@ export default {
|
||||
if (res && (res.code === 0 || res.code === 200)) {
|
||||
const list = Array.isArray(res.data) ? res.data : []
|
||||
this.paymentMethodList = list
|
||||
// 支付方式加载后尝试设置默认筛选
|
||||
this.ensureDefaultPayFilterSelection()
|
||||
}
|
||||
} catch (e) {
|
||||
// 忽略错误,保持页面可用
|
||||
@@ -185,6 +266,7 @@ export default {
|
||||
console.log(res)
|
||||
if (res && res.code === 200) {
|
||||
console.log(res.data, 'res.rows');
|
||||
this.total = res.total||0;
|
||||
// 新数据结构:机器为扁平 rows 列表;仅当后端返回有效支付方式时才覆盖,避免清空 getPayTypes 的结果
|
||||
try {
|
||||
const payList = res && res.data && res.data.payConfigList
|
||||
@@ -203,6 +285,8 @@ export default {
|
||||
// 清空旧的两层结构数据,避免误用
|
||||
this.productListData = []
|
||||
this.expandedRowKeys = []
|
||||
// 机器加载后尝试设置默认筛选
|
||||
this.ensureDefaultPayFilterSelection()
|
||||
this.$nextTick(() => {
|
||||
this.machinesLoaded = true
|
||||
})
|
||||
@@ -221,17 +305,17 @@ export default {
|
||||
|
||||
if (!this.product) {
|
||||
this.$message({
|
||||
message: '商品不存在',
|
||||
type: 'error',
|
||||
showClose: true
|
||||
message: '商品不存在',
|
||||
type: 'error',
|
||||
showClose: true
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载商品详情失败:', error)
|
||||
this.$message({
|
||||
message: '加载商品详情失败,请稍后重试',
|
||||
type: 'error',
|
||||
showClose: true
|
||||
message: '加载商品详情失败,请稍后重试',
|
||||
type: 'error',
|
||||
showClose: true
|
||||
})
|
||||
} finally {
|
||||
this.loading = false
|
||||
@@ -240,7 +324,7 @@ export default {
|
||||
//加入购物车
|
||||
async fetchAddCart(params) {
|
||||
const res = await addCart(params)
|
||||
|
||||
|
||||
return res
|
||||
},
|
||||
//查询购物车列表
|
||||
@@ -342,7 +426,7 @@ export default {
|
||||
},
|
||||
|
||||
// 已取消对比购物车的自动勾选/禁用逻辑
|
||||
autoSelectAndDisable() {},
|
||||
autoSelectAndDisable() { },
|
||||
|
||||
// 选择器可选控制:已在购物车中的机器不可再选
|
||||
isSelectable(row, index) {
|
||||
@@ -433,7 +517,7 @@ export default {
|
||||
variant.quantity = 1
|
||||
} catch (error) {
|
||||
console.error('添加到购物车失败:', error)
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
// 统一加入购物车
|
||||
@@ -457,7 +541,7 @@ export default {
|
||||
this.selectedMap = {}
|
||||
} catch (e) {
|
||||
console.error('统一加入购物车失败', e)
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
// 打开确认弹窗:以当前界面勾选(_selected)为准,并在打开后清空左侧勾选状态
|
||||
@@ -520,14 +604,14 @@ export default {
|
||||
})
|
||||
this.$nextTick(() => this.autoSelectAndDisable())
|
||||
} catch (e) { /* noop */ }
|
||||
|
||||
|
||||
this.$message({
|
||||
message: `已加入 ${allSelected.length} 台矿机到购物车`,
|
||||
type: 'success',
|
||||
duration: 3000,
|
||||
showClose: true,
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
this.confirmAddDialog.visible = false
|
||||
// 清空选中映射,然后重新加载数据(数据加载时会自动设置 _selected: false)
|
||||
this.selectedMap = {}
|
||||
@@ -636,6 +720,21 @@ export default {
|
||||
console.error('添加到购物车失败:', error)
|
||||
this.$message.error('添加到购物车失败,请稍后重试')
|
||||
}
|
||||
}
|
||||
},
|
||||
handleSizeChange(val) {
|
||||
console.log(`每页 ${val} 条`);
|
||||
this.params.pageSize = val;
|
||||
this.params.pageNum = 1;
|
||||
this.currentPage = 1;
|
||||
// 携带当前激活的排序字段
|
||||
this.fetchGetMachineInfo(this.buildQueryParams());
|
||||
|
||||
},
|
||||
handleCurrentChange(val) {
|
||||
console.log(`当前页: ${val}`);
|
||||
this.params.pageNum = val;
|
||||
// 携带当前激活的排序字段
|
||||
this.fetchGetMachineInfo(this.buildQueryParams());
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user