import React from 'react'
import {
  amisRender,
  commonInfo,
  crudCommonOptions,
  paginationTemplate,
  remoteOptions,
  stockListColumns,
} from '../../util/amis.tsx'

function StockList() {
  return (
    <div className="stock-list">
      {amisRender(
        {
          type: 'page',
          title: '股票列表',
          body: [
            {
              type: 'crud',
              api: {
                method: 'post',
                url: `${commonInfo.baseUrl}/stock/list`,
                data: {
                  query: {
                    contain: {
                      code: '${filter_code|default:undefined}',
                      name: '${filter_keyword|default:undefined}',
                      fullname: '${filter_keyword|default:undefined}',
                    },
                    inside: {
                      market: '${filter_market|default:undefined}',
                      industry: '${filter_industry|default:undefined}',
                    },
                  },
                  page: {
                    index: '${page}',
                    size: '${perPage}',
                  },
                  sort: [
                    {
                      column: 'code',
                      direction: 'ASC',
                    },
                  ],
                },
              },
              ...crudCommonOptions(),
              ...paginationTemplate(15, undefined, ['filter-toggler']),
              filterTogglable: true,
              filterDefaultVisible: false,
              filter: {
                title: '快速搜索',
                mode: 'default',
                columnCount: 4,
                body: [
                  {
                    type: 'input-text',
                    name: 'filter_code',
                    label: '编号',
                    placeholder: '请输入编号',
                    clearable: true,
                  },
                  {
                    type: 'input-text',
                    name: 'filter_keyword',
                    label: '关键字',
                    placeholder: '请输入关键字',
                    clearable: true,
                  },
                  {
                    name: 'filter_market',
                    label: '市场',
                    ...remoteOptions('select', 'stock_market'),
                    multiple: true,
                    extractValue: true,
                    joinValues: false,
                    clearable: true,
                    checkAll: true,
                    checkAllBySearch: true,
                    defaultCheckAll: true,
                  },
                  {
                    name: 'filter_industry',
                    label: '行业',
                    ...remoteOptions('select', 'stock_industry'),
                    searchable: true,
                    multiple: true,
                    extractValue: true,
                    joinValues: false,
                    clearable: true,
                    checkAll: true,
                    checkAllBySearch: true,
                  },
                ],
              },
              columns: stockListColumns(),
            },
          ],
        },
      )}
    </div>
  )
}

export default React.memo(StockList)