import { useState, useEffect } from 'react'
import Taro from '@tarojs/taro'
import CustomNav from '@/components/CustomNav'
import Popup from '@/components/Popup'
import Picker from '@/components/Picker'
import ShopCommission from '@/components/ShopCommission'
import eyes from '@/assets/icons/shopKeeper/小眼睛.png'
import ceyes from '@/assets/icons/shopKeeper/小眼睛-闭上.png'
import cutoverUser from '@/assets/icons/UserCenter/cutoverUser.png'
import touristOFF from '@/assets/icons/UserCenter/touristOFF.png'
import hotelBossOFF from '@/assets/icons/UserCenter/hotelBossOFF.png'
import shopBossON from '@/assets/icons/UserCenter/shopBossON.png'
import { getAccount } from '@/services/shopBoss'

import './spreadMoney.less'
import ToggleRole from '@/components/toggleRole/ToggleRole'

export default (props) => {
  const { shopList, shop, onHotelChange, shopMoney } = props
  const [showCutover, setShowCutover] = useState(false)
  const [isyear, setYear] = useState(false)
  const [isMomth, setMonth] = useState(false)
  const [shopAccount, setShopAccount] = useState([])
  const acc = shopMoney?.acc
  const { accountId } = acc



  useEffect(() => {
    getAccount(accountId).then((e) => {
      const accContent = e.records
      setShopAccount(accContent)

    })
  }, [accountId])

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

  //商铺更改
  const handleHotelChange = (shopId, current) => {
    onHotelChange(current)
  }



  const ShowMoldeOn = () => {
    setShowCutover(true)
  }
  const onClose = () => {
    setShowCutover(false)
  }

  return (
    <view>
      <view>
      </view>
      <ToggleRole showCutover={showCutover} onClose={onClose} role='shop' />
      <view style={{ padding: '30rpx', height: '100%' }}>
        <scroll-view scroll-y="true" 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='title'>推广收入记录</view>
          {
            shopAccount.map((item, index) => {
              return (
                <ShopCommission key={(index)} item={item} />

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

    </view>
  )
}