周五固定更新
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
|
||||
import { getProductById } from '../../utils/productService'
|
||||
import { addToCart } from '../../utils/cartManager'
|
||||
import { getMachineInfo } from '../../api/products'
|
||||
import { getMachineInfo, getPayTypes } from '../../api/products'
|
||||
import { addCart, getGoodsList } from '../../api/shoppingCart'
|
||||
|
||||
export default {
|
||||
@@ -13,6 +13,21 @@ export default {
|
||||
// 默认展开的行keys
|
||||
expandedRowKeys: [],
|
||||
selectedMap: {},
|
||||
// 新接口:单层矿机列表 & 支付方式
|
||||
machineList: [],
|
||||
paymentMethodList: [],
|
||||
// 筛选状态
|
||||
selectedPayKey: null,
|
||||
filters: {
|
||||
chain: '',
|
||||
coin: '',
|
||||
minPrice: null,
|
||||
maxPrice: null,
|
||||
minPower: null,
|
||||
maxPower: null,
|
||||
minPowerDissipation: null,
|
||||
maxPowerDissipation: null
|
||||
},
|
||||
params: {
|
||||
id: "",
|
||||
|
||||
@@ -120,6 +135,7 @@ export default {
|
||||
this.expandedRowKeys = [this.productListData[0].id]
|
||||
}
|
||||
this.fetchGetMachineInfo(this.params)
|
||||
this.fetchPayTypes()
|
||||
} else {
|
||||
this.$message.error('商品不存在')
|
||||
this.product = false
|
||||
@@ -127,6 +143,41 @@ export default {
|
||||
this.fetchGetGoodsList()
|
||||
},
|
||||
methods: {
|
||||
// 组合查询参数(带上商品 id 与筛选条件)
|
||||
buildQueryParams() {
|
||||
const q = { id: this.params.id }
|
||||
// 仅当用户真实填写(>0)时才传参;默认/空值不传
|
||||
const addNum = (obj, key, name) => {
|
||||
const raw = obj[key]
|
||||
if (raw === null || raw === undefined || raw === '') return
|
||||
const n = Number(raw)
|
||||
if (Number.isFinite(n) && n > 0) q[name] = n
|
||||
}
|
||||
// 支付方式条件:有值才传
|
||||
if (this.filters.chain && String(this.filters.chain).trim()) q.chain = String(this.filters.chain).trim()
|
||||
if (this.filters.coin && String(this.filters.coin).trim()) q.coin = String(this.filters.coin).trim()
|
||||
addNum(this.filters, 'minPrice', 'minPrice')
|
||||
addNum(this.filters, 'maxPrice', 'maxPrice')
|
||||
addNum(this.filters, 'minPower', 'minPower')
|
||||
addNum(this.filters, 'maxPower', 'maxPower')
|
||||
addNum(this.filters, 'minPowerDissipation', 'minPowerDissipation')
|
||||
addNum(this.filters, 'maxPowerDissipation', 'maxPowerDissipation')
|
||||
return q
|
||||
},
|
||||
// 拉取支付方式
|
||||
async fetchPayTypes() {
|
||||
try {
|
||||
const res = await getPayTypes({ productId: this.params.id })
|
||||
// 接口示例:{ code: 0, data: [ { payChain, payCoin, payCoinImage, shopId } ], msg: '' }
|
||||
if (res && (res.code === 0 || res.code === 200)) {
|
||||
const list = Array.isArray(res.data) ? res.data : []
|
||||
this.paymentMethodList = list
|
||||
}
|
||||
} catch (e) {
|
||||
// 忽略错误,保持页面可用
|
||||
this.paymentMethodList = []
|
||||
}
|
||||
},
|
||||
|
||||
async fetchGetMachineInfo(params) {
|
||||
this.productDetailLoading = true
|
||||
@@ -134,31 +185,26 @@ export default {
|
||||
console.log(res)
|
||||
if (res && res.code === 200) {
|
||||
console.log(res.data, 'res.rows');
|
||||
this.paymentMethodList = res.data.payConfigList || []
|
||||
const list =res.data.machineRangeInfoList || []
|
||||
const withKeys = list.map((group, idx) => {
|
||||
const fallbackId = `grp-${idx}`
|
||||
const groupId = group.id || group.onlyKey || (group.productMachineRangeGroupDto && group.productMachineRangeGroupDto.id)
|
||||
const firstMachineId = Array.isArray(group.productMachines) && group.productMachines.length > 0 ? group.productMachines[0].id : undefined
|
||||
// 为机器行设置默认租赁天数为1,并确保未选中状态
|
||||
const normalizedMachines = Array.isArray(group.productMachines)
|
||||
? group.productMachines.map(m => ({
|
||||
...m,
|
||||
leaseTime: (m && m.leaseTime && Number(m.leaseTime) > 0) ? Number(m.leaseTime) : 1,
|
||||
_selected: false // 确保所有机器行初始状态为未选中
|
||||
}))
|
||||
: []
|
||||
return { ...group, id: groupId || (firstMachineId ? `m-${firstMachineId}` : fallbackId), productMachines: normalizedMachines }
|
||||
})
|
||||
|
||||
this.productListData = withKeys
|
||||
if (this.productListData.length && (!this.expandedRowKeys || !this.expandedRowKeys.length)) {
|
||||
this.expandedRowKeys = [this.productListData[0].id]
|
||||
}
|
||||
// 产品机器加载完成后,依据购物车集合执行一次本地禁用与勾选
|
||||
// 新数据结构:机器为扁平 rows 列表;仅当后端返回有效支付方式时才覆盖,避免清空 getPayTypes 的结果
|
||||
try {
|
||||
const payList = res && res.data && res.data.payConfigList
|
||||
if (Array.isArray(payList) && payList.length) {
|
||||
this.paymentMethodList = payList
|
||||
}
|
||||
} catch (e) { /* keep existing paymentMethodList */ }
|
||||
const rows = (res && res.data && (res.data.rows || res.data.list)) || (res && res.rows) || []
|
||||
const normalized = (Array.isArray(rows) ? rows : []).map((m, idx) => ({
|
||||
...m,
|
||||
id: m && (m.id !== undefined && m.id !== null) ? m.id : `m-${idx}`,
|
||||
leaseTime: (m && m.leaseTime && Number(m.leaseTime) > 0) ? Number(m.leaseTime) : 1,
|
||||
_selected: false
|
||||
}))
|
||||
this.machineList = normalized
|
||||
// 清空旧的两层结构数据,避免误用
|
||||
this.productListData = []
|
||||
this.expandedRowKeys = []
|
||||
this.$nextTick(() => {
|
||||
this.machinesLoaded = true
|
||||
// 已取消与购物车对比:不再自动禁用或勾选
|
||||
})
|
||||
}
|
||||
|
||||
@@ -503,9 +549,12 @@ export default {
|
||||
// 取消所有商品勾选(内层表格的自定义 checkbox)
|
||||
clearAllSelections() {
|
||||
try {
|
||||
// 清空选中映射
|
||||
// 清空选中映射(遗留字段)
|
||||
this.selectedMap = {}
|
||||
// 遍历所有系列与机器,复位 _selected
|
||||
if (Array.isArray(this.machineList) && this.machineList.length) {
|
||||
this.machineList.forEach(m => { if (m) this.$set(m, '_selected', false) })
|
||||
return
|
||||
}
|
||||
const groups = Array.isArray(this.productListData) ? this.productListData : []
|
||||
groups.forEach(g => {
|
||||
const list = Array.isArray(g.productMachines) ? g.productMachines : []
|
||||
|
||||
Reference in New Issue
Block a user