<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
|
:product-table-list="productTableList"
|
@inputContent="inputContent"
|
@addProductClick="addProductClick"
|
@emptyProductClick="emptyProductClick"
|
@clearupProduct="clearupProduct"
|
/>
|
</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 { getAddContact, getUpdateContact } from "@/api/client/contacts"
|
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: "80%",
|
editConfig: this.addCommonConfig,
|
productTableList: {},
|
tableData: [],
|
productId: 1,
|
isNoProduct: true
|
}
|
},
|
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() {
|
console.log(this.editConfig.infomation)
|
const params = this.saveParams()
|
console.log(params)
|
if (this.editConfig.title === "添加") {
|
getAddContact(params).then((res) => {
|
console.log(res)
|
this.editConfig.visible = false
|
if (res.code === 200) {
|
this.$message.success("添加成功")
|
this.$parent.getData()
|
}
|
})
|
} else {
|
getUpdateContact(params).then((res) => {
|
console.log(res)
|
this.editConfig.visible = false
|
if (res.code === 200) {
|
this.$message.success("编辑成功")
|
this.$parent.getData()
|
}
|
})
|
}
|
},
|
saveParams() {
|
let data = this.editConfig.infomation
|
let params = {
|
id: this.editConfig.title === "添加" ? 0 : data.id,
|
birthday: data.birthday || "",
|
city_id: data.city_id || 0,
|
client_id: this.clientId || 0,
|
country_id: data.country_id || 0,
|
desc: data.desc || "",
|
email: data.email || "",
|
is_first: data.is_first || false,
|
member_id: data.member_id || 0,
|
name: data.name || "",
|
number: data.number || "",
|
phone: data.phone || "",
|
position: data.position || "",
|
province_id: data.province_id || 0,
|
region_id: data.region_id || 0,
|
wechat: data.wechat || ""
|
}
|
return params
|
},
|
setTableForm() {
|
if (this.editConfig.title === "添加" || this.editConfig.infomation.products.length === 0) {
|
this.tableData = [
|
{
|
productId: this.productId,
|
id: 0,
|
amount: 0,
|
desc: "",
|
name: "",
|
number: "",
|
price: 0,
|
total: 0
|
}
|
]
|
} else {
|
this.tableData = this.editConfig.infomation.products
|
this.tableData.map((item, index) => {
|
item.productId = index + 1
|
})
|
}
|
this.productTableList = {
|
tableData: this.tableData,
|
tableColumn: [
|
{ label: "产品名称", prop: "name", productName: true, isRequird: true },
|
{ label: "产品编码", prop: "number" },
|
{ label: "计量单位", prop: "number" },
|
{ label: "规格型号", prop: "number" },
|
{ label: "采购价格", prop: "amount", inputFloat: true, isRequird: true },
|
{ label: "供货时长", prop: "price", inputNumber: true, isRequird: true },
|
{ label: "物流时长", prop: "total", inputNumber: true, isRequird: true }
|
]
|
}
|
},
|
// 产品列表输入
|
inputContent(val, prop, row) {
|
this.productId = row.productId
|
this.tableData.map((item) => {
|
if (item.productId === row.productId) {
|
item[prop] = val
|
}
|
})
|
},
|
// 产品新增
|
addProductClick() {
|
this.productId++
|
this.tableData.push({
|
productId: this.productId,
|
id: 0,
|
amount: 0,
|
desc: "",
|
name: "",
|
number: "",
|
price: 0,
|
total: 0
|
})
|
},
|
// 产品清空
|
emptyProductClick() {
|
this.productId = 1
|
this.tableData = [
|
{
|
productId: this.productId,
|
id: 0,
|
amount: 0,
|
desc: "",
|
name: "",
|
number: "",
|
price: 0,
|
total: 0
|
}
|
]
|
this.productTableList.tableData = this.tableData
|
},
|
// 产品清除
|
clearupProduct(data) {
|
this.tableData = data
|
this.productTableList.tableData = this.tableData
|
}
|
}
|
}
|
</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>
|