import React, { useState, useEffect, useRef } from 'react';
import ProTable from '@ant-design/pro-table';
import { Form, Select,Card,Tabs,Pagination} from 'antd';
const { TabPane } = Tabs;
import {GetStoreGoods,GetStoreInfoPage} from "../../service";

const key = 'message';

const GoodsList = (props) => {
    //编辑商品信息 form实例
    const [dataLsit, SetDataLsit] = useState([]);
    const [total, SetTotal] = useState(0);
    const [loading, SetLoading] = useState(false);
    const goodscolumns = [
        {
          title: '主键',
          dataIndex: 'id',
          hideInSearch: true,
          hideInTable: true,
          tip: '规则名称是唯一的 key',
        },
        {
          title: '商品',
          dataIndex: 'goods_Name',
          valueType: 'textarea',
        },
        {
          title: '商品价格',
          dataIndex: 'price',
          valueType: 'money',
    
        },
        {
          title: '商品会员价格',
          dataIndex: 'vipPrice',
          valueType: 'money',
    
        },
    
        {
          title: '是否设备制作',
          dataIndex: 'isDevice',
          valueEnum: {
            0: { text: '店铺', status: 'Processing' },
            1: { text: '设备', status: 'Success' },
          },
        },
        {
          title: '状态',
          dataIndex: 'status',
          valueEnum: {
            0: { text: '上架', status: 'Processing' },
            1: { text: '下架', status: 'Success' },
          },
        },
        {
          title: '估清',
          dataIndex: 'stopSales',
          valueEnum: {
            0: { text: '销售', status: 'Processing' },
            1: { text: '估清', status: 'Success' },
          }
        }
      ];
      
  const getStoreInfoPageInfo = async (page) => {
    SetLoading(true);
    try {
      await GetStoreInfoPage({ current: page, pageSize: 10 }).then((r) => {
        SetTotal(1);
        SetDataLsit(r.data);
        SetLoading(false);
      });
    } catch {
      SetLoading(false);
    }

  }
    const actionRef = useRef();
    const goodsactionRef = useRef();
    useEffect(() => {
        getStoreInfoPageInfo(1);
    }, []);
    return <>
      <Card headStyle={{ border: '0px ' }} title="店铺商品" style={{ marginTop: '17px' }}>
        <Tabs defaultActiveKey="1" tabPosition="left" onChange={(key) => {
        }}>
          {dataLsit?.map((item) => {
            return (
              <TabPane tab={item.name}
                key={item.id}>
                <ProTable
                  actionRef={goodsactionRef}
                  rowKey="id"
                  search={false}
                  loading={loading}
                  bordered
                  columns={goodscolumns}
                  key={item.id}
                  request={async (params) => {
                    var data = [];
                    var total = 0;
                    params.StoreId = item.id;
                    await GetStoreGoods(params).then((r) => {
                      data = r.data?.data;
                      total = r.data?.total;
                    });
                    return {
                      data: data,
                      success: true,
                      total: total,
                    };
                  }}
                  rowSelection={{
                    type: "radio",
                    onChange: (_, selectedRows) => {
                        props.oncheck(selectedRows)
                        //setSelectedRows(selectedRows);
                    },
                  }}
                />
              </TabPane>
            );

          })}
        </Tabs>
        <Pagination
          size='small'
          style={{ float: 'right' }}
          total={total}
          onChange={(page, pageSize) => { getStoreInfoPageInfo(page) }}
          showTotal={(total, range) => `总共 ${total} 条`}
          defaultPageSize={10}
          defaultCurrent={1}
        />
      </Card>
    </>
}

export default GoodsList;