index.jsx 6.1KB

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