123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- <template>
- <view class="form">
- <form @submit="formSubmit">
- <view class="value other">
- <view class="title">类型</view>
- <view class="label">
- <picker v-if="type=='0'" name="type" @change="typeChange" :value="index" :range="typeList"
- range-key="dictLabel">
- <view class="picker">{{form.type||'普通训练'}}</view>
- </picker>
- <picker v-else name="type" @change="typeChange" :value="index" :range="activityList"
- range-key="dictLabel">
- <view class="picker">{{form.type||'请选择'}}</view>
- </picker>
- </view>
- </view>
- <view class="value other">
- <view class="title">日期</view>
- <view class="label">
- <picker name="date" mode="date" @change="dateChange" :value="index">
- <view class="picker">{{form.date||'请选择'}}</view>
- </picker>
- </view>
- </view>
- <view class="value other">
- <view class="title">时间</view>
- <view class="label">
- <picker name="time" mode="time" @change="timeChange" :value="index">
- <view class="picker">{{form.time||'请选择'}}</view>
- </picker>
- </view>
- </view>
- <view class="value other">
- <view class="title">时长</view>
- <view class="label">
- <picker name="duration" @change="durationChange" :value="index" :range="durationList"
- range-key="dictLabel">
- <view class="picker">{{form.duration||'请选择时长'}}</view>
- </picker>
- </view>
- </view>
- <view class="value other margin">
- <view class="title">地点</view>
- <view class="label">
- <input name="name" class="input" :value="form.address" placeholder="请选择" />
- </view>
- </view>
- <view class="value other">
- <view class="title">费用</view>
- <view class="label">
- <input name="money" class="input" :value="form.money" placeholder="请输入费用" />
- </view>
- </view>
- <view class="value other">
- <view class="title">人数上限</view>
- <view class="label">
- <input name="name" class="input" :value="form.max_person" placeholder="请输入人数上限" />
- </view>
- </view>
- <view class="value other">
- <view class="title">公开报名</view>
- <view class="label">
- <picker name="is_open" @change="openChange" :value="index" :range="openList" range-key="dictLabel">
- <view class="picker">{{form.is_open||'请选择'}}</view>
- </picker>
- </view>
- </view>
- <view class="value other" v-if="form.date&&form.time">
- <view class="title">报名截止时间</view>
- <view class="label">
- <uni-datetime-picker :start="form.date" :border="false" v-model="form.end_time" />
- </view>
- </view>
- <view class="value other">
- <view class="title">活动标题</view>
- <view class="label">
- <input name="title" class="input" :value="form.title" placeholder="请输入活动标题" />
- </view>
- </view>
- <view class="remark margin">
- <view class="label">
- <textarea name="brief" :value="form.brief" placeholder="请输入简介" />
- </view>
- </view>
- <view class="remark">
- <view class="title">上传图片</view>
- <view class="label">
- <uni-file-picker v-model="form.file" fileMediatype="image" :list-styles="imageStyles" limit="6"
- title="最多选择6张图片" @select="toUpload" @delete="toDelete"></uni-file-picker>
- </view>
- </view>
- </form>
- </view>
- </template>
- <script setup lang="ts">
- import { ref, toRefs, getCurrentInstance } from 'vue';
- // 请求接口
- const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
- const $apifile = getCurrentInstance()?.appContext.config.globalProperties.$apifile;
- // 信息
- const form = ref({ file: [] });
- const listStyles = ref({
- width: 64,
- height: 64,
- border: {
- color: "#ff5a5f",
- width: 2,
- style: 'dashed',
- radius: '2px'
- }
- });
- const props = defineProps({
- type: { type: String, default: () => '0' },
- typeList: { type: Array, default: () => [] },
- activityList: { type: Array, default: () => [] },
- openList: { type: Array, default: () => [] },
- durationList: { type: Array, default: () => [] },
- });
- const { type, typeList, activityList, durationList, openList } = toRefs(props);
- // 类型选择
- const typeChange = (e) => {
- let data
- if (type.value == 0) {
- data = typeList.value[e.detail.value]
- if (data) form.value.type = data.dictLabel
- } else {
- data = activityList.value[e.detail.value]
- if (data) form.value.type = data.dictLabel
- }
- };
- // 时长选择选择
- const durationChange = (e) => {
- const data = durationList.value[e.detail.value]
- if (data) form.value.duration = data.dictLabel
- };
- // 日期选择器
- const dateChange = (e) => {
- form.value.date = e.detail.value
- };
- // 时间选择器
- const timeChange = (e) => {
- form.value.time = e.detail.value
- };
- // 是否公开选择器
- const openChange = (e) => {
- form.value.is_open = e.detail.value
- };
- // 上传图片
- const toUpload = async (e) => {
- const arr = await $apifile(`/common/upload`, 'file', e.tempFilePaths[0],
- 'file');
- if (arr.code == 200) {
- form.value.file.push({
- newFileName: arr.newFileName,
- originalFilename: arr.originalFilename,
- url: arr.url
- })
- console.log(form.value.file);
- } else {
- uni.showToast({
- title: arr.msg,
- icon: 'none'
- });
- }
- };
- // 删除图片
- const toDelete = async (e) => {
- form.value.file = form.value.file.filter(i => i.originalFilename != e.tempFile.name)
- console.log(form.value.file);
- };
- </script>
- <style lang="scss" scoped>
- .form {
- display: flex;
- flex-direction: column;
- background-color: var(--f9Color);
- .other {
- padding: 4vw 2vw;
- border-bottom: 1px solid var(--footColor);
- }
- .margin {
- margin: 0 0 3vw 0;
- }
- .remark {
- background-color: var(--mainColor);
- padding: 3vw 2vw 0 2vw;
- .title {
- padding: 0 0 3vw 0;
- border-bottom: 1px solid var(--footColor);
- }
- }
- .value {
- display: flex;
- justify-content: space-between;
- align-items: center;
- background-color: var(--mainColor);
- .label {
- .input {
- text-align: right;
- }
- }
- }
- }
- </style>
|