|
|
<template>
|
|
|
<div>
|
|
|
<xy-dialog ref="dialog" :is-show.sync="isShow" type="form" :title="type === 'add' ? '新增线路' : '编辑线路'"
|
|
|
:form="form" :rules="rules" @submit="submit">
|
|
|
<template v-slot:activity_list_id>
|
|
|
<div class="xy-table-item">
|
|
|
<div class="xy-table-item-label">
|
|
|
<span style="color: red; font-weight: 600; padding-right: 4px">*</span>
|
|
|
项目 :
|
|
|
</div>
|
|
|
<div class="xy-table-item-content">
|
|
|
<el-select :disabled="hasActiveId" style="width: 300px" @change="changeActive" v-model="form.activity_list_id" placeholder="请选择">
|
|
|
<el-option
|
|
|
v-for="item in listActivity"
|
|
|
:key="item.id"
|
|
|
:label="item.name"
|
|
|
:value="item.id">
|
|
|
</el-option>
|
|
|
</el-select>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
<template v-slot:name>
|
|
|
<div class="xy-table-item">
|
|
|
<div class="xy-table-item-label">
|
|
|
<span style="color: red; font-weight: 600; padding-right: 4px">*</span>
|
|
|
名称 :
|
|
|
</div>
|
|
|
<div class="xy-table-item-content">
|
|
|
<el-input v-model="form.name" clearable placeholder="请输入名称" style="width: 300px"></el-input>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
<template v-slot:sort>
|
|
|
<div class="xy-table-item">
|
|
|
<div class="xy-table-item-label">
|
|
|
<span style="color: red; font-weight: 600; padding-right: 4px">*</span>
|
|
|
排序 :
|
|
|
</div>
|
|
|
<div class="xy-table-item-content">
|
|
|
<el-input v-model="form.sort" clearable placeholder="请输入排序" style="width: 300px"></el-input>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
<template v-slot:pointer_list>
|
|
|
<div class="xy-table-item">
|
|
|
<div class="xy-table-item-label">点位 :</div>
|
|
|
<div class="xy-table-item-content">
|
|
|
<el-select v-model="form.pointer_list" style="width: 300px" multiple placeholder="请选择">
|
|
|
<el-option
|
|
|
v-for="item in listPointer"
|
|
|
:key="item.id"
|
|
|
:label="item.name"
|
|
|
:value="item.id">
|
|
|
</el-option>
|
|
|
</el-select>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
<template v-slot:image_id>
|
|
|
<div class="xy-table-item">
|
|
|
<div class="xy-table-item-label">封面图 :</div>
|
|
|
<div class="xy-table-item-content">
|
|
|
<el-upload style="width: 300px" class="upload-demo" :action="action" :on-success="
|
|
|
(response, file, fileList) =>
|
|
|
successHandle(response, file, fileList, 'image_id')
|
|
|
" :before-upload="uploadBefore" :file-list="image_id" :on-remove="
|
|
|
(file, fileList) => removeHande(file, fileList, 'image_id')
|
|
|
" :limit="1" list-type="picture-card">
|
|
|
<i slot="default" class="el-icon-plus"></i>
|
|
|
<div slot="tip" class="el-upload__tip">
|
|
|
只能上传jpg/png文件,且不超过500kb
|
|
|
</div>
|
|
|
</el-upload>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
<template v-slot:content>
|
|
|
<div class="xy-table-item">
|
|
|
<div class="xy-table-item-label">简介 :</div>
|
|
|
<div class="xy-table-item-content">
|
|
|
<el-input v-model="form.content" style="width: 300px" type="textarea"></el-input>
|
|
|
<!-- <tinymce style="width: 700px;" v-model="form.content"></tinymce> -->
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
</xy-dialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import {
|
|
|
show,
|
|
|
save
|
|
|
} from "@/api/index";
|
|
|
import { index as activityIndex } from "@/api/activity/index";
|
|
|
import { index as pointerIndex } from "@/api/index";
|
|
|
import tinymce from "@/components/XyTinymce"
|
|
|
export default {
|
|
|
components: {
|
|
|
tinymce
|
|
|
},
|
|
|
props: {},
|
|
|
data() {
|
|
|
return {
|
|
|
isShow: false,
|
|
|
hasActiveId:false,
|
|
|
id: "",
|
|
|
type: "",
|
|
|
image_id: [],
|
|
|
action: process.env.VUE_APP_UPLOAD_API,
|
|
|
listActivity:[],
|
|
|
listPointer:[],
|
|
|
form: {
|
|
|
activity_list_id: '',
|
|
|
name: "",
|
|
|
sort:0,
|
|
|
pointer_list:[],
|
|
|
image_id: "",
|
|
|
content: "",
|
|
|
},
|
|
|
rules: {
|
|
|
name: [{
|
|
|
required: true,
|
|
|
message: "请填写名称",
|
|
|
}, ],
|
|
|
},
|
|
|
};
|
|
|
},
|
|
|
created(){
|
|
|
// this.loadActivity()
|
|
|
},
|
|
|
methods: {
|
|
|
async load() {
|
|
|
if(!this.form.activity_list_id){
|
|
|
this.$message({
|
|
|
type:'warning',
|
|
|
message:'请先选择项目,获取点位'
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
const res =await pointerIndex({
|
|
|
page: 1,
|
|
|
page_size: 999,
|
|
|
table_name: "map_points",
|
|
|
activity_list_id: this.form.activity_list_id,
|
|
|
});
|
|
|
this.listPointer = res.data;
|
|
|
},
|
|
|
async loadActivity() {
|
|
|
const res = await activityIndex({
|
|
|
page: 1,
|
|
|
page_size: 999,
|
|
|
});
|
|
|
this.listActivity = res.data;
|
|
|
},
|
|
|
show() {
|
|
|
this.isShow = true;
|
|
|
},
|
|
|
hidden() {
|
|
|
this.isShow = false;
|
|
|
},
|
|
|
init() {
|
|
|
for (let key in this.form) {
|
|
|
if (this.form[key] instanceof Array) {
|
|
|
this.form[key] = [];
|
|
|
} else {
|
|
|
this.form[key] = "";
|
|
|
}
|
|
|
}
|
|
|
this.$refs["dialog"].clearValidate();
|
|
|
},
|
|
|
setId(id) {
|
|
|
if (typeof id == "number") {
|
|
|
this.id = id;
|
|
|
} else {
|
|
|
console.error("error typeof id: " + typeof id);
|
|
|
}
|
|
|
},
|
|
|
setList(e){
|
|
|
if(e){
|
|
|
this.listActivity = e
|
|
|
}else{
|
|
|
this.loadActivity()
|
|
|
}
|
|
|
},
|
|
|
changeActive(e){
|
|
|
if(e){
|
|
|
this.form.activity_list_id = e
|
|
|
this.load()
|
|
|
}
|
|
|
},
|
|
|
setActivityId(e){
|
|
|
if(e){
|
|
|
this.form.activity_list_id = e
|
|
|
if(this.form.activity_list_id){
|
|
|
this.hasActiveId = true
|
|
|
}
|
|
|
this.load()
|
|
|
}
|
|
|
},
|
|
|
getId() {
|
|
|
return this.id;
|
|
|
},
|
|
|
setType(type = "add") {
|
|
|
let types = ["add", "editor"];
|
|
|
if (types.includes(type)) {
|
|
|
this.type = type;
|
|
|
} else {
|
|
|
console.warn("Unknown type: " + type);
|
|
|
}
|
|
|
},
|
|
|
setForm(key = [], value = []) {
|
|
|
if (key instanceof Array) {
|
|
|
key.forEach((key, index) => {
|
|
|
this.form[key] = value[index] ?? "";
|
|
|
});
|
|
|
}
|
|
|
if (typeof key === "string") {
|
|
|
this.form[key] = value;
|
|
|
}
|
|
|
if (!key) {
|
|
|
this.init();
|
|
|
}
|
|
|
},
|
|
|
|
|
|
//上传
|
|
|
successHandle(response, file, fileList, key) {
|
|
|
this[key] = fileList;
|
|
|
},
|
|
|
removeHande(file, fileList, key) {
|
|
|
console.log("fileList", fileList)
|
|
|
console.log("key", key)
|
|
|
this[key] = fileList;
|
|
|
this.form[key] = "";
|
|
|
},
|
|
|
uploadBefore(file) {
|
|
|
console.log(file);
|
|
|
if (file.size / 1000 > 300 * 1024) {
|
|
|
this.$message({
|
|
|
type: "warning",
|
|
|
message: "上传大小超过300MB!",
|
|
|
});
|
|
|
return false;
|
|
|
}
|
|
|
},
|
|
|
|
|
|
async getDetail() {
|
|
|
const res = await show({
|
|
|
id: this.id,
|
|
|
table_name: "circuits",
|
|
|
with_relations: ['image']
|
|
|
});
|
|
|
this.$integrateData(this.form, res);
|
|
|
this.image_id = res.image ? [{
|
|
|
url: res.image?.url,
|
|
|
name: res.image?.original_name,
|
|
|
response: res.image
|
|
|
}] : []
|
|
|
},
|
|
|
|
|
|
submit() {
|
|
|
|
|
|
if (this.type === "add") {
|
|
|
if (this.form.hasOwnProperty("id")) {
|
|
|
delete this.form.id;
|
|
|
}
|
|
|
}
|
|
|
if (this.type === "editor") {
|
|
|
Object.defineProperty(this.form, "id", {
|
|
|
value: this.id,
|
|
|
enumerable: true,
|
|
|
configurable: true,
|
|
|
writable: true,
|
|
|
});
|
|
|
}
|
|
|
this.form.image_id = this.image_id.length == 0 ? "" : (this.image_id[0]?.response?.id);
|
|
|
save(Object.assign(this.form, {
|
|
|
table_name: "circuits"
|
|
|
})).then(
|
|
|
(res) => {
|
|
|
this.$message({
|
|
|
type: "success",
|
|
|
message: this.type === "add" ? "新增线路" : "编辑线路" + "成功",
|
|
|
});
|
|
|
this.isShow = false;
|
|
|
this.$emit("refresh");
|
|
|
}
|
|
|
);
|
|
|
},
|
|
|
},
|
|
|
|
|
|
watch: {
|
|
|
isShow(val) {
|
|
|
if (val) {
|
|
|
console.log("form",this.form.activity_list_id)
|
|
|
if (this.type === "editor") {
|
|
|
this.getDetail();
|
|
|
}
|
|
|
} else {
|
|
|
this.id = "";
|
|
|
this.type = "";
|
|
|
this.image_id = [];
|
|
|
this.init();
|
|
|
this.$refs["dialog"].clearValidate();
|
|
|
delete this.form.id;
|
|
|
}
|
|
|
},
|
|
|
},
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
::v-deep .el-input__inner {
|
|
|
text-align: left;
|
|
|
}
|
|
|
|
|
|
.xy-table-item-price-per {
|
|
|
position: relative;
|
|
|
|
|
|
&::after {
|
|
|
position: absolute;
|
|
|
right: 10px;
|
|
|
top: 0;
|
|
|
content: "%";
|
|
|
}
|
|
|
|
|
|
::v-deep .el-input__clear {
|
|
|
position: relative;
|
|
|
right: 46px;
|
|
|
z-index: 2;
|
|
|
}
|
|
|
}
|
|
|
</style>
|