<template>
|
<GlobalAlertWindow
|
v-loading="isUploading"
|
:title="title"
|
:visible.sync="visible"
|
:confirm-working="isWorking"
|
@confirm="confirm"
|
>
|
<el-form :model="form" ref="form" :rules="rules" label-width="120px" label-suffix=":" inline>
|
<el-form-item label="位置" prop="position">
|
<!-- {{ form.position }} -->
|
<el-select
|
v-model="form.position"
|
placeholder="请选择轮播所在位置"
|
>
|
<el-option
|
v-for="item in postions()"
|
:key="item.id"
|
:value="item.id"
|
:label="item.label"
|
></el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="展示图" prop="imgFullUrl">
|
<!-- {{ form.imgFullUrl }} -->
|
<UploadAvatarImage
|
:file="{ 'imgurlfull': form.imgFullUrl, 'imgurl': form.imgurl }"
|
:uploadData="uploadData"
|
@uploadSuccess="uploadAvatarSuccess"
|
@uploadEnd="isUploading = false"
|
@uploadBegin="isUploading = true"
|
/>
|
</el-form-item>
|
<el-form-item label="展示城市" prop="cityId">
|
<div class="address">
|
<el-select v-model="form.provinceId" placeholder="请选择省份" filterable @change="selectProvince">
|
<el-option
|
v-for="item in province"
|
:key="item.id"
|
:value="item.id"
|
:label="item.name"
|
></el-option>
|
</el-select>
|
<el-select v-model="form.cityId" filterable placeholder="请选择城市">
|
<el-option
|
v-for="item in cities"
|
:key="item.id"
|
:value="item.id"
|
:label="item.name"
|
></el-option>
|
</el-select>
|
</div>
|
</el-form-item>
|
<el-form-item label="跳转类型" prop="type">
|
<el-select
|
v-model="form.type"
|
placeholder="请选择跳转类型"
|
@change="selectType"
|
>
|
<el-option
|
v-for="item in types()"
|
:key="item.id"
|
:value="item.id"
|
:label="item.label"
|
></el-option>
|
</el-select>
|
</el-form-item>
|
<!-- // 0富文本 1外链 2活动 3商家 -->
|
<el-form-item v-if="form.type==0" label="富文本内容" prop="content">
|
<RichEditor :content="{ content : form.content}" @edit="form.content=$event" />
|
</el-form-item>
|
<el-form-item v-if="form.type==1" label="链接" prop="content">
|
<el-input v-model="form.content" placeholder="请输入链接" v-trim/>
|
</el-form-item>
|
<el-form-item v-if="form.type==2" label="活动名称" prop="content">
|
<el-select
|
v-model="form.content"
|
placeholder="请输入活动名称,再选择"
|
filterable
|
remote
|
reserve-keyword
|
:remote-method="remoteMethod"
|
:loading="searchLoading"
|
@change="selectActivity"
|
>
|
<el-option
|
v-for="item in activities"
|
:key="item.id"
|
:label="item.name"
|
:value="item.id">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item v-if="form.type==3" label="商家名称" prop="content">
|
<el-select
|
v-model="form.content"
|
placeholder="请输入店铺名称,再选择"
|
filterable
|
remote
|
reserve-keyword
|
:remote-method="remoteMethod"
|
:loading="searchLoading"
|
@change="selectShop"
|
>
|
<el-option
|
v-for="item in shops"
|
:key="item.id"
|
:label="item.name"
|
:value="item.id">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="排序码" prop="sortnum">
|
<el-input v-model="form.sortnum" placeholder="请输入排序码" v-trim/>
|
</el-form-item>
|
</el-form>
|
</GlobalAlertWindow>
|
</template>
|
|
<script>
|
import BaseOpera from '@/components/base/BaseOpera'
|
import GlobalAlertWindow from '@/components/common/GlobalAlertWindow'
|
import RichEditor from '@/components/common/RichEditor'
|
import UploadAvatarImage from '@/components/common/UploadAvatarImage'
|
import { listByParentId } from '@/api/business/areas'
|
import { fetchList as shopList } from '@/api/business/shop'
|
import { fetchList as activityList } from '@/api/business/activity'
|
export default {
|
name: 'OperaBannerWindow',
|
extends: BaseOpera,
|
components: { GlobalAlertWindow, RichEditor, UploadAvatarImage },
|
data () {
|
let positionRule = (rule, value, callBack) => {
|
// debugger
|
if (value < 0) {
|
callBack(new Error())
|
} else {
|
callBack()
|
}
|
}
|
return {
|
isUploading: false,
|
searchLoading: false,
|
uploadData: {
|
folder: 'banner'
|
},
|
// 表单数据
|
form: {
|
id: null,
|
creator: '',
|
createDate: '',
|
editor: '',
|
editDate: '',
|
isdeleted: '',
|
info: '',
|
title: '',
|
sortnum: '',
|
status: '',
|
imgurl: '',
|
imgFullUrl: '',
|
type: 0,
|
position: '',
|
provinceId: '',
|
cityId: '',
|
content: '',
|
objName: ''
|
},
|
province: [],
|
cities: [],
|
activities: [],
|
shops: [],
|
// 验证规则
|
rules: {
|
position: [
|
{ required: true, validator: positionRule, message: '请选择轮播图位置', tigger: 'change' }
|
],
|
imgFullUrl: [
|
{ required: true, message: '请选择轮播图位置', tigger: 'change' }
|
],
|
}
|
}
|
},
|
inject: ['postions', 'types'],
|
created () {
|
this.config({
|
api: '/business/banner',
|
'field.id': 'id'
|
})
|
listByParentId({type: 0, parentId: ''})
|
.then(data => {
|
this.province = data
|
})
|
},
|
methods: {
|
open (title, target) {
|
|
this.title = title
|
this.visible = true
|
this.activities = []
|
this.shops = []
|
// 新建
|
if (target == null) {
|
this.$nextTick(() => {
|
this.$refs.form.resetFields()
|
this.form.provinceId = ''
|
// this.selectProvince(this.form.provinceId, 0)
|
this.form[this.configData['field.id']] = null
|
})
|
return
|
}
|
// 编辑
|
this.$nextTick(() => {
|
for (const key in this.form) {
|
this.form[key] = target[key]
|
}
|
this.selectProvince(this.form.provinceId, 1)
|
if (this.form.type==2) {
|
this.activities = [ { name: this.form.objName, id: this.form.content } ]
|
} else if (this.form.type==3) {
|
this.shops = [ { name: this.form.objName, id: this.form.content } ]
|
}
|
})
|
},
|
// 上传图片
|
uploadAvatarSuccess(file) {
|
this.form.imgurl = file.imgurl;
|
this.form.imgFullUrl = file.imgurlfull;
|
},
|
// 选择省份
|
selectProvince(val, isInit) {
|
if (!isInit) {
|
this.cities = []
|
this.form.cityId = ''
|
}
|
listByParentId({ type: 1, parentId: val })
|
.then(data => {
|
this.cities = data
|
})
|
.catch(e => {
|
this.$tip.error(e)
|
})
|
},
|
selectType() {
|
this.form.content = ''
|
// this.form.title = ''
|
this.form.objName = ''
|
},
|
remoteMethod(query) {
|
if (query !== '') {
|
this.searchLoading = true
|
let action = this.form.type==2 ? activityList : shopList
|
action({
|
capacity: 999,
|
model: {
|
name: query
|
}
|
})
|
.then(res => {
|
if (this.type==2) {
|
this.activities = res.records
|
} else {
|
this.shops = res.records
|
}
|
})
|
.finally(() => {
|
this.searchLoading = false
|
})
|
}
|
},
|
selectActivity(val) {
|
const temp = this.activities.find(item => item.id == val)
|
this.form.objName = temp.name
|
},
|
selectShop(val) {
|
const temp = this.shops.find(item => item.id == val)
|
this.form.objName = temp.name
|
},
|
},
|
}
|
</script>
|
|
<style lang="scss" scoped>
|
@import "@/assets/style/alertstyle.scss";
|
::v-deep .el-select {
|
width: 100%;
|
.el-input__inner {
|
width: 100%;
|
}
|
}
|
</style>
|