talk_appAmin/pages/activity/publish.vue

361 lines
12 KiB
Vue
Raw Normal View History

2024-06-04 18:57:45 +08:00
<template>
<view>
<!-- 顶部导航栏 -->
<up-navbar leftText="" title="" :placeholder="true" :safeAreaInsetTop="true" @leftClick="leftClick"
:bgColor="bgColor">
<template #center>
<div class="navbarcenter"><span>发布活动</span></div>
</template>
</up-navbar>
</view>
<view class="bgc"></view>
<up-form :model="form" :rules="rules" ref="uFormRef">
<view class="cardz">
<view class="titleInfo">
<up-form-item label="" prop="acTitle" borderBottom>
<up-input placeholder="输入活动标题~5~20个字" v-model="form.acTitle" border="none" maxlength="20"
fontSize="34rpx" color="#C0C0C0" clearable></up-input>
</up-form-item>
<view class="xian"></view>
</view>
<view class="contentInfo">
<up-form-item label="" prop="acContent" borderBottom>
<textarea class="text_style" v-model="form.acContent"
placeholder="输入活动内容\n活动图片最多可发布两张\n输入准确定位可以更好提供活动信息奥\n安全指南请勿发布带有个人信息住址\n" cols="50"
rows="10" maxlength="500"
placeholderStyle="color: #c0c0c0;font-size: 30rpx; white-space: pre-wrap"
@linechange="inputtextInfo"></textarea>
<view class="char-count">{{ form.acContent.length }}/500</view>
</up-form-item>
</view>
<up-form-item label="" prop="file" borderBottom>
<view class="cardzfile">
<fileUpload v-model="form.file" :fileTypeInfo="fileTypeInfo1" :limit="2"></fileUpload>
</view>
</up-form-item>
2024-06-05 16:57:58 +08:00
</view>
<view class="cardx">
<up-cell-group :border="false">
<up-form-item label="" prop="startTime" borderBottom @click="showStartTime = !showStartTime">
<view style="margin-top: 2rpx;width: 100%;height: 30rpx;display: flex;align-items: center;">
<image v-if="showtext1" :src="tu52" style="width: 30rpx; height: 32rpx; margin-right: 12rpx;">
</image>
<image v-else :src="tu522" style="width: 30rpx; height: 32rpx; margin-right: 12rpx;"></image>
<up-input v-model="form.startTime" disabled disabledColor="#ffffff" color="#C9F6F5"
placeholder="请选择活动开始时间" placeholderStyle="color: #333333 !important;font-size: 30rpx;"
border="none">
<span v-if="showtext2"></span>
</up-input>
<up-icon slot="right" name="arrow-right"></up-icon>
</view>
</up-form-item>
<up-form-item label="" prop="endTime" borderBottom @click="showEndTime = !showEndTime">
<view style="margin-top: 2rpx;width: 100%;height: 30rpx;display: flex;align-items: center;">
<image v-if="showtext2" :src="tu53" style="width: 30rpx; height: 32rpx;margin-right: 12rpx;">
</image>
<image v-else :src="tu532" style="width: 30rpx; height: 32rpx; margin-right: 12rpx;"></image>
<up-input v-model="form.endTime" disabled disabledColor="#ffffff" color="#C9F6F5"
placeholder="请选择活动结束时间" placeholderStyle="color: #333333 !important;font-size: 30rpx;"
border="none">
<span v-if="showtext2"></span>
</up-input>
<up-icon slot="right" name="arrow-right"></up-icon>
</view>
</up-form-item>
<up-form-item label="" prop="addres" borderBottom @click="showaddres = !showaddres">
<view style="margin-top: 2rpx;width: 100%;height: 30rpx;display: flex;align-items: center;">
<image v-if="showtext3" :src="tu51" style="width: 30rpx; height: 32rpx;margin-right: 12rpx;">
</image>
<image v-else :src="tu512" style="width: 30rpx; height: 32rpx; margin-right: 12rpx;"></image>
<up-input v-model="form.addres" disabledColor="#ffffff" color="#C9F6F5" @change="change1"
placeholder="添加活动具体位置" placeholderStyle="color: #333333 !important;font-size: 30rpx;"
border="none">
<span v-if="showtext2"></span>
</up-input>
<up-icon slot="right" name="arrow-right"></up-icon>
</view>
</up-form-item>
</up-cell-group>
</view>
<up-datetime-picker :show="showStartTime" v-model="newData" :modelValue="newData" @confirm="confirm1"
format="YYYY-MM-DD HH:mm:ss" @cancel="cancel" mode="datetime"></up-datetime-picker>
<up-datetime-picker :show="showEndTime" v-model="newData" @confirm="confirm2" :modelValue="newData"
format="YYYY-MM-DD HH:mm:ss" @cancel="cancel" mode="datetime"></up-datetime-picker>
<view class="cardxx">
<up-button color="#C9F6F5" size="large" shape="circle" @click="publish" throttleTime="500"><span
class="fbText">发布</span></up-button>
<view style="width: 26rpx;height: 80rpx;"></view>
<up-button color="#F8F8E3" size="large" shape="circle" @click="draft" style="margin-left: 26rpx;"><span
class="cgText">存草稿</span></up-button>
</view>
</up-form>
2024-06-04 18:57:45 +08:00
</template>
2024-06-04 18:57:45 +08:00
<script setup>
import { listInfo, getInfo, delInfo, addInfo, updateInfo } from "@/api/activityInfo/info";
2024-06-04 18:57:45 +08:00
import fileUpload from '../common/file/fileUpload'
import { onShow, onLoad } from '@dcloudio/uni-app'
import { ref, reactive, getCurrentInstance, computed, toRefs } from 'vue'
2024-06-04 18:57:45 +08:00
import { useStore } from 'vuex';
const { proxy } = getCurrentInstance();
const iconConfig = proxy.iconConfig;
const tu51 = iconConfig.tu51;
2024-06-05 16:57:58 +08:00
const tu512 = iconConfig.tu512;
2024-06-04 18:57:45 +08:00
const tu52 = iconConfig.tu52;
2024-06-05 16:57:58 +08:00
const tu522 = iconConfig.tu522;
2024-06-04 18:57:45 +08:00
const tu53 = iconConfig.tu53;
2024-06-05 16:57:58 +08:00
const tu532 = iconConfig.tu532;
2024-06-04 18:57:45 +08:00
const title = ref('')
const content = ref('');
const data = reactive({
form: {
acTitle: '',
acContent: '',
startTime: null,
endTime: null,
file: null,
state: null,
addres: null,
longitude: null,
latitude: null
},
rules: {
acTitle: [
{ required: true, message: '请输入活动标题', trigger: 'blur' },
{ min: 5, max: 20, message: '标题长度在 5 到 20 个字符', trigger: 'blur' }
],
acContent: [
{ required: true, message: '请输入活动内容', trigger: 'blur' },
{ max: 500, message: '内容不能超过 500 字', trigger: 'blur' }
],
startTime: [
{ required: true, message: '请选择活动开始时间', trigger: 'change' }
],
endTime: [
{ required: true, message: '请选择活动结束时间', trigger: 'change' },
{
validator: (rule, value, callback) => {
console.log(form.value.startTime, " ", value, " ", value <= form.value.startTime)
if (value <= form.value.startTime) {
callback(proxy.$modal.msgError('时间选择错误'));
} else {
callback();
}
}, trigger: 'change'
}
],
addres: []
}
});
const { form, rules } = toRefs(data);
2024-06-04 18:57:45 +08:00
const fileList1 = ref([])
const fileTypeInfo1 = ref('image')
const bgColor = ref('');
bgColor.value = 'rgba(170, 0, 0, 0)'
2024-06-05 16:57:58 +08:00
const showStartTime = ref(false);
const showEndTime = ref(false);
const showaddres = ref(false);
const StartTime = ref('请选择活动开始时间');
const showtext1 = ref(true);
const showtext2 = ref(true);
const showtext3 = ref(true);
const EndTime = ref('请选择活动结束时间');
const newData = ref(new Date().getTime());
const timeFormat = uni.$u.timeFormat;
// 表单引用
const uFormRef = ref(null);
2024-06-04 18:57:45 +08:00
onLoad((options) => {
console.log("页面参数:", options.id);
})
2024-06-04 18:57:45 +08:00
const leftClick = () => {
proxy.$tab.navigateBack(1)
}
2024-06-04 18:57:45 +08:00
const draft = () => {
form.value.auditStatus = "5"
submitForm('draft');
2024-06-04 18:57:45 +08:00
console.log("存草稿");
}
2024-06-04 18:57:45 +08:00
const publish = () => {
form.value.auditStatus = "1"
submitForm('publish');
2024-06-04 18:57:45 +08:00
console.log("发布");
}
const change1 = (e) => {
showtext3.value = false;
}
const inputtextInfo = (e) => {
console.log("测试输入1", e);
}
const submitForm = (type) => {
if (uFormRef.value) {
uFormRef.value.validate().then(valid => {
if (valid) {
console.log('表单验证通过:', form.value);
proxy.$modal.loading('正在提交数据,请稍候...');
// 提交表单数据
if (type === 'publish') {
console.log("调用发布接口", form.value);
// 调用发布接口
addInfo(form.value).then(response => {
proxy.$modal.closeLoading();
proxy.$modal.msgSuccess("发布成功");
proxy.$tab.navigateTo('/pages/common/talkState/publish')
});
} else {
// 调用存草稿接口
addInfo(form.value).then(response => {
proxy.$modal.closeLoading();
proxy.$modal.msgSuccess("存草稿成功");
});
}
} else {
console.log('表单验证失败');
}
}).catch(error => {
console.log('表单验证错误:', error);
});
} else {
console.log('表单引用未定义');
}
}
2024-06-05 16:57:58 +08:00
const startTime = (e) => {
showStartTime.value = !showStartTime.value
}
2024-06-05 16:57:58 +08:00
const confirm1 = (e) => {
console.log(e);
showtext1.value = false;
StartTime.value = e.value
form.value.startTime = timeFormat(e.value, 'yyyy-mm-dd hh:MM:ss');
showStartTime.value = !showStartTime.value
2024-06-05 16:57:58 +08:00
}
2024-06-05 16:57:58 +08:00
const confirm2 = (e) => {
console.log(e);
showtext2.value = false;
EndTime.value = e.value
form.value.endTime = timeFormat(e.value, 'yyyy-mm-dd hh:MM:ss');
showEndTime.value = !showEndTime.value
2024-06-05 16:57:58 +08:00
}
2024-06-05 16:57:58 +08:00
const cancel = (e) => {
showStartTime.value = false;
showEndTime.value = false;
2024-06-05 16:57:58 +08:00
}
2024-06-04 18:57:45 +08:00
</script>
2024-06-05 16:57:58 +08:00
<style lang="scss">
page{
background-color: #FFFFFF;
}
2024-06-04 18:57:45 +08:00
.navbarcenter {
font-weight: 400;
font-size: 36rpx;
text-align: left;
color: #000000;
}
.bgc {
width: 100%;
height: 500rpx;
background: linear-gradient(-180deg, #c9f6f5, #ffffff);
position: fixed;
top: 0rpx;
left: 0rpx;
2024-06-04 18:57:45 +08:00
}
.cardz {
margin-left: 32rpx;
margin-right: 32rpx;
.titleInfo {
margin-top: 40rpx;
.xian {
margin-top: 32rpx;
height: 2rpx;
border-radius: 1rpx 1rpx 1rpx 1rpx;
background: #ffffff;
}
}
.contentInfo {
margin-top: 46rpx;
.text_style {
white-space: pre-wrap;
width: 100%;
overflow: auto;
color: #c0c0c0;
font-weight: 400;
font-size: 30rpx;
line-height: 46rpx;
}
.char-count {
text-align: right;
font-size: 24rpx;
color: #999999;
}
2024-06-04 18:57:45 +08:00
}
.cardzfile {
background-color: #FFFFFF;
}
}
.cardx {
background-color: #FFFFFF;
padding-top: 72rpx;
margin-left: 32rpx;
margin-right: 32rpx;
.c1 {
margin-top: 2rpx;
width: 100%;
height: 102rpx;
display: flex;
align-items: center;
}
}
.cardxx {
display: flex;
margin-left: 32rpx;
margin-right: 32rpx;
margin-top: 80rpx;
2024-06-05 16:57:58 +08:00
.fbText {
2024-06-04 18:57:45 +08:00
font-weight: 400;
font-size: 30rpx;
color: #FBFBFB !important;
}
2024-06-05 16:57:58 +08:00
.cgText {
2024-06-04 18:57:45 +08:00
font-weight: 400;
font-size: 30rpx;
color: #999999 !important;
}
2024-06-05 16:57:58 +08:00
}
.text2 {
2024-06-05 16:57:58 +08:00
margin-left: 12rpx;
font-weight: 400;
font-size: 30rpx;
text-align: left;
color: #C9F6F5 !important;
2024-06-04 18:57:45 +08:00
}
</style>