<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"
|
>
|
<el-form
|
ref="form"
|
:model="editConfig.infomation"
|
:rules="rules"
|
label-position="right"
|
label-width="308px"
|
size="mini"
|
>
|
<!-- 信息 -->
|
<div class="basic-info">
|
<!-- 基本信息 -->
|
<div class="basic-info-title">基本信息</div>
|
<div class="basic-info-view">
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="产品编号" prop="number">
|
<el-input v-model="editConfig.infomation.number"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="产品名称" prop="product_name">
|
<el-input v-model="editConfig.infomation.name"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="产品类别" prop="supplierType_id">
|
<div class="custom-name">
|
<el-select
|
v-model="editConfig.infomation.supplierType_id"
|
placeholder="请选择产品类别"
|
class="common-select-sel"
|
size="mini"
|
>
|
<el-option v-for="item in supplierTypeOptions" :key="item.id" :label="item.name" :value="item.id">
|
</el-option>
|
</el-select>
|
<div class="common-select-btn" @click="setProductType"><i class="el-icon-setting"></i></div>
|
</div>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="供应商" prop="supplier_name">
|
<div class="custom-name">
|
<el-autocomplete
|
v-model="editConfig.infomation.supplier_name"
|
:fetch-suggestions="querySearchAsync"
|
value-key="name"
|
@select="handleSelectClient"
|
></el-autocomplete>
|
<div class="common-select-btn" @click="selClientClick">
|
<i class="el-icon-circle-plus-outline" title="选择"></i>
|
</div>
|
<div class="common-select-btn" @click="clearupClient">
|
<i class="el-icon-edit-outline" title="清除"></i>
|
</div>
|
</div>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="规格" prop="supplier_name">
|
<el-input v-model="editConfig.infomation.name"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="型号" prop="supplier_name">
|
<el-input v-model="editConfig.infomation.name"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="单位" prop="industry_id">
|
<div class="custom-name">
|
<el-select
|
v-model="editConfig.infomation.industry_id"
|
placeholder="请选择供应商行业"
|
class="common-select-sel"
|
size="mini"
|
>
|
<el-option v-for="item in industryOptions" :key="item.id" :label="item.name" :value="item.id">
|
</el-option>
|
</el-select>
|
<div class="common-select-btn" @click="setUnit"><i class="el-icon-setting"></i></div>
|
</div>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="价格" prop="amount">
|
<el-input-number
|
v-model="editConfig.infomation.amount"
|
placeholder="请输入"
|
:min="0"
|
:precision="2"
|
:controls="false"
|
style="width: 100%; margin-right: 5px"
|
></el-input-number>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="最低库存" prop="phone">
|
<el-input-number
|
v-model="editConfig.infomation.projected_amount"
|
placeholder="请输入"
|
:min="0"
|
:controls="false"
|
style="width: 100%; margin-right: 5px"
|
></el-input-number>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="最高库存" prop="phone">
|
<el-input-number
|
v-model="editConfig.infomation.projected_amount"
|
placeholder="请输入"
|
:min="0"
|
:controls="false"
|
style="width: 100%; margin-right: 5px"
|
></el-input-number>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="图片" prop="phone">
|
<div class="bigImg-div" @click="toGetImg">
|
<i class="el-icon-plus icon" v-if="!valueUrl"></i>
|
<img class="bigImg" :src="valueUrl" v-if="valueUrl" />
|
</div>
|
</el-form-item>
|
</el-col>
|
<el-col :span="24">
|
<el-form-item label="备注信息" prop="desc">
|
<el-input
|
type="textarea"
|
:autosize="{ minRows: 2, maxRows: 4 }"
|
placeholder="请输入内容"
|
v-model="editConfig.infomation.desc"
|
></el-input>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</div>
|
</div>
|
</el-form>
|
<div slot="footer" class="dialog-footer">
|
<el-button type="primary" size="small" @click="saveClick('form')">保 存</el-button>
|
<el-button size="small" @click="editConfig.visible = false">取 消</el-button>
|
</div>
|
</el-dialog>
|
<!-- 编辑下拉框 -->
|
<EditDropdownDialog v-if="editDropdownConfig.editVisible" :edit-dropdown-config="editDropdownConfig" />
|
</div>
|
</template>
|
|
<script>
|
let inputElement = null
|
import EditDropdownDialog from "@/views/other/commonDialog/EditDropdownDialog"
|
export default {
|
name: "AddProductDialog",
|
props: {
|
addCommonConfig: {
|
type: Object,
|
default: () => {
|
return {
|
visible: false,
|
title: "新建",
|
infomation: {}
|
}
|
}
|
}
|
},
|
components: { EditDropdownDialog },
|
computed: {},
|
data() {
|
return {
|
dialogWidth: "80%",
|
editConfig: this.addCommonConfig,
|
rules: {
|
supplier_name: [{ required: true, message: "请输入", trigger: "blur" }],
|
product_name: [{ required: true, message: "请选择", trigger: "change" }]
|
},
|
supplierTypeOptions: [], // 供应商类型
|
industryOptions: [], // 所属行业
|
memberOptions: [],
|
editDropdownConfig: {
|
editVisible: false,
|
title: "",
|
infomation: {}
|
},
|
supplierId: this.addCommonConfig.infomation.supplierId,
|
valueUrl: ""
|
}
|
},
|
created() {
|
if (this.editConfig.title !== "新建" && this.editConfig.infomation.province_id !== 0) {
|
this.getCityList(this.editConfig.infomation.province_id, "edit")
|
}
|
},
|
methods: {
|
handleClose() {
|
this.editConfig.visible = false
|
},
|
// 保存
|
saveClick(formName) {
|
this.$refs[formName].validate((valid) => {
|
if (valid) {
|
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()
|
// }
|
// })
|
}
|
} else {
|
console.log("error submit")
|
return false
|
}
|
})
|
},
|
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.supplierId || 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
|
},
|
// 添加附件
|
addAnnexClick() {},
|
// 设置产品类别
|
setProductType() {
|
this.editDropdownConfig.editVisible = true
|
this.editDropdownConfig.title = "产品类别"
|
},
|
// 设置单位
|
setUnit() {
|
this.editDropdownConfig.editVisible = true
|
this.editDropdownConfig.title = "单位"
|
},
|
// 选择客户相关方法
|
querySearchAsync(queryString, cb) {
|
var restaurants = this.clientList
|
var results = queryString ? restaurants.filter(this.createStateFilter(queryString)) : restaurants
|
cb(results)
|
},
|
createStateFilter(queryString) {
|
return (state) => {
|
return state.name.toLowerCase().indexOf(queryString.toLowerCase()) === 0
|
}
|
},
|
handleSelectClient(item) {
|
this.supplierId = item.id
|
},
|
selClientClick() {
|
this.editSelectClientConfig.editVisible = true
|
},
|
selClient(row) {
|
console.log(row)
|
this.editConfig.infomation.product_name = row.name
|
this.supplierId = row.id
|
},
|
// 清除已选择用户
|
clearupClient() {
|
this.editConfig.infomation.product_name = ""
|
this.supplierId = 0
|
},
|
// 上传图片
|
toGetImg() {
|
if (inputElement === null) {
|
// 生成文件上传的控件
|
inputElement = document.createElement("input")
|
inputElement.setAttribute("type", "file")
|
inputElement.style.display = "none"
|
|
if (window.addEventListener) {
|
inputElement.addEventListener("change", this.uploadFile, false)
|
} else {
|
inputElement.attachEvent("onchange", this.uploadFile)
|
}
|
|
document.body.appendChild(inputElement)
|
}
|
inputElement.click()
|
},
|
uploadFile(el) {
|
if (el && el.target && el.target.files && el.target.files.length > 0) {
|
console.log(el)
|
const files = el.target.files[0]
|
const isLt2M = files.size / 1024 / 1024 < 2
|
const size = files.size / 1024 / 1024
|
console.log(size)
|
// 判断上传文件的大小
|
if (!isLt2M) {
|
this.$message.error("上传头像图片大小不能超过 2MB!")
|
} else if (files.type.indexOf("image") === -1) {
|
//如果不是图片格式
|
// this.$dialog.toast({ mes: '请选择图片文件' });
|
this.$message.error("请选择图片文件")
|
} else {
|
const that = this
|
const reader = new FileReader() // 创建读取文件对象
|
reader.readAsDataURL(el.target.files[0]) // 发起异步请求,读取文件
|
reader.onload = function () {
|
// 文件读取完成后
|
// 读取完成后,将结果赋值给img的src
|
that.valueUrl = this.result
|
console.log(this.result)
|
}
|
}
|
}
|
}
|
}
|
}
|
</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;
|
padding-right: 40px;
|
.custom-name,
|
.common-select {
|
display: flex;
|
.common-select-btn {
|
margin-left: 5px;
|
font-size: 18px;
|
cursor: pointer;
|
}
|
}
|
.common-select {
|
.common-select-sel {
|
width: 270px;
|
}
|
}
|
}
|
.bigImg-div {
|
width: 100px;
|
height: 100px;
|
line-height: 100px;
|
text-align: center;
|
overflow: hidden;
|
border: 1px solid #ddd;
|
.icon {
|
font-size: 16px;
|
}
|
.bigImg {
|
display: block;
|
width: 100px;
|
height: 100px;
|
}
|
}
|
}
|
.dialog-footer {
|
background-color: #f5f5f5;
|
height: 55px;
|
line-height: 55px;
|
}
|
.el-input__inner {
|
text-align: left;
|
}
|
}
|
}
|
</style>
|