<template>
|
<div class="mod-index-img">
|
<el-dialog :title="!dataForm.imgId ? '新增' : '修改'"
|
:close-on-click-modal="false"
|
:visible.sync="visible"
|
@close = 'handClose'
|
>
|
<el-form :model="dataForm"
|
ref="dataForm"
|
:rules="dataRule"
|
label-width="100px">
|
<el-form-item v-if="row" label="用户名" prop="userName">
|
<el-input v-model="dataForm.userName" disabled
|
placeholder="用户名"></el-input>
|
</el-form-item>
|
<el-form-item label="用户UID" prop="userCode">
|
<el-input v-model="dataForm.userCode" :disabled="row?true:false"
|
placeholder="用户UID"></el-input>
|
</el-form-item>
|
<el-form-item label="类型">
|
<el-select v-model="options.value" @change="changeVal"
|
placeholder="请选择">
|
<el-option v-for="item in options"
|
:key="item.value"
|
:label="item.label"
|
:value="item.value">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="备注" prop="remark">
|
<el-input
|
type="textarea"
|
placeholder="请输入内容"
|
v-model="dataForm.remark"
|
maxlength="500"
|
:autosize="{ minRows: 8, maxRows: 8 }"
|
show-word-limit
|
>
|
</el-input>
|
</el-form-item>
|
</el-form>
|
<span slot="footer" class="dialog-footer">
|
<el-button @click="visible = false">取消</el-button>
|
<el-button type="primary" @click="dataFormSubmit()">确定</el-button>
|
</span>
|
</el-dialog>
|
<!-- 商品选择弹窗-->
|
<prods-select v-if="prodsSelectVisible"
|
ref="prodsSelect"
|
:isSingle="true"
|
@refreshSelectProds="selectCouponProds"></prods-select>
|
</div>
|
</template>
|
|
<script>
|
import PicUpload from '@/components/pic-upload'
|
import ProdsSelect from '@/components/prods-select'
|
import { Debounce } from '@/utils/debounce'
|
export default {
|
data () {
|
return {
|
dataForm: {
|
userCode: '',
|
userName:'',
|
remark:'',
|
uuid:'',
|
},
|
row:'',
|
options: [], // 模块
|
dataRule: {
|
userCode: [
|
{required: true, message: 'UID不能为空', trigger: 'blur'}
|
],
|
remark: [
|
{required: true, message: '备注不能为空', trigger: 'blur'}
|
],
|
},
|
// 关联数据
|
card: {
|
id: 0,
|
pic: '',
|
name: '',
|
realData: {
|
prod: [],
|
shop: [],
|
activity: []
|
}
|
},
|
page: {
|
total: 0, // 总页数
|
currentPage: 1, // 当前页数
|
pageSize: 10 // 每页显示多少条
|
},
|
prodsSelectVisible: false,
|
visible: false
|
}
|
},
|
components: {
|
PicUpload,
|
ProdsSelect
|
},
|
methods: {
|
// 获取分类数据
|
init (arr,row) {
|
this.options = arr
|
this.row = row || ''
|
if(row){
|
this.dataForm.remark = row.remark
|
this.dataForm.uuid = row.uuid
|
this.dataForm.userCode = row.userCode
|
this.dataForm.userName = row.userName
|
this.options.value = row.type
|
}else{
|
this.options.value = this.options[0].value
|
}
|
this.visible = true
|
// if (this.dataForm.imgId) {
|
// // 获取产品数据
|
// this.$http({
|
// url: this.$http.adornUrl(`/admin/indexImg/info/${this.dataForm.imgId}`),
|
// method: 'get',
|
// params: this.$http.adornParams()
|
// }).then(({ data }) => {
|
// this.dataForm = data
|
// if (data.relation) {
|
// this.card.pic = data.pic
|
// this.card.name = data.prodName
|
// this.card.id = data.relation
|
// }
|
// })
|
// } else {
|
// this.$nextTick(() => {
|
// this.$refs['dataForm'].resetFields()
|
// this.dataForm.imgUrl = ''
|
// this.relation = null
|
// })
|
// }
|
},
|
// 表单提交
|
dataFormSubmit: Debounce(function () {
|
if(this.row){
|
this.$refs['dataForm'].validate((valid) => {
|
if (!valid) {
|
return
|
}
|
this.$http({
|
url: this.$http.adornUrl(`/normal/adminProfitAndLossConfigAction!/update.action`),
|
method:'post',
|
data: this.$http.adornData({
|
remark:this.dataForm.remark,
|
type:this.options.value,
|
uuid:this.dataForm.uuid,
|
})
|
}).then(({ data }) => {
|
if(data.code==0){
|
this.$message({
|
message: '操作成功',
|
type: 'success',
|
duration: 1500,
|
onClose: () => {
|
this.visible = false
|
this.$emit('refreshDataList', this.page)
|
}
|
})
|
}else{
|
this.$message({
|
message: data.msg,
|
type: 'error',
|
duration: 1500,
|
onClose: () => {
|
}
|
})
|
}
|
|
})
|
})
|
}else{
|
this.$refs['dataForm'].validate((valid) => {
|
if (!valid) {
|
return
|
}
|
this.$http({
|
url: this.$http.adornUrl(`/normal/adminProfitAndLossConfigAction!/add.action`),
|
method:'post',
|
data: this.$http.adornData({
|
remark:this.dataForm.remark,
|
type:this.options.value,
|
userCode:this.dataForm.userCode,
|
})
|
}).then(({ data }) => {
|
if(data.code==0){
|
this.$message({
|
message: '操作成功',
|
type: 'success',
|
duration: 1500,
|
onClose: () => {
|
this.visible = false
|
this.$emit('refreshDataList', this.page)
|
}
|
})
|
}else{
|
this.$message({
|
message: data.msg,
|
type: 'error',
|
duration: 1500,
|
onClose: () => {
|
}
|
})
|
}
|
|
})
|
})
|
}
|
|
}),
|
handClose(){
|
this.$data.dataForm=JSON.parse(JSON.stringify(this.$options.data().dataForm))
|
this.$nextTick(() => {
|
this.$refs['dataForm'].clearValidate() // 清除表单验证
|
})
|
},
|
// 删除关联数据
|
deleteRelation () {
|
this.dataForm.relation = null
|
},
|
// 打开选择商品
|
addProd () {
|
this.prodsSelectVisible = true
|
this.$nextTick(() => {
|
this.$refs.prodsSelect.init(this.card.realData.prod)
|
})
|
},
|
changeVal(val) {
|
this.$forceUpdate();
|
},
|
// 添加指定商品
|
selectCouponProds (prods) {
|
this.card.realData.prods = prods
|
if (prods.length) {
|
let selectProd = prods[0]
|
this.dataForm.relation = selectProd.prodId
|
this.card.pic = selectProd.pic
|
this.card.name = selectProd.prodName
|
this.card.id = selectProd.prodId
|
} else {
|
this.card = {}
|
this.relation = null
|
}
|
},
|
addShop () {
|
alert('选择店铺')
|
},
|
addActivity () {
|
alert('选择活动')
|
}
|
}
|
}
|
</script>
|
<style lang="scss" scoped>
|
//card样式
|
.card-prod-bottom {
|
position: relative;
|
text-align: left;
|
.card-prod-name {
|
margin: auto;
|
padding: 0 6px;
|
overflow: hidden;
|
text-overflow: ellipsis;
|
white-space: nowrap;
|
width: 118px;
|
display: inline-block;
|
}
|
.card-prod-name-button {
|
position: absolute;
|
top: 24px;
|
right: 10px;
|
}
|
}
|
</style>
|