spreadIndex.jsx 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import React, { useState, useEffect, useRef } from 'react'
  2. import CustomNav from '@/components/CustomNav'
  3. import { useRouter } from '@tarojs/taro'
  4. import { getShopList, getShopMoney, getVerifiedOrder } from '@/services/shopBoss'
  5. import { withSubscribeMessage } from '@/utils/subscribeMessage'
  6. import withLayout from '@/layouts'
  7. import {
  8. TPL_MESSAGE_SHOP_PAY_SUCCESS,
  9. TPL_MESSAGE_SHOP_VERIFY_RESULT,
  10. } from '@/utils/constants'
  11. import tabList from './Shoptabbar'
  12. import ShopKeeper from '../../components/ShopKeeper/shopKeeper'
  13. import Sparead from '../../components/Sparead/spreadMoney'
  14. import './spreadIndex.less'
  15. import { View } from '@tarojs/components'
  16. export default withLayout((props) => {
  17. const { router, person } = props
  18. const { params } = useRouter()
  19. const { tab,shopOrderId } = params || {}
  20. const [currentTab, setCurrentTab] = useState(0)
  21. //顶部的商铺列表
  22. const [shopList, setShopList] = useState([])
  23. //当前商铺
  24. const [shop, setShop] = useState()
  25. // const shopOrderId='1a8deba868489b0be19cba941e6f577e'
  26. const shopId = shop?.shopId
  27. const [amountType, setAmountType] = useState('order')
  28. const [isVerified, setisVerified] = useState(0)
  29. const [shopMoney, setShopMoney] = useState([])
  30. const [verifiedOrder, setVerifiedOrder] = useState([])
  31. const listRef = useRef()
  32. const handleTabChange = (e) => {
  33. const { index } = e.detail
  34. index ? setAmountType('commission') : setAmountType('order')
  35. setCurrentTab(index)
  36. //如果context有的话代表他滚动了 那么切换tab页就置顶
  37. if (listRef.current?.context) {
  38. listRef.current.context.scrollTo({ top: 0 })
  39. }
  40. withSubscribeMessage([TPL_MESSAGE_SHOP_PAY_SUCCESS, TPL_MESSAGE_SHOP_VERIFY_RESULT])
  41. }
  42. //商铺列表
  43. useEffect(() => {
  44. getShopList().then((res) => {
  45. const { shopList: list, shop: current } = res
  46. setShopList(list)
  47. if (shopOrderId) {
  48. setShop(list.filter(x=>x.shopId==shopOrderId)[0])
  49. }
  50. else{
  51. setShop(current)
  52. }
  53. })
  54. }, [])
  55. // 搜索核销手机号
  56. const setVer = (e) => {
  57. setVerifiedOrder(e.records)
  58. }
  59. const onVarified = () => {
  60. setisVerified(1)
  61. }
  62. const onVarifiedTwo = () => {
  63. setisVerified(0)
  64. }
  65. useEffect(() => {
  66. if (shopId) {
  67. getShopMoney(shopId, amountType).then((e) => {
  68. setShopMoney(e)
  69. })
  70. }
  71. }, [amountType, shopId, currentTab])
  72. //店铺选择
  73. const handleHotelChange = (current) => {
  74. getShopMoney(current.shopId, amountType).then((e) => {
  75. setShop(current)
  76. getVerifiedOrder({
  77. isVerified: isVerified,
  78. pageNum: 1,
  79. pageSize: 99,
  80. shopId: current.shopId,
  81. }).then((res) => {
  82. const order = res.records
  83. setVerifiedOrder(order)
  84. })
  85. })
  86. }
  87. useEffect(() => {
  88. if (tab) {
  89. setCurrentTab(tab - 0)
  90. }
  91. }, [tab])
  92. return (
  93. <View className='page-index'>
  94. <view className='index-navbar'>
  95. <CustomNav logo='none' title={shop?.shopName} />
  96. </view>
  97. <view className='index-container'>
  98. {currentTab === 0 && <ShopKeeper isVerified={isVerified} shopId={shopId} amountType={amountType} setVer={setVer} onVarifiedTwo={onVarifiedTwo} onVarified={onVarified} verifiedOrder={verifiedOrder} shopList={shopList} shop={shop} onHotelChange={handleHotelChange} shopMoney={shopMoney} />
  99. }
  100. {currentTab === 1 && <Sparead shopList={shopList} shop={shop} verifiedOrder={verifiedOrder} onHotelChange={handleHotelChange} shopMoney={shopMoney} />}
  101. </view>
  102. <view className='index-tabbar'>
  103. <mp-tabbar extClass='custom-tabbar' current={currentTab} list={tabList} onChange={handleTabChange}></mp-tabbar>
  104. </view>
  105. </View>
  106. )
  107. })