import { React, useState, useEffect, useRef } from 'react'
import Taro, { useRouter } from '@tarojs/taro'
import CustomNav from '@/components/CustomNav'
import Picker from '@/components/Picker'
import Popup from '@/components/Popup'
import ShopUsed from '@/components/ShopUsed' //已核销
import ShopUnused from '@/components/ShopUnused' //未核销
import SearchBar from '@/components/SearchBar'
import { getShopList, getShopMoney, getAccount, getVerifiedOrder, setGetVerifiedOrder } from '@/services/shopBoss'
import List from '@/components/List';

import eyes from '@/assets/icons/shopKeeper/小眼睛.png'
import ceyes from '@/assets/icons/shopKeeper/小眼睛-闭上.png'
import iconsearch from '@/assets/icons/housemantj/search.png'
import ms from '@/assets/icons/housemantj/ms3.jpg'
import ToggleRole from '@/components/toggleRole/ToggleRole'

import cutoverUser from '@/assets/icons/UserCenter/cutoverUser.png'
import './shopKeeper.less'
import { useMemo } from 'react'


export default (props) => {
  const { shopList, shop, onHotelChange, shopMoney, verifiedOrder, isVerified, onVarified, onVarifiedTwo, setVer } = props
  const { params } = useRouter()
  const { tabJump } = params || {}

  const [activeTab, setActiveTab] = useState(0)
  const [phone, setPhone] = useState()
  // const [isVerified, setisVerified] = useState(0)
  // const [queryParams, setQueryParams] = useState({ isVerified: isVerified, pageNum: 1, pageSize: 10, shopId: shop?.shopId, phone: phone })

  const queryParams = useMemo(() => ({
    shopId: shop?.shopId,
    isVerified: `${tabJump}` === '1' ? 1 : 0,
    phone: phone || '',
  }), [phone, shop?.shopId, tabJump])


  // 获取资源表信息
  const [alllist, setAllList] = useState([])

  const [isyear, setYear] = useState(true)
  const [isMomth, setMonth] = useState(false)
  //小眼睛开关
  const handleYear = () => {
    isyear ? setYear(false) : setYear(true)
  }
  const handleMonth = () => {
    isMomth ? setMonth(false) : setMonth(true)
  }


  const handleHotelChange = (e, current) => {
    onHotelChange(current)
  }


  const handelSearch = (e) => {
    const val = e.detail.value
    setPhone(val)
  }
  useEffect(() => {
    if (tabJump) {
      setActiveTab(tabJump - 0)
    }
  }, [tabJump])

  const handleTabChange = (e) => {
    const { index } = e.detail
    setActiveTab(index)
  }
  const tabs = [
    {
      title: '未核销订单',
    },
    {
      title: '已核销订单',
    },
  ]

  //给父组件传val
  const handleVarified = () => {
    onVarified()
  }


  const [showCutover, setShowCutover] = useState(false)
  const ShowMoldeOn = () => {
    setShowCutover(true)
  }
  const onClose = () => {
    setShowCutover(false)
  }
  return (
    <view>
      <view>
      </view>
      <ToggleRole showCutover={showCutover} onClose={onClose} maskClosable={showCutover} role='shop' />
      <view style={{ padding: '30rpx', height: '100%' }}>
        <scroll-view scroll-y scroll-view='true' bindscrolltoupper='upper' bindscrolltolower='lower' bindscroll='scroll' style={{ height: 'calc(100vh - 120px)' }}>
          <view className='storexx'>
            <view className='storeName'>店名：<Picker style={{ display: 'inline-block' }} placeholder='请选择商铺' value={shop?.shopId} kv={['shopName', 'shopId']} dicts={shopList} onChange={handleHotelChange} /></view>
            <view onClick={ShowMoldeOn} className='User-info-cutover'>
              <image className='User-info-cutover-image' src={cutoverUser} />
            </view>
            <view className='tip'>（计算收入以核销为准）</view>
            <view className='money'>
              <view className='sleft'>
                <view className='lword'>全年订单收入（税前）</view>

                <view className='yearMoney'>
                  <text>{isyear ? shopMoney?.totalCharges / 100 : '******'}</text>元
                  <image className='micon' src={isyear ? eyes : ceyes} onClick={handleYear} />
                </view>
              </view>
              <view className='line' />
              <view className='sright'>
                <view className='rword'>当月订单收入（税前）</view>
                <view className='monthMoney'>
                  <text>{isMomth ? shopMoney?.currentCharges / 100 : '******'}</text>元
                  <image className='micon2' src={isMomth ? eyes : ceyes} onClick={handleMonth}></image>
                </view></view>
            </view>
          </view>
          <view className='search'>

            <SearchBar placeholder='搜索订单(输入客户手机号码)' onBlur={handelSearch} />
          </view>
          <view className='index-tabs'>
            <mp-tabs
              tabClass='tabs-Unselected'
              swiperClass='tabs-swiper'
              activeClass='tabs-Selected'
              tabs={tabs}
              current={activeTab}
              onChange={handleTabChange}
              activeTab={activeTab}
            >
            </mp-tabs>
          </view>
          <view>
            {/* 未核销 */}
            {activeTab === 0 &&
              <>
                <List
                  style={{ height: 'calc(100% - 145px)' }}
                  request={getVerifiedOrder}
                  params={queryParams}
                  onDataChange={setAllList}
                  render={({ item, index }) => <ShopUnused key={(index)} item={item} />}
                >
                </List>
              </>

            }
            {/* 已核销 */}
            {activeTab === 1 &&
              <>
                <List
                  style={{ height: 'calc(100% - 145px)' }}
                  request={getVerifiedOrder}
                  params={queryParams}
                  onDataChange={setAllList}
                  render={({ item, index }) => <ShopUsed verifiedOrder={verifiedOrder} key={(index)} item={item} />}
                >
                </List>

              </>
            }
          </view>
          {/* <view className='botton'>已经到底了~</view> */}
        </scroll-view>
      </view>
    </view>
  )
}