Files
dvcp_v2_wxcp_app/src/apps/AppUniMsg/Add.vue

194 lines
4.7 KiB
Vue
Raw Normal View History

2021-12-21 19:13:37 +08:00
<template>
<div class="add">
<div class="header-description">
<u-form :model="forms" ref="uForm" label-width="auto" :border-bottom="false">
<u-form-item label="标题" prop="title" required :border-bottom="false" class="names">
<u-input v-model="forms.title" placeholder="请输入标题" maxlength="30" />
</u-form-item>
2021-12-23 17:30:17 +08:00
<u-form-item label="发布组织" prop="publishUnitName" required :border-bottom="false" class="phones">
2021-12-21 19:13:37 +08:00
<u-input v-model="forms.publishUnitName" placeholder="请输入发布单位" maxlength="16" />
</u-form-item>
<u-form-item label="正文" prop="content" required :border-bottom="false" label-position="top" class="contents">
<u-input v-model="forms.content" placeholder="请输入正文" type="textarea" auto-height height="100" maxlength="500" />
</u-form-item>
<div class="line"></div>
<u-form-item label="图片上传 (最多9张)" prop="images" :border-bottom="false" class="avatars" label-position="top">
2021-12-24 09:40:19 +08:00
<AiUploader :def.sync="forms.images" multiple placeholder="上传图片" :limit="9" action="/admin/file/add2"></AiUploader>
2021-12-21 19:13:37 +08:00
</u-form-item>
</u-form>
</div>
<div class="btn" @click="submit">保存</div>
</div>
</template>
<script>
import { mapState } from 'vuex'
export default {
name: 'Add',
components: {},
props: {},
data() {
return {
id: '',
forms: {
title: '',
publishUnitName: '',
content: '',
images: [],
},
flag: false,
}
},
computed: { ...mapState(['user']) },
onLoad(o) {
this.id = o.id
this.getDetail()
},
2021-12-24 15:27:36 +08:00
onShow() {
document.title = '新增通知公告'
},
2021-12-21 19:13:37 +08:00
mounted() {},
methods: {
getDetail() {
2021-12-22 09:44:40 +08:00
if (this.id) {
this.$http.post(`/app/appmininotice/queryDetailById?id=${this.id}`).then((res) => {
if (res?.data) {
this.forms = res.data
if (res.data.images) {
this.forms.images = JSON.parse(res.data.images || '[]')
}
2021-12-21 19:13:37 +08:00
}
2021-12-22 09:44:40 +08:00
})
}
2021-12-21 19:13:37 +08:00
},
submit() {
if (this.flag) return
this.$refs.uForm.validate((valid) => {
if (valid) {
if (!this.forms.title) {
return this.$u.toast('请输入标题')
}
if (!this.forms.publishUnitName) {
2021-12-23 17:30:17 +08:00
return this.$u.toast('请输入发布组织')
2021-12-21 19:13:37 +08:00
}
2021-12-24 09:04:23 +08:00
if (!this.forms.content) {
return this.$u.toast('请输入正文')
}
2021-12-21 19:13:37 +08:00
const imgs = []
if (this.forms.images) {
this.forms.images.map((e) => {
imgs.push({ url: e.url, id: e.id })
})
}
this.flag = true
this.$http
.post(`/app/appmininotice/addOrUpdate`, {
title: this.forms.title,
publishUnitName: this.forms.publishUnitName,
content: this.forms.content,
images: JSON.stringify(imgs) || [],
id: this.id,
})
.then((res) => {
if (res.code == 0) {
this.flag = false
2021-12-24 11:33:28 +08:00
this.$u.toast('提交成功')
uni.$emit('updateList')
setTimeout(() => {
uni.navigateBack()
}, 600)
2021-12-21 19:13:37 +08:00
}
})
} else {
this.$u.toast('失败')
}
})
},
},
}
</script>
<style lang="scss" scoped>
2021-12-22 09:44:40 +08:00
uni-page-body {
height: 100%;
}
2021-12-21 19:13:37 +08:00
.add {
height: 100%;
.header-description {
2021-12-22 09:44:40 +08:00
padding-bottom: 112px;
2021-12-21 19:13:37 +08:00
::v-deep .u-form {
.u-form-item {
padding: 0 45px !important;
.u-form-item__body {
.u-form-item--right__content__slot {
padding-bottom: 0;
.u-input {
text-align: right !important;
}
}
}
}
.names,
.modeTypes,
.phones {
.u-form-item__body {
border-bottom: 1px solid #dddddd;
}
}
.u-form-item:last-child {
margin-bottom: 40px;
}
.avatars,
.contents {
padding-bottom: 20px !important;
.u-form-item__body {
.u-form-item--right__content__slot {
.u-input {
text-align: left !important;
}
}
.default {
width: 160px;
height: 160px;
}
}
}
.line {
height: 24px;
background: #f3f6f9;
}
}
}
.btn {
position: fixed;
bottom: 0;
width: 100%;
height: 112px;
line-height: 112px;
background: #1365dd;
text-align: center;
font-size: 32px;
font-weight: 500;
color: #ffffff;
}
}
</style>