新增产品修复

dev
Jo 3 years ago
parent a10c817516
commit 0748a8ba1e
  1. 166
      src/views/data/Product.vue

@ -82,7 +82,7 @@
</el-form-item> </el-form-item>
<el-form-item label="配置数据"> <el-form-item label="配置数据">
<el-button type="primary" @click="configData">配置数据权限</el-button> <el-button type="primary" @click="configData">配置数据权限</el-button>
<div class="type-wrap" ref="typeWrap" @scroll="loadType" style="display: none"> <div class="type-wrap" ref="typeWrap" @scroll="loadType" v-show="checkedIds.length">
<el-tree ref="type" :data="typeList" show-checkbox accordion node-key="id" :default-expanded-keys="checkedIds" :default-checked-keys="checkedIds" :props="defaultProps" @node-expand="typeExpand"> <el-tree ref="type" :data="typeList" show-checkbox accordion node-key="id" :default-expanded-keys="checkedIds" :default-checked-keys="checkedIds" :props="defaultProps" @node-expand="typeExpand">
<span class="custom-tree-node" slot-scope="{ node, data }"> <span class="custom-tree-node" slot-scope="{ node, data }">
<span :title="node.label">{{ node.label }}</span> <span :title="node.label">{{ node.label }}</span>
@ -137,7 +137,7 @@
</el-container> </el-container>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button @click="configVisible = false"> </el-button> <el-button @click="configVisible = false"> </el-button>
<el-button type="primary" @click="confirmConfig"> </el-button> <el-button type="primary" :loading="configLoading" @click="confirmConfig"> </el-button>
</span> </span>
</el-dialog> </el-dialog>
@ -194,11 +194,9 @@ export default {
typeUnit: 20, typeUnit: 20,
typeScrollTop: 0, typeScrollTop: 0,
typeTimer: null, typeTimer: null,
tableId: [],
configVisible: false, configVisible: false,
configChecked: [], configLoading: false,
configCheckedTableId: [],
categoryId: '', categoryId: '',
configIds: [], configIds: [],
updateTime: '', updateTime: '',
@ -294,6 +292,7 @@ export default {
}) })
} }
handleId(res) handleId(res)
this.typeConfigList = JSON.parse(JSON.stringify(res))
// //
function getTable(data){ function getTable(data){
@ -381,7 +380,6 @@ export default {
const data = res.product const data = res.product
this.productName = data.productName this.productName = data.productName
this.market = data.market this.market = data.market
this.configChecked = data.tableId
this.checkedIds = this.handleType(data.tableId.split(','),this.typeList) this.checkedIds = this.handleType(data.tableId.split(','),this.typeList)
this.$refs.type.setCheckedNodes(this.checkedIds) this.$refs.type.setCheckedNodes(this.checkedIds)
}).catch(res => {}) }).catch(res => {})
@ -415,8 +413,8 @@ export default {
}).catch(err => {}) }).catch(err => {})
}, },
preview(row){ preview(row){
this.isDetail = true
this.getType() this.getType()
this.isDetail = true
this.id = row.id this.id = row.id
this.getDetail() this.getDetail()
}, },
@ -460,21 +458,19 @@ export default {
this.isDetail = false this.isDetail = false
this.typeIndex = 100000 this.typeIndex = 100000
this.typeList = [] this.typeList = []
this.tableId = []
this.configChecked = []
this.configIds = [] this.configIds = []
}, },
// tableId, // tableId,
getIds(){ getIds(list){
// //
let list = this.checkedIds this.checkedIds = []
this.tableId = []
const proList = [] const proList = []
this.configLoading = true
// ididid // ididid
list.map(e => { list.map(e => {
proList.push(new Promise((resolve,reject) => { proList.push(new Promise((resolve,reject) => {
this.$get(`${this.api.getAllTableIdBycategoryId}?categoryId=${e}`).then(res => { this.$get(`${this.api.getAllTableIdBycategoryId}?categoryId=${e}`).then(res => {
res.tableId && this.tableId.push(...res.tableId.split(',')) res.tableId && this.checkedIds.push(...res.tableId.split(','))
resolve() resolve()
}).catch(res => { }).catch(res => {
this.submited = false this.submited = false
@ -483,8 +479,11 @@ export default {
}) })
// idresolve // idresolve
return Promise.all(proList).then(res => { return Promise.all(proList).then(res => {
this.configLoading = false
resolve() resolve()
}).catch(err => {}) }).catch(err => {
this.configLoading = false
})
}, },
confirm(){ confirm(){
if(this.submited) return false if(this.submited) return false
@ -493,57 +492,52 @@ export default {
if(isNaN(this.market)) return this.$message.warning('市场价格请输入数字') if(isNaN(this.market)) return this.$message.warning('市场价格请输入数字')
if(!this.checkedIds.length) return this.$message.warning('请选择数据') if(!this.checkedIds.length) return this.$message.warning('请选择数据')
this.submited = true // this.submited = true //
this.getIds().then(() => { let tableId = this.checkedIds
let tableId = Array.from(new Set(this.tableId)) if(!tableId.length) return this.$message.warning('请选择数据')
if(!tableId.length) return this.$message.warning('请选择数据') let data = {
let data = { id: this.id,
id: this.id, productName: this.productName,
productName: this.productName, market: this.market,
market: this.market, tableId: tableId.join(),
tableId: tableId.join(), userId: this.userId,
userId: this.userId, userName: this.userName,
userName: this.userName, createTime: '',
createTime: '', orderNum: '',
orderNum: '', status: '',
status: '', tableNum: tableId.length,
tableNum: tableId.length, updateTime: ''
updateTime: '' }
} if(this.id){
if(this.id){ this.$post(this.api.updateProduct,data).then(res => {
this.$post(this.api.updateProduct,data).then(res => { this.$message.success('新增成功')
this.$message.success('新增成功') this.productVisible = false
this.productVisible = false this.getData()
this.getData() this.submited = false
this.submited = false }).catch(res => {
}).catch(res => { this.submited = false
this.submited = false })
}) }else{
}else{ this.$post(this.api.saveProduct,data).then(res => {
this.$post(this.api.saveProduct,data).then(res => { this.$message.success('新增成功')
this.$message.success('新增成功') this.productVisible = false
this.productVisible = false this.getData()
this.getData() this.submited = false
this.submited = false }).catch(res => {
}).catch(res => { this.submited = false
this.submited = false })
}) }
}
})
}, },
configData(){ configData(){
this.configVisible = true this.configVisible = true
this.getConfigType() this.getConfigType()
// //
if (this.id) { if (this.checkedIds.length) {
let list = this.$refs.type.getCheckedNodes() let list = this.$refs.type.getCheckedNodes()
let configIds = [] this.configIds = list.filter(n => !n.name).map(n => n.id)
list.map(n => { this.$refs.typeConfig.setCheckedKeys(this.configIds)
if(!n.name) configIds.push(n.originId) // nameidid
})
this.configIds = configIds
} }
}, },
typeConfigClick(data,node){ typeConfigClick(data){
this.categoryId = data.id this.categoryId = data.id
this.getConfigTable() this.getConfigTable()
}, },
@ -553,25 +547,22 @@ export default {
}, },
// //
getConfigType(){ getConfigType(){
this.$post(this.api.getTableByClassification).then(res => { const list = this.typeConfigList
function handleId(data){ function handleId(data){
data.map(n => { data.map(n => {
n.id = String(n.id) n.disabled = false //
n.label = n.categoryName if(n.children.length){
if(n.children.length){ handleId(n.children)
handleId(n.children) }
} })
}) }
} handleId(list)
handleId(res) if(list[0].children.length){
this.typeConfigList = res this.categoryId = list[0].children[0].id
if(res[0].children.length){ }else{
this.categoryId = res[0].children[0].id this.categoryId = list[0].id
}else{ }
this.categoryId = res[0].id this.getConfigTable()
}
this.getConfigTable()
}).catch(res => {})
}, },
// //
getConfigTable(){ getConfigTable(){
@ -614,26 +605,11 @@ export default {
this.previewVisible = true this.previewVisible = true
}).catch(res => {}) }).catch(res => {})
}, },
// id
getTableId(list){
let checked = this.configChecked
list.map(n => {
if(n.children && n.children.length){
this.getTableId(n.children)
if(checked.includes(n.originId) && n.children[0].name){ // name
this.configCheckedTableId = [...this.configCheckedTableId,...n.children.map(n => n.id)]
}else{
this.getTableId(n.children)
}
}
})
},
confirmConfig(){ confirmConfig(){
this.configChecked = this.$refs.typeConfig.getCheckedKeys().map(n => n) // id const list = this.$refs.typeConfig.getCheckedNodes().map(e => e.originId) // id
this.checkedIds = this.configChecked this.getIds(list).then(() => {
this.configVisible = false this.$refs.type.setCheckedKeys(this.checkedIds)
this.$nextTick(() => { this.configVisible = false
this.$refs.type.setCheckedNodes(this.checkedIds)
}) })
} }
} }

Loading…
Cancel
Save