index.jsx 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import React, { useEffect, useMemo, useState } from "react";
  2. import Taro, { useDidShow } from "@tarojs/taro";
  3. import "./index.scss";
  4. import { View, Text } from "@tarojs/components";
  5. import ContainerLayout from "../../compents/container/index";
  6. import Tab from "../../compents/tab/index";
  7. import Layout from "../../layout/index";
  8. import request from "../../util/request";
  9. import InifiniteList from "@/compents/InifiniteList";
  10. import IsLogin from "../../layout/IsLogin";
  11. const account = props => {
  12. const [list, setList] = useState([]);
  13. const [page, setPage] = useState({ total: 0, pageNum: 0 });
  14. const [loading, setLoading] = useState(false);
  15. const radioHouseState = useMemo(() => props.radioHouseState, [
  16. props.radioHouseState
  17. ]);
  18. console.log(props, radioHouseState);
  19. useEffect(() => {
  20. }, []);
  21. useDidShow(() => {
  22. getShopList({ pageNum: 1, pageSize: 10 });
  23. // if(page.pageNum==1){
  24. // }else{
  25. // getShopList({ pageNum: 1, pageSize: 10 });
  26. // }
  27. });
  28. function getShopList(params) {
  29. request({ url: "/taShop", params, method: "get" })
  30. .then(res => {
  31. const { records, ...page } = res.data.data;
  32. setPage({
  33. ...page,
  34. pageNum: page.current
  35. });
  36. if(page.current===1){
  37. setList(records || []);
  38. }else {
  39. setList(list.concat(records || []));
  40. }
  41. })
  42. .catch(() => setLoading(false));
  43. }
  44. const onDelete = shopId => {
  45. Taro.showModal({
  46. title: "确定删除该店铺吗",
  47. // content: '确定后,该老板房源信息将一并删除',
  48. cancelColor: "#d2d2d2",
  49. confirmColor: "#274191",
  50. success: function(res) {
  51. if (res.confirm) {
  52. request({ url: `/taShop/${shopId}`, method: "delete" }).then(res => {
  53. setList(list.filter(x => x.shopId != shopId));
  54. });
  55. } else if (res.cancel) {
  56. console.log("用户点击取消");
  57. }
  58. }
  59. });
  60. };
  61. const loadMore = () => {
  62. getShopList({ pageNum: page.pageNum + 1 });
  63. };
  64. const renderItem = (index, key) => (
  65. <View className="account-view" key={key}>
  66. {/* <Text className='account-view-title'>店铺编号:{index}</Text> */}
  67. <ContainerLayout className="account-view-card">
  68. <View className="top">
  69. <View>店铺名称:{list[index].name || ""}</View>
  70. {/* <View>电话:{x.user.name}</View>
  71. <View>微信号:{x.user.name}</View>
  72. <View>房源数:{x.user.name}</View> */}
  73. </View>
  74. <View className="bottom">
  75. <Text
  76. onClick={() => {
  77. Taro.navigateTo({
  78. url: `/pages/account/index?id=${list[index].shopId}`
  79. });
  80. }}
  81. >
  82. 店主
  83. </Text>
  84. <Text onClick={() => {
  85. Taro.navigateTo({
  86. url: `/pages/shop/edit/index?id=${list[index].shopId}`
  87. })
  88. }}>编辑</Text>
  89. <Text onClick={() => onDelete(list[index].shopId)}>删除</Text>
  90. </View>
  91. </ContainerLayout>
  92. </View>
  93. );
  94. return (
  95. <IsLogin>
  96. <View className="account">
  97. <Layout>
  98. <InifiniteList
  99. length={list.length}
  100. total={page.total}
  101. height={600}
  102. itemRenderer={renderItem}
  103. loadMore={loadMore}
  104. />
  105. </Layout>
  106. <Tab
  107. value={["+新增店铺"]}
  108. color="#ffffff"
  109. onClick={() => {
  110. Taro.navigateTo({ url: `/pages/shop/edit/index` });
  111. }}
  112. ></Tab>
  113. </View>
  114. </IsLogin>
  115. );
  116. };
  117. export default account;