|
|
|
|
@ -17,9 +17,19 @@
|
|
|
|
|
<el-switch v-model="form['status']" :active-value="1" :inactive-value="0" active-text="启用"
|
|
|
|
|
inactive-text="禁用" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
<el-form-item label="站点产品价格" prop="accompany_product_site">
|
|
|
|
|
<div v-for="(item, index) in accompany_product_site" :key="index" style="display: flex; align-items: center;">
|
|
|
|
|
<vxe-tree-select v-model="item.site_id" placeholder="请选择站点" :options="siteType" clearable
|
|
|
|
|
:multiple="false" :option-props="{ value: 'id', label: 'name' }" style="width: 45%;" />
|
|
|
|
|
<el-input v-model="item.price" placeholder="请输入价格" style="width: 45%; margin-left: 10px;" />
|
|
|
|
|
<el-button type="danger" icon="el-icon-delete" @click="removeProductSite(index)" style="margin-left: 10px;"></el-button>
|
|
|
|
|
</div>
|
|
|
|
|
<el-button type="primary" @click="addProductSite">添加站点产品价格</el-button>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="关联站点" prop="site_id">
|
|
|
|
|
<vxe-tree-select v-model="form['site_id']" placeholder="请选择关联站点" :options="siteType" clearable
|
|
|
|
|
:multiple="true" :option-props="{ value: 'id', label: 'name' }" style="width: 100%;" />
|
|
|
|
|
:multiple="true" :option-props="{ value: 'id', label: 'name' }" style="width: 100%;" disabled />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="标题图片" prop="cover_id">
|
|
|
|
|
<el-upload :action="action" :file-list="coverList"
|
|
|
|
|
@ -78,7 +88,8 @@
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import {
|
|
|
|
|
save
|
|
|
|
|
save,
|
|
|
|
|
show
|
|
|
|
|
} from '@/api/accompany/accompany'
|
|
|
|
|
import {
|
|
|
|
|
getToken
|
|
|
|
|
@ -113,7 +124,9 @@
|
|
|
|
|
visible: false,
|
|
|
|
|
coverList:[],
|
|
|
|
|
imageList:[],
|
|
|
|
|
accompany_product_site:[],
|
|
|
|
|
form: {
|
|
|
|
|
id:'',
|
|
|
|
|
type: 1,
|
|
|
|
|
name: '',
|
|
|
|
|
price: '',
|
|
|
|
|
@ -126,13 +139,17 @@
|
|
|
|
|
flow_content: '',
|
|
|
|
|
price_content: '',
|
|
|
|
|
appoint_content: '',
|
|
|
|
|
|
|
|
|
|
accompany_product_site: [],
|
|
|
|
|
},
|
|
|
|
|
rules: {
|
|
|
|
|
|
|
|
|
|
name: [{
|
|
|
|
|
'required': true,
|
|
|
|
|
'message': '产品名称必填'
|
|
|
|
|
}],
|
|
|
|
|
accompany_product_site: [{
|
|
|
|
|
'required': true,
|
|
|
|
|
'message': '站点产品价格必填'
|
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@ -144,6 +161,7 @@
|
|
|
|
|
if(!newVal){
|
|
|
|
|
this.coverList = []
|
|
|
|
|
this.imageList = []
|
|
|
|
|
this.accompany_product_site = []
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
visible(newVal) {
|
|
|
|
|
@ -213,7 +231,9 @@
|
|
|
|
|
reset() {
|
|
|
|
|
this.coverList = []
|
|
|
|
|
this.imageList = []
|
|
|
|
|
this.accompany_product_site = []
|
|
|
|
|
this.form = {
|
|
|
|
|
id:'',
|
|
|
|
|
name: '',
|
|
|
|
|
site_id: '',
|
|
|
|
|
cover_id: '',
|
|
|
|
|
@ -224,48 +244,104 @@
|
|
|
|
|
flow_content: '',
|
|
|
|
|
price_content: '',
|
|
|
|
|
appoint_content: '',
|
|
|
|
|
accompany_product_site: [],
|
|
|
|
|
price: '',
|
|
|
|
|
}
|
|
|
|
|
this.$refs['elForm'].resetFields()
|
|
|
|
|
},
|
|
|
|
|
async getDetail(id) {
|
|
|
|
|
try {
|
|
|
|
|
const detail = await show({
|
|
|
|
|
id,
|
|
|
|
|
show_relation: ['cover', 'accompanyProductSite']
|
|
|
|
|
});
|
|
|
|
|
console.log('Detail fetched:', detail); // Log the response
|
|
|
|
|
for (const key in this.form) {
|
|
|
|
|
if (detail.hasOwnProperty(key)) {
|
|
|
|
|
this.form[key] = detail[key];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.form.id = id;
|
|
|
|
|
// Handle specific fields like images if necessary
|
|
|
|
|
if (detail['images']) {
|
|
|
|
|
this.imageList = detail['images'];
|
|
|
|
|
}
|
|
|
|
|
if(detail['cover']){
|
|
|
|
|
this.coverList = [detail['cover']]
|
|
|
|
|
}
|
|
|
|
|
this.accompany_product_site = detail['accompany_product_site'] || [];
|
|
|
|
|
this.form.site_id = this.form.site_id?this.form.site_id.split(",") : [];
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
submit() {
|
|
|
|
|
if (window.$_uploading) {
|
|
|
|
|
this.$message.warning('文件正在上传中')
|
|
|
|
|
return
|
|
|
|
|
this.$message.warning('文件正在上传中');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (this.accompany_product_site.some(item => !item.site_id || !item.price)) {
|
|
|
|
|
this.$message.error('站点和价格不能为空');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const siteIds = this.accompany_product_site.map(item => item.site_id);
|
|
|
|
|
const hasDuplicateSiteId = siteIds.some((id, index) => siteIds.indexOf(id) !== index);
|
|
|
|
|
if (hasDuplicateSiteId) {
|
|
|
|
|
this.$message.error('站点ID不能重复');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.form.site_id = siteIds.join(",");
|
|
|
|
|
this.form.accompany_product_site = this.accompany_product_site;
|
|
|
|
|
// Ensure ID is included
|
|
|
|
|
if (this.form.id) {
|
|
|
|
|
this.form.id = this.form.id;
|
|
|
|
|
}
|
|
|
|
|
this.form['cover_id'] = ''
|
|
|
|
|
if(this.coverList.length>0){
|
|
|
|
|
this.form['cover_id'] = this.coverList[0]?.response?.id ?? ''
|
|
|
|
|
if(this.coverList[0]?.response?.id){
|
|
|
|
|
this.form['cover_id'] = this.coverList[0]?.response?.id
|
|
|
|
|
}else{
|
|
|
|
|
this.form['cover_id'] = this.coverList[0].id
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
this.form['cover_id'] = ''
|
|
|
|
|
}
|
|
|
|
|
this.form['images_ids'] = []
|
|
|
|
|
if(this.imageList.length>0){
|
|
|
|
|
this.imageList.map(item=>{
|
|
|
|
|
this.form.images_ids.push(item?.response?.id ?? '')
|
|
|
|
|
if(item.response?.id){
|
|
|
|
|
this.form['images_ids'].push(item.response.id)
|
|
|
|
|
}else{
|
|
|
|
|
this.form['images_ids'].push(item.id)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}else{
|
|
|
|
|
this.form['images_ids'] = []
|
|
|
|
|
}
|
|
|
|
|
if(this.form.site_id.length>0){
|
|
|
|
|
this.form.site_id = this.form.site_id.join(",")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log("this.form",this.form)
|
|
|
|
|
console.log("this.form", this.form,this.imageList,this.coverList);
|
|
|
|
|
// return
|
|
|
|
|
this.$refs['elForm'].validate(async valid => {
|
|
|
|
|
if (valid) {
|
|
|
|
|
this.loading = true
|
|
|
|
|
this.loading = true;
|
|
|
|
|
try {
|
|
|
|
|
await save(this.form)
|
|
|
|
|
this.$message.success('新增成功')
|
|
|
|
|
this.$emit('refresh')
|
|
|
|
|
this.$emit('update:isShow', false)
|
|
|
|
|
this.loading = false
|
|
|
|
|
this.reset()
|
|
|
|
|
await save(this.form);
|
|
|
|
|
this.$message.success('新增成功');
|
|
|
|
|
this.$emit('refresh');
|
|
|
|
|
this.$emit('update:isShow', false);
|
|
|
|
|
this.loading = false;
|
|
|
|
|
this.reset();
|
|
|
|
|
} catch (err) {
|
|
|
|
|
this.loading = false
|
|
|
|
|
this.loading = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
addProductSite() {
|
|
|
|
|
const price = this.form['price'] || '';
|
|
|
|
|
this.accompany_product_site.push({ site_id: '', price });
|
|
|
|
|
},
|
|
|
|
|
removeProductSite(index) {
|
|
|
|
|
this.accompany_product_site.splice(index, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|