503 lines
16 KiB
Vue
503 lines
16 KiB
Vue
<template>
|
|
<div>
|
|
<el-card shadow="never">
|
|
<el-form ref="form" label-width="80px">
|
|
|
|
<el-card v-for="(s,idx) in subject" :key="s.id" class="item" shadow="hover">
|
|
<!-- <el-form-item :label="(s.subjectType==='radio'?'(单选)':'(多选)')+ (idx+1)+'.'" prop="subjectName">-->
|
|
<el-form-item label="" prop="subjectName">
|
|
<div class="s-title-wrap">
|
|
<el-row align="middle" style="width: 100%" type="flex">
|
|
<el-col :xl="20"
|
|
style="border: 1px dashed rgb(217, 217, 217);border-radius:6px;display: flex;align-items: center;">
|
|
<el-input v-model="s.subjectName" class="text-input"
|
|
data-type="subject"></el-input>
|
|
</el-col>
|
|
<el-col :xl="2" style="text-align: center"></el-col>
|
|
<el-col :xl="2" style="text-align: center">
|
|
<div class="option-delete">
|
|
<el-button circle
|
|
icon="el-icon-delete"
|
|
size="mini" type="danger"
|
|
@click="subject.splice(idx,1)"></el-button>
|
|
</div>
|
|
</el-col>
|
|
</el-row>
|
|
</div>
|
|
<div class="s-options-list" style="margin-top: 10px;">
|
|
<el-table :data="s.options" border>
|
|
<el-table-column
|
|
align="center"
|
|
header-align="center"
|
|
label="类型"
|
|
>
|
|
<template slot-scope="{row}">
|
|
<el-select v-model="row.optionType" placeholder="请选择"
|
|
@change="optionTypeChange(row)">
|
|
<el-option
|
|
v-for="item in typeOptions"
|
|
:key="item"
|
|
:label="item"
|
|
:value="item">
|
|
</el-option>
|
|
</el-select>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column
|
|
align="center"
|
|
header-align="center"
|
|
label="福利名称"
|
|
>
|
|
<template slot-scope="{row}">
|
|
<div
|
|
style="border: 1px dashed rgb(217, 217, 217);border-radius:6px;display: flex;align-items: center;padding-left: 10px;">
|
|
<i v-if="s.subjectType==='radio'" class="fa fa-circle-o"
|
|
style="cursor: pointer"></i>
|
|
<i v-else-if="s.subjectType==='checkBox'" class="fa fa-square-o"
|
|
style="cursor: pointer"></i>
|
|
|
|
<template v-if="row.optionType==='套餐'">
|
|
<el-input v-model="row.optionName" autosize
|
|
class="text-input"
|
|
data-type="option"
|
|
></el-input>
|
|
</template>
|
|
|
|
<template v-if="row.optionType==='提货券'">
|
|
<el-select v-model="row.optionNameId" placeholder="请选择"
|
|
@change="optionNameIdChange(row)">
|
|
<el-option
|
|
v-for="item in shoppingTypeOptions"
|
|
:key="item.id"
|
|
:disabled="item.disabled"
|
|
:label="item.shoppingName"
|
|
:value="item.id">
|
|
</el-option>
|
|
</el-select>
|
|
</template>
|
|
|
|
|
|
</div>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column
|
|
align="center"
|
|
header-align="center"
|
|
label="排序" width="120px">
|
|
<template slot-scope="{row}">
|
|
<div
|
|
style="border: 1px dashed rgb(217, 217, 217);border-radius:6px;display: flex;align-items: center;padding-left: 10px;">
|
|
<el-input v-model="row.optionSort" autosize
|
|
class="text-input"
|
|
data-type="option"
|
|
></el-input>
|
|
</div>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column
|
|
align="center"
|
|
header-align="center"
|
|
label="图片"
|
|
width="200px"
|
|
>
|
|
<template slot-scope="{row,$index}">
|
|
<div @click="uploadClick(idx,$index)">
|
|
<el-upload :action="FILE_UPLOAD_ADDRESS" :on-success="onFileSuccess"
|
|
:show-file-list="false" class="avatar-uploader">
|
|
<div v-if="row.imgUrl" style="position: relative">
|
|
<img :src="FILE_STREAM_PREVIEW_ADDRESS+'?id='+row.imgUrl" class="avatar">
|
|
<div @click.stop="closePopover(row)">
|
|
<i class="el-icon-delete avatar-delete"></i>
|
|
</div>
|
|
</div>
|
|
<!-- <img :src="FILE_STREAM_PREVIEW_ADDRESS+'?id='+row.imgUrl" class="avatar">-->
|
|
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
|
|
</el-upload>
|
|
<!-- <el-popover
|
|
placement="top-start"
|
|
width="200"
|
|
>
|
|
<img :src="FILE_STREAM_PREVIEW_ADDRESS+'?id='+row.imgUrl" style="width: 100%;height: 150px">
|
|
<el-button size="mini" style="margin-top: 10px;width: 100%;" type="danger"
|
|
@click="closePopover(row)">
|
|
删除
|
|
</el-button>
|
|
<img v-if="row.imgUrl" slot="reference" :src="FILE_STREAM_PREVIEW_ADDRESS+'?id='+row.imgUrl"
|
|
style="width: 40px;height: 40px">
|
|
</el-popover>-->
|
|
|
|
</div>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column align="center"
|
|
header-align="center"
|
|
label="说明"
|
|
width="100px">
|
|
<template slot-scope="scope">
|
|
<el-link type="primary"
|
|
@click="openDescRichText(scope.row.description,idx,scope.$index)">编辑说明
|
|
</el-link>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column
|
|
align="center"
|
|
header-align="center"
|
|
label="默认值"
|
|
width="100px">
|
|
<template slot-scope="{row,$index}">
|
|
<el-checkbox v-model="row.isSystemDefault"
|
|
@change="(val,event)=>{systemDefaultChange(idx,$index,val)}"
|
|
></el-checkbox>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column
|
|
align="center"
|
|
header-align="center"
|
|
label="没选系统自动分配"
|
|
width="200px">
|
|
<template slot-scope="{row,$index}">
|
|
<el-checkbox v-model="row.isDefaultOption"
|
|
@change="(val,event)=>{defaultOptionChange(idx,$index,val)}"
|
|
></el-checkbox>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column
|
|
align="center"
|
|
header-align="center"
|
|
label="操作"
|
|
width="100px"
|
|
>
|
|
<template slot-scope="{row,$index}">
|
|
<div class="option-delete">
|
|
<el-button circle
|
|
icon="el-icon-delete"
|
|
size="mini" type="danger"
|
|
@click="deleteRow(s.options,row,$index)"></el-button>
|
|
</div>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table>
|
|
|
|
<div class="s-operation">
|
|
<el-button size="small" type="primary"
|
|
@click="s.options.push({optionType:'套餐',optionNameId:'',optionName:'福利'+(s.options.length+1),optionSort:s.options.length+1,imgUrl:null})">
|
|
添加福利
|
|
</el-button>
|
|
</div>
|
|
</div>
|
|
</el-form-item>
|
|
</el-card>
|
|
|
|
</el-form>
|
|
<!-- <div class="text-center">-->
|
|
<!-- <el-button type="primary" size="small" @click="addSubject('radio')">添加单选题</el-button>-->
|
|
<!-- <el-button type="primary" size="small" @click="addSubject('checkBox')">添加多选题</el-button>-->
|
|
<!-- </div>-->
|
|
</el-card>
|
|
|
|
<el-dialog
|
|
:close-on-click-modal="false"
|
|
:visible.sync="richTextDialog"
|
|
title="编辑说明"
|
|
:append-to-body="true"
|
|
width="60%">
|
|
<div id="descRichText">
|
|
|
|
</div>
|
|
<span slot="footer" class="dialog-footer">
|
|
<el-button @click="richTextDialog = false">取 消</el-button>
|
|
<el-button type="primary" @click="getRichText">确 定</el-button>
|
|
</span>
|
|
</el-dialog>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
|
|
let questionRichTextEditor = null
|
|
|
|
module.exports = {
|
|
components: {
|
|
vuedraggable: window.vuedraggable,
|
|
},
|
|
watch: {
|
|
subject(val) {
|
|
console.log(val)
|
|
}
|
|
},
|
|
props: {
|
|
subject: {
|
|
type: Array,
|
|
default: []
|
|
}
|
|
},
|
|
data() {
|
|
return {
|
|
typeOptions: ["套餐", "提货券"],
|
|
shoppingTypeOptions: null,
|
|
richTextDialog: false,
|
|
subjectIndex: 0,
|
|
optionIndex: 0,
|
|
imgPopover: false,
|
|
//题目列表
|
|
// subject: [
|
|
// {
|
|
// subjectName: '题目1',
|
|
// subjectType: 'radio',
|
|
// defaultOption: null,
|
|
// options: [
|
|
// {
|
|
// optionName: '选项1',
|
|
// imgUrl: '/r809h67mpsiulphfg1coehd5v3.jpg'
|
|
// },
|
|
// {
|
|
// optionName: '选项2',
|
|
// imgUrl: '/r809h67mpsiulphfg1coehd5v3.jpg'
|
|
// }
|
|
// ]
|
|
// }
|
|
// ],
|
|
idx: null,
|
|
oidx: null
|
|
}
|
|
},
|
|
methods: {
|
|
deleteRow(options, row, index) {
|
|
options.splice(index, 1)
|
|
const shoppingTypeOption = this.shoppingTypeOptions.find(v => v.id === row.optionNameId)
|
|
shoppingTypeOption.disabled = false
|
|
},
|
|
optionTypeChange(row) {
|
|
this.optionNameIdChange()
|
|
row.optionNameId = null
|
|
row.optionName = null
|
|
},
|
|
optionNameIdChange(row) {
|
|
if (row) {
|
|
row.optionName = this.shoppingTypeOptions.find(v => v.id === row.optionNameId).shoppingName
|
|
}
|
|
const optionNameIds = this.subject[0].options.map(v => v.optionNameId)
|
|
this.shoppingTypeOptions.forEach(v => {
|
|
v.disabled = optionNameIds.includes(v.id)
|
|
})
|
|
this.$forceUpdate()
|
|
},
|
|
addSubject(type) {
|
|
let subject = {
|
|
subjectName: '题目' + (this.subject.length + 1),
|
|
subjectType: type,
|
|
options: [
|
|
{optionName: '选项一', imgUrl: null},
|
|
{optionName: '选项一', imgUrl: null}
|
|
]
|
|
}
|
|
this.subject.push(subject)
|
|
},
|
|
onFileSuccess(response, file, fileList) {
|
|
const {data} = response
|
|
this.subject[this.idx].options[this.oidx].imgUrl = data.filepath
|
|
// this.$set()
|
|
this.$forceUpdate()
|
|
// this.subject[this.idx].options[this.oidx].optionName = data.filepath
|
|
},
|
|
uploadClick(idx, oidx) {
|
|
this.idx = idx
|
|
this.oidx = oidx
|
|
},
|
|
closePopover(o) {
|
|
const popovers = document.getElementsByClassName('el-popover')
|
|
for (let i = 0; i < popovers.length; i++) {
|
|
popovers[i].style.display = 'none'
|
|
}
|
|
o.imgUrl = null
|
|
},
|
|
defaultOptionChange(idx, oidx, val) {
|
|
const subject = this.subject[idx]
|
|
const {subjectType} = subject
|
|
if (val) {
|
|
// subject.options.forEach(v => v.isDefaultOption = false)
|
|
subject.options[oidx].isDefaultOption = true
|
|
}
|
|
},
|
|
systemDefaultChange(idx, oidx, val) {
|
|
console.log(2)
|
|
const subject = this.subject[idx]
|
|
const {subjectType} = subject
|
|
if (val) {
|
|
subject.options.forEach(v => v.isSystemDefault = false)
|
|
subject.options[oidx].isSystemDefault = true
|
|
}
|
|
},
|
|
validate(fn) {
|
|
const that = this
|
|
// return new Promise((resolve, reject) => {
|
|
// const s = that.formData.subject.some(v => {
|
|
// if (!v.subjectName) return true
|
|
// return v.options.some(x => {
|
|
// if (!x.optionName) return true
|
|
// })
|
|
// })
|
|
// if (s) reject(false)
|
|
// resolve(true)
|
|
// })
|
|
if (this._validate()) {
|
|
return false
|
|
}
|
|
return true
|
|
|
|
},
|
|
_validate() {
|
|
return this.subject.some(v => {
|
|
if (!v.subjectName) return true
|
|
return v.options.some(x => {
|
|
if (!x.optionName) return true
|
|
})
|
|
})
|
|
},
|
|
openDescRichText(richText, sIdx, oIdx) {
|
|
this.richTextDialog = true
|
|
this.subjectIndex = sIdx
|
|
this.optionIndex = oIdx
|
|
this.$nextTick(() => {
|
|
/*if (questionRichTextEditor == null) {
|
|
questionRichTextEditor = new wangEditor('#descRichText')
|
|
questionRichTextEditor.create()
|
|
}
|
|
console.log(richText)
|
|
questionRichTextEditor.txt.clear()
|
|
questionRichTextEditor.txt.html(richText)*/
|
|
$("#descRichText").html("")
|
|
questionRichTextEditor = new wangEditor("#descRichText")
|
|
questionRichTextEditor.config.onchange = (html) => {
|
|
richText = (html ? html : "")
|
|
}
|
|
questionRichTextEditor.config.uploadImgShowBase64 = true
|
|
questionRichTextEditor.create()
|
|
if (richText) {
|
|
questionRichTextEditor.txt.html(richText)
|
|
}
|
|
})
|
|
},
|
|
getRichText() {
|
|
// console.log(this.subject[this.subjectIndex]['options'][this.optionIndex])
|
|
this.subject[this.subjectIndex]['options'][this.optionIndex].description = questionRichTextEditor.txt.html()
|
|
this.richTextDialog = false
|
|
},
|
|
async getShoppingType() {
|
|
const resp = await $.get("/platform/shoppingType/apply/getShoppingType", {typeName: "商超"})
|
|
this.shoppingTypeOptions = resp.data
|
|
}
|
|
|
|
},
|
|
created() {
|
|
this.getShoppingType()
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
|
|
.avatar-uploader .el-upload {
|
|
border: 1px dashed #d9d9d9;
|
|
border-radius: 6px;
|
|
cursor: pointer;
|
|
position: relative;
|
|
overflow: hidden;
|
|
/* width: 40px;
|
|
height: 40px;*/
|
|
/*line-height: 40px;*/
|
|
}
|
|
|
|
.avatar-uploader .el-upload:hover {
|
|
border-color: #409EFF;
|
|
}
|
|
|
|
.avatar-uploader-icon {
|
|
font-size: 14px;
|
|
color: #8c939d;
|
|
width: 40px;
|
|
height: 40px;
|
|
line-height: 40px;
|
|
text-align: center;
|
|
}
|
|
|
|
|
|
.el-upload el-upload--text {
|
|
width: 100px;
|
|
height: 100px;
|
|
}
|
|
|
|
.avatar {
|
|
width: 100px;
|
|
height: 80px;
|
|
display: block;
|
|
}
|
|
|
|
/*被拖拽对象的样式*/
|
|
.item {
|
|
padding: 6px;
|
|
background-color: #FFF;
|
|
border: solid 1px #eee;
|
|
margin-bottom: 10px;
|
|
cursor: move;
|
|
}
|
|
|
|
.item:hover {
|
|
/*background-color: #f1f1f1;*/
|
|
cursor: move;
|
|
}
|
|
|
|
/*选中样式*/
|
|
.chosen {
|
|
border: solid 1px #3089dc !important;
|
|
}
|
|
|
|
.s-title-wrap {
|
|
display: flex;
|
|
width: 100%;
|
|
overflow: hidden;
|
|
word-break: break-word;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
|
|
.s-operation {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
justify-content: start;
|
|
padding: 5px 0;
|
|
}
|
|
|
|
.s-operation > span {
|
|
display: flex;
|
|
height: 22px;
|
|
cursor: pointer;
|
|
color: #2672ff;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
|
|
.option-delete {
|
|
width: 80px;
|
|
text-align: center;
|
|
}
|
|
|
|
.s-operation i {
|
|
margin-right: 10px;
|
|
}
|
|
|
|
.text-input > input, .text-input > textarea {
|
|
resize: none;
|
|
overflow: hidden;
|
|
/*border: 1px dashed rgb(217, 217, 217);*/
|
|
border: none;
|
|
}
|
|
|
|
.avatar-delete {
|
|
font-size: 20px;
|
|
color: red;
|
|
}
|
|
|
|
</style>
|