index.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import { useState } from "react";
  2. import { View, Text, Image } from "@tarojs/components";
  3. import Taro, { useRouter } from "@tarojs/taro";
  4. import PageCustom from "@/components/page-custom/index";
  5. import NavBarNormal from "@/components/nav-bar-normal/index";
  6. import Popup from "@/components/popup/popup";
  7. import editorStyle from "../editor.module.less";
  8. import { useCharacterStore } from "@/store/characterStore";
  9. import { useComponentStore } from "@/store/componentStore";
  10. import WemetaInput from "@/components/wemeta-input/index";
  11. export default function Index() {
  12. const router = useRouter();
  13. const { id } = router.params;
  14. const deltaNum = id ? 1 : 2;
  15. let currentComponent = useComponentStore((state) => state.currentComponent);
  16. const character = useCharacterStore((state) => state.character);
  17. const { saveComponent } = useComponentStore();
  18. const loading = useComponentStore((state) => state.loading);
  19. const { value } = currentComponent?.data ?? {};
  20. const [storeProductValue, setStoreProductValue] = useState<{
  21. appid: string;
  22. productId: string;
  23. }>(value ?? {});
  24. const [show, setShow] = useState(false);
  25. const [tipsType, setTipsType] = useState(1);
  26. const handleSave = async () => {
  27. if (loading) {
  28. return;
  29. }
  30. if (!storeProductValue.appid || !storeProductValue.productId) {
  31. return;
  32. }
  33. const c = {
  34. data: {
  35. value: storeProductValue,
  36. layout: 'mini',
  37. },
  38. enabled: currentComponent?.enabled ?? true,
  39. id: currentComponent?.id,
  40. name: currentComponent?.name ?? "微信小店商品",
  41. characterProfileId:
  42. currentComponent?.characterProfileId ?? character?.profileId,
  43. type: "storeProduct",
  44. };
  45. console.log(c);
  46. await saveComponent(c);
  47. };
  48. const handleNavBack = async () => {
  49. await handleSave();
  50. };
  51. const setValueByKey = (key: string, v: string) => {
  52. setStoreProductValue((prev)=> {
  53. return {
  54. ...prev,
  55. [key]: v
  56. }
  57. });
  58. };
  59. const showTips = (type: number) => () => {
  60. setTipsType(type);
  61. setShow(true);
  62. };
  63. const renderTips = (type: number) => {
  64. if (type === 1) {
  65. return (
  66. <>
  67. <View>
  68. 🌟 <Text className="font-medium">小绿提示:</Text>
  69. <Text>通过微信小店后台 - 商品管理 - 商品列表 - 规格/编码获取。</Text>
  70. </View>
  71. <Image
  72. className="w-full"
  73. mode="widthFix"
  74. src="https://cdn.wehome.cn/cmn/png/214/META-H8UKXHWU-PIWQ5G6H7F9LO74FT7QR2-9SOBIJ4M-KC.png"
  75. ></Image>
  76. </>
  77. );
  78. }
  79. return (
  80. <>
  81. <View>
  82. 🌟 <Text className="font-medium">小绿提示:</Text>
  83. <Text>
  84. 通过微信小店后台 - 商品管理 - 商品规格/编码
  85. </Text>
  86. </View>
  87. <Image
  88. className="w-full"
  89. mode="widthFix"
  90. src="https://cdn.wehome.cn/cmn/png/39/META-H8UKXHWU-PIWQ5G6H7F9LO74FT7QR2-DVYBIJ4M-LC.png"
  91. ></Image>
  92. </>
  93. );
  94. };
  95. return (
  96. <PageCustom>
  97. <NavBarNormal
  98. backText="保存"
  99. navDelta={deltaNum}
  100. onNavBack={handleNavBack}
  101. >
  102. 填写小店商品信息
  103. </NavBarNormal>
  104. <View className="flex flex-col items-center w-full pt-20">
  105. <View className={editorStyle.container}>
  106. <View className={editorStyle.formContainer}>
  107. <View className={editorStyle.formItem}>
  108. <View className={editorStyle.formItemLabel}>
  109. <View className="flex-1">小店ID</View>
  110. <View className="text-green" onClick={showTips(1)}>
  111. 如何获取?
  112. </View>
  113. </View>
  114. <WemetaInput
  115. value={storeProductValue.appid}
  116. onInput={(value: string) => setValueByKey("appid", value)}
  117. placeholder="长按粘贴小店ID..."
  118. />
  119. </View>
  120. <View className={editorStyle.formItem}>
  121. <View className={editorStyle.formItemLabel}>
  122. <View className="flex-1">商品ID</View>
  123. <View className="text-green" onClick={showTips(2)}>
  124. 如何获取?
  125. </View>
  126. </View>
  127. <WemetaInput
  128. value={storeProductValue.productId}
  129. onInput={(value: string) => setValueByKey("productId", value)}
  130. placeholder="长按粘贴商品ID..."
  131. />
  132. </View>
  133. </View>
  134. </View>
  135. </View>
  136. <Popup
  137. title={tipsType === 1 ? "获取小店ID" : "获取商品ID"}
  138. show={show}
  139. setShow={setShow}
  140. >
  141. <View className="flex flex-col gap-16 mb-44">
  142. <View
  143. className={`flex flex-col p-12 gap-10 text-14 rounded-20 leading-22 text-gray-65 bg-gray-f8 overflow-hidden`}
  144. >
  145. {renderTips(tipsType)}
  146. </View>
  147. <View className='button-rounded-big mt-20' onClick={() => setShow(false)}>知道了</View>
  148. </View>
  149. </Popup>
  150. </PageCustom>
  151. );
  152. }