feat:无ISBN上传分类改为根据书名从孔网接口获取
This commit is contained in:
parent
e24d4f81b9
commit
6edc8aeb5b
@ -265,7 +265,7 @@
|
||||
<text class="info-inline-label">书名</text>
|
||||
<view class="inline-fields" style="flex:1;">
|
||||
<view class="inline-field" style="flex:1;">
|
||||
<input class="form-input" v-model="noIsbnBookName" placeholder="请输入书名" style="flex:1;" />
|
||||
<input class="form-input" v-model="noIsbnBookName" placeholder="请输入书名" @input="onNoIsbnBookNameInput" style="flex:1;" />
|
||||
</view>
|
||||
<view class="inline-field" style="flex:none;">
|
||||
<view class="search-btn" @click="searchNoIsbn">
|
||||
@ -371,19 +371,12 @@
|
||||
<text class="info-inline-label">图书分类 & 装订</text>
|
||||
<view class="inline-fields" style="flex:1;align-items:stretch;">
|
||||
<view class="inline-field" style="flex:1;">
|
||||
<picker v-if="noIsbnCategoryColumns.length > 0" mode="multiSelector" :range="noIsbnCategoryColumns" range-key="name" @columnchange="onNoIsbnCategoryColumnChange" @change="onNoIsbnCategoryChange" :value="noIsbnCategoryIndexes">
|
||||
<picker @change="onNoIsbnCategoryChange" :value="noIsbnCategoryIndex" :range="noIsbnCategoryNames">
|
||||
<view class="category-select" style="height:100%;">
|
||||
<text class="category-value">{{ noIsbnCategoryPathText || '请选择分类' }}</text>
|
||||
<text class="category-value">{{ noIsbnCategoryNames[noIsbnCategoryIndex] || '请选择分类' }}</text>
|
||||
<text class="picker-arrow">›</text>
|
||||
</view>
|
||||
</picker>
|
||||
<view v-else-if="noIsbnCategoryLoading" class="category-select" style="height:100%;">
|
||||
<text class="category-value" style="color:#999;">加载中...</text>
|
||||
</view>
|
||||
<view v-else class="category-select" style="height:100%;" @click="loadNoIsbnCategory">
|
||||
<text class="category-value" style="color:#999;">点击加载分类</text>
|
||||
<text class="picker-arrow">›</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="inline-field" style="flex:1;">
|
||||
<view class="dropdown-wrapper" style="flex:1;">
|
||||
@ -898,7 +891,7 @@
|
||||
|
||||
<script>
|
||||
import { getWarehouseList, getLocationList, searchBookByIsbn, calculateSign, buildFormBodyWithImages } from '@/utils/api.js'
|
||||
import { login as kongfzLogin, searchProducts, searchFacet } from '@/utils/kongfz.js'
|
||||
import { login as kongfzLogin, searchProducts, searchFacet, searchCategories } from '@/utils/kongfz.js'
|
||||
import { uploadImages } from '@/utils/minio.js'
|
||||
|
||||
export default {
|
||||
@ -969,15 +962,13 @@ export default {
|
||||
noIsbnBookPopupVisible: false,
|
||||
noIsbnBookList: [],
|
||||
|
||||
// 分类(从API加载)
|
||||
noIsbnCategoryData: [],
|
||||
noIsbnCategoryColumns: [],
|
||||
noIsbnCategoryIndexes: [],
|
||||
noIsbnCategoryLevels: [],
|
||||
noIsbnMaxCategoryLevel: 3,
|
||||
noIsbnCategoryPathText: '',
|
||||
// 分类(从孔网按书名搜索获取)
|
||||
noIsbnCategoryList: [],
|
||||
noIsbnCategoryNames: ['请输入书名后自动获取分类'],
|
||||
noIsbnCategoryIndex: 0,
|
||||
noIsbnCategoryLoading: false,
|
||||
noIsbnSelectedCategoryId: '',
|
||||
noIsbnSelectedCategoryValue: '',
|
||||
_noIsbnCategoryTimer: null,
|
||||
|
||||
// 无ISBN - 市场竞争/在售
|
||||
noIsbnProductList: [],
|
||||
@ -1069,8 +1060,6 @@ export default {
|
||||
this.loadSavedAccounts()
|
||||
// 恢复定价策略配置
|
||||
this.loadPriceConfig()
|
||||
// 预加载图书分类
|
||||
this.loadNoIsbnCategory()
|
||||
// 初始化印刷时间选择器默认值
|
||||
this.syncNoIsbnPrintTimeIndexes()
|
||||
// 恢复选择的仓库货位
|
||||
@ -1898,137 +1887,52 @@ export default {
|
||||
|
||||
// 分类
|
||||
// 无ISBN - 分类选择器:列变化
|
||||
onNoIsbnCategoryColumnChange(e) {
|
||||
const { column, value } = e.detail
|
||||
this.noIsbnCategoryIndexes[column] = value
|
||||
this.noIsbnCategoryLevels[column] = this.noIsbnCategoryColumns[column][value]
|
||||
if (column < this.noIsbnMaxCategoryLevel - 1) {
|
||||
this.updateNoIsbnSubsequentColumns(column + 1)
|
||||
}
|
||||
this.updateNoIsbnCategoryPathText()
|
||||
// 根据书名搜索孔网分类(防抖)
|
||||
onNoIsbnBookNameInput() {
|
||||
if (this._noIsbnCategoryTimer) clearTimeout(this._noIsbnCategoryTimer)
|
||||
this._noIsbnCategoryTimer = setTimeout(() => {
|
||||
this.fetchNoIsbnCategories()
|
||||
}, 600)
|
||||
},
|
||||
|
||||
// 无ISBN - 分类选择器:确认选择
|
||||
onNoIsbnCategoryChange(e) {
|
||||
const values = e.detail.value
|
||||
this.noIsbnCategoryIndexes = [...values]
|
||||
for (let i = 0; i < values.length; i++) {
|
||||
if (this.noIsbnCategoryColumns[i] && this.noIsbnCategoryColumns[i][values[i]]) {
|
||||
this.noIsbnCategoryLevels[i] = this.noIsbnCategoryColumns[i][values[i]]
|
||||
}
|
||||
}
|
||||
this.updateNoIsbnCategoryPathText()
|
||||
this.updateNoIsbnSelectedCategoryId()
|
||||
},
|
||||
|
||||
updateNoIsbnSubsequentColumns(startColumn) {
|
||||
const parentCategory = this.noIsbnCategoryLevels[startColumn - 1]
|
||||
if (!parentCategory || !parentCategory.children || parentCategory.children.length === 0) {
|
||||
for (let i = startColumn; i < this.noIsbnMaxCategoryLevel; i++) {
|
||||
this.noIsbnCategoryColumns[i] = [{ name: '暂无数据', id: '' }]
|
||||
this.noIsbnCategoryIndexes[i] = 0
|
||||
this.noIsbnCategoryLevels[i] = { name: '暂无数据', id: '' }
|
||||
}
|
||||
return
|
||||
}
|
||||
this.noIsbnCategoryColumns[startColumn] = parentCategory.children
|
||||
this.noIsbnCategoryIndexes[startColumn] = 0
|
||||
this.noIsbnCategoryLevels[startColumn] = parentCategory.children[0]
|
||||
if (startColumn < this.noIsbnMaxCategoryLevel - 1) {
|
||||
this.updateNoIsbnSubsequentColumns(startColumn + 1)
|
||||
}
|
||||
},
|
||||
|
||||
updateNoIsbnCategoryPathText() {
|
||||
const validLevels = this.noIsbnCategoryLevels.filter(level => level && level.name && level.name !== '暂无数据')
|
||||
this.noIsbnCategoryPathText = validLevels.map(level => level.name).join(' / ')
|
||||
},
|
||||
|
||||
updateNoIsbnSelectedCategoryId() {
|
||||
const validLevels = this.noIsbnCategoryLevels.filter(level => level && level.id && level.id !== '')
|
||||
this.noIsbnSelectedCategoryId = validLevels.length > 0 ? validLevels[validLevels.length - 1].id : ''
|
||||
},
|
||||
|
||||
// 加载图书分类(从API)
|
||||
loadNoIsbnCategory() {
|
||||
// 从孔网搜索图书分类
|
||||
async fetchNoIsbnCategories() {
|
||||
var bookName = (this.noIsbnBookName || '').trim()
|
||||
if (!bookName) return
|
||||
this.noIsbnCategoryLoading = true
|
||||
const cookies = uni.getStorageSync('cookies') || this.kongfzToken || ''
|
||||
uni.request({
|
||||
url: 'https://api.buzhiyushu.cn/api/kongfz/getCategory',
|
||||
method: 'GET',
|
||||
data: { token: cookies },
|
||||
header: { 'Content-Type': 'application/json' },
|
||||
success: (res) => {
|
||||
const responseData = res.data
|
||||
if (responseData && responseData.successResponse) {
|
||||
this.noIsbnCategoryData = responseData.successResponse
|
||||
this.initNoIsbnCategoryPicker()
|
||||
try {
|
||||
var list = await searchCategories(bookName, {
|
||||
phpsessid: this.kongfzToken || ''
|
||||
})
|
||||
this.noIsbnCategoryList = list
|
||||
if (list.length > 0) {
|
||||
this.noIsbnCategoryNames = list.map(function(item) { return item.showName })
|
||||
this.noIsbnCategoryIndex = 0
|
||||
this.onNoIsbnCategorySelect(0)
|
||||
} else {
|
||||
console.error('获取分类数据失败:', responseData)
|
||||
// 使用本地默认分类
|
||||
this.loadDefaultNoIsbnCategory()
|
||||
this.noIsbnCategoryNames = ['未获取到分类']
|
||||
this.noIsbnCategoryIndex = 0
|
||||
this.noIsbnSelectedCategoryValue = ''
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('获取分类数据异常:', err)
|
||||
this.loadDefaultNoIsbnCategory()
|
||||
},
|
||||
complete: () => {
|
||||
} catch (e) {
|
||||
console.error('获取孔网分类失败:', e)
|
||||
this.noIsbnCategoryNames = ['获取分类失败']
|
||||
this.noIsbnCategoryIndex = 0
|
||||
} finally {
|
||||
this.noIsbnCategoryLoading = false
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
loadDefaultNoIsbnCategory() {
|
||||
const defaultCategories = [
|
||||
{ name: '文学', id: '1', level: 1, children: [{ name: '中国文学', id: '11', level: 2, children: [] }] },
|
||||
{ name: '艺术', id: '2', level: 1, children: [] },
|
||||
{ name: '历史', id: '3', level: 1, children: [] },
|
||||
{ name: '哲学', id: '4', level: 1, children: [] },
|
||||
{ name: '科学', id: '5', level: 1, children: [] },
|
||||
{ name: '技术', id: '6', level: 1, children: [] },
|
||||
{ name: '教育', id: '7', level: 1, children: [] },
|
||||
{ name: '经济', id: '8', level: 1, children: [] },
|
||||
{ name: '政治', id: '9', level: 1, children: [] },
|
||||
{ name: '军事', id: '10', level: 1, children: [] },
|
||||
{ name: '法律', id: '11', level: 1, children: [] },
|
||||
{ name: '社会', id: '12', level: 1, children: [] },
|
||||
{ name: '文化', id: '13', level: 1, children: [] },
|
||||
{ name: '语言', id: '14', level: 1, children: [] },
|
||||
{ name: '工具书', id: '15', level: 1, children: [] },
|
||||
{ name: '其他', id: '16', level: 1, children: [] }
|
||||
]
|
||||
this.noIsbnCategoryData = defaultCategories
|
||||
this.initNoIsbnCategoryPicker()
|
||||
// 选择分类
|
||||
onNoIsbnCategoryChange(e) {
|
||||
var index = e.detail.value
|
||||
this.onNoIsbnCategorySelect(index)
|
||||
},
|
||||
|
||||
initNoIsbnCategoryPicker() {
|
||||
this.noIsbnCategoryColumns = []
|
||||
this.noIsbnCategoryLevels = []
|
||||
this.noIsbnCategoryIndexes = []
|
||||
const level1Categories = (this.noIsbnCategoryData || []).filter(item => item.level === 1)
|
||||
if (level1Categories.length === 0) return
|
||||
this.noIsbnCategoryColumns[0] = level1Categories
|
||||
this.noIsbnCategoryIndexes[0] = 0
|
||||
let currentParent = level1Categories[0]
|
||||
let currentLevel = 1
|
||||
this.noIsbnCategoryLevels[0] = currentParent
|
||||
while (currentLevel < this.noIsbnMaxCategoryLevel) {
|
||||
const children = currentParent.children || []
|
||||
if (children.length === 0) break
|
||||
this.noIsbnCategoryColumns[currentLevel] = children
|
||||
this.noIsbnCategoryIndexes[currentLevel] = 0
|
||||
this.noIsbnCategoryLevels[currentLevel] = children[0]
|
||||
currentParent = children[0]
|
||||
currentLevel++
|
||||
}
|
||||
while (this.noIsbnCategoryColumns.length < this.noIsbnMaxCategoryLevel) {
|
||||
this.noIsbnCategoryColumns.push([{ name: '暂无数据', id: '' }])
|
||||
this.noIsbnCategoryIndexes.push(0)
|
||||
this.noIsbnCategoryLevels.push({ name: '暂无数据', id: '' })
|
||||
}
|
||||
this.updateNoIsbnCategoryPathText()
|
||||
this.updateNoIsbnSelectedCategoryId()
|
||||
onNoIsbnCategorySelect(index) {
|
||||
this.noIsbnCategoryIndex = index
|
||||
var item = this.noIsbnCategoryList[index]
|
||||
this.noIsbnSelectedCategoryValue = item ? item.value : ''
|
||||
},
|
||||
|
||||
// 印刷时间 - 列变化
|
||||
|
||||
@ -254,9 +254,64 @@ export function searchProducts(keyword, options = {}) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取孔网图书分类(根据书名搜索孔网 facet 接口)
|
||||
* @param {string} keyword 书名
|
||||
* @param {object} options { phpsessid, userArea }
|
||||
* @returns {Promise<Array<{value:string, showName:string}>>} 图书分类列表(normal组)
|
||||
*/
|
||||
export function searchCategories(keyword, options = {}) {
|
||||
const { phpsessid = '', userArea = '1006000000' } = options
|
||||
return new Promise((resolve) => {
|
||||
if (!keyword || !keyword.trim()) {
|
||||
resolve([])
|
||||
return
|
||||
}
|
||||
uni.request({
|
||||
url: 'https://search.kongfz.com/pc-gw/search-web/client/pc/product/keyword/normal/facet',
|
||||
method: 'GET',
|
||||
data: {
|
||||
dataType: 0,
|
||||
keyword: keyword.trim(),
|
||||
page: 1,
|
||||
userArea: userArea
|
||||
},
|
||||
header: {
|
||||
'Cookie': phpsessid ? `PHPSESSID=${phpsessid}` : ''
|
||||
},
|
||||
success: (res) => {
|
||||
if (res.statusCode === 200 && res.data && res.data.status === 1 && res.data.data) {
|
||||
var categories = res.data.data.categories || []
|
||||
// 找到 normal 组(图书分类)
|
||||
var normalGroup = null
|
||||
for (var i = 0; i < categories.length; i++) {
|
||||
if (categories[i].type === 'GROUP' && categories[i].name === 'normal') {
|
||||
normalGroup = categories[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
if (normalGroup && normalGroup.subLabels) {
|
||||
resolve(normalGroup.subLabels.map(function(item) {
|
||||
return { value: item.value, showName: item.showName }
|
||||
}))
|
||||
} else {
|
||||
resolve([])
|
||||
}
|
||||
} else {
|
||||
resolve([])
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
resolve([])
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
login,
|
||||
searchFacet,
|
||||
fetchItems,
|
||||
searchProducts
|
||||
searchProducts,
|
||||
searchCategories
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user