修复开通空间问题

This commit is contained in:
al 2024-11-01 15:46:26 +08:00
parent 90c9cac703
commit 7883872ee4
5 changed files with 291 additions and 89 deletions

View File

@ -1,7 +1,15 @@
"use client";
import React, { useState, useRef, useMemo, Fragment } from "react";
import { Switch, Space, Checkbox, Button, Toast, TextArea } from "antd-mobile";
import {
Switch,
Space,
Checkbox,
Button,
Toast,
TextArea,
Radio,
} from "antd-mobile";
import { useRouter, useSearchParams } from "next/navigation";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faAngleLeft } from "@fortawesome/free-solid-svg-icons";
@ -32,23 +40,46 @@ const ListItemWithCheckbox = ({
}}
>
<div onClick={(e) => e.stopPropagation()}>
<Checkbox
<Radio
value={superSingle.key}
ref={checkboxRef}
onChange={(value) => {
const newFormData = { ...formData };
newFormData.superSingle.forEach((el) => {
el.enable = 0;
});
newFormData.superSingle[superSingle.key].enable = value;
// newFormData.superSingle[superSingle.key].price = 0;
// newFormData.superSingle[superSingle.key].wechatFree = false;
setFormData(newFormData);
}}
>
{superSingle.text}
</Radio>
{/* <Checkbox
value={superSingle.key}
ref={checkboxRef}
onChange={(value) => {
const newFormData = { ...formData };
newFormData.superSingle[superSingle.key].enable = value;
newFormData.superSingle[superSingle.key].price = 0;
newFormData.superSingle[superSingle.key].wechatFree = false;
setFormData(newFormData);
}}
>
{superSingle.text}
</Checkbox>
</Checkbox> */}
<div
className={`mt-2 px-4 h-12 py-3 rounded-[0.8rem] bg-[#FFFFFF1a] flex justify-between items-center ${
!superSingleCheckeds.includes(superSingle.key)
superSingleCheckeds != superSingle.key
? "mt-0 px-0 py-0 hidden"
: ""
}`}
// className={`mt-2 px-4 h-12 py-3 rounded-[0.8rem] bg-[#FFFFFF1a] flex justify-between items-center ${
// !superSingleCheckeds.includes(superSingle.key)
// ? "mt-0 px-0 py-0 hidden"
// : ""
// }`}
>
<div className="flex items-center">
<span className="mr-1 text-[#ffffffae] text-sm">¥</span>
@ -65,7 +96,7 @@ const ListItemWithCheckbox = ({
</div>
<div className="flex items-center">
<span className="text-[#ffffff26] mr-2">|</span>
<Checkbox
<Radio
block
checked={formData.superSingle[superSingle.key].wechatFree}
onChange={(value) => {
@ -75,7 +106,18 @@ const ListItemWithCheckbox = ({
}}
>
<p className="text-sm whitespace-nowrap">赠送微信</p>
</Checkbox>
</Radio>
{/* <Checkbox
block
checked={formData.superSingle[superSingle.key].wechatFree}
onChange={(value) => {
const newFormData = { ...formData };
newFormData.superSingle[superSingle.key].wechatFree = value;
setFormData(newFormData);
}}
>
<p className="text-sm whitespace-nowrap">赠送微信</p>
</Checkbox> */}
</div>
</div>
</div>
@ -101,7 +143,8 @@ export default function CreateProfile() {
const [spacePriceAble, setSpacePriceAble] = useState(false);
const [tiefenPriceAble, setTiefenPriceAble] = useState(false);
const [isSubmitting, setIsSubmitting] = useState(false);
const [superSingleCheckeds, setSuperSingleCheckeds] = useState([]);
// const [superSingleCheckeds, setSuperSingleCheckeds] = useState([]);
const [superSingleChecked, setSuperSingleChecked] = useState(null);
const listItemWithCheckboxMemo = useMemo(() => {
return superSingles.map((item) => (
@ -110,11 +153,12 @@ export default function CreateProfile() {
superSingle={item}
formData={formData}
setFormData={setFormData}
superSingleCheckeds={superSingleCheckeds}
superSingleCheckeds={superSingleChecked}
// superSingleCheckeds={superSingleCheckeds}
/>
</Fragment>
));
}, [formData, superSingleCheckeds]);
}, [formData, superSingleChecked]);
const handleSubmit = async () => {
const { spaceIntro, spacePrice, ironFanPrice, openSuper, superSingle } =
@ -155,16 +199,65 @@ export default function CreateProfile() {
}
let isPrice = false;
if (openSuper) {
Object.values(superSingle).forEach((it) => {
if (it.enable) {
const superFanPrice = it.price;
// Object.values(superSingle).forEach((it) => {
// if (it.enable) {
// const superFanPrice = it.price;
// if (!superFanPrice) {
// Toast.show({
// icon: "fail",
// content: "",
// position: "top",
// });
// isPrice = true;
// return;
// } else {
// const _superFanPrice = parseInt(superFanPrice * 100, 10);
// if (
// openSuper &&
// (isNaN(_superFanPrice) ||
// _superFanPrice < 100 ||
// _superFanPrice > 388800)
// ) {
// isPrice = true;
// Toast.show({
// icon: "fail",
// content: "",
// position: "top",
// });
// return;
// }
// if (openSuper && _superFanPrice <= _ironFanPrice) {
// isPrice = true;
// Toast.show({
// icon: "fail",
// content: "",
// position: "top",
// });
// return;
// }
// }
// }
// });
if (superSingleChecked == null) {
Toast.show({
icon: "fail",
content: "请选择铁粉类型",
position: "top",
});
} else {
const superChecked = superSingle.filter(
(_, index) => index == superSingleChecked
)[0];
if (superChecked) {
const superFanPrice = superChecked.price;
if (!superFanPrice) {
isPrice = true;
Toast.show({
icon: "fail",
content: "请填写超粉价格",
position: "top",
});
isPrice = true;
return;
} else {
const _superFanPrice = parseInt(superFanPrice * 100, 10);
if (
@ -192,51 +285,52 @@ export default function CreateProfile() {
}
}
}
});
}
if (isSubmitting) return;
const superfan_price_list = superSingle.map((it, index) => ({
period: index,
enable: it.enable ? 1 : 0,
price: parseInt(it.price * 100, 10),
is_superfanship_give_wechat: it.wechatFree ? 1 : 0,
}));
setIsSubmitting(true);
}
if (isPrice) return;
if (isSubmitting) return;
const superfan_price_list = superSingle.map((it, index) => ({
period: index,
enable: it.enable ? 1 : 0,
price: parseInt(it.price * 100, 10),
is_superfanship_give_wechat: it.wechatFree ? 1 : 0,
}));
setIsSubmitting(true);
try {
const body = {
profile: spaceIntro,
admission_price: parseInt(spacePrice * 100, 10),
ironfanship_price: parseInt(ironFanPrice * 100, 10),
is_superfanship_enabled: openSuper ? 1 : 0,
superfan_price_list,
};
const _data = await requireAPI(
"POST",
"/api/zone/create",
{
body,
},
true
);
if (_data.ret === -1) {
try {
const body = {
profile: spaceIntro,
admission_price: parseInt(spacePrice * 100, 10),
ironfanship_price: parseInt(ironFanPrice * 100, 10),
is_superfanship_enabled: openSuper ? 1 : 0,
superfan_price_list,
};
const _data = await requireAPI(
"POST",
"/api/zone/create",
{
body,
},
true
);
if (_data.ret === -1) {
Toast.show({
icon: "fail",
content: _data.msg,
position: "top",
});
return;
}
Toast.show({
icon: "fail",
content: _data.msg,
icon: "success",
content: "开通空间成功!空间简介将在审核完成后生效。",
position: "top",
});
return;
router.back();
} catch (error) {
console.error(error);
} finally {
setIsSubmitting(false);
}
Toast.show({
icon: "success",
content: "修改成功,请重进空间刷新查看",
position: "top",
});
router.back();
} catch (error) {
console.error(error);
} finally {
setIsSubmitting(false);
}
};
return (
@ -384,13 +478,24 @@ export default function CreateProfile() {
</p>
</div>
<Space direction="vertical" block>
<Checkbox.Group
<Radio.Group
value={superSingleChecked}
// value={superSingleCheckeds}
onChange={(values) => {
setSuperSingleChecked(values);
// setSuperSingleCheckeds(values);
}}
>
<ul>{listItemWithCheckboxMemo}</ul>
</Radio.Group>
{/* <Checkbox.Group
value={superSingleCheckeds}
onChange={(values) => {
setSuperSingleCheckeds(values);
}}
>
<ul>{listItemWithCheckboxMemo}</ul>
</Checkbox.Group>
</Checkbox.Group> */}
</Space>
</div>
)}

View File

@ -88,7 +88,7 @@ export default function EditHome() {
info: "",
autoResponse: "",
wechat: "",
wechatAddWay: 0,
wechatAddWay: 1,
});
const [spacePriceAble, setSpacePriceAble] = useState(false);
// const [wechatAddWay, setWechatAddWay] = useState("0");
@ -137,8 +137,8 @@ export default function EditHome() {
}
}, [data]);
const superSingles = [
{ key: 0, text: "主动添加对方" },
{ key: 1, text: "向对方展示微信" },
{ key: 1, text: "主动添加对方" },
{ key: 0, text: "向对方展示微信" },
];
const [fieldNamesOptions, setFieldNamesOptions] = useState([]);
const ListItemWithCheckbox = ({ superSingle }) => {
@ -224,7 +224,7 @@ export default function EditHome() {
});
return;
}
if (values.wechatAddWay === "1" && !values.wechat) {
if (values.wechatAddWay === "0" && !values.wechat) {
Toast.show({
icon: "fail",
content: "请填写微信号",
@ -595,7 +595,7 @@ export default function EditHome() {
))}
</ul>
</Radio.Group>
{formData.wechatAddWay == 1 && (
{formData.wechatAddWay == 0 && (
<div className="mt-2 px-4 h-12 py-3 rounded-[0.8rem] bg-[#FFFFFF1a] flex justify-between items-center">
<div>
<OwnInput

View File

@ -26,7 +26,7 @@ export default function Editprofile() {
}}
/>
</div>
<p className="text-base text-center leading-9">编辑资</p>
<p className="text-base text-center leading-9">编辑资</p>
</div>
{/* 内容 */}
<div className="mt-16 pt-6 p-4 grid grid-cols-2 gap-6">

View File

@ -103,7 +103,7 @@ export default function CompleteStreamerInformation() {
info: "",
autoResponse: "",
wechat: "",
wechatAddWay: 0,
wechatAddWay: 1,
fans: 0,
imageAssets: [],
displayImage: [],
@ -156,7 +156,7 @@ export default function CompleteStreamerInformation() {
setFormData((old) => ({
...old,
fans,
wechatPrice: wechat_coin_price,
wechatPrice: wechat_coin_price / 10,
gender: [`${gender}`],
age: [`${age}`],
height: [`${height}`],
@ -190,8 +190,8 @@ export default function CompleteStreamerInformation() {
setFormData((old) => ({ ...old, imageAssets: oldPhotos }));
}, [oldPhotos]);
const superSingles = [
{ key: 0, text: "主动添加对方" },
{ key: 1, text: "向对方展示微信" },
{ key: 1, text: "主动添加对方" },
{ key: 0, text: "向对方展示微信" },
];
const [fieldNamesOptions, setFieldNamesOptions] = useState([]);
const ListItemWithCheckbox = ({ superSingle }) => {
@ -360,7 +360,7 @@ export default function CompleteStreamerInformation() {
});
return;
}
if (wechatAddWay === 1 && !wechat) {
if (wechatAddWay === 0 && !wechat) {
Toast.show({
icon: "fail",
content: "请填写微信号",
@ -883,7 +883,7 @@ export default function CompleteStreamerInformation() {
))}
</ul>
</Radio.Group>
{formData.wechatAddWay == 1 && (
{formData.wechatAddWay == 0 && (
<div className="mt-2 px-4 h-12 py-3 rounded-[0.8rem] bg-[#FFFFFF1a] flex justify-between items-center">
<div>
<OwnInput

View File

@ -1,7 +1,7 @@
"use client";
import React, { useState, useEffect, useRef, useMemo, Fragment } from "react";
import { Switch, Space, Checkbox, Button, Toast } from "antd-mobile";
import { Switch, Space, Checkbox, Button, Toast, Radio } from "antd-mobile";
import { useRouter, useSearchParams } from "next/navigation";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faAngleLeft } from "@fortawesome/free-solid-svg-icons";
@ -31,7 +31,23 @@ const ListItemWithCheckbox = ({
}}
>
<div onClick={(e) => e.stopPropagation()}>
<Checkbox
<Radio
value={superSingle.key}
ref={checkboxRef}
onChange={(value) => {
const newFormData = { ...formData };
newFormData.superSingle.forEach((el) => {
el.enable = 0;
});
newFormData.superSingle[superSingle.key].enable = value;
// newFormData.superSingle[superSingle.key].price = 0;
// newFormData.superSingle[superSingle.key].wechatFree = false;
setFormData(newFormData);
}}
>
{superSingle.text}
</Radio>
{/* <Checkbox
value={superSingle.key}
ref={checkboxRef}
onChange={(value) => {
@ -43,13 +59,18 @@ const ListItemWithCheckbox = ({
}}
>
{superSingle.text}
</Checkbox>
</Checkbox> */}
<div
className={`mt-2 px-4 h-12 py-3 rounded-[0.8rem] bg-[#FFFFFF1a] flex justify-between items-center ${
!superSingleCheckeds.includes(superSingle.key)
superSingleCheckeds != superSingle.key
? "mt-0 px-0 py-0 hidden"
: ""
}`}
// className={`mt-2 px-4 h-12 py-3 rounded-[0.8rem] bg-[#FFFFFF1a] flex justify-between items-center ${
// !superSingleCheckeds.includes(superSingle.key)
// ? "mt-0 px-0 py-0 hidden"
// : ""
// }`}
>
<div className="flex items-center">
<span className="mr-1 text-[#ffffffae] text-sm">¥</span>
@ -66,7 +87,7 @@ const ListItemWithCheckbox = ({
</div>
<div className="flex items-center">
<span className="text-[#ffffff26] mr-2">|</span>
<Checkbox
<Radio
block
checked={formData.superSingle[superSingle.key].wechatFree}
onChange={(value) => {
@ -76,7 +97,18 @@ const ListItemWithCheckbox = ({
}}
>
<p className="text-sm whitespace-nowrap">赠送微信</p>
</Checkbox>
</Radio>
{/* <Checkbox
block
checked={formData.superSingle[superSingle.key].wechatFree}
onChange={(value) => {
const newFormData = { ...formData };
newFormData.superSingle[superSingle.key].wechatFree = value;
setFormData(newFormData);
}}
>
<p className="text-sm whitespace-nowrap">赠送微信</p>
</Checkbox> */}
</div>
</div>
</div>
@ -101,16 +133,23 @@ export default function spacePaymentSetting() {
const [spacePriceAble, setSpacePriceAble] = useState(false);
const [tiefenPriceAble, setTiefenPriceAble] = useState(false);
const [isSubmitting, setIsSubmitting] = useState(false);
const [superSingleCheckeds, setSuperSingleCheckeds] = useState([]);
// const [superSingleCheckeds, setSuperSingleCheckeds] = useState([]);
const [superSingleChecked, setSuperSingleChecked] = useState(null);
useEffect(() => {
const account = get("account");
getStreamerInfo(Number(account.mid)).then((res) => {
setSuperSingleCheckeds(
res.superfan_price_list
.map((it, index) => ({ ...it, index }))
.filter((it) => it.enable)
.map((it) => superSingles[it.index].key)
);
const haveChecked = res.superfan_price_list
.map((it, index) => ({ ...it, index }))
.filter((it) => it.enable);
if (haveChecked.length > 0) {
setSuperSingleChecked(haveChecked[0].period);
}
// setSuperSingleCheckeds(
// res.superfan_price_list
// .map((it, index) => ({ ...it, index }))
// .filter((it) => it.enable)
// .map((it) => superSingles[it.index].key)
// );
setFormData({
spacePrice: res.admission_price / 100,
ironFanPrice: res.ironfanship_price / 100,
@ -131,11 +170,12 @@ export default function spacePaymentSetting() {
superSingle={item}
formData={formData}
setFormData={setFormData}
superSingleCheckeds={superSingleCheckeds}
superSingleCheckeds={superSingleChecked}
// superSingleCheckeds={superSingleCheckeds}
/>
</Fragment>
));
}, [formData, superSingleCheckeds]);
}, [formData, superSingleChecked]);
const handleSubmit = async () => {
const { spacePrice, ironFanPrice, openSuper, superSingle } = formData;
const openSuperEveryFalse = Object.values(superSingle).every(
@ -169,9 +209,57 @@ export default function spacePaymentSetting() {
}
let isPrice = false;
if (openSuper) {
Object.values(superSingle).forEach((it) => {
if (it.enable) {
const superFanPrice = it.price;
// Object.values(superSingle).forEach((it) => {
// if (it.enable) {
// const superFanPrice = it.price;
// if (!superFanPrice) {
// Toast.show({
// icon: "fail",
// content: "",
// position: "top",
// });
// isPrice = true;
// return;
// } else {
// const _superFanPrice = parseInt(superFanPrice * 100, 10);
// if (
// openSuper &&
// (isNaN(_superFanPrice) ||
// _superFanPrice < 100 ||
// _superFanPrice > 388800)
// ) {
// isPrice = true;
// Toast.show({
// icon: "fail",
// content: "",
// position: "top",
// });
// return;
// }
// if (openSuper && _superFanPrice <= _ironFanPrice) {
// isPrice = true;
// Toast.show({
// icon: "fail",
// content: "",
// position: "top",
// });
// return;
// }
// }
// }
// });
if (superSingleChecked == null) {
Toast.show({
icon: "fail",
content: "请选择铁粉类型",
position: "top",
});
} else {
const superChecked = superSingle.filter(
(_, index) => index == superSingleChecked
)[0];
if (superChecked) {
const superFanPrice = superChecked.price;
if (!superFanPrice) {
Toast.show({
icon: "fail",
@ -207,7 +295,7 @@ export default function spacePaymentSetting() {
}
}
}
});
}
}
if (isPrice) return;
// if (
@ -233,7 +321,6 @@ export default function spacePaymentSetting() {
price: parseInt(it.price * 100, 10),
is_superfanship_give_wechat: it.wechatFree ? 1 : 0,
}));
setIsSubmitting(true);
try {
const body = {
@ -416,14 +503,24 @@ export default function spacePaymentSetting() {
</p>
</div>
<Space direction="vertical" block>
<Checkbox.Group
<Radio.Group
value={superSingleChecked}
// value={superSingleCheckeds}
onChange={(values) => {
setSuperSingleChecked(values);
// setSuperSingleCheckeds(values);
}}
>
<ul>{listItemWithCheckboxMemo}</ul>
</Radio.Group>
{/* <Checkbox.Group
value={superSingleCheckeds}
onChange={(values) => {
setSuperSingleCheckeds(values);
}}
>
<ul>{listItemWithCheckboxMemo}</ul>
</Checkbox.Group>
</Checkbox.Group> */}
</Space>
</div>
)}