191 lines
5.8 KiB
Vue
Raw Normal View History

2024-02-25 11:17:48 +08:00
<template>
<a-modal
2024-03-25 13:54:04 +08:00
title='操作'
style='top: 20px;'
:width='800'
v-model='visible'
:confirmLoading='confirmLoading'
@ok='handleSubmit'
2024-02-25 11:17:48 +08:00
>
2024-03-25 13:54:04 +08:00
<a-form :form='form'>
<a-form-item style='display:none'>
<a-input v-decorator="['id']" />
2024-02-25 11:17:48 +08:00
</a-form-item>
2024-03-25 13:54:04 +08:00
<a-form-item style='display:none'>
<a-input v-decorator="['version']" />
2024-02-25 11:17:48 +08:00
</a-form-item>
2024-03-25 13:54:04 +08:00
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='服务名称'>
<a-input placeholder='服务名称'
v-decorator="['serveName',{rules:[{required: true, message: '请输入服务名称' }]}]" />
2024-02-25 11:17:48 +08:00
</a-form-item>
2024-03-25 13:54:04 +08:00
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='服务类型'>
<a-select placeholder='服务类型' @change='changeServeType'
v-decorator="['serveType', {rules: [{required: true, message: '请选择服务类型' }]}]">
<a-select-option :value='1'>免费服务</a-select-option>
<a-select-option :value='2'>增值服务</a-select-option>
2024-02-27 16:42:34 +08:00
</a-select>
</a-form-item>
2024-03-25 13:54:04 +08:00
<a-form-item v-if='mdl.serveType === 2' :labelCol='labelCol' :wrapperCol='wrapperCol' label='金额描述'>
<a-input placeholder='金额描述'
v-decorator="['money',{rules:[{required: true, message: '请输入金额描述' }]}]" />
</a-form-item>
2024-03-25 13:54:04 +08:00
<a-form-item v-if='mdl.serveType === 1' :labelCol='labelCol' :wrapperCol='wrapperCol' label='服务图标'>
2024-03-02 17:03:44 +08:00
<!-- <a-input placeholder="室内图片url" v-decorator="['indoorPicUrl']" />-->
<a-upload
v-decorator="['pic']"
2024-03-25 13:54:04 +08:00
list-type='picture-card'
class='avatar-uploader'
:show-upload-list='false'
:action='uploadUrl'
:headers='headers'
:before-upload='beforeUpload'
@change='handleChange'
2024-03-02 17:03:44 +08:00
>
2024-03-25 13:54:04 +08:00
<img v-if='imageUrl' :src='imageUrl' style='width: 102px; height: 102px' />
2024-03-02 17:03:44 +08:00
<div v-else>
<a-icon :type="loading ? 'loading' : 'plus'" />
2024-03-25 13:54:04 +08:00
<div class='ant-upload-text'> 上传</div>
2024-03-02 17:03:44 +08:00
</div>
</a-upload>
2024-02-25 11:17:48 +08:00
</a-form-item>
2024-03-25 13:54:04 +08:00
<a-form-item :labelCol='labelCol' :wrapperCol='wrapperCol' label='备注'>
<a-input placeholder='备注' v-decorator="['remake']" />
</a-form-item>
2024-02-25 11:17:48 +08:00
</a-form>
</a-modal>
</template>
<script>
2024-03-02 17:03:44 +08:00
import { saveRoomServe } from '@/api/admin/meeting/roomServe'
import pick from 'lodash.pick'
import storage from 'store'
import { ACCESS_TOKEN } from '@/store/mutation-types'
2024-03-25 13:54:04 +08:00
2024-03-02 17:03:44 +08:00
export default {
2024-02-25 11:17:48 +08:00
name: 'RoomServeModal',
2024-03-25 13:54:04 +08:00
props: {},
components: {},
data() {
2024-02-25 11:17:48 +08:00
return {
visible: false,
labelCol: {
xs: { span: 24 },
sm: { span: 5 }
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 16 }
},
2024-03-02 17:03:44 +08:00
loading: false,
uploadUrl: process.env.VUE_APP_API_BASE_URL + '/api/dfs/upload',
2024-03-02 17:03:44 +08:00
imageUrl: '',
headers: {
Authorization: 'Bearer ' + storage.get(ACCESS_TOKEN)
},
2024-02-25 11:17:48 +08:00
confirmLoading: false,
mdl: {},
form: this.$form.createForm(this)
}
},
2024-03-25 13:54:04 +08:00
beforeCreate() {
2024-02-25 11:17:48 +08:00
},
2024-03-25 13:54:04 +08:00
created() {
2024-02-25 11:17:48 +08:00
},
methods: {
2024-03-25 13:54:04 +08:00
changeServeType(value) {
this.mdl.serveType = value
},
2024-03-25 13:54:04 +08:00
beforeUpload(file) {
2024-03-02 17:03:44 +08:00
const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png'
if (!isJpgOrPng) {
this.$message.error('You can only upload JPG file!')
}
const isLt2M = file.size / 1024 < 500
if (!isLt2M) {
this.$message.error('图片必须小于 500kb!')
}
return isJpgOrPng && isLt2M
},
2024-03-25 13:54:04 +08:00
handleChange(info) {
2024-03-02 17:03:44 +08:00
if (info.file.status === 'uploading') {
this.loading = true
return
}
if (info.file.status === 'done') {
const { form: { setFieldsValue } } = this
const result = info.file.response
// 设置值
this.$nextTick(() => {
setFieldsValue({
// 设置相对路径
pic: result.fileName
})
})
// Get this url from response in real world.
getBase64(info.file.originFileObj, imageUrl => {
this.imageUrl = imageUrl
this.loading = false
})
}
},
2024-03-25 13:54:04 +08:00
add() {
2024-02-25 11:17:48 +08:00
this.form.resetFields()
this.edit({ id: 0 })
},
2024-03-25 13:54:04 +08:00
edit(record) {
2024-02-25 11:17:48 +08:00
this.mdl = Object.assign(record)
2024-03-22 17:34:16 +08:00
if (this.mdl.pic) {
this.imageUrl = process.env.VUE_APP_API_BASE_URL + this.mdl.pic
}
2024-02-25 11:17:48 +08:00
this.visible = true
this.$nextTick(() => {
2024-03-25 13:54:04 +08:00
this.form.setFieldsValue(pick(this.mdl, 'id', 'serveName', 'serveType', 'serveTime', 'remake', 'type', 'createBy', 'createTime', 'updateBy', 'updateTime', 'version', 'deleteFlag'))
2024-02-25 11:17:48 +08:00
})
},
2024-03-25 13:54:04 +08:00
handleSubmit(e) {
2024-02-25 11:17:48 +08:00
e.preventDefault()
this.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values)
this.confirmLoading = true
saveRoomServe(values).then(res => {
if (res.code === 0) {
this.$message.success('保存成功')
this.$emit('ok')
this.visible = false
} else {
this.$message.error(res.msg)
}
}).catch(() => {
this.$message.error('系统错误,请稍后再试')
}).finally(() => {
this.confirmLoading = false
})
}
})
}
},
watch: {
/*
'selectedRows': function (selectedRows) {
this.needTotalList = this.needTotalList.map(item => {
return {
...item,
total: selectedRows.reduce( (sum, val) => {
return sum + val[item.dataIndex]
}, 0)
}
})
}
*/
}
}
2024-03-25 13:54:04 +08:00
function getBase64(img, callback) {
2024-03-02 17:03:44 +08:00
const reader = new FileReader()
reader.addEventListener('load', () => callback(reader.result))
reader.readAsDataURL(img)
}
2024-02-25 11:17:48 +08:00
</script>