123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import Taro from "@tarojs/taro";
  2. import { Button, View } from "@tarojs/components";
  3. import { useState, useEffect } from "react";
  4. import withLayout from "@/layouts";
  5. import CustomNav from "@/components/CustomNav";
  6. import { getShopDetail } from '@/services/home';
  7. import { getVerifyTargetList, putVerifyTarget } from "@/services/payOrder";
  8. import Popup from "@/components/Popup";
  9. import SpinBox from "@/components/Spin/SpinBox";
  10. import LocationBig from "@/assets/icons/UserCenter/LocationBig.png";
  11. import Perfection from "@/assets/icons/UserCenter/Perfection.png";
  12. import BlackSpot from "@/assets/icons/GuideCheck/BlackSpot.png";
  13. import TBCard from './Card'
  14. import "./style.less";
  15. export default withLayout((props) => {
  16. const { router, person, location } = props;
  17. const { id, subOrderId } = props.router.params;
  18. const [submiting, setSubmiting] = useState(false)
  19. const [showDialog, setShowDialog] = useState(false);
  20. //核销
  21. const [Consumption, setConsumption] = useState(false);
  22. const [checked, setChecked] = useState([]);
  23. const [shopContent, setShopContent] = useState([])
  24. const [loading, setLoading] = useState(false)
  25. const [list, setList] = useState([]);
  26. const getShop = () => {
  27. getShopDetail(id, { location: location }).then(e => {
  28. setShopContent(e)
  29. })
  30. }
  31. const getList = (params) => {
  32. setLoading(true)
  33. getVerifyTargetList({
  34. shopId: id,
  35. isMine: true,
  36. isVerified: 0,
  37. pageNum: 1,
  38. pageSize: 50,
  39. }).then((res) => {
  40. if (res) {
  41. setList(res.records)
  42. if (res.records && res.records.length > 0) {
  43. if (res.records.length === 1) {
  44. setChecked([res.records[0].verifyNo])
  45. } else {
  46. setChecked([res?.records.filter(x => x.subOrderId == subOrderId)[0]?.verifyNo].filter(Boolean))
  47. }
  48. } else {
  49. Taro.navigateBack({ delta: 1 })
  50. }
  51. }
  52. setLoading(false)
  53. }).catch(() => setLoading(false));
  54. };
  55. useEffect(() => {
  56. if (id) {
  57. getList();
  58. getShop();
  59. }
  60. }, [id]);
  61. const handleCheck = (verifyNo) => {
  62. const inx = checked.indexOf(verifyNo)
  63. if (inx === -1) {
  64. setChecked([...checked, verifyNo])
  65. } else {
  66. const p1 = checked.slice(0, inx)
  67. const p2 = checked.slice(inx + 1)
  68. setChecked(p1.concat(p2))
  69. }
  70. }
  71. const handleVerifyClick = () => {
  72. if (!checked || !checked.length) {
  73. Taro.showToast({
  74. title: '请选择待核销套餐',
  75. icon: 'none',
  76. })
  77. return;
  78. }
  79. setShowDialog(true);
  80. };
  81. const ButtonCancel = () => {
  82. setShowDialog(false);
  83. };
  84. const ButtonOK = (e) => {
  85. if (!submiting) {
  86. setSubmiting(true);
  87. Promise.all(checked.map(verifyNo => putVerifyTarget(verifyNo)))
  88. .then(res => {
  89. setSubmiting(false);
  90. setShowDialog(false);
  91. setConsumption(true);
  92. })
  93. .catch(e => {
  94. setShowDialog(false);
  95. setSubmiting(false);
  96. getList(); // 刷新数据
  97. Taro.showToast({
  98. title: '核销失败',
  99. icon: 'none',
  100. duration: 2000
  101. })
  102. })
  103. }
  104. };
  105. const PerfectionOK = () => {
  106. setConsumption(false);
  107. if (list?.length > 1) {
  108. getList()
  109. } else {
  110. Taro.redirectTo({
  111. url: '/pages/MineUserAll/AllOrder/index?tabJump=3',
  112. });
  113. // Taro.navigateBack({ delta: 1 })
  114. }
  115. };
  116. const btnText = ['确认核销', checked && checked.length > 0 ? `(${checked.length})` : undefined].filter(Boolean).join(' ')
  117. return (
  118. <view className='page-index shop-Eat'>
  119. <view className='index-navbar'>
  120. <CustomNav title='到店核销' />
  121. </view>
  122. <Popup show={showDialog} maskClosable={false}>
  123. <View className='Consumption-Now'>真的要翻我的牌子吗?</View>
  124. <View className='Consumption-text'>核销后套餐券不退不换,</View>
  125. <View className='Consumption-text'>请核对无误后再点击确认。</View>
  126. <view className='buy-button-box'>
  127. <button className='button-Cancel' onClick={ButtonCancel}>
  128. 取消
  129. </button>
  130. <button className='button-OK' onClick={ButtonOK} loading={submiting}>
  131. 确定
  132. </button>
  133. </view>
  134. </Popup>
  135. <Popup show={Consumption} maskClosable={false}>
  136. <view className='Perfection-image-view'>
  137. <image src={Perfection} className='Perfection-image' />
  138. <View>
  139. <text className='tleft'>请和店员说一下:</text><text className='tright'>“我核销好了”</text>
  140. </View>
  141. </view>
  142. <view className='buy-button-box'>
  143. <button className='button-OK' onClick={PerfectionOK}>
  144. 说过了
  145. </button>
  146. </view>
  147. </Popup>
  148. <view>
  149. <view className='position-header'>
  150. <image className='position-LocationBig' src={LocationBig} />
  151. <text cla='position-LocationBig-text'>
  152. 当前所在店铺:{shopContent?.shopName || []}
  153. </text>
  154. </view>
  155. <view className='shop-image'>
  156. <image
  157. mode='scaleToFill'
  158. className='shop-title-image-cup'
  159. src={BlackSpot}
  160. />
  161. <text className='shop-title-title'>请选择你要核销的套餐</text>
  162. </view>
  163. <SpinBox loading={loading}>
  164. {(list || []).map((item) => {
  165. return (
  166. <TBCard item={item} key={item.verifyNo} checked={checked} handleCheck={handleCheck} />
  167. )
  168. })}
  169. </SpinBox>
  170. <view className='button-info'>
  171. <Button className='button-box' onClick={handleVerifyClick}>
  172. {btnText}
  173. </Button>
  174. </view>
  175. </view>
  176. </view>
  177. );
  178. });