AddGoodsClassification.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. import * as WebBrowser from "expo-web-browser";
  2. import * as React from "react";
  3. import {
  4. Image,
  5. Platform,
  6. StyleSheet,
  7. TouchableOpacity,
  8. View,
  9. ImageBackground,
  10. } from "react-native";
  11. import scrollPage from "../decorator/scrollPage";
  12. import { useModel } from "flooks";
  13. import {
  14. Layout,
  15. Tab,
  16. TabView,
  17. Text,
  18. useTheme,
  19. Button,
  20. Card,
  21. List,
  22. } from "@ui-kitten/components";
  23. import FormInput from "../components/FormInput";
  24. import { useFocusEffect } from "@react-navigation/native";
  25. import ScrollPage from "../components/ScrollPage";
  26. import NavHeaderBar from "../components/NavHeaderBar";
  27. import GoodsCard from "../components/GoodsCard";
  28. import EmptyComponent from "../components/EmptyComponent";
  29. import ActionButton from "react-native-action-button";
  30. import TabBarIcon from "../components/TabBarIcon";
  31. const Header = (props, title) => (
  32. <Text {...props} category='s1'>
  33. {title}
  34. </Text>
  35. );
  36. export default function AddGoodsClassification({ navigation, route }) {
  37. const theme = useTheme();
  38. const { changeBackground } = useModel("barModel");
  39. const { httpGet, httpPost } = useModel("httpModel", true);
  40. const { registerSecend, guideStep } = useModel("userModel", true);
  41. const { success } = useModel("loadingModel", true);
  42. const {
  43. goodsClassificationTitle1,
  44. goodsClassificationTitle2,
  45. goodsClassificationTitle3,
  46. add,
  47. remove,
  48. successText,
  49. removeTips,
  50. addClassTips,
  51. } = useModel("wordsModel");
  52. const { showDialog } = useModel("dialogModel", true);
  53. const { selectInfos, changeSelect } = useModel("goodsModel");
  54. const [categoryList, changeCategoryList] = React.useState([]);
  55. const [merchantNatureList, changeMerchantNatureList] = React.useState([]);
  56. const [goods, changeGoods] = React.useState([]);
  57. const [selectId, changeSelectId] = React.useState(0);
  58. const [goodsClass, setGoodsClass] = React.useState([]);
  59. const [pageType, changeType] = React.useState("signboard");
  60. useFocusEffect(
  61. React.useCallback(() => {
  62. changeBackground(theme["color-primary-500"]);
  63. console.log(route);
  64. if (route.params.type == "classification") {
  65. changeSelectId(route.params.classificationId);
  66. }
  67. if (route.params.type) {
  68. changeType(route.params.type);
  69. } else {
  70. changeType("signboard");
  71. }
  72. getAllGoods();
  73. }, [])
  74. );
  75. React.useEffect(() => {
  76. if (selectId && selectId != "new") {
  77. getSelectGoods();
  78. } else if (selectId == "new") {
  79. setGoodsClass(selectInfos);
  80. }
  81. }, [selectId]);
  82. function getSelectGoods() {
  83. httpGet("/classification/allGoods", {
  84. classificationId: selectId,
  85. }).then(res => {
  86. let list = res || [];
  87. list = list.filter(item => {
  88. return item != null;
  89. });
  90. setGoodsClass(list);
  91. });
  92. }
  93. function getAllGoods() {
  94. httpGet("/goods/my").then(res => {
  95. changeGoods(res);
  96. });
  97. }
  98. const topGoods = React.useMemo(() => {
  99. if (pageType == "signboard") {
  100. return goods.filter(item => {
  101. return item.signboard;
  102. });
  103. } else {
  104. return [...goodsClass];
  105. }
  106. }, [goods, goodsClass]);
  107. const elseGoods = React.useMemo(() => {
  108. if (pageType === "signboard") {
  109. return goods.filter(item => {
  110. return !item.signboard;
  111. });
  112. } else {
  113. let _topIds = topGoods.map(item => {
  114. return item.id;
  115. });
  116. return goods.filter(item => {
  117. return _topIds.indexOf(item.id) === -1;
  118. });
  119. }
  120. }, [goods, goodsClass]);
  121. const [name, changeName] = React.useState("");
  122. const [sort, changeSort] = React.useState("");
  123. const [goodsIds, changeGoodsIds] = React.useState("");
  124. const canNext = React.useMemo(() => {
  125. return true;
  126. }, [name]);
  127. const chooseGoodsItem = ({ item, index }) => (
  128. <GoodsCard
  129. info={item}
  130. key={item.id}
  131. isAdd={true}
  132. removeEvent={() => {
  133. showDialog({
  134. bodyText: removeTips,
  135. status: "danger",
  136. cancelable: true,
  137. confirmCallback: () => {
  138. changeSignboard(item.id, false, remove, item);
  139. },
  140. });
  141. }}
  142. />
  143. );
  144. const goodsItem = ({ item, index }) => (
  145. <GoodsCard
  146. info={item}
  147. key={item.id}
  148. isAdd={false}
  149. addEvent={() => {
  150. if (topGoods.length < 2 || pageType != "signboard") {
  151. changeSignboard(item.id, true, add, item);
  152. } else {
  153. showDialog({
  154. bodyText: addClassTips,
  155. });
  156. }
  157. }}
  158. />
  159. );
  160. function changeSignboard(id, signboard, tips, info) {
  161. if (pageType == "signboard") {
  162. httpPost(
  163. "/goods/save",
  164. {
  165. id,
  166. signboard,
  167. },
  168. { body: "json" }
  169. ).then(res => {
  170. success(tips + successText);
  171. let _goods = goods.map(item => {
  172. if (item.id != id) {
  173. return item;
  174. } else {
  175. return res;
  176. }
  177. });
  178. changeGoods(_goods);
  179. });
  180. } else if (pageType == "classification" && selectId == "new") {
  181. let _goodsClass = [...goodsClass];
  182. if (signboard) {
  183. _goodsClass.push(info);
  184. } else {
  185. _goodsClass.splice(
  186. _goodsClass.findIndex(item => {
  187. return item.id == id;
  188. }),
  189. 1
  190. );
  191. }
  192. success(tips + successText);
  193. setGoodsClass(_goodsClass);
  194. changeSelect(_goodsClass);
  195. } else {
  196. if (signboard) {
  197. let ids = topGoods.map(item => {
  198. return item.id;
  199. });
  200. ids.push(id);
  201. httpGet(
  202. "/classification/saveGoods",
  203. {
  204. classificationId: selectId,
  205. string: ids.join(","),
  206. },
  207. { body: "json" }
  208. ).then(res => {
  209. success(tips + successText);
  210. getSelectGoods();
  211. });
  212. } else {
  213. httpGet(
  214. "/classification/delGoods",
  215. {
  216. classificationId: selectId,
  217. goodId: id,
  218. },
  219. { body: "json" }
  220. ).then(res => {
  221. success(tips + successText);
  222. getSelectGoods();
  223. });
  224. }
  225. }
  226. }
  227. return (
  228. <>
  229. <NavHeaderBar title={goodsClassificationTitle1} />
  230. <ScrollPage>
  231. <Layout style={styles.container}>
  232. <Card
  233. appearance='headerList'
  234. header={props => {
  235. return Header(props, goodsClassificationTitle2);
  236. }}
  237. disabled={true}
  238. >
  239. <List
  240. data={topGoods}
  241. style={styles.list}
  242. renderItem={chooseGoodsItem}
  243. ListEmptyComponent={EmptyComponent}
  244. />
  245. </Card>
  246. <Card
  247. appearance='headerList'
  248. header={props => {
  249. return Header(props, goodsClassificationTitle3);
  250. }}
  251. disabled={true}
  252. >
  253. <List
  254. data={elseGoods}
  255. style={styles.list}
  256. renderItem={goodsItem}
  257. ListEmptyComponent={EmptyComponent}
  258. />
  259. </Card>
  260. </Layout>
  261. {/* <ActionButton
  262. style={{ zIndex: 2 }}
  263. buttonColor={theme["color-primary-500"]}
  264. onPress={() => {
  265. let ids = topGoods.map((item) => {
  266. return item.id;
  267. });
  268. ids = ids.join(",");
  269. console.log(ids);
  270. navigation.navigate(route.params.preKey, {
  271. choosIds: ids,
  272. });
  273. }}
  274. position='center'
  275. /> */}
  276. </ScrollPage>
  277. </>
  278. );
  279. }
  280. const styles = StyleSheet.create({
  281. flex1: {
  282. backgroundColor: "rgba(0,0,0,0)",
  283. paddingHorizontal: 15,
  284. paddingBottom: 20,
  285. },
  286. list: {
  287. backgroundColor: "rgba(0,0,0,0)",
  288. },
  289. container: {
  290. backgroundColor: "#EEEEEE",
  291. paddingTop: 20,
  292. },
  293. tabContent: {
  294. backgroundColor: "#fff",
  295. marginTop: 20,
  296. },
  297. img: {
  298. width: 100,
  299. height: 100,
  300. alignSelf: "center",
  301. },
  302. img2: {
  303. width: 97,
  304. height: 21,
  305. alignSelf: "center",
  306. marginTop: 2,
  307. },
  308. text: {
  309. marginTop: 16,
  310. },
  311. layoutLeft: {
  312. // flexDirection: "row",
  313. paddingVertical: 10,
  314. justifyContent: "center",
  315. alignItems: "center",
  316. },
  317. form: {
  318. paddingHorizontal: 26,
  319. paddingVertical: 20,
  320. },
  321. textareaContainer: {
  322. backgroundColor: "#F0F0F0",
  323. height: 100,
  324. borderRadius: 4,
  325. },
  326. textarea: {
  327. textAlignVertical: "top", // hack android
  328. fontSize: 13,
  329. color: "#333",
  330. paddingHorizontal: 14,
  331. paddingVertical: 10,
  332. height: 100,
  333. },
  334. });