123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- import React, { useEffect, useMemo, useState } from "react";
- import Taro, { useDidShow } from "@tarojs/taro";
- import "./index.scss";
- import { View, Text } from "@tarojs/components";
- import ContainerLayout from "../../compents/container/index";
- import Tab from "../../compents/tab/index";
- import Layout from "../../layout/index";
- import request from "../../util/request";
- import InifiniteList from "@/compents/InifiniteList";
- import IsLogin from "../../layout/IsLogin";
-
- const account = props => {
- const [list, setList] = useState([]);
- const [page, setPage] = useState({ total: 0, pageNum: 0 });
- const [loading, setLoading] = useState(false);
-
- const radioHouseState = useMemo(() => props.radioHouseState, [
- props.radioHouseState
- ]);
-
- console.log(props, radioHouseState);
- useEffect(() => {
-
- }, []);
-
- useDidShow(() => {
- getShopList({ pageNum: 1, pageSize: 10 });
- // if(page.pageNum==1){
-
- // }else{
- // getShopList({ pageNum: 1, pageSize: 10 });
- // }
-
- });
-
- function getShopList(params) {
- request({ url: "/taShop", params, method: "get" })
- .then(res => {
- const { records, ...page } = res.data.data;
- setPage({
- ...page,
- pageNum: page.current
- });
- if(page.current===1){
- setList(records || []);
- }else {
- setList(list.concat(records || []));
- }
-
- })
- .catch(() => setLoading(false));
- }
-
- const onDelete = shopId => {
- Taro.showModal({
- title: "确定删除该店铺吗",
- // content: '确定后,该老板房源信息将一并删除',
- cancelColor: "#d2d2d2",
- confirmColor: "#274191",
- success: function(res) {
- if (res.confirm) {
- request({ url: `/taShop/${shopId}`, method: "delete" }).then(res => {
- setList(list.filter(x => x.shopId != shopId));
- });
- } else if (res.cancel) {
- console.log("用户点击取消");
- }
- }
- });
- };
-
- const loadMore = () => {
- getShopList({ pageNum: page.pageNum + 1 });
- };
-
- const renderItem = (index, key) => (
- <View className="account-view" key={key}>
- {/* <Text className='account-view-title'>店铺编号:{index}</Text> */}
- <ContainerLayout className="account-view-card">
- <View className="top">
- <View>店铺名称:{list[index].name || ""}</View>
- {/* <View>电话:{x.user.name}</View>
- <View>微信号:{x.user.name}</View>
- <View>房源数:{x.user.name}</View> */}
- </View>
- <View className="bottom">
- <Text
- onClick={() => {
- Taro.navigateTo({
- url: `/pages/account/index?id=${list[index].shopId}`
- });
- }}
- >
- 店主
- </Text>
- <Text onClick={() => {
- Taro.navigateTo({
- url: `/pages/shop/edit/index?id=${list[index].shopId}`
- })
- }}>编辑</Text>
- <Text onClick={() => onDelete(list[index].shopId)}>删除</Text>
- </View>
- </ContainerLayout>
- </View>
- );
-
- return (
- <IsLogin>
- <View className="account">
- <Layout>
- <InifiniteList
- length={list.length}
- total={page.total}
- height={600}
- itemRenderer={renderItem}
- loadMore={loadMore}
- />
- </Layout>
- <Tab
- value={["+新增店铺"]}
- color="#ffffff"
- onClick={() => {
- Taro.navigateTo({ url: `/pages/shop/edit/index` });
- }}
- ></Tab>
- </View>
- </IsLogin>
- );
- };
-
- export default account;
|