From e5851c1c3b2785aefa6e543d31007841da7a5b45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AD=B1=E9=87=8E?= Date: Sat, 27 Sep 2025 21:23:45 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E8=BE=91=E7=90=83=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/PublishMenu/PublishMenu.tsx | 4 +- .../SelectStadium/StadiumDetail.tsx | 3 +- src/publish_pages/publishBall/index.tsx | 86 ++++++++++++++----- src/services/publishService.ts | 6 ++ src/store/publishBallStore.ts | 12 ++- 5 files changed, 83 insertions(+), 28 deletions(-) diff --git a/src/components/PublishMenu/PublishMenu.tsx b/src/components/PublishMenu/PublishMenu.tsx index ce8e9ed..c71f868 100644 --- a/src/components/PublishMenu/PublishMenu.tsx +++ b/src/components/PublishMenu/PublishMenu.tsx @@ -89,7 +89,7 @@ const PublishMenu: React.FC = () => { - {/* handleMenuItemClick('ai')} > @@ -105,7 +105,7 @@ const PublishMenu: React.FC = () => { - */} + )} diff --git a/src/publish_pages/publishBall/components/SelectStadium/StadiumDetail.tsx b/src/publish_pages/publishBall/components/SelectStadium/StadiumDetail.tsx index 92d6083..035ef8d 100644 --- a/src/publish_pages/publishBall/components/SelectStadium/StadiumDetail.tsx +++ b/src/publish_pages/publishBall/components/SelectStadium/StadiumDetail.tsx @@ -108,7 +108,8 @@ const StadiumDetail = forwardRef(({ description:{ description: '', description_tag: [] - } + }, + venue_id: stadium.id }) // 暴露方法给父组件 diff --git a/src/publish_pages/publishBall/index.tsx b/src/publish_pages/publishBall/index.tsx index a39804c..b78251b 100644 --- a/src/publish_pages/publishBall/index.tsx +++ b/src/publish_pages/publishBall/index.tsx @@ -1,6 +1,7 @@ import React, { useState, useEffect } from 'react' import { View, Text, Button, Image } from '@tarojs/components' import { Checkbox } from '@nutui/nutui-react-taro' +import dayjs from 'dayjs' import Taro from '@tarojs/taro' import { type ActivityType } from '../../components/ActivityTypeSwitch' import CommonDialog from '../../components/CommonDialog' @@ -15,8 +16,8 @@ import GeneralNavbar from "@/components/GeneralNavbar" import images from '@/config/images' import { useUserInfo } from '@/store/userStore' import styles from './index.module.scss' -import dayjs from 'dayjs' import { usePublishBallData } from '@/store/publishBallStore' +import DetailService from "@/services/detailService"; const defaultFormData: PublishBallFormData = { title: '', @@ -171,17 +172,17 @@ const PublishBall: React.FC = () => { } const validateFormData = (formData: PublishBallFormData, isOnSubmit: boolean = false) => { - const { activityInfo, title, timeRange } = formData; + const { activityInfo, title, timeRange, image_list } = formData; const { play_type, price, location_name } = activityInfo; - // if (!image_list?.length) { - // if (!isOnSubmit) { - // Taro.showToast({ - // title: `请上传活动封面`, - // icon: 'none' - // }) - // } - // return false - // } + if (!image_list?.length && activityType === 'group') { + if (!isOnSubmit) { + Taro.showToast({ + title: `请上传活动封面`, + icon: 'none' + }) + } + return false + } if (!title) { if (!isOnSubmit) { Taro.showToast({ @@ -252,10 +253,17 @@ const PublishBall: React.FC = () => { return true } + const getParams = () => { + const currentInstance = Taro.getCurrentInstance() + const params = currentInstance.router?.params + return params + } // 提交表单 const handleSubmit = async () => { // 基础验证 console.log(formData, 'formData'); + const params = getParams() + const { republish } = params || {}; if (activityType === 'individual') { const isValid = validateFormData(formData[0]) if (!isValid) { @@ -277,10 +285,11 @@ const PublishBall: React.FC = () => { is_wechat_contact: wechat.is_wechat_contact, wechat_contact: wechat.wechat_contact || wechat.default_wechat_contact, } - const res = await PublishService.createPersonal(options); + const res = republish === '0' ? await PublishService.gamesUpdate(options) : await PublishService.createPersonal(options); + const successText = republish === '0' ? '更新成功' : '发布成功'; if (res.code === 0 && res.data) { Taro.showToast({ - title: '发布成功', + title: successText, icon: 'success' }) delay(1000) @@ -325,10 +334,11 @@ const PublishBall: React.FC = () => { image_list: item.image_list.map(img => img.url) } }) - const res = await PublishService.create_play_pmoothlys({rows: options}); + const successText = republish === '0' ? '更新成功' : '发布成功'; + const res = republish === '0' ? await PublishService.gamesUpdate(options[0]) : await PublishService.create_play_pmoothlys({rows: options}); if (res.code === 0 && res.data) { Taro.showToast({ - title: '发布成功', + title: successText, icon: 'success' }) delay(1000) @@ -346,9 +356,11 @@ const PublishBall: React.FC = () => { } } } + const mergeWithDefault = (data: any): PublishBallFormData => { const userPhone = (userInfo as any)?.phone || '' - const { start_time, end_time, play_type, price, + const { start_time, end_time, play_type, price, venue_id, location_name, location, latitude, + longitude, court_type, court_surface, venue_description_tag, venue_description, venue_image_list, description, description_tag, max_players, min_players, skill_level_max, skill_level_min, venueDtl } = data; @@ -377,6 +389,16 @@ const PublishBall: React.FC = () => { ...defaultFormData.activityInfo, ...(play_type ? { play_type } : {}), ...((price) ? { price } : {}), + ...(venue_id ? { venue_id } : {}), + ...(location_name ? { location_name } : {}), + ...(location ? { location } : {}), + ...(latitude ? { latitude } : {}), + ...(longitude ? { longitude } : {}), + ...(court_type ? { court_type } : {}), + ...(court_surface ? { court_surface } : {}), + ...(venue_description_tag ? { venue_description_tag } : {}), + ...(venue_description ? { venue_description } : {}), + ...(venue_image_list ? { venue_image_list } : {}), ...activityInfo }, descriptionInfo: { @@ -390,7 +412,6 @@ const PublishBall: React.FC = () => { } } - const formatConfig = () => { const newFormSchema = publishBallFormSchema.reduce((acc, item) => { if (item.prop === 'wechat') { @@ -412,8 +433,7 @@ const PublishBall: React.FC = () => { setOptionsConfig(newFormSchema) } const initFormData = () => { - const currentInstance = Taro.getCurrentInstance() - const params = currentInstance.router?.params + const params = getParams() const userPhone = (userInfo as any)?.phone || '' if (params?.type) { const type = params.type as ActivityType @@ -429,8 +449,6 @@ const PublishBall: React.FC = () => { } } else if (type === 'ai') { // 从 Store 注入 AI 生成的表单 JSON - - if (publishAiData && Array.isArray(publishAiData) && publishAiData.length > 0) { Taro.showToast({ title: '智能识别成功,请完善剩余信息', @@ -453,7 +471,33 @@ const PublishBall: React.FC = () => { } } } + if (params?.gameId) { + getGameDetail(params.gameId) + } } + + + + const getGameDetail = async (gameId) => { + if (!gameId) return; + try { + const res = await DetailService.getDetail(Number(gameId)); + if (res.code === 0) { + const merged = mergeWithDefault(res.data) + setFormData([merged]) + if (merged.activityInfo.play_type === '个人球局') { + setTitleBar('发布') + setActivityType('individual') + } else { + setTitleBar('发布畅打活动') + setActivityType('group') + } + } + } catch (e) { + if (e.message === '球局不存在') { + } + } + }; const onCheckedChange = (checked: boolean) => { setChecked(checked) } diff --git a/src/services/publishService.ts b/src/services/publishService.ts index 634c9aa..5041260 100644 --- a/src/services/publishService.ts +++ b/src/services/publishService.ts @@ -154,6 +154,12 @@ class PublishService { showToast: false, }) } + async gamesUpdate(data: PublishBallData): Promise> { + return httpService.post('/games/update', data, { + showLoading: true, + loadingText: '发布中...' + }) + } async getPictures(req) { const { type, tag, otherReq = {} } = req if (type === 'history') { diff --git a/src/store/publishBallStore.ts b/src/store/publishBallStore.ts index 0f01836..8becffe 100644 --- a/src/store/publishBallStore.ts +++ b/src/store/publishBallStore.ts @@ -1,17 +1,21 @@ import { create } from "zustand"; -import { PublishBallFormData } from "../../types/publishBall"; + +type PublishData = { + game_type: string; + [key: string]: any; +} interface PublishBallState { // 待注入到发布页面的表单数据(支持单场或多场) - publishData: PublishBallFormData | PublishBallFormData[] | null; + publishData: PublishData[] | null; // 赋值/覆盖整份数据 setPublishData: ( - data: PublishBallFormData | PublishBallFormData[] | null + data: PublishData[] | null ) => void; // 读取当前数据 - getPublishData: () => PublishBallFormData | PublishBallFormData[] | null; + getPublishData: () => PublishData[] | null; // 清空 clearPublishData: () => void;