@@ -352,7 +407,7 @@
import {
listJdComment, getJdComment, updateJdComment, delJdComment, resetJdCommentByProductId,
listTbComment, getTbComment, updateTbComment, delTbComment, resetTbCommentByProductId,
- getCommentStatistics, getJdProductTypeMap, getTbProductTypeMap, fetchComments
+ getCommentStatistics, getJdProductTypeMap, getTbProductTypeMap, saveProductTypeMap, delProductTypeMap, fetchComments
} from '@/api/jarvis/comment'
import { mapGetters } from 'vuex'
import MobileSearchForm from '@/components/MobileSearchForm'
@@ -407,7 +462,18 @@ export default {
// 获取评论 loading
jdFetchLoading: false,
tbFetchLoading: false,
- statFetchLoading: false
+ statFetchLoading: false,
+ // 商品ID映射
+ mapSource: 'jd',
+ mapKeyword: '',
+ mapDialogVisible: false,
+ mapDialogTitle: '新增商品ID',
+ mapSaving: false,
+ mapForm: {
+ key: '',
+ value: '',
+ oldKey: ''
+ }
}
},
computed: {
@@ -432,6 +498,30 @@ export default {
{ key: 'fetchComments', label: '获取评论', type: 'warning', icon: 'el-icon-upload2', handler: () => this.handleTbFetchComments(), disabled: this.tbFetchLoading },
{ key: 'export', label: '导出', type: 'success', icon: 'el-icon-download', handler: () => this.handleTbExport(), disabled: false }
]
+ },
+ mapKeyLabel() {
+ return this.mapSource === 'tb' ? '京东商品ID' : '型号名称'
+ },
+ mapValueLabel() {
+ return this.mapSource === 'tb' ? '淘宝商品ID' : '京东商品ID'
+ },
+ mapRules() {
+ return {
+ key: [{ required: true, message: '请输入' + this.mapKeyLabel, trigger: 'blur' }],
+ value: [{ required: true, message: '请输入' + this.mapValueLabel, trigger: 'blur' }]
+ }
+ },
+ mapTableRows() {
+ const sourceMap = this.mapSource === 'tb' ? this.tbProductTypeMap : this.jdProductTypeMap
+ const keyword = (this.mapKeyword || '').trim()
+ return Object.keys(sourceMap || {}).sort().filter(key => {
+ if (!keyword) return true
+ const value = sourceMap[key] == null ? '' : String(sourceMap[key])
+ return key.indexOf(keyword) !== -1 || value.indexOf(keyword) !== -1
+ }).map(key => ({
+ key: key,
+ value: sourceMap[key]
+ }))
}
},
created() {
@@ -607,6 +697,54 @@ export default {
this.tbProductTypeMap = response.data || {}
})
},
+ reloadProductTypeMap() {
+ if (this.mapSource === 'tb') {
+ this.getTbProductTypeMap()
+ } else {
+ this.getJdProductTypeMap()
+ }
+ },
+ openMapDialog(row) {
+ this.mapDialogTitle = row ? '编辑商品ID' : '新增商品ID'
+ this.mapForm = {
+ key: row ? row.key : '',
+ value: row ? row.value : '',
+ oldKey: row ? row.key : ''
+ }
+ this.mapDialogVisible = true
+ this.$nextTick(() => {
+ if (this.$refs.mapForm) {
+ this.$refs.mapForm.clearValidate()
+ }
+ })
+ },
+ submitMapForm() {
+ this.$refs.mapForm.validate(valid => {
+ if (!valid) return
+ this.mapSaving = true
+ saveProductTypeMap({
+ source: this.mapSource,
+ key: (this.mapForm.key || '').trim(),
+ value: (this.mapForm.value || '').trim(),
+ oldKey: this.mapForm.oldKey || ''
+ }).then(() => {
+ this.$modal.msgSuccess('保存成功')
+ this.mapDialogVisible = false
+ this.reloadProductTypeMap()
+ }).finally(() => {
+ this.mapSaving = false
+ })
+ })
+ },
+ handleMapDelete(row) {
+ const label = this.mapKeyLabel + '「' + row.key + '」'
+ this.$modal.confirm('是否确认删除' + label + '?').then(() => {
+ return delProductTypeMap(this.mapSource, row.key)
+ }).then(() => {
+ this.reloadProductTypeMap()
+ this.$modal.msgSuccess('删除成功')
+ }).catch(() => {})
+ },
// 标签页切换
handleTabClick(tab) {
if (tab.name === 'jd') {
@@ -621,6 +759,9 @@ export default {
if (this.statisticsList.length === 0) {
this.getStatistics()
}
+ } else if (tab.name === 'productMap') {
+ this.getJdProductTypeMap()
+ this.getTbProductTypeMap()
}
},
// 查看图片