checkout.vue 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874
  1. <template>
  2. <view class="container">
  3. <view v-if="loading" class="loading-wrap">
  4. <text class="loading-text">加载中...</text>
  5. </view>
  6. <scroll-view v-else scroll-y class="content">
  7. <!-- Address Section -->
  8. <view class="section address-section" @click="openAddressPicker">
  9. <view v-if="selectedAddress" class="address-content">
  10. <view class="address-top">
  11. <text class="receiver-name">{{ selectedAddress.receiverName }}</text>
  12. <text class="receiver-phone">{{ formatPhone(selectedAddress.phone) }}</text>
  13. <text v-if="selectedAddress.isDefault === 1" class="default-badge">默认</text>
  14. </view>
  15. <text class="address-detail">
  16. {{ selectedAddress.province }}{{ selectedAddress.city }}{{ selectedAddress.district }}{{ selectedAddress.street }}
  17. </text>
  18. <text class="address-arrow">›</text>
  19. </view>
  20. <view v-else class="address-empty" @click.stop="goAddAddress">
  21. <text class="address-empty-icon">📍</text>
  22. <text class="address-empty-text">请选择收货地址</text>
  23. <text class="address-arrow">›</text>
  24. </view>
  25. </view>
  26. <!-- 配送方式选择 -->
  27. <view class="section" v-if="deliveryMethod > 1">
  28. <text class="section-title">{{ deliveryMethodLabel(deliveryMethod) }}</text>
  29. <!-- 自提/线上服务区域 -->
  30. <view v-if="deliveryMethod === 2 || deliveryMethod === 3">
  31. <view class="delivery-sub-label">自取地点</view>
  32. <view class="picker-row" @click="showPickupLocationPicker">
  33. <text class="picker-value" v-if="selectedPickupLocation">{{ selectedPickupLocation.name }}</text>
  34. <text class="picker-placeholder" v-else>请选择自取地点</text>
  35. <text class="picker-arrow">›</text>
  36. </view>
  37. <view v-if="selectedPickupLocation && selectedPickupLocation.timeSlots && selectedPickupLocation.timeSlots.length > 0" class="picker-row" @click="showTimeSlotPicker">
  38. <text class="picker-value" v-if="selectedTimeSlot">{{ selectedTimeSlot.startTime }} - {{ selectedTimeSlot.endTime }}</text>
  39. <text class="picker-placeholder" v-else>请选择取货时间</text>
  40. <text class="picker-arrow">›</text>
  41. </view>
  42. </view>
  43. <view v-if="deliveryMethod === 4">
  44. <view class="picker-row" @click="showServicePersonPicker">
  45. <text class="picker-value" v-if="selectedServicePerson">{{ selectedServicePerson.name }}({{ selectedServicePerson.title || '服务者' }})</text>
  46. <text class="picker-placeholder" v-else>请选择服务者</text>
  47. <text class="picker-arrow">›</text>
  48. </view>
  49. <view v-if="selectedServicePerson" class="picker-row" @click="showOnlineSlotPicker">
  50. <text class="picker-value" v-if="selectedTimeSlot">{{ formatOnlineTime(selectedTimeSlot.startTime) }} - {{ formatOnlineTime(selectedTimeSlot.endTime) }}</text>
  51. <text class="picker-placeholder" v-else>请选择服务时间</text>
  52. <text class="picker-arrow">›</text>
  53. </view>
  54. </view>
  55. <view v-if="deliveryMethod === 5">
  56. <view class="picker-row" @click="showOnlineSlotPicker">
  57. <text class="picker-value" v-if="selectedTimeSlot">{{ formatOnlineTime(selectedTimeSlot.startTime) }} - {{ formatOnlineTime(selectedTimeSlot.endTime) }}</text>
  58. <text class="picker-placeholder" v-else>请选择预约时段</text>
  59. <text class="picker-arrow">›</text>
  60. </view>
  61. </view>
  62. </view>
  63. <!-- 配送方式选择 -->
  64. <view class="section" v-if="deliveryMethod > 1">
  65. <text class="section-title">{{ deliveryMethodLabel(deliveryMethod) }}</text>
  66. <!-- 自提/线上服务区域 -->
  67. <view v-if="deliveryMethod === 2 || deliveryMethod === 3">
  68. <view class="delivery-sub-label">自取地点</view>
  69. <view class="picker-row" @click="showPickupLocationPicker">
  70. <text class="picker-value" v-if="selectedPickupLocation">{{ selectedPickupLocation.name }}</text>
  71. <text class="picker-placeholder" v-else>请选择自取地点</text>
  72. <text class="picker-arrow">›</text>
  73. </view>
  74. <view v-if="selectedPickupLocation && selectedPickupLocation.timeSlots && selectedPickupLocation.timeSlots.length > 0" class="picker-row" @click="showTimeSlotPicker">
  75. <text class="picker-value" v-if="selectedTimeSlot">{{ selectedTimeSlot.startTime }} - {{ selectedTimeSlot.endTime }}</text>
  76. <text class="picker-placeholder" v-else>请选择取货时间</text>
  77. <text class="picker-arrow">›</text>
  78. </view>
  79. </view>
  80. <view v-if="deliveryMethod === 4">
  81. <view class="picker-row" @click="showServicePersonPicker">
  82. <text class="picker-value" v-if="selectedServicePerson">{{ selectedServicePerson.name }}({{ selectedServicePerson.title || '服务者' }})</text>
  83. <text class="picker-placeholder" v-else>请选择服务者</text>
  84. <text class="picker-arrow">›</text>
  85. </view>
  86. <view v-if="selectedServicePerson" class="picker-row" @click="showOnlineSlotPicker">
  87. <text class="picker-value" v-if="selectedTimeSlot">{{ formatOnlineTime(selectedTimeSlot.startTime) }} - {{ formatOnlineTime(selectedTimeSlot.endTime) }}</text>
  88. <text class="picker-placeholder" v-else>请选择服务时间</text>
  89. <text class="picker-arrow">›</text>
  90. </view>
  91. </view>
  92. <view v-if="deliveryMethod === 5">
  93. <view class="picker-row" @click="showOnlineSlotPicker">
  94. <text class="picker-value" v-if="selectedTimeSlot">{{ formatOnlineTime(selectedTimeSlot.startTime) }} - {{ formatOnlineTime(selectedTimeSlot.endTime) }}</text>
  95. <text class="picker-placeholder" v-else>请选择预约时段</text>
  96. <text class="picker-arrow">›</text>
  97. </view>
  98. </view>
  99. </view>
  100. <!-- Purchase Info Section (when product requires it) -->
  101. <view class="section" v-if="requiredFields.length > 0">
  102. <text class="section-title">购买信息</text>
  103. <view
  104. v-for="field in requiredFields"
  105. :key="field.fieldKey"
  106. class="purchase-field-row"
  107. >
  108. <text class="purchase-field-label">
  109. {{ field.fieldName }}
  110. <text v-if="field.isRequired" class="required-mark">*</text>
  111. </text>
  112. <input
  113. v-model="purchaseForm[field.fieldKey]"
  114. class="purchase-field-input"
  115. :placeholder="'请输入' + field.fieldName + (field.isRequired ? '' : '(选填)')"
  116. :disabled="!!field.prefillValue"
  117. placeholder-style="color: #ccc; font-size: 26rpx;"
  118. />
  119. <text v-if="field.prefillValue" class="purchase-field-prefill">已填写</text>
  120. </view>
  121. </view>
  122. <!-- Order Items Section -->
  123. <view class="section">
  124. <text class="section-title">商品信息</text>
  125. <view
  126. v-for="item in items"
  127. :key="item.productId"
  128. class="order-item"
  129. >
  130. <image
  131. class="item-image"
  132. :src="getImageUrl(item.coverImage) || '/static/default-product.png'"
  133. mode="aspectFill"
  134. />
  135. <view class="item-info">
  136. <text class="item-name">{{ item.productName }}</text>
  137. <text v-if="item.specDesc" class="item-spec-desc">{{ item.specDesc }}</text>
  138. <text v-if="item.supplierName" class="item-supplier-name">供应商: {{ item.supplierName }}</text>
  139. <text class="item-qty">x{{ item.quantity }}</text>
  140. </view>
  141. <text class="item-price">{{ formatPriceWithSymbol(effectivePrice(item)) }}</text>
  142. </view>
  143. </view>
  144. <!-- 赠会员提示 -->
  145. <view v-if="giftLevelNames.length > 0" class="section gift-member-section">
  146. <view class="gift-member-row">
  147. <text class="gift-member-icon">🎁</text>
  148. <text class="gift-member-text">本单含{{ giftLevelNames.join('、') }}赠送商品,支付成功后将自动开通会员</text>
  149. </view>
  150. </view>
  151. <!-- 赠会员累计进度 -->
  152. <view v-if="giftProgress && !giftIsGranted && giftProgress.threshold > 0" class="section gift-progress-section">
  153. <view class="gift-progress-header">
  154. <text class="gift-progress-icon">🎁</text>
  155. <text class="gift-progress-title">购会员商品累计进度</text>
  156. <text class="gift-progress-percent">{{ giftProgressPercent }}%</text>
  157. </view>
  158. <view class="gift-progress-bar-bg">
  159. <view class="gift-progress-bar-fill" :style="{ width: giftProgressPercent + '%' }"></view>
  160. </view>
  161. <view class="gift-progress-info">
  162. <text class="gift-progress-accumulated">已累 {{ giftAccumulatedYuan }} 元</text>
  163. <text class="gift-progress-remaining">还差 {{ giftRemainingYuan }} 元送会员</text>
  164. </view>
  165. <text class="gift-progress-note">单笔订单送会员商品原价达标即送,折扣订单也计入</text>
  166. <view v-if="giftProgress.grantedLevel" class="gift-progress-level">
  167. <text>达标将赠送 {{ giftProgress.grantedLevel === 'FAMILY' ? '家庭会员' : giftProgress.grantedLevel }} 权益</text>
  168. </view>
  169. </view>
  170. <view v-else-if="giftIsGranted" class="section gift-granted-section">
  171. <view class="gift-granted-row">
  172. <text class="gift-granted-icon">✅</text>
  173. <text class="gift-granted-text">本家庭已赠送会员,可前往会员中心查看</text>
  174. </view>
  175. </view>
  176. <!-- Freight Section -->
  177. <view class="section">
  178. <view class="info-row">
  179. <text class="info-label">运费</text>
  180. <text class="info-value">{{ formatPriceWithSymbol(freight) }}</text>
  181. </view>
  182. </view>
  183. <!-- Member Upgrade Hint -->
  184. <view v-if="!isMember" class="section member-upgrade-section" @click="goUpgrade">
  185. <view class="member-upgrade-row">
  186. <text class="member-upgrade-icon">👑</text>
  187. <text class="member-upgrade-text">开通会员享全场商品专享价</text>
  188. <text class="member-upgrade-arrow">›</text>
  189. </view>
  190. </view>
  191. <!-- Limited-Time Discount Section -->
  192. <view v-if="discountInfo" class="section discount-section">
  193. <view class="info-row">
  194. <text class="info-label">限时折扣</text>
  195. <text class="discount-amount">-{{ formatPriceWithSymbol(discountInfo.discountAmount) }}</text>
  196. </view>
  197. <view class="discount-rule-name">{{ discountInfo.ruleName || '' }}</view>
  198. <countdown-tag v-if="discountInfo.endTime" :end-time="discountInfo.endTime" />
  199. </view>
  200. <!-- Gift Promo Section -->
  201. <view v-if="giftPromo && giftPromo.active" class="section gift-promo-section">
  202. <view class="gift-promo-row">
  203. <text class="gift-promo-icon">🎁</text>
  204. <view class="gift-promo-content">
  205. <text class="gift-promo-title">送会员一口价</text>
  206. <text class="gift-promo-desc">送会员商品原价 {{ formatPriceWithSymbol(giftPromo.giftOriginalTotal) }} 元 → 实付 {{ formatPriceWithSymbol(giftPromo.payPrice) }} 元</text>
  207. <text class="gift-promo-save">已优惠 {{ formatPriceWithSymbol(giftPromoDiscount) }} 元</text>
  208. </view>
  209. </view>
  210. </view>
  211. <!-- Coupon Section -->
  212. <view class="section coupon-section" @click="openCouponPicker">
  213. <view class="info-row">
  214. <text class="info-label">优惠券</text>
  215. <view class="coupon-selected" v-if="selectedCoupon">
  216. <text class="coupon-discount">-{{ formatPriceWithSymbol(selectedCoupon.value) }}</text>
  217. <text class="coupon-name-tag">{{ selectedCoupon.name }}</text>
  218. </view>
  219. <view class="coupon-placeholder" v-else>
  220. <text class="placeholder-text">选择优惠券</text>
  221. </view>
  222. <text class="address-arrow">›</text>
  223. </view>
  224. </view>
  225. <view v-if="!isMember" class="section member-coupon-hint">
  226. <view class="member-coupon-hint-content">
  227. <text class="hint-icon">👑</text>
  228. <text class="hint-text">加入会员可使用优惠券享更多优惠</text>
  229. </view>
  230. </view>
  231. <!-- Points Deduction Section -->
  232. <view class="section" v-if="userTotalPoints > 0">
  233. <view class="info-row">
  234. <text class="info-label">积分抵扣</text>
  235. <text class="points-balance">可用 {{ userTotalPoints }} 积分</text>
  236. </view>
  237. <view class="points-input-row">
  238. <input
  239. class="points-input"
  240. type="number"
  241. :value="pointsUsed"
  242. @input="onPointsInput"
  243. placeholder="输入使用积分"
  244. placeholder-style="color: #ccc; font-size: 26rpx;"
  245. />
  246. <text class="points-hint">≈ ¥{{ pointsYuanEquivalent }}</text>
  247. </view>
  248. <view class="points-tip">
  249. <text class="points-tip-text">1积分 = ¥0.01,最多使用 {{ maxPoints }} 积分</text>
  250. </view>
  251. </view>
  252. <!-- Remark Section -->
  253. <view class="section">
  254. <view class="info-row">
  255. <text class="info-label">备注</text>
  256. <input
  257. class="remark-input"
  258. v-model="remark"
  259. placeholder="选填,给商家留言"
  260. placeholder-style="color: #ccc; font-size: 26rpx;"
  261. />
  262. </view>
  263. </view>
  264. <view class="bottom-spacer"></view>
  265. </scroll-view>
  266. <!-- 优惠券选择器必须与 scroll-view 平级,否则 iOS 上 position: fixed 在 scroll-view 内不生效(优惠券弹窗不显示) -->
  267. <view class="modal-mask" v-if="showCouponPicker" @click="closeCouponPicker">
  268. <view class="coupon-picker" @click.stop>
  269. <view class="picker-header">
  270. <text class="picker-title">选择优惠券</text>
  271. <text class="picker-close" @click="closeCouponPicker">关闭</text>
  272. </view>
  273. <scroll-view scroll-y class="picker-list">
  274. <!-- 已拥有优惠券 -->
  275. <view class="picker-section-title" v-if="ownedCoupons.length > 0">已拥有优惠券</view>
  276. <view
  277. v-for="coupon in ownedCoupons"
  278. :key="coupon.id"
  279. class="picker-item"
  280. :class="selectedCoupon && selectedCoupon.id === coupon.id ? 'picker-item-active' : ''"
  281. @click="selectCoupon(coupon)"
  282. >
  283. <view class="picker-item-left">
  284. <text class="picker-item-value">{{ formatPriceWithSymbol(coupon.value) }}</text>
  285. </view>
  286. <view class="picker-item-right">
  287. <text class="picker-item-name">{{ coupon.name }}</text>
  288. <text class="picker-item-condition">{{ getConditionText(coupon.minSpend) }}</text>
  289. </view>
  290. <view class="picker-item-check" v-if="selectedCoupon && selectedCoupon.id === coupon.id">
  291. <text class="check-icon">✓</text>
  292. </view>
  293. </view>
  294. <!-- 可兑换优惠券(需CF值):仅在 CF 足够兑换其中一张券时才提醒 -->
  295. <view class="picker-section-title" v-if="affordableExchangeCoupons.length > 0">
  296. 可用CF值兑换(当前余额 {{ cfBalance }} CF)
  297. </view>
  298. <view
  299. v-for="coupon in affordableExchangeCoupons"
  300. :key="coupon.id"
  301. class="picker-item picker-item-exchange"
  302. >
  303. <view class="picker-item-left">
  304. <text class="picker-item-value">{{ formatPriceWithSymbol(coupon.value) }}</text>
  305. </view>
  306. <view class="picker-item-right">
  307. <text class="picker-item-name">{{ coupon.name }}</text>
  308. <text class="picker-item-condition">{{ getConditionText(coupon.minSpend) }}</text>
  309. </view>
  310. <button
  311. class="exchange-btn"
  312. :disabled="coupon.exchanging"
  313. @click.stop="doExchangeCoupon(coupon)"
  314. >
  315. {{ coupon.exchanging ? '兑换中...' : '兑换' }}
  316. </button>
  317. </view>
  318. <view class="picker-empty" v-if="ownedCoupons.length === 0 && affordableExchangeCoupons.length === 0">
  319. <text>暂无可用优惠券</text>
  320. </view>
  321. </scroll-view>
  322. <view class="picker-footer" v-if="selectedCoupon">
  323. <button class="picker-btn-remove" @click="removeCoupon">不使用优惠券</button>
  324. </view>
  325. </view>
  326. </view>
  327. <!-- 自取地点选择器 -->
  328. <view class="modal-mask" v-if="showPickupLocationModal" @click="showPickupLocationModal=false">
  329. <view class="picker-modal" @click.stop>
  330. <view class="picker-header">
  331. <text class="picker-title">选择自取地点</text>
  332. <text class="picker-close" @click="showPickupLocationModal=false">关闭</text>
  333. </view>
  334. <scroll-view scroll-y class="picker-list">
  335. <view
  336. v-for="(loc, idx) in pickupLocations"
  337. :key="loc.id"
  338. class="picker-item"
  339. :class="selectedPickupLocation && selectedPickupLocation.id === loc.id ? 'picker-item-active' : ''"
  340. @click="selectPickupLocation(loc)"
  341. >
  342. <view class="picker-item-left">
  343. <text class="picker-item-name">{{ loc.name }}</text>
  344. <text class="picker-item-addr">{{ loc.address }}</text>
  345. </view>
  346. <view class="picker-item-check" v-if="selectedPickupLocation && selectedPickupLocation.id === loc.id">
  347. <text class="check-icon">✓</text>
  348. </view>
  349. </view>
  350. </scroll-view>
  351. </view>
  352. </view>
  353. <!-- 时间段选择器 -->
  354. <view class="modal-mask" v-if="showTimeSlotModal" @click="showTimeSlotModal=false">
  355. <view class="picker-modal" @click.stop>
  356. <view class="picker-header">
  357. <text class="picker-title">选择取货时间</text>
  358. <text class="picker-close" @click="showTimeSlotModal=false">关闭</text>
  359. </view>
  360. <scroll-view scroll-y class="picker-list">
  361. <view
  362. v-for="(slot, idx) in (selectedPickupLocation && selectedPickupLocation.timeSlots) || []"
  363. :key="slot.id"
  364. class="picker-item"
  365. :class="selectedTimeSlot && selectedTimeSlot.id === slot.id ? 'picker-item-active' : ''"
  366. @click="selectTimeSlot(slot)"
  367. >
  368. <view class="picker-item-left">
  369. <text class="picker-item-name">{{ slot.startTime }} - {{ slot.endTime }}</text>
  370. </view>
  371. <view class="picker-item-check" v-if="selectedTimeSlot && selectedTimeSlot.id === slot.id">
  372. <text class="check-icon">✓</text>
  373. </view>
  374. </view>
  375. </scroll-view>
  376. </view>
  377. </view>
  378. <!-- 服务者选择器 -->
  379. <view class="modal-mask" v-if="showServicePersonModal" @click="showServicePersonModal=false">
  380. <view class="picker-modal" @click.stop>
  381. <view class="picker-header">
  382. <text class="picker-title">选择服务者</text>
  383. <text class="picker-close" @click="showServicePersonModal=false">关闭</text>
  384. </view>
  385. <scroll-view scroll-y class="picker-list">
  386. <view
  387. v-for="(person, idx) in servicePersons"
  388. :key="person.id"
  389. class="picker-item"
  390. :class="selectedServicePerson && selectedServicePerson.id === person.id ? 'picker-item-active' : ''"
  391. @click="selectServicePerson(person)"
  392. >
  393. <view class="picker-item-left">
  394. <text class="picker-item-name">{{ person.name }}</text>
  395. <text class="picker-item-desc">{{ person.title || '' }}</text>
  396. <text class="picker-item-price">{{ formatPriceWithSymbol(person.price) }}</text>
  397. </view>
  398. <view class="picker-item-check" v-if="selectedServicePerson && selectedServicePerson.id === person.id">
  399. <text class="check-icon">✓</text>
  400. </view>
  401. </view>
  402. </scroll-view>
  403. </view>
  404. </view>
  405. <!-- 线上时间段选择器 -->
  406. <view class="modal-mask" v-if="showOnlineSlotModal" @click="showOnlineSlotModal=false">
  407. <view class="picker-modal" @click.stop>
  408. <view class="picker-header">
  409. <text class="picker-title">选择服务时间</text>
  410. <text class="picker-close" @click="showOnlineSlotModal=false">关闭</text>
  411. </view>
  412. <scroll-view scroll-y class="picker-list">
  413. <view
  414. v-for="slot in onlineTimeSlots"
  415. :key="slot.id"
  416. class="picker-item"
  417. :class="selectedTimeSlot && selectedTimeSlot.id === slot.id ? 'picker-item-active' : ''"
  418. @click="selectOnlineSlot(slot)"
  419. >
  420. <view class="picker-item-left">
  421. <text class="picker-item-name">{{ formatOnlineTime(slot.startTime) }} - {{ formatOnlineTime(slot.endTime) }}</text>
  422. </view>
  423. <view class="picker-item-check" v-if="selectedTimeSlot && selectedTimeSlot.id === slot.id">
  424. <text class="check-icon">✓</text>
  425. </view>
  426. </view>
  427. </scroll-view>
  428. </view>
  429. </view>
  430. <view class="bottom-bar">
  431. <view class="bottom-left">
  432. <text class="total-label">合计: </text>
  433. <text class="total-amount">{{ formatPriceWithSymbol(finalAmount) }}</text>
  434. <text v-if="selectedCoupon" class="total-original">{{ formatPriceWithSymbol(actualAmount + freight) }}</text>
  435. </view>
  436. <button
  437. :class="['submit-btn', submitting ? 'disabled' : '']"
  438. :disabled="submitting"
  439. @click="onSubmit"
  440. >提交订单</button>
  441. </view>
  442. </view>
  443. </template>
  444. <script>
  445. import config from '@/config.js'
  446. import { getCouponList, getCouponCheckoutList, addressList, getProductRequiredFields, getMyMembership, getGiftMembershipProgress, productDetail, getFamilyPlatformBalance, exchangeCouponByCf, shopDiscountCalculate } from '../../../utils/api.js'
  447. import { parseDate } from '@/utils/format.js'
  448. import CountdownTag from '@/pages/shop/components/countdown-tag.vue'
  449. export default {
  450. components: {
  451. CountdownTag
  452. },
  453. data() {
  454. return {
  455. items: [],
  456. selectedAddress: null,
  457. requiredFields: [], // 需要的购买信息字段
  458. purchaseForm: {}, // 用户填写的购买信息
  459. addressList: [],
  460. freight: 0,
  461. remark: '',
  462. loading: false,
  463. submitting: false,
  464. actualAmount: 0,
  465. coupons: [],
  466. exchangeableCoupons: [],
  467. cfBalance: 0,
  468. selectedCoupon: null,
  469. showCouponPicker: false,
  470. pointsUsed: 0,
  471. userTotalPoints: 0,
  472. pointsLoading: false,
  473. isMember: false,
  474. // 配送配置
  475. deliveryMethod: 1,
  476. productDeliveryConfig: null,
  477. pickupLocations: [],
  478. selectedPickupLocation: null,
  479. selectedTimeSlot: null,
  480. servicePersons: [],
  481. selectedServicePerson: null,
  482. onlineSlots: [],
  483. // 弹窗控制
  484. showPickupLocationModal: false,
  485. showTimeSlotModal: false,
  486. showServicePersonModal: false,
  487. showOnlineSlotModal: false,
  488. giftItemIds: [],
  489. giftProgress: null, // 赠会员累计进度
  490. discountInfo: null,
  491. giftPromo: null // 送会员一口价促销信息
  492. }
  493. },
  494. computed: {
  495. giftAccumulatedYuan() {
  496. if (!this.giftProgress || !this.giftProgress.accumulatedAmount) return 0
  497. return this.giftProgress.accumulatedAmount / 100
  498. },
  499. giftThresholdYuan() {
  500. if (!this.giftProgress || !this.giftProgress.threshold) return 0
  501. return this.giftProgress.threshold / 100
  502. },
  503. giftRemainingYuan() {
  504. if (!this.giftProgress || !this.giftProgress.remaining) return 0
  505. return this.giftProgress.remaining / 100
  506. },
  507. giftProgressPercent() {
  508. if (!this.giftProgress || !this.giftProgress.threshold || this.giftProgress.threshold <= 0) return 0
  509. if (!this.giftProgress.accumulatedAmount) return 0
  510. return Math.min(100, Math.round(this.giftProgress.accumulatedAmount / this.giftProgress.threshold * 100))
  511. },
  512. giftIsGranted() {
  513. return this.giftProgress && this.giftProgress.granted === 1
  514. },
  515. giftPromoDiscount() {
  516. if (!this.giftPromo || this.giftPromo.active !== true) return 0
  517. return this.giftPromo.discount || 0
  518. },
  519. giftLevelNames() {
  520. var names = []
  521. for (var i = 0; i < this.items.length; i++) {
  522. if (this.items[i].giftLevelName && names.indexOf(this.items[i].giftLevelName) < 0) {
  523. names.push(this.items[i].giftLevelName)
  524. }
  525. }
  526. return names
  527. },
  528. finalAmount() {
  529. var total = (this.actualAmount || 0) + (this.freight || 0)
  530. if (this.selectedCoupon) {
  531. total = total - this.selectedCoupon.value
  532. }
  533. total = total - (this.pointsUsed || 0)
  534. total = total - this.giftPromoDiscount
  535. if (total < 0) total = 0
  536. return total
  537. },
  538. maxPoints() {
  539. var total = (this.actualAmount || 0) + (this.freight || 0)
  540. if (this.selectedCoupon) {
  541. total = total - this.selectedCoupon.value
  542. }
  543. if (total < 0) total = 0
  544. if (this.userTotalPoints < total) {
  545. return this.userTotalPoints
  546. }
  547. return total
  548. },
  549. pointsYuanEquivalent() {
  550. return (this.pointsUsed / 100).toFixed(2)
  551. },
  552. ownedCoupons() {
  553. var self = this
  554. var currentProductId = (self.items && self.items.length > 0) ? self.items[0].productId : null
  555. return this.coupons.filter(function(c) {
  556. if (c.status && c.status !== 'AVAILABLE') return false
  557. if (c.minSpend && c.minSpend > self.actualAmount) return false
  558. if (c.applicableTo === 'PRODUCT' && c.productId != null) {
  559. return c.productId === currentProductId
  560. }
  561. if (c.applicableTo && c.applicableTo !== 'ALL' && c.applicableTo !== 'PRODUCT') return false
  562. return true
  563. })
  564. },
  565. availableCoupons() {
  566. var self = this
  567. var currentProductId = (self.items && self.items.length > 0) ? self.items[0].productId : null
  568. return this.coupons.filter(function(c) {
  569. if (c.status && c.status !== 'AVAILABLE') return false
  570. if (c.minSpend && c.minSpend > self.actualAmount) return false
  571. if (c.applicableTo === 'PRODUCT' && c.productId != null) {
  572. return c.productId === currentProductId
  573. }
  574. if (c.applicableTo && c.applicableTo !== 'ALL' && c.applicableTo !== 'PRODUCT') return false
  575. return true
  576. })
  577. },
  578. affordableExchangeCoupons() {
  579. var self = this
  580. return (this.exchangeableCoupons || []).filter(function(c) {
  581. return c.pointsPrice > 0 && self.cfBalance >= c.pointsPrice
  582. })
  583. },
  584. onlineTimeSlots() {
  585. if (this.deliveryMethod === 4 && this.selectedServicePerson) {
  586. return this.selectedServicePerson.slots || []
  587. }
  588. if (this.deliveryMethod === 5) {
  589. return this.onlineSlots
  590. }
  591. return []
  592. }
  593. },
  594. onLoad(options) {
  595. var that = this
  596. var stored = uni.getStorageSync('checkoutItems')
  597. var giftIds = uni.getStorageSync('checkoutGiftItemIds')
  598. var giftPromo = uni.getStorageSync('checkoutGiftPromo')
  599. this.giftItemIds = (giftIds && giftIds.length > 0) ? giftIds : []
  600. this.giftPromo = giftPromo || null
  601. if (stored && stored.length > 0) {
  602. this.items = stored
  603. this.calcAmount()
  604. } else if (options.productId) {
  605. // Load product directly from detail page
  606. var productData = {
  607. productId: parseInt(options.productId),
  608. productName: options.productName || '商品',
  609. coverImage: options.coverImage || '',
  610. unitPrice: parseInt(options.price) || 0,
  611. quantity: parseInt(options.quantity) || 1
  612. }
  613. if (options.skuId) {
  614. productData.skuId = parseInt(options.skuId)
  615. }
  616. this.items = [productData]
  617. this.calcAmount()
  618. }
  619. this.checkMemberStatus()
  620. this.loadDefaultAddress()
  621. this.loadRequiredFields()
  622. this.loadCoupons()
  623. this.loadExchangeableCoupons()
  624. this.loadCfBalance()
  625. this.loadUserPoints()
  626. this.loadDeliveryConfig()
  627. this.loadDiscount()
  628. this.loadGiftProgress()
  629. this._onLoadFired = true
  630. },
  631. onShow() {
  632. // 从地址选择/编辑页返回后重新加载地址列表(首次进入跳过,避免与 onLoad 双发)
  633. if (this._onLoadFired) {
  634. this._onLoadFired = false
  635. } else {
  636. this.loadDefaultAddress()
  637. }
  638. },
  639. methods: {
  640. effectivePrice(item) {
  641. if (!item) return 0
  642. var price = item.unitPrice || 0
  643. // 会员可享会员价
  644. if (this.isMember && item.memberPrice && item.memberPrice > 0 && item.memberPrice < price) {
  645. price = item.memberPrice
  646. }
  647. return price
  648. },
  649. calcAmount() {
  650. var total = 0
  651. for (var i = 0; i < this.items.length; i++) {
  652. total = total + (this.items[i].unitPrice * this.items[i].quantity)
  653. }
  654. this.actualAmount = total
  655. },
  656. async loadCoupons() {
  657. try {
  658. var res = await getCouponList()
  659. this.coupons = res.data || []
  660. } catch (e) {
  661. this.coupons = []
  662. }
  663. },
  664. async loadExchangeableCoupons() {
  665. try {
  666. var productId = null
  667. if (this.items && this.items.length > 0) {
  668. productId = this.items[0].productId
  669. }
  670. var res = await getCouponCheckoutList({ productId: productId })
  671. this.exchangeableCoupons = res.data || []
  672. } catch (e) {
  673. console.error('加载可兑换优惠券失败', e)
  674. this.exchangeableCoupons = []
  675. }
  676. },
  677. async loadCfBalance() {
  678. try {
  679. var res = await getFamilyPlatformBalance()
  680. if (res.code === 200 && res.data) {
  681. this.cfBalance = res.data.available || 0
  682. }
  683. } catch (e) {
  684. console.error('加载CF余额失败', e)
  685. }
  686. },
  687. async doExchangeCoupon(coupon) {
  688. if (coupon.pointsPrice > this.cfBalance) {
  689. uni.showToast({ title: 'CF值不足,当前可用 ' + this.cfBalance + ' CF值', icon: 'none' })
  690. return
  691. }
  692. coupon.exchanging = true
  693. uni.showLoading({ title: '兑换中...' })
  694. try {
  695. var res = await exchangeCouponByCf({ couponId: coupon.id })
  696. uni.hideLoading()
  697. coupon.exchanging = false
  698. if (res.code === 200) {
  699. uni.showToast({ title: '兑换成功', icon: 'success' })
  700. // 从可兑换列表移除,加入已拥有列表
  701. var idx = this.exchangeableCoupons.findIndex(function(c) { return c.id === coupon.id })
  702. if (idx >= 0) {
  703. this.exchangeableCoupons.splice(idx, 1)
  704. }
  705. coupon.isExchangeable = false
  706. coupon.status = 'AVAILABLE'
  707. this.coupons.push(coupon)
  708. // 刷新余额
  709. this.loadCfBalance()
  710. } else {
  711. uni.showToast({ title: res.message || '兑换失败', icon: 'none' })
  712. }
  713. } catch (e) {
  714. uni.hideLoading()
  715. coupon.exchanging = false
  716. uni.showToast({ title: '兑换失败', icon: 'none' })
  717. }
  718. },
  719. openCouponPicker() {
  720. if (this.availableCoupons.length === 0 && !this.selectedCoupon) {
  721. uni.showToast({ title: '暂无可用优惠券', icon: 'none' })
  722. return
  723. }
  724. this.showCouponPicker = true
  725. },
  726. closeCouponPicker() {
  727. this.showCouponPicker = false
  728. },
  729. selectCoupon(coupon) {
  730. this.selectedCoupon = coupon
  731. this.showCouponPicker = false
  732. },
  733. removeCoupon() {
  734. this.selectedCoupon = null
  735. this.showCouponPicker = false
  736. },
  737. onPointsInput(e) {
  738. var val = parseInt(e.detail.value) || 0
  739. if (val < 0) val = 0
  740. var maxP = this.maxPoints
  741. if (val > maxP) {
  742. val = maxP
  743. uni.showToast({ title: '最多使用 ' + maxP + ' 积分', icon: 'none' })
  744. }
  745. this.pointsUsed = val
  746. },
  747. getConditionText(minSpend) {
  748. if (!minSpend || minSpend <= 0) return '无门槛'
  749. return '满' + (minSpend / 100).toFixed(2) + '元可用'
  750. },
  751. async loadDefaultAddress() {
  752. this.loading = true
  753. try {
  754. var res = await addressList()
  755. if (res.code === 200) {
  756. var list = res.data || []
  757. this.addressList = list
  758. // 如果当前已有选中地址,保持选中状态
  759. if (this.selectedAddress) {
  760. var stillExists = false
  761. for (var k = 0; k < list.length; k++) {
  762. if (list[k].id === this.selectedAddress.id) {
  763. stillExists = true
  764. break
  765. }
  766. }
  767. if (!stillExists) {
  768. this.selectedAddress = null
  769. }
  770. }
  771. if (!this.selectedAddress) {
  772. for (var i = 0; i < list.length; i++) {
  773. if (list[i].isDefault === 1) {
  774. this.selectedAddress = list[i]
  775. break
  776. }
  777. }
  778. if (!this.selectedAddress && list.length > 0) {
  779. this.selectedAddress = list[0]
  780. }
  781. }
  782. }
  783. } catch (e) {
  784. console.error(e)
  785. } finally {
  786. this.loading = false
  787. }
  788. },
  789. async loadRequiredFields() {
  790. if (this.items.length === 0) return
  791. var productId = this.items[0].productId
  792. try {
  793. var res = await getProductRequiredFields(productId)
  794. if (res.code === 200) {
  795. this.requiredFields = res.data || []
  796. this.autoFillPurchaseForm()
  797. }
  798. } catch (e) {
  799. console.error(e)
  800. }
  801. },
  802. autoFillPurchaseForm() {
  803. if (!this.selectedAddress || this.requiredFields.length === 0) return
  804. var form = {}
  805. for (var i = 0; i < this.requiredFields.length; i++) {
  806. var field = this.requiredFields[i]
  807. if (field.prefillValue) {
  808. form[field.fieldKey] = field.prefillValue
  809. } else {
  810. form[field.fieldKey] = ''
  811. }
  812. }
  813. this.purchaseForm = form
  814. },
  815. openAddressPicker() {
  816. if (this.addressList.length === 0) {
  817. uni.showToast({ title: '暂无地址,请先添加', icon: 'none' })
  818. return
  819. }
  820. uni.navigateTo({ url: '/pages/shop/address/address?selectMode=1' })
  821. },
  822. checkMemberStatus() {
  823. var that = this
  824. getMyMembership().then(function(res) {
  825. if (res.data && res.data.memberLevel) {
  826. that.isMember = res.data.memberLevel !== 'FREE'
  827. }
  828. }).catch(function() {})
  829. },
  830. loadGiftProgress() {
  831. var that = this
  832. getGiftMembershipProgress().then(function(res) {
  833. if (res.data && res.data.code === 200) {
  834. that.giftProgress = res.data.data || null
  835. }
  836. }).catch(function() {})
  837. },
  838. goUpgrade() {
  839. uni.navigateTo({ url: '/pages/membership/upgrade' })
  840. },
  841. goAddAddress() {
  842. uni.navigateTo({ url: '/pages/shop/address-edit/address-edit' })
  843. },
  844. // ========== 配送方式相关 ==========
  845. loadDeliveryConfig() {
  846. if (this.items.length === 0) return
  847. var productId = this.items[0].productId
  848. if (!productId) return
  849. var stored = uni.getStorageSync('checkoutItems')
  850. var storageData = stored && stored.length > 0 ? stored[0] : {}
  851. var deliveryMethod = storageData.deliveryMethod
  852. if (!deliveryMethod || deliveryMethod <= 1) return
  853. this.deliveryMethod = deliveryMethod
  854. this.productDeliveryConfig = storageData.deliveryConfig || null
  855. // 如果来自产品详情,可能已有选中值
  856. if (storageData.pickupLocationId) {
  857. this.selectedPickupLocation = { id: storageData.pickupLocationId }
  858. }
  859. if (storageData.timeSlotId) {
  860. this.selectedTimeSlot = { id: storageData.timeSlotId }
  861. }
  862. if (storageData.servicePersonId) {
  863. this.selectedServicePerson = { id: storageData.servicePersonId }
  864. }
  865. // 加载完整配置
  866. var that = this
  867. productDetail({ id: productId }).then(function(res) {
  868. if (res.code === 200 && res.data && res.data.deliveryConfig) {
  869. that.productDeliveryConfig = res.data.deliveryConfig
  870. that.deliveryMethod = res.data.deliveryMethod || that.deliveryMethod
  871. that.pickupLocations = res.data.deliveryConfig.pickupLocations || []
  872. that.servicePersons = res.data.deliveryConfig.servicePersons || []
  873. that.onlineSlots = res.data.deliveryConfig.onlineSlots || []
  874. }
  875. }).catch(function() {})
  876. },
  877. loadDiscount() {
  878. var that = this
  879. if (this.items.length === 0) return
  880. var productIds = []
  881. for (var i = 0; i < this.items.length; i++) {
  882. if (this.items[i].productId) productIds.push(this.items[i].productId)
  883. }
  884. if (productIds.length === 0) return
  885. shopDiscountCalculate({
  886. productIds: productIds,
  887. orderAmount: this.actualAmount
  888. }).then(function(res) {
  889. if (res.code === 200 && res.data) {
  890. that.discountInfo = res.data
  891. }
  892. }).catch(function() {})
  893. },
  894. onDeliveryMethodChange: function(e) {
  895. this.deliveryMethod = parseInt(e.detail.value)
  896. this.selectedPickupLocation = null
  897. this.selectedTimeSlot = null
  898. this.selectedServicePerson = null
  899. },
  900. onPickupLocationChange: function(e) {
  901. var idx = parseInt(e.detail.value)
  902. if (this.pickupLocations[idx]) {
  903. this.selectedPickupLocation = this.pickupLocations[idx]
  904. this.selectedTimeSlot = null
  905. }
  906. },
  907. onTimeSlotChange: function(e) {
  908. var idx = parseInt(e.detail.value)
  909. if (this.selectedPickupLocation && this.selectedPickupLocation.timeSlots && this.selectedPickupLocation.timeSlots[idx]) {
  910. this.selectedTimeSlot = this.selectedPickupLocation.timeSlots[idx]
  911. }
  912. },
  913. onServicePersonChange: function(e) {
  914. var idx = parseInt(e.detail.value)
  915. if (this.servicePersons[idx]) {
  916. this.selectedServicePerson = this.servicePersons[idx]
  917. this.selectedTimeSlot = null
  918. }
  919. },
  920. onOnlineSlotChange: function(e) {
  921. var idx = parseInt(e.detail.value)
  922. if (this.onlineSlots[idx]) {
  923. this.selectedTimeSlot = this.onlineSlots[idx]
  924. }
  925. },
  926. deliveryMethodLabel: function(method) {
  927. var map = { 1: '快递配送', 2: '到店自提', 3: '快递/自提', 4: '线上服务', 5: '线上预约' }
  928. return map[method] || '快递配送'
  929. },
  930. deliveryMethodHint: function(method) {
  931. var map = { 1: '', 2: '请选择自取地点和时间段', 3: '请选择配送方式', 4: '请选择服务者和时间', 5: '请选择预约时段' }
  932. return map[method] || ''
  933. },
  934. selectPickupLocation(loc) {
  935. this.selectedPickupLocation = loc
  936. this.selectedTimeSlot = null
  937. this.showPickupLocationModal = false
  938. },
  939. selectTimeSlot(slot) {
  940. this.selectedTimeSlot = slot
  941. this.showTimeSlotModal = false
  942. },
  943. selectServicePerson(person) {
  944. this.selectedServicePerson = person
  945. this.selectedTimeSlot = null
  946. this.showServicePersonModal = false
  947. },
  948. selectOnlineSlot(slot) {
  949. this.selectedTimeSlot = slot
  950. this.showOnlineSlotModal = false
  951. },
  952. loadUserPoints() {
  953. var that = this
  954. uni.request({
  955. url: config.api('/api/user/info'),
  956. method: 'POST',
  957. data: {},
  958. header: {
  959. 'Content-Type': 'application/json',
  960. 'Authorization': 'Bearer ' + uni.getStorageSync('token')
  961. },
  962. success: function(res) {
  963. if (res.data && res.data.code === 200) {
  964. that.userTotalPoints = res.data.data.totalPoints || 0
  965. }
  966. }
  967. })
  968. },
  969. onSubmit() {
  970. if (!this.selectedAddress) {
  971. uni.showToast({ title: '请选择收货地址', icon: 'none' })
  972. return
  973. }
  974. if (this.items.length === 0) {
  975. uni.showToast({ title: '请选择商品', icon: 'none' })
  976. return
  977. }
  978. this.submitting = true
  979. var orderItems = []
  980. for (var i = 0; i < this.items.length; i++) {
  981. var itemData = {
  982. productId: this.items[i].productId,
  983. quantity: this.items[i].quantity
  984. }
  985. if (this.items[i].skuId) {
  986. itemData.skuId = this.items[i].skuId
  987. }
  988. orderItems.push(itemData)
  989. }
  990. var that = this
  991. uni.request({
  992. url: config.api('/api/product/order/create'),
  993. method: 'POST',
  994. data: {
  995. items: orderItems,
  996. giftItemIds: that.giftItemIds,
  997. remark: this.remark,
  998. addressId: that.selectedAddress.id,
  999. purchaseInfo: that.purchaseForm,
  1000. pointsUsed: that.pointsUsed,
  1001. discountAmount: (that.discountInfo ? that.discountInfo.discountAmount : 0) + that.giftPromoDiscount,
  1002. deliveryMethod: that.deliveryMethod,
  1003. pickupLocationId: that.selectedPickupLocation ? that.selectedPickupLocation.id : null,
  1004. timeSlotId: that.selectedTimeSlot ? that.selectedTimeSlot.id : null,
  1005. servicePersonId: that.selectedServicePerson ? that.selectedServicePerson.id : null
  1006. },
  1007. header: {
  1008. 'Content-Type': 'application/json',
  1009. 'Authorization': 'Bearer ' + uni.getStorageSync('token')
  1010. },
  1011. success: function(res) {
  1012. that.submitting = false
  1013. if (res.data && res.data.code === 200) {
  1014. var order = res.data.data
  1015. uni.showToast({ title: '下单成功', icon: 'success' })
  1016. uni.removeStorageSync('checkoutItems')
  1017. uni.removeStorageSync('checkoutGiftItemIds')
  1018. uni.removeStorageSync('checkoutGiftPromo')
  1019. var moneyAmount = order.moneyAmount != null ? order.moneyAmount : order.totalAmount
  1020. var pointsUsed = order.pointsUsed || 0
  1021. setTimeout(function() {
  1022. uni.navigateTo({
  1023. url: '/pages/shop/payment/payment?orderNo=' + order.orderNo + '&amount=' + moneyAmount + '&pointsUsed=' + pointsUsed
  1024. })
  1025. }, 1000)
  1026. } else {
  1027. uni.showToast({ title: res.data.message || '下单失败', icon: 'none' })
  1028. }
  1029. },
  1030. fail: function() {
  1031. that.submitting = false
  1032. uni.showToast({ title: '网络请求失败', icon: 'none' })
  1033. }
  1034. })
  1035. },
  1036. formatPrice(price) {
  1037. if (price === null || price === undefined) return '0.00'
  1038. return (Number(price) / 100).toFixed(2)
  1039. },
  1040. formatPhone(phone) {
  1041. if (!phone) return ''
  1042. if (phone.length === 11) {
  1043. return phone.substr(0, 3) + '****' + phone.substr(7)
  1044. }
  1045. return phone
  1046. },
  1047. selectServicePerson(person) {
  1048. this.selectedServicePerson = person
  1049. this.selectedTimeSlot = null
  1050. this.showServicePersonModal = false
  1051. },
  1052. selectOnlineSlot(slot) {
  1053. this.selectedTimeSlot = slot
  1054. this.showOnlineSlotModal = false
  1055. },
  1056. formatOnlineTime: function(timeStr) {
  1057. if (!timeStr) return ''
  1058. try {
  1059. var d = parseDate(timeStr)
  1060. if (!d) return timeStr
  1061. return (d.getMonth() + 1) + '月' + d.getDate() + '日 ' + String(d.getHours()).padStart(2, '0') + ':' + String(d.getMinutes()).padStart(2, '0')
  1062. } catch (e) {
  1063. return timeStr
  1064. }
  1065. },
  1066. showPickupLocationPicker: function() {
  1067. this.showPickupLocationModal = true
  1068. },
  1069. showTimeSlotPicker: function() {
  1070. if (!this.selectedPickupLocation) return
  1071. this.showTimeSlotModal = true
  1072. },
  1073. showServicePersonPicker: function() {
  1074. this.showServicePersonModal = true
  1075. },
  1076. showOnlineSlotPicker: function() {
  1077. this.showOnlineSlotModal = true
  1078. },
  1079. selectPickupLocation: function(loc) {
  1080. this.selectedPickupLocation = loc
  1081. this.selectedTimeSlot = null
  1082. this.showPickupLocationModal = false
  1083. },
  1084. selectTimeSlot: function(slot) {
  1085. this.selectedTimeSlot = slot
  1086. this.showTimeSlotModal = false
  1087. },
  1088. selectServicePerson: function(person) {
  1089. this.selectedServicePerson = person
  1090. this.showServicePersonModal = false
  1091. },
  1092. getImageUrl: function(path) {
  1093. return config.API_BASE_URL + path
  1094. }
  1095. }
  1096. }
  1097. </script>
  1098. <style scoped>
  1099. .container {
  1100. min-height: 100vh;
  1101. background: #f5f5f5;
  1102. }
  1103. .loading-wrap {
  1104. display: flex;
  1105. justify-content: center;
  1106. padding-top: 200rpx;
  1107. }
  1108. .loading-text {
  1109. font-size: 28rpx;
  1110. color: #999;
  1111. }
  1112. .content {
  1113. height: calc(100vh - 120rpx);
  1114. }
  1115. .section {
  1116. background: #fff;
  1117. margin: 20rpx;
  1118. border-radius: 16rpx;
  1119. padding: 24rpx;
  1120. }
  1121. .section-title {
  1122. font-size: 28rpx;
  1123. font-weight: bold;
  1124. color: #333;
  1125. margin-bottom: 20rpx;
  1126. display: block;
  1127. }
  1128. .address-section {
  1129. position: relative;
  1130. }
  1131. .address-content {
  1132. position: relative;
  1133. }
  1134. .address-top {
  1135. display: flex;
  1136. align-items: center;
  1137. margin-bottom: 10rpx;
  1138. }
  1139. .receiver-name {
  1140. font-size: 30rpx;
  1141. font-weight: bold;
  1142. color: #333;
  1143. margin-right: 20rpx;
  1144. }
  1145. .receiver-phone {
  1146. font-size: 26rpx;
  1147. color: #666;
  1148. }
  1149. .default-badge {
  1150. font-size: 20rpx;
  1151. color: #F97316;
  1152. background: #fff7e6;
  1153. padding: 2rpx 12rpx;
  1154. border-radius: 20rpx;
  1155. margin-left: 12rpx;
  1156. }
  1157. .address-detail {
  1158. font-size: 26rpx;
  1159. color: #999;
  1160. line-height: 1.5;
  1161. }
  1162. .address-arrow {
  1163. position: absolute;
  1164. right: 0;
  1165. top: 50%;
  1166. font-size: 40rpx;
  1167. color: #ccc;
  1168. transform: translateY(-50%);
  1169. }
  1170. .address-empty {
  1171. display: flex;
  1172. align-items: center;
  1173. justify-content: center;
  1174. padding: 30rpx 0;
  1175. position: relative;
  1176. }
  1177. .address-empty-icon {
  1178. font-size: 40rpx;
  1179. margin-right: 12rpx;
  1180. }
  1181. .address-empty-text {
  1182. font-size: 28rpx;
  1183. color: #999;
  1184. }
  1185. .order-item {
  1186. display: flex;
  1187. align-items: center;
  1188. padding: 16rpx 0;
  1189. border-bottom: 1rpx solid #f5f5f5;
  1190. }
  1191. .order-item:last-child {
  1192. border-bottom: none;
  1193. }
  1194. .item-image {
  1195. width: 80rpx;
  1196. height: 80rpx;
  1197. border-radius: 8rpx;
  1198. background: #f0f0f0;
  1199. margin-right: 16rpx;
  1200. }
  1201. .item-info {
  1202. flex: 1;
  1203. display: flex;
  1204. flex-direction: column;
  1205. min-width: 0;
  1206. }
  1207. .item-name {
  1208. font-size: 26rpx;
  1209. color: #333;
  1210. overflow: hidden;
  1211. text-overflow: ellipsis;
  1212. white-space: nowrap;
  1213. margin-bottom: 6rpx;
  1214. }
  1215. .item-spec-desc {
  1216. font-size: 22rpx;
  1217. color: #999;
  1218. display: block;
  1219. margin-top: 2rpx;
  1220. }
  1221. .item-supplier-name {
  1222. font-size: 20rpx;
  1223. color: #0EA5E9;
  1224. display: block;
  1225. margin-top: 2rpx;
  1226. }
  1227. .item-qty {
  1228. font-size: 22rpx;
  1229. color: #999;
  1230. }
  1231. .item-price {
  1232. font-size: 26rpx;
  1233. color: #F97316;
  1234. font-weight: bold;
  1235. margin-left: 16rpx;
  1236. }
  1237. .info-row {
  1238. display: flex;
  1239. justify-content: space-between;
  1240. align-items: center;
  1241. padding: 8rpx 0;
  1242. }
  1243. .info-label {
  1244. font-size: 26rpx;
  1245. color: #999;
  1246. }
  1247. .info-value {
  1248. font-size: 26rpx;
  1249. color: #333;
  1250. }
  1251. .remark-input {
  1252. flex: 1;
  1253. text-align: right;
  1254. font-size: 26rpx;
  1255. color: #333;
  1256. }
  1257. /* ===== Coupon Section ===== */
  1258. .coupon-section {
  1259. position: relative;
  1260. }
  1261. .coupon-section:active {
  1262. background: #fafafa;
  1263. }
  1264. .coupon-selected {
  1265. display: flex;
  1266. align-items: center;
  1267. flex: 1;
  1268. justify-content: flex-end;
  1269. margin-right: 30rpx;
  1270. }
  1271. .coupon-discount {
  1272. font-size: 26rpx;
  1273. color: #F97316;
  1274. font-weight: 600;
  1275. margin-right: 12rpx;
  1276. }
  1277. .coupon-name-tag {
  1278. font-size: 22rpx;
  1279. color: #fff;
  1280. background: #F97316;
  1281. padding: 2rpx 12rpx;
  1282. border-radius: 6rpx;
  1283. max-width: 200rpx;
  1284. overflow: hidden;
  1285. text-overflow: ellipsis;
  1286. white-space: nowrap;
  1287. }
  1288. .coupon-placeholder {
  1289. flex: 1;
  1290. text-align: right;
  1291. margin-right: 30rpx;
  1292. }
  1293. .placeholder-text {
  1294. font-size: 26rpx;
  1295. color: #ccc;
  1296. }
  1297. .total-original {
  1298. font-size: 22rpx;
  1299. color: #bbb;
  1300. text-decoration: line-through;
  1301. margin-left: 8rpx;
  1302. }
  1303. /* ===== Member Upgrade Hint ===== */
  1304. .member-upgrade-section {
  1305. position: relative;
  1306. }
  1307. .member-upgrade-row {
  1308. display: flex;
  1309. align-items: center;
  1310. }
  1311. .member-upgrade-icon {
  1312. font-size: 32rpx;
  1313. margin-right: 12rpx;
  1314. }
  1315. .member-upgrade-text {
  1316. flex: 1;
  1317. font-size: 26rpx;
  1318. color: #F97316;
  1319. font-weight: 500;
  1320. }
  1321. .member-upgrade-arrow {
  1322. font-size: 32rpx;
  1323. color: #F97316;
  1324. }
  1325. /* ===== Member Coupon Hint ===== */
  1326. .member-coupon-hint {
  1327. margin-top: -10rpx;
  1328. margin-bottom: 20rpx;
  1329. }
  1330. .member-coupon-hint-content {
  1331. display: flex;
  1332. align-items: center;
  1333. padding: 20rpx 24rpx;
  1334. background: linear-gradient(135deg, #FFF7ED 0%, #FFEDD5 100%);
  1335. border-radius: 16rpx;
  1336. border: 1rpx solid #FED7AA;
  1337. }
  1338. .hint-icon {
  1339. font-size: 32rpx;
  1340. margin-right: 12rpx;
  1341. }
  1342. .hint-text {
  1343. font-size: 24rpx;
  1344. color: #C2410C;
  1345. font-weight: 500;
  1346. }
  1347. /* ===== Coupon Picker Modal ===== */
  1348. .modal-mask {
  1349. position: fixed;
  1350. top: 0;
  1351. left: 0;
  1352. right: 0;
  1353. bottom: 0;
  1354. background: rgba(0,0,0,0.5);
  1355. z-index: 999;
  1356. display: flex;
  1357. align-items: flex-end;
  1358. }
  1359. .coupon-picker {
  1360. background: #fff;
  1361. border-radius: 24rpx 24rpx 0 0;
  1362. width: 100%;
  1363. max-height: 70vh;
  1364. display: flex;
  1365. flex-direction: column;
  1366. }
  1367. .picker-header {
  1368. display: flex;
  1369. justify-content: space-between;
  1370. align-items: center;
  1371. padding: 30rpx;
  1372. border-bottom: 1rpx solid #eee;
  1373. }
  1374. .picker-title {
  1375. font-size: 30rpx;
  1376. font-weight: 600;
  1377. color: #333;
  1378. }
  1379. .picker-close {
  1380. font-size: 26rpx;
  1381. color: #999;
  1382. }
  1383. .picker-list {
  1384. max-height: 50vh;
  1385. padding: 0 20rpx;
  1386. }
  1387. .picker-item {
  1388. display: flex;
  1389. align-items: center;
  1390. padding: 24rpx 16rpx;
  1391. border-bottom: 1rpx solid #f5f5f5;
  1392. }
  1393. .picker-item:active {
  1394. background: #fafafa;
  1395. }
  1396. .picker-item-active {
  1397. background: #FFF7ED;
  1398. }
  1399. .picker-item-left {
  1400. width: 120rpx;
  1401. text-align: center;
  1402. flex-shrink: 0;
  1403. }
  1404. .picker-item-value {
  1405. font-size: 32rpx;
  1406. font-weight: bold;
  1407. color: #F97316;
  1408. }
  1409. .picker-item-right {
  1410. flex: 1;
  1411. margin: 0 16rpx;
  1412. }
  1413. .picker-item-name {
  1414. font-size: 26rpx;
  1415. color: #333;
  1416. display: block;
  1417. margin-bottom: 4rpx;
  1418. }
  1419. .picker-item-condition {
  1420. font-size: 22rpx;
  1421. color: #999;
  1422. }
  1423. .picker-item-check {
  1424. width: 40rpx;
  1425. height: 40rpx;
  1426. background: #F97316;
  1427. border-radius: 50%;
  1428. display: flex;
  1429. align-items: center;
  1430. justify-content: center;
  1431. flex-shrink: 0;
  1432. }
  1433. .check-icon {
  1434. color: #fff;
  1435. font-size: 24rpx;
  1436. font-weight: bold;
  1437. }
  1438. .picker-empty {
  1439. text-align: center;
  1440. padding: 60rpx 0;
  1441. font-size: 26rpx;
  1442. color: #999;
  1443. }
  1444. .picker-footer {
  1445. padding: 20rpx;
  1446. border-top: 1rpx solid #eee;
  1447. }
  1448. .picker-btn-remove {
  1449. background: #f5f5f5;
  1450. color: #666;
  1451. font-size: 26rpx;
  1452. border-radius: 12rpx;
  1453. border: none;
  1454. }
  1455. .picker-btn-remove::after {
  1456. border: none;
  1457. }
  1458. .bottom-spacer {
  1459. height: 140rpx;
  1460. }
  1461. .bottom-bar {
  1462. position: fixed;
  1463. bottom: 0;
  1464. left: 0;
  1465. right: 0;
  1466. height: 100rpx;
  1467. background: #fff;
  1468. border-top: 1rpx solid #eee;
  1469. display: flex;
  1470. align-items: center;
  1471. justify-content: space-between;
  1472. padding: 0 30rpx;
  1473. z-index: 100;
  1474. }
  1475. .bottom-left {
  1476. display: flex;
  1477. align-items: baseline;
  1478. }
  1479. .total-label {
  1480. font-size: 26rpx;
  1481. color: #666;
  1482. }
  1483. .total-amount {
  1484. font-size: 36rpx;
  1485. color: #F97316;
  1486. font-weight: bold;
  1487. }
  1488. .submit-btn {
  1489. background: linear-gradient(135deg, #F97316, #FB923C);
  1490. color: #fff;
  1491. font-size: 28rpx;
  1492. font-weight: bold;
  1493. padding: 0 60rpx;
  1494. height: 72rpx;
  1495. line-height: 72rpx;
  1496. border-radius: 36rpx;
  1497. border: none;
  1498. }
  1499. .submit-btn::after {
  1500. border: none;
  1501. }
  1502. .submit-btn.disabled {
  1503. background: #ddd;
  1504. color: #999;
  1505. }
  1506. .points-balance {
  1507. font-size: 24rpx;
  1508. color: #F97316;
  1509. }
  1510. .points-input-row {
  1511. display: flex;
  1512. align-items: center;
  1513. margin-top: 16rpx;
  1514. padding: 12rpx 0;
  1515. border-top: 1rpx solid #f5f5f5;
  1516. }
  1517. .points-input {
  1518. flex: 1;
  1519. height: 60rpx;
  1520. font-size: 28rpx;
  1521. color: #333;
  1522. background: #f9f9f9;
  1523. border-radius: 8rpx;
  1524. padding: 0 16rpx;
  1525. }
  1526. .points-hint {
  1527. font-size: 24rpx;
  1528. color: #999;
  1529. margin-left: 12rpx;
  1530. min-width: 100rpx;
  1531. text-align: right;
  1532. }
  1533. .points-tip {
  1534. margin-top: 8rpx;
  1535. }
  1536. .points-tip-text {
  1537. font-size: 22rpx;
  1538. color: #bbb;
  1539. }
  1540. .total-original {
  1541. font-size: 24rpx;
  1542. color: #bbb;
  1543. text-decoration: line-through;
  1544. margin-left: 8rpx;
  1545. }
  1546. /* ===== Purchase Info Fields ===== */
  1547. .purchase-field-row {
  1548. display: flex;
  1549. align-items: center;
  1550. padding: 16rpx 0;
  1551. border-bottom: 1rpx solid #f5f5f5;
  1552. }
  1553. .purchase-field-row:last-child {
  1554. border-bottom: none;
  1555. }
  1556. .purchase-field-label {
  1557. font-size: 26rpx;
  1558. color: #333;
  1559. width: 160rpx;
  1560. flex-shrink: 0;
  1561. }
  1562. .required-mark {
  1563. color: #f56c6c;
  1564. }
  1565. .purchase-field-input {
  1566. flex: 1;
  1567. font-size: 26rpx;
  1568. color: #333;
  1569. text-align: right;
  1570. padding: 8rpx 0;
  1571. }
  1572. .purchase-field-input[disabled] {
  1573. background: transparent;
  1574. color: #999;
  1575. }
  1576. .purchase-field-prefill {
  1577. font-size: 22rpx;
  1578. color: #67c23a;
  1579. margin-left: 8rpx;
  1580. }
  1581. /* 配送方式选择 */
  1582. .delivery-sub-label {
  1583. font-size: 24rpx;
  1584. color: #999;
  1585. margin-bottom: 12rpx;
  1586. margin-top: 16rpx;
  1587. }
  1588. .picker-row {
  1589. display: flex;
  1590. align-items: center;
  1591. justify-content: space-between;
  1592. padding: 20rpx 0;
  1593. border-bottom: 1rpx solid #f5f5f5;
  1594. }
  1595. .picker-row:last-child {
  1596. border-bottom: none;
  1597. }
  1598. .picker-value {
  1599. font-size: 28rpx;
  1600. color: #333;
  1601. flex: 1;
  1602. }
  1603. .picker-placeholder {
  1604. font-size: 28rpx;
  1605. color: #999;
  1606. flex: 1;
  1607. }
  1608. .picker-arrow {
  1609. font-size: 32rpx;
  1610. color: #ccc;
  1611. margin-left: 10rpx;
  1612. }
  1613. .modal-mask {
  1614. position: fixed;
  1615. top: 0;
  1616. left: 0;
  1617. right: 0;
  1618. bottom: 0;
  1619. background: rgba(0,0,0,0.5);
  1620. z-index: 999;
  1621. display: flex;
  1622. align-items: flex-end;
  1623. }
  1624. .picker-modal {
  1625. width: 100%;
  1626. background: #fff;
  1627. border-radius: 24rpx 24rpx 0 0;
  1628. max-height: 70vh;
  1629. display: flex;
  1630. flex-direction: column;
  1631. }
  1632. .picker-modal .picker-header {
  1633. display: flex;
  1634. justify-content: space-between;
  1635. align-items: center;
  1636. padding: 30rpx;
  1637. border-bottom: 1rpx solid #eee;
  1638. }
  1639. .picker-modal .picker-title {
  1640. font-size: 32rpx;
  1641. font-weight: bold;
  1642. color: #333;
  1643. }
  1644. .picker-modal .picker-close {
  1645. font-size: 28rpx;
  1646. color: #999;
  1647. }
  1648. .picker-modal .picker-list {
  1649. flex: 1;
  1650. max-height: 50vh;
  1651. padding: 20rpx 30rpx;
  1652. }
  1653. .picker-modal .picker-item {
  1654. display: flex;
  1655. align-items: center;
  1656. padding: 24rpx 0;
  1657. border-bottom: 1rpx solid #f5f5f5;
  1658. }
  1659. .picker-modal .picker-item:last-child {
  1660. border-bottom: none;
  1661. }
  1662. .picker-modal .picker-item-active {
  1663. background: #fff7e6;
  1664. border-radius: 12rpx;
  1665. padding: 24rpx 16rpx;
  1666. }
  1667. .picker-modal .picker-item-left {
  1668. flex: 1;
  1669. min-width: 0;
  1670. }
  1671. .picker-modal .picker-item-name {
  1672. font-size: 28rpx;
  1673. color: #333;
  1674. display: block;
  1675. }
  1676. .picker-modal .picker-item-addr {
  1677. font-size: 24rpx;
  1678. color: #999;
  1679. margin-top: 6rpx;
  1680. display: block;
  1681. }
  1682. .picker-modal .picker-item-desc {
  1683. font-size: 24rpx;
  1684. color: #999;
  1685. margin-top: 4rpx;
  1686. display: block;
  1687. }
  1688. .picker-modal .picker-item-price {
  1689. font-size: 26rpx;
  1690. color: #F97316;
  1691. font-weight: bold;
  1692. margin-top: 4rpx;
  1693. display: block;
  1694. }
  1695. .picker-modal .picker-item-check {
  1696. margin-left: 16rpx;
  1697. color: #F97316;
  1698. font-size: 32rpx;
  1699. }
  1700. /* Gift membership progress */
  1701. .gift-progress-section {
  1702. background: #FFF7ED;
  1703. border-radius: 16rpx;
  1704. border: 2rpx solid #FED7AA;
  1705. }
  1706. .gift-progress-header {
  1707. display: flex;
  1708. align-items: center;
  1709. margin-bottom: 16rpx;
  1710. }
  1711. .gift-progress-icon {
  1712. font-size: 32rpx;
  1713. margin-right: 12rpx;
  1714. }
  1715. .gift-progress-title {
  1716. flex: 1;
  1717. font-size: 26rpx;
  1718. color: #C2410C;
  1719. font-weight: 500;
  1720. }
  1721. .gift-progress-percent {
  1722. font-size: 28rpx;
  1723. color: #F97316;
  1724. font-weight: bold;
  1725. }
  1726. .gift-progress-bar-bg {
  1727. height: 20rpx;
  1728. background: #FED7AA;
  1729. border-radius: 10rpx;
  1730. overflow: hidden;
  1731. margin-bottom: 12rpx;
  1732. }
  1733. .gift-progress-bar-fill {
  1734. height: 100%;
  1735. background: linear-gradient(90deg, #F97316, #FB923C);
  1736. border-radius: 10rpx;
  1737. }
  1738. .gift-progress-info {
  1739. display: flex;
  1740. justify-content: space-between;
  1741. }
  1742. .gift-progress-accumulated {
  1743. font-size: 22rpx;
  1744. color: #9A3412;
  1745. }
  1746. .gift-progress-remaining {
  1747. font-size: 22rpx;
  1748. color: #C2410C;
  1749. font-weight: 500;
  1750. }
  1751. .gift-progress-level {
  1752. margin-top: 12rpx;
  1753. font-size: 22rpx;
  1754. color: #F97316;
  1755. }
  1756. .gift-progress-note {
  1757. display: block;
  1758. margin-top: 8rpx;
  1759. font-size: 20rpx;
  1760. color: #9A3412;
  1761. }
  1762. .gift-granted-section {
  1763. background: #F0FDF4;
  1764. border-radius: 16rpx;
  1765. border: 2rpx solid #BBF7D0;
  1766. }
  1767. .gift-granted-row {
  1768. display: flex;
  1769. align-items: center;
  1770. }
  1771. .gift-granted-icon {
  1772. font-size: 32rpx;
  1773. margin-right: 12rpx;
  1774. }
  1775. .gift-granted-text {
  1776. flex: 1;
  1777. font-size: 26rpx;
  1778. color: #15803D;
  1779. }
  1780. .gift-promo-section {
  1781. background: #FFF7ED;
  1782. border-radius: 16rpx;
  1783. border: 2rpx solid #FED7AA;
  1784. margin: 20rpx;
  1785. padding: 20rpx;
  1786. }
  1787. .gift-promo-row {
  1788. display: flex;
  1789. align-items: center;
  1790. justify-content: space-between;
  1791. }
  1792. .gift-promo-icon {
  1793. font-size: 32rpx;
  1794. margin-right: 12rpx;
  1795. }
  1796. .gift-promo-content {
  1797. flex: 1;
  1798. }
  1799. .gift-promo-title {
  1800. font-size: 26rpx;
  1801. color: #C2410C;
  1802. font-weight: 500;
  1803. }
  1804. .gift-promo-desc {
  1805. font-size: 22rpx;
  1806. color: #9A3412;
  1807. margin-top: 4rpx;
  1808. }
  1809. .gift-promo-save {
  1810. font-size: 22rpx;
  1811. color: #F97316;
  1812. }
  1813. /* 保持原有样式向下延伸 */
  1814. </style>