<template>
|
<div class="add-common">
|
<el-dialog
|
:title="addCommonConfig.title + '提供的产品'"
|
:visible.sync="editConfig.visible"
|
:width="dialogWidth"
|
:before-close="handleClose"
|
:close-on-click-modal="false"
|
append-to-body
|
custom-class="iframe-dialog"
|
>
|
<div class="basic-info">
|
<!-- 产品信息 -->
|
<div class="basic-info-title">产品信息</div>
|
<div class="basic-info-view">
|
<CommonFormTableView
|
ref="productTable"
|
:addTypeIdMultiple="true"
|
:product-table-list="productTableList"
|
:detail-enter="detailEnter"
|
:isOperate="isOperate"
|
@inputContent="inputContent"
|
@addProductClick="addProductClick"
|
@getSelectArray="getSelectArray"
|
@emptyProductClick="emptyProductClick"
|
@clearupProduct="clearupProduct"
|
@selCommonName="selCommonName"
|
@handleProduct="handleProduct"
|
/>
|
</div>
|
</div>
|
<div slot="footer" class="dialog-footer">
|
<el-button type="primary" size="small" @click="saveClick">保 存</el-button>
|
<el-button size="small" @click="editConfig.visible = false">取 消</el-button>
|
</div>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script>
|
import { createProduct, updateProduct } from "@/api/productManage/product"
|
import CommonFormTableView from "@/components/makepager/CommonFormTableView"
|
export default {
|
name: "AddNewProduct",
|
props: {
|
addCommonConfig: {
|
type: Object,
|
default: () => {
|
return {
|
visible: false,
|
title: "添加",
|
infomation: {}
|
}
|
}
|
}
|
},
|
components: { CommonFormTableView },
|
computed: {},
|
data() {
|
return {
|
dialogWidth: "60%",
|
editConfig: this.addCommonConfig,
|
productTableList: {},
|
tableData: [],
|
productId: 1,
|
isNoProduct: true,
|
supplierId: this.addCommonConfig.infomation.supplierId,
|
detailEnter: true,
|
isOperate: true,
|
deliveryTime: this.addCommonConfig.infomation.deliveryTime, // 供货时长
|
shippingDuration: this.addCommonConfig.infomation.shippingDuration, // 物流时长
|
purchasePrice: this.addCommonConfig.infomation.purchasePrice // 采购价格
|
}
|
},
|
created() {
|
// if (this.editConfig.title !== "添加" && this.editConfig.infomation.province_id !== 0) {
|
// this.getCityList(this.editConfig.infomation.province_id, "edit")
|
// }
|
this.setTableForm()
|
},
|
methods: {
|
handleClose() {
|
this.editConfig.visible = false
|
},
|
// 保存
|
saveClick() {
|
this.$refs.productTable.$refs.form.validate((valid) => {
|
if (valid) {
|
console.log(this.editConfig.infomation)
|
for (let i = 0; i < this.tableData.length; i++) {
|
if (this.tableData[i].name.length === 0) {
|
this.isNoProduct = true
|
break
|
} else {
|
this.isNoProduct = false
|
}
|
}
|
if (this.isNoProduct) {
|
this.$message.error("产品名称不能为空")
|
} else {
|
if (this.editConfig.title === "添加") {
|
createProduct({
|
list: this.tableData
|
})
|
.then((res) => {
|
console.log(res)
|
this.editConfig.visible = false
|
if (res.code === 200) {
|
this.$message.success("添加成功")
|
this.$parent.getProductList()
|
}
|
})
|
.catch((e) => {
|
console.log(e)
|
})
|
} else {
|
const params = this.saveParams()
|
updateProduct(params).then((res) => {
|
console.log(res)
|
this.editConfig.visible = false
|
if (res.code === 200) {
|
this.$message.success("编辑成功")
|
this.$parent.getProductList()
|
}
|
})
|
}
|
}
|
}
|
})
|
},
|
saveParams() {
|
let data = this.editConfig.infomation
|
let params = {
|
deliveryTime: this.deliveryTime || 0,
|
id: data.id || 0,
|
// maximumStock: data.maximumStock || 0,
|
// minimumStock: data.minimumStock || 0,
|
// modelNumber: data.modelNumber || "",
|
// name: data.name || "",
|
// number: data.number || "",
|
// productType: data.productType || "",
|
purchasePrice: this.purchasePrice || 0,
|
// remark: data.remark || "",
|
shippingDuration: this.shippingDuration || 0,
|
// specifications: data.specifications || "",
|
supplierId: this.supplierId || 0,
|
// unit: data.unit || ""
|
...this.tableData[0]
|
}
|
return params
|
},
|
handleProduct(item, row) {
|
this.editConfig.infomation.id = row.id
|
},
|
setTableForm() {
|
if (this.editConfig.title === "添加") {
|
this.detailEnter = false
|
this.tableData = [
|
{
|
productId: this.productId,
|
id: 0,
|
amount: 0,
|
desc: "",
|
name: "",
|
number: "",
|
price: 0,
|
total: 0,
|
supplierId: this.supplierId
|
}
|
]
|
} else {
|
this.tableData = [{ ...this.editConfig.infomation }]
|
this.detailEnter = true
|
}
|
this.productTableList = {
|
tableData: this.tableData,
|
isReturn: true,
|
tableColumn: [
|
{ label: "产品名称", prop: "name", productName: true, isRequird: true, width: 250 },
|
{ label: "产品编码", prop: "number" },
|
{ label: "计量单位", prop: "unit" },
|
{ label: "规格型号", prop: "specifications" },
|
{ label: "采购价格", prop: "purchasePrice", inputFloat: true, isRequird: true },
|
{ label: "供货时长", prop: "deliveryTime", inputNumber: true, isRequird: true },
|
{ label: "物流时长", prop: "shippingDuration", inputNumber: true, isRequird: true }
|
]
|
}
|
},
|
// 产品列表输入
|
inputContent(val, prop, row) {
|
this.tableData.map((item) => {
|
if (item.number == row.number) {
|
item[prop] = val
|
item.supplierId = Number(this.supplierId)
|
}
|
})
|
},
|
// 产品新增
|
addProductClick() {
|
// this.productId++
|
// this.tableData.push({
|
// productId: this.productId,
|
// id: 0,
|
// amount: 0,
|
// desc: "",
|
// name: "",
|
// number: "",
|
// purchasePrice: 0,
|
// total: 0,
|
// deliveryTime: 0,
|
// shippingDuration: 0,
|
// supplierId: this.supplierId
|
// })
|
},
|
// 新增方式修改
|
getSelectArray(val, index) {
|
console.log(val, "ddd99999")
|
if (this.tableData.length == 1 && this.tableData[0].number.length == 0) {
|
this.tableData = []
|
}
|
if (index < this.tableData.length) {
|
this.tableData.splice(index, 1)
|
val.map((item, ind) => {
|
this.tableData.splice(index + ind, 0, item)
|
})
|
} else {
|
this.tableData = this.tableData.concat(val)
|
}
|
this.productTableList.tableData = this.tableData
|
// this.showSummary.show = true
|
},
|
// 产品清空
|
emptyProductClick() {
|
this.productId = 1
|
this.tableData = [
|
{
|
productId: this.productId,
|
id: 0,
|
amount: 0,
|
desc: "",
|
name: "",
|
number: "",
|
purchasePrice: 0,
|
total: 0,
|
deliveryTime: 0,
|
shippingDuration: 0,
|
supplierId: this.supplierId
|
}
|
]
|
this.productTableList.tableData = this.tableData
|
},
|
// 产品清除
|
clearupProduct(data) {
|
this.tableData = data
|
this.productTableList.tableData = this.tableData
|
},
|
selCommonName(row) {
|
console.log("1133")
|
console.log(row)
|
this.editConfig.infomation = row
|
}
|
}
|
}
|
</script>
|
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
<style lang="scss" scoped>
|
::v-deep {
|
.iframe-dialog .el-dialog__body {
|
.basic-info {
|
.basic-info-title {
|
background-color: #f4f8fe;
|
padding-left: 10px;
|
font-size: 15px;
|
font-weight: bold;
|
color: #666;
|
height: 42px;
|
line-height: 42px;
|
}
|
.basic-info-view {
|
margin-top: 10px;
|
}
|
}
|
.dialog-footer {
|
background-color: #f5f5f5;
|
height: 55px;
|
line-height: 55px;
|
}
|
}
|
}
|
</style>
|