<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=":">
|
|
<el-form-item label="展示图" prop="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="labelId">
|
<el-select
|
v-model="form.labelId"
|
placeholder="请选择专区名称"
|
clearable
|
@change="labelChange"
|
>
|
<el-option
|
v-for="item in types"
|
:key="item.id"
|
:value="item.id"
|
:label="item.name"
|
></el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item 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 goods"
|
: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" type="number" placeholder="请输入排序码" v-trim/>
|
</el-form-item>
|
</el-form>
|
</GlobalAlertWindow>
|
</template>
|
|
<script>
|
import BaseOpera from '@/components/base/BaseOpera'
|
import GlobalAlertWindow from '@/components/common/GlobalAlertWindow'
|
import UploadAvatarImage from '@/components/common/UploadAvatarImage'
|
import { findAll } from "@/api/business/labels";
|
import { findListByParentCategory } from '@/api/business/goods'
|
export default {
|
name: 'OperaBannerWindow',
|
extends: BaseOpera,
|
components: { GlobalAlertWindow, UploadAvatarImage },
|
data () {
|
let positionRule = (rule, value, callBack) => {
|
if (!value) {
|
callBack(new Error(rule.message))
|
} else {
|
callBack()
|
}
|
}
|
return {
|
isUploading: false,
|
searchLoading: false,
|
uploadData: {
|
folder: 'banner'
|
},
|
// 表单数据
|
form: {
|
id: null,
|
imgurl: '',
|
imgFullUrl: '',
|
content: '',
|
labelId: '',
|
sortnum: '',
|
objName: '',
|
|
},
|
types:[],
|
goods: [],
|
// 验证规则
|
rules: {
|
content: [
|
{ required: true, validator: positionRule, message: '请选择关联产品', tigger: 'change' }
|
],
|
imgFullUrl: [
|
{ required: true, message: '请上传专区图片', tigger: 'change' }
|
],
|
}
|
}
|
},
|
created () {
|
this.config({
|
api: '/business/banner',
|
'field.id': 'id'
|
})
|
findAll({ type: 12 })
|
.then(res => {
|
console.log(res);
|
this.types = res
|
})
|
},
|
methods: {
|
open (title, target) {
|
|
this.title = title
|
this.visible = true
|
this.activities = []
|
this.goods = []
|
// 新建
|
if (target == null) {
|
this.$nextTick(() => {
|
this.$refs.form.resetFields()
|
this.form.provinceId = ''
|
this.form[this.configData['field.id']] = null
|
})
|
return
|
}
|
// 编辑
|
this.$nextTick(() => {
|
for (const key in this.form) {
|
this.form[key] = target[key]
|
}
|
this.form.content = +this.form.content
|
this.remoteMethod(target.goodsName)
|
})
|
},
|
labelChange() {
|
this.this.goods = []
|
this.form.labelId = ''
|
},
|
// 上传图片
|
uploadAvatarSuccess(file) {
|
this.form.imgurl = file.imgurl;
|
this.form.imgFullUrl = file.imgurlfull;
|
},
|
remoteMethod(query) {
|
if (query !== '') {
|
this.searchLoading = true
|
findListByParentCategory({
|
name: query,
|
categoryId: this.form.labelId
|
})
|
.then(res => {
|
this.goods = res
|
})
|
.finally(() => {
|
this.searchLoading = false
|
})
|
}
|
},
|
selectShop(val) {
|
const temp = this.goods.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>
|