<template>
|
<div class="add-common">
|
<el-dialog
|
:title="modalTitle + '产品类别'"
|
:visible.sync="editConfig.visible"
|
:width="dialogWidth"
|
:before-close="handleClose"
|
>
|
<!-- 头 -->
|
<div slot="title" class="dialog-header">
|
<span>{{ modalTitle + "产品类别" }}</span>
|
<div class="header_btns">
|
<!-- <span class="btn">
|
<i class="el-icon-printer"></i>
|
<span>打印</span>
|
</span> -->
|
<span class="btn" style="margin-left: 15px">
|
<i class="el-icon-s-tools"></i>
|
<span>动作</span>
|
<!-- <el-button
|
plain
|
size="mini"
|
style="margin-left: 15px"
|
@click="deleteClick"
|
>删除</el-button
|
> -->
|
</span>
|
<el-button v-if="showEdit" plain size="mini" style="margin-left: 15px" @click="editClick">编辑</el-button>
|
</div>
|
</div>
|
<!-- 内容 -->
|
<el-form
|
ref="form"
|
:model="editConfig.infomation"
|
:rules="rules"
|
label-position="right"
|
label-width="110px"
|
size="mini"
|
>
|
<div class="basic-info">
|
<FormBtnsView
|
:showProduct="true"
|
:countObject="statisticsMap"
|
@productClick="productClick"
|
@listingRulesClick="listingRulesClick"
|
/>
|
<div class="basic-info-view">
|
<!-- <el-row> -->
|
<!-- <el-col :span="24">
|
<div style="margin-left: 20px"><span class="color_F56C6C">*</span>类别</div>
|
<el-form-item label="" prop="name" label-width="20px">
|
<el-input
|
v-model="editConfig.infomation.name"
|
placeholder=""
|
:disabled="!showFooter"
|
style="width: 85%"
|
></el-input>
|
</el-form-item>
|
</el-col> -->
|
<!-- <el-col :span="24">
|
<el-form-item label="上级品类" prop="parentId" style="margin-left: 20px">
|
<el-select
|
v-model="editConfig.infomation.parentId"
|
placeholder="请选择"
|
size="mini"
|
style="width: 45%"
|
:disabled="!showFooter"
|
>
|
<el-option v-for="item in productCategoryList" :key="item.id" :label="item.name" :value="item.id">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row> -->
|
</div>
|
<div class="bottom">
|
<div class="purchase-view">
|
<div class="left">
|
<!-- <div class="second-label">物流</div> -->
|
<el-form-item label="类别" prop="name">
|
<el-input
|
v-model="editConfig.infomation.name"
|
placeholder=""
|
:disabled="!showFooter"
|
style="width: 85%"
|
></el-input>
|
</el-form-item>
|
<el-form-item label="上级品类" v-if="editConfig.infomation.parentId" prop="parentId">
|
<el-select
|
v-model="editConfig.infomation.parentId"
|
placeholder="请选择"
|
size="mini"
|
style="width: 85%"
|
:disabled="editConfig.infomation.parentId"
|
>
|
<el-option v-for="item in productCategoryList" :key="item.id" :label="item.name" :value="item.id">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
<!-- <el-form-item label="路线" prop="client_name" style="margin-left: 20px">
|
<el-select
|
v-model="editConfig.infomation.memberId"
|
multiple
|
placeholder="请选择"
|
size="mini"
|
style="width: 63%"
|
:disabled="!showFooter"
|
>
|
<el-option v-for="item in memberOptions" :key="item.id" :label="item.username" :value="item.id">
|
</el-option>
|
</el-select>
|
</el-form-item> -->
|
<el-form-item label="强制下架策略" prop="forceRemovalStrategy">
|
<el-select
|
v-model="editConfig.infomation.forceRemovalStrategy"
|
placeholder="请选择"
|
size="mini"
|
style="width: 85%"
|
:disabled="!showFooter"
|
>
|
<el-option
|
v-for="item in forceRemovalStrategyList"
|
:key="item.id"
|
:label="item.name"
|
:value="item.id"
|
>
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</div>
|
<div class="right">
|
<!-- <div class="second-label">库存计价</div> -->
|
<el-form-item label="成本方法" prop="costingMethod">
|
<el-select
|
v-model="editConfig.infomation.costingMethod"
|
placeholder="请选择"
|
size="mini"
|
style="width: 85%"
|
:disabled="!showFooter"
|
>
|
<el-option v-for="item in costingMethodList" :key="item.id" :label="item.name" :value="item.id">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="库存计价" prop="inventoryValuation">
|
<el-select
|
v-model="editConfig.infomation.inventoryValuation"
|
placeholder="请选择"
|
size="mini"
|
style="width: 85%"
|
:disabled="!showFooter"
|
>
|
<el-option
|
v-for="item in inventoryValuationList"
|
:key="item.id"
|
:label="item.name"
|
:value="item.id"
|
>
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</div>
|
</div>
|
</div>
|
</div>
|
</el-form>
|
<!-- 尾 -->
|
<div slot="footer" class="dialog-footer">
|
<!-- <el-button type="primary" size="small" @click="editConfig.visible = false">保并提交审批</el-button> -->
|
<el-button type="primary" size="small" @click="saveClick('form')" :disabled="!showFooter">保存</el-button>
|
<el-button size="small" @click="editConfig.visible = false">取消</el-button>
|
</div>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script>
|
import { addProductCategory, updateProductCategory, deleteProductCategory } from "@/api/product/productCategory"
|
|
import { getDataByType } from "@/api/data"
|
import { getProductList } from "@/api/product/product"
|
export default {
|
name: "AddProductCategoryDialog",
|
props: {
|
editCommonConfig: {
|
type: Object,
|
default: () => {
|
return {
|
visible: false,
|
title: "新建",
|
infomation: { type: [] },
|
autoEdit: false
|
}
|
}
|
},
|
productCategoryList: {
|
type: Array,
|
default: () => {
|
return []
|
}
|
}
|
},
|
components: {},
|
computed: {
|
modalTitle() {
|
if (this.editConfig.title === "编辑" && this.editConfig.autoEdit) {
|
return "编辑"
|
} else if (this.editConfig.title === "编辑") {
|
return !this.showEdit ? "编辑" : "查看"
|
} else {
|
return "新建"
|
}
|
}
|
},
|
data() {
|
return {
|
dialogWidth: "50%",
|
editConfig: this.editCommonConfig,
|
rules: {
|
name: [{ required: true, message: "请输入", trigger: "change" }]
|
},
|
forceRemovalStrategyList: getDataByType("forceRemovalStrategy"),
|
// 成本方法
|
costingMethodList: getDataByType("costingMethod"),
|
// 库存计价
|
inventoryValuationList: getDataByType("inventoryValuation"),
|
memberOptions: [],
|
paymentTypeListOptions: [],
|
showButton: true,
|
showEdit: false, // 是否显示编辑按钮
|
isDelClick: false, // 删除按钮是否可点击
|
showFooter: false, // 是否显示取消保存,
|
statisticsMap: {
|
product: 0 // 产品数量
|
}
|
}
|
},
|
created() {
|
this.setBottonView()
|
this.getProductCount()
|
if (this.editConfig.autoEdit) {
|
this.editClick()
|
}
|
this.setOptionalFieldsToEmpty()
|
},
|
methods: {
|
/**
|
* 非必填项后端返回的是数字 0,表单需要空串才能视为未选择回显
|
*/
|
setOptionalFieldsToEmpty() {
|
let arr = ["parentId", "costingMethod", "inventoryValuation", "forceRemovalStrategy"]
|
arr
|
.filter((filed) => this.editConfig.infomation[filed] === 0)
|
.forEach((filed) => {
|
this.editConfig.infomation[filed] = ""
|
})
|
},
|
/**
|
* 后端只接受数字形式, 保存时还得再转回去
|
*/
|
unsetFieldsToNumber() {
|
let arr = ["parentId", "costingMethod", "inventoryValuation", "forceRemovalStrategy"]
|
arr
|
.filter((filed) => this.editConfig.infomation[filed] === "")
|
.forEach((filed) => {
|
this.editConfig.infomation[filed] = 0
|
})
|
},
|
// 获取产品数量
|
getProductCount() {
|
if (this.editConfig.title !== "新建") {
|
getProductList({
|
keyWord: "",
|
categoryId: this.editConfig.title === "新建" ? null : this.editConfig.infomation.id,
|
page: 1,
|
pageSize: 1
|
})
|
.then((res) => {
|
if (res.code === 200) {
|
this.statisticsMap.product = res?.total ?? 0
|
} else {
|
this.statisticsMap.product = 0
|
}
|
})
|
.catch((err) => {
|
console.error(err)
|
this.statisticsMap.product = 0
|
})
|
}
|
},
|
// 设置删除/打印/编辑是否显示
|
setBottonView() {
|
if (this.editConfig.title === "新建") {
|
this.showButton = false
|
this.showEdit = false
|
this.showFooter = true
|
} else {
|
this.showEdit = true
|
this.showFooter = false
|
}
|
},
|
// 关闭
|
handleClose() {
|
this.editConfig.visible = false
|
},
|
// 刪除
|
deleteClick() {
|
let data = JSON.parse(JSON.stringify(this.editConfig.infomation))
|
deleteProductCategory({ id: data.id }).then((res) => {
|
if (res.code === 200) {
|
this.editConfig.visible = false
|
this.$message.success("刪除成功!")
|
this.$emit("refresh")
|
} else {
|
this.$message.warning(res.msg ? res.msg : "删除失败!")
|
}
|
})
|
},
|
// 编辑
|
editClick() {
|
this.showEdit = false
|
this.showButton = false
|
this.showFooter = true
|
},
|
saveParams() {
|
this.unsetFieldsToNumber()
|
let data = JSON.parse(JSON.stringify(this.editConfig.infomation))
|
|
let params = {
|
costingMethod: data.costingMethod,
|
forceRemovalStrategy: data.forceRemovalStrategy,
|
inventoryValuation: data.inventoryValuation,
|
name: data.name,
|
parentId: data.parentId
|
}
|
if (data.id) {
|
params.id = data.id
|
}
|
return params
|
},
|
// 保存
|
saveClick(formName) {
|
this.$refs[formName].validate((valid) => {
|
if (valid) {
|
const params = this.saveParams()
|
if (this.editConfig.title === "新建") {
|
addProductCategory(params).then((res) => {
|
if (res.code === 200) {
|
this.editConfig.visible = false
|
this.$message.success("添加成功!")
|
this.$emit("refresh")
|
} else {
|
this.$message.warning(res.msg ? res.msg : "添加失败!")
|
}
|
})
|
} else {
|
updateProductCategory(params).then((res) => {
|
if (res.code === 200) {
|
this.editConfig.visible = false
|
this.$message.success("编辑成功!")
|
this.$emit("refresh")
|
} else {
|
this.$message.warning(res.msg ? res.msg : "编辑失败!")
|
}
|
})
|
}
|
} else {
|
console.log("error submit")
|
return false
|
}
|
})
|
},
|
// 删除
|
delClick() {},
|
// 产品
|
productClick() {
|
this.$refs.form.validate((valid) => {
|
if (valid) {
|
this.$router.push({
|
path: "/productManage/product",
|
query: {
|
categoryName: this.editConfig.infomation.name,
|
id: this.editConfig.title === "新建" ? "" : this.editConfig.infomation.id
|
}
|
})
|
}
|
})
|
},
|
// 上架规则
|
listingRulesClick() {
|
this.$refs.form.validate((valid) => {
|
if (valid) {
|
this.$router.push({
|
path: "/warehouseManage/listingRules",
|
query: {
|
categoryName: this.editConfig.infomation.name,
|
id: this.editConfig.title === "新建" ? "" : this.editConfig.infomation.id
|
}
|
})
|
}
|
})
|
}
|
}
|
}
|
</script>
|
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
<style lang="scss" scoped>
|
.dialog-header {
|
display: flex;
|
align-items: center;
|
font-size: 14px;
|
color: #333;
|
.header_btns {
|
margin-left: auto;
|
margin-right: 60px;
|
.btn {
|
cursor: no-drop;
|
}
|
}
|
}
|
.content-btn {
|
height: 37px;
|
line-height: 37px;
|
padding-left: 20px;
|
border-bottom: 1px solid #e9e9e9;
|
}
|
.basic-info {
|
height: calc(100% - 80px);
|
overflow: auto;
|
margin: 20px;
|
// border: 1px solid #dcdfe6;
|
// box-shadow: inset 0 0 2px #dee2e6;
|
// -moz-box-shadow: inset 0 0 2px #dee2e6;
|
// -webkit-box-shadow: inset 0 0 2px #dee2e6;
|
.content-number {
|
display: flex;
|
justify-content: right;
|
height: 44px;
|
// border-bottom: 1px solid #e9e9e9;
|
font-size: 13px;
|
.sub-number {
|
width: 12.5%;
|
border-right: 1px solid #e9e9e9;
|
display: flex;
|
padding: 3px 9px;
|
.left {
|
margin-top: 3px;
|
font-size: 22px;
|
font-weight: 600;
|
}
|
.icon-view {
|
transform: rotate(270deg);
|
}
|
.right {
|
margin-left: 6px;
|
.right-label {
|
color: #495057;
|
}
|
.right-one {
|
height: 38px;
|
line-height: 38px;
|
}
|
}
|
}
|
}
|
.basic-info-view {
|
margin-top: 20px;
|
.upload {
|
position: relative;
|
width: 90px;
|
height: 90px;
|
margin-left: 40px;
|
border: 1px dotted #d9d9d9;
|
border-radius: 4px;
|
.upload-icon {
|
position: absolute;
|
top: 40%;
|
right: 43%;
|
}
|
}
|
}
|
.purchase-view {
|
display: flex;
|
.left {
|
width: 50%;
|
}
|
.right {
|
width: 50%;
|
}
|
}
|
.second-label {
|
margin-left: 20px;
|
border-bottom: 1px solid #d9d9d9;
|
margin-bottom: 10px;
|
}
|
.list-item {
|
width: 300px;
|
}
|
.avatar-uploader .el-upload {
|
border: 1px dashed #d9d9d9;
|
border-radius: 6px;
|
cursor: pointer;
|
position: relative;
|
overflow: hidden;
|
}
|
.avatar-uploader .el-upload:hover {
|
border-color: #409eff;
|
}
|
.avatar-uploader-icon {
|
font-size: 28px;
|
color: #8c939d;
|
width: 178px;
|
height: 178px;
|
line-height: 178px;
|
text-align: center;
|
}
|
.avatar {
|
width: 178px;
|
height: 178px;
|
display: block;
|
}
|
}
|
::v-deep {
|
.el-dialog__headerbtn {
|
position: absolute;
|
top: 18px;
|
}
|
.el-button {
|
&:hover {
|
border: 1px solid #dcdfe6;
|
color: #333;
|
}
|
}
|
.el-tabs--card > .el-tabs__header {
|
border-bottom: none;
|
}
|
.el-tabs__item.is-active {
|
color: #fff;
|
background: #2a78fb;
|
}
|
.el-tabs__item {
|
height: 30px;
|
line-height: 30px;
|
font-size: 13px;
|
background: #f3f3f3;
|
}
|
}
|
</style>
|