敢为人鲜小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

387 lines
12 KiB

7 months ago
  1. <template>
  2. <view class="place-order">
  3. <uv-popup ref="popup" @change="change" mode="bottom">
  4. <view class="place-order-content">
  5. <view class="place-order-title">
  6. <image src="@/static/image/多人下单.webp" mode="aspectFit" class="place-order-title-image" />
  7. <text class="number">{{ item.sales }}</text><text class="text">人下单</text>
  8. <view class="place-order-title-close" @click="close">
  9. <uv-icon name="close" size="40rpx" />
  10. </view>
  11. </view>
  12. <!-- 选择取餐地点 -->
  13. <view class="place-order-address" @click="gotoPickupPoint">
  14. <uv-icon name="map-fill" color="#019245" size="55rpx" />
  15. <text style="font-size: 42rpx;" v-show="!pickupPoint">
  16. 请选择取餐地点
  17. </text>
  18. <view v-if="pickupPoint" class="place-order-address-content">
  19. <view class="place-order-address-content-name">
  20. {{ pickupPoint.name }}{{ pickupPoint.phone }}
  21. </view>
  22. <view class="place-order-address-content-address"> {{ pickupPoint.area }} {{ pickupPoint.address
  23. }} </view>
  24. </view>
  25. <view class="place-order-address-arrow">
  26. <uv-icon name="arrow-right" size="40rpx" />
  27. </view>
  28. </view>
  29. <uv-gap height="20rpx" bgColor="#F7F7F7" />
  30. <!-- 货品信息 -->
  31. <view class="item">
  32. <image :src="item.image" mode="aspectFill" class="item-image"></image>
  33. <view style="font-size: 36rpx;">
  34. <view>{{ item.title }}</view>
  35. <view style="color: red; ">{{ (priceAll || 0).toFixed(2) }}</view>
  36. <view style="margin-top: 30rpx;">
  37. <uv-number-box v-model="value" button-size="36"></uv-number-box>
  38. </view>
  39. </view>
  40. </view>
  41. <!-- 选项框 -->
  42. <uv-radio-group v-model="payMethod">
  43. <view class="option-box">
  44. <view class="option-box-item">
  45. <uv-icon name="weixin-circle-fill" size="70rpx" color="#019245" />
  46. <text style="flex: 1;">
  47. 微信支付
  48. </text>
  49. <uv-radio activeColor="#019245" size="40rpx" name="0" />
  50. </view>
  51. <view class="option-box-item">
  52. <uv-icon name="red-packet" size="70rpx" color="#019245" />
  53. <text style="flex: 1;">
  54. 账户余额
  55. <text style="color: gray; margin-left: 20rpx;">(余额: {{ (userInfo.balance || 0).toFixed(2) }})</text>
  56. </text>
  57. <uv-radio activeColor="#019245" size="40rpx" name="1" :disabled="userInfo.balance < pricePay" />
  58. </view>
  59. </view>
  60. </uv-radio-group>
  61. <uv-gap height="20rpx" bgColor="#F7F7F7" />
  62. <!-- 优惠 -->
  63. <view class="discount">
  64. <text style="font-size: 35rpx;">优惠</text>
  65. <view style="display: flex; align-items: center; gap: 20rpx" @click="gotoCoupon">
  66. <image src="@/static/image/券.webp" mode="aspectFill" class="discount-image"
  67. v-if="couponData.id" />
  68. <text v-if="couponData.id">{{ couponData.couponId_dictText || '优惠卷' }}</text>
  69. <text v-else style="color: gray;">请选择您的优惠卷</text>
  70. <text style="color: red;" v-if="couponData.discount">-{{ couponData.discount || 0 }}</text>
  71. </view>
  72. </view>
  73. <uv-gap height="20rpx" bgColor="#F7F7F7" />
  74. <!-- 备注 -->
  75. <view class="remark">
  76. <text style="align-self: start;">备注</text>
  77. <textarea class="remark-textarea" placeholder="请输入您需要备注的内容" v-model="remark" />
  78. </view>
  79. <!-- 购物车与支付 -->
  80. <view class="cart-pay">
  81. <view class="cart" @click="$emit('addCart')">
  82. <uv-icon name="shopping-cart-fill" size="60rpx" color="#019245" label="加入购物车" labelPos="bottom"
  83. labelSize="25rpx" />
  84. </view>
  85. <view class="total-section">
  86. <text>合计</text>
  87. <text class="total-price">{{ (pricePay || 0).toFixed(2) }}</text>
  88. </view>
  89. <view class="pay" @tap="createOrder">
  90. 立即支付
  91. </view>
  92. </view>
  93. </view>
  94. </uv-popup>
  95. </view>
  96. </template>
  97. <script>
  98. import { mapState } from 'vuex'
  99. import order from '@/mixins/order'
  100. export default {
  101. mixins: [order],
  102. name: 'placeOrder',
  103. data() {
  104. return {
  105. value: 1,
  106. payMethod: '0',
  107. pickupPoint: null,
  108. remark: '',
  109. }
  110. },
  111. props: {
  112. item: {
  113. type: Object,
  114. default: () => {}
  115. }
  116. },
  117. computed: {
  118. ...mapState(['userInfo', 'couponData']),
  119. priceAll () {
  120. return this.item?.price * this.value || 0
  121. },
  122. goodss () {
  123. return this.item?.id ? `${this.item.id},${this.value},${this.priceAll};` : ''
  124. },
  125. pricePay () {
  126. const discount = this.couponData?.discount || 0
  127. return (this.priceAll - discount) > 0.01 ? (this.priceAll - discount) : 0.01
  128. },
  129. orderParams () {
  130. return {
  131. priceAll: this.priceAll,
  132. pricePay: this.pricePay,
  133. pricePreferential: this.couponData?.discount || 0,
  134. payType: this.payMethod,
  135. leaderId: this.pickupPoint?.id || '',
  136. userCouponId: this.couponData?.id || '',
  137. goodss: this.goodss,
  138. remark: this.remark
  139. }
  140. }
  141. },
  142. methods: {
  143. // ...mapMutations(['clearCouponData']),
  144. // 跳转到优惠卷选择页面
  145. gotoCoupon() {
  146. this.$utils.navigateTo('/pages_order/mine/coupon?usein=1')
  147. },
  148. // 添加open方法,用于外部调用打开弹窗
  149. open() {
  150. this.$refs.popup.open();
  151. },
  152. // 添加close方法,用于关闭弹窗
  153. close(){
  154. this.$refs.popup.close();
  155. },
  156. // 添加change方法,用于处理弹窗状态变化
  157. change(e) {
  158. console.log('弹窗状态变化:', e);
  159. // 可以在这里添加弹窗打开或关闭后的逻辑处理
  160. },
  161. // 跳转到取餐点选择页面
  162. gotoPickupPoint() {
  163. this.$utils.navigateTo('/pages_order/location/pickupPoint')
  164. },
  165. // 获取并监听取餐点选择事件
  166. listenPickupPoint() {
  167. const pickupPointStr = uni.getStorageSync('selectedPickupPoint');
  168. if (pickupPointStr) {
  169. this.pickupPoint = JSON.parse(pickupPointStr);
  170. }
  171. uni.$on('updatePickupPoint', (point) => {
  172. this.pickupPoint = point;
  173. })
  174. },
  175. // 创建订单
  176. createOrder(){
  177. if (!this.pickupPoint) {
  178. uni.showModal({
  179. title: '提示',
  180. content: '请选择取餐地点',
  181. showCancel: false,
  182. confirmColor: '#019245',
  183. success: () => {
  184. this.gotoPickupPoint()
  185. }
  186. })
  187. return
  188. }
  189. if (this.payMethod == '1' && this.userInfo && this.userInfo.balance < this.pricePay) {
  190. uni.showModal({
  191. title: '余额不足',
  192. showCancel: false,
  193. content: '前往充值',
  194. confirmColor: '#019245',
  195. success: () => {
  196. this.$utils.navigateTo('/pages_order/mine/wallet')
  197. }
  198. })
  199. return
  200. }
  201. this.handlePay(this.orderParams)
  202. }
  203. },
  204. mounted(){
  205. this.listenPickupPoint();
  206. },
  207. beforeDestroy() {
  208. uni.$off('updatePickupPoint');
  209. // this.clearCouponData();
  210. }
  211. }
  212. </script>
  213. <style lang="scss" scoped>
  214. .place-order-title{
  215. font-size: 35rpx;
  216. height: 90rpx;
  217. display: flex;
  218. align-items: center;
  219. justify-content: center;
  220. position: relative;
  221. .number{
  222. color: $uni-color;
  223. }
  224. .text{
  225. color: #000;
  226. }
  227. .place-order-title-image{
  228. width: 100rpx;
  229. height: 50rpx;
  230. }
  231. .place-order-title-close{
  232. position: absolute;
  233. right: 20rpx;
  234. top: 50%;
  235. transform: translateY(-50%);
  236. color: $uni-color-third;
  237. }
  238. }
  239. .place-order-address{
  240. display: flex;
  241. height: 80rpx;
  242. line-height: 80rpx;
  243. align-items: center;
  244. // background-color: red;
  245. gap: 30rpx;
  246. padding-left: 20rpx;
  247. position: relative;
  248. text{
  249. font-size: 32rpx;
  250. font-weight: 500;
  251. }
  252. &-arrow{
  253. position: absolute;
  254. right: 20rpx;
  255. top: 50%;
  256. transform: translateY(-50%);
  257. }
  258. &-content{
  259. display: flex;
  260. flex-direction: column;
  261. justify-content: space-around;
  262. gap: 0rpx;
  263. height: 100%;
  264. // width: 100%;
  265. &-name{
  266. height: 30rpx;
  267. line-height: 30rpx;
  268. }
  269. &-address{
  270. height: 30rpx;
  271. line-height: 30rpx;
  272. width: 90%;
  273. text-overflow: ellipsis; // 三个连着一起才会出现省略号
  274. overflow: hidden;
  275. white-space: nowrap;
  276. }
  277. }
  278. }
  279. .item{
  280. display: flex;
  281. padding: 40rpx;
  282. gap: 40rpx;
  283. &-image{
  284. width: 250rpx;
  285. height: 200rpx;
  286. }
  287. }
  288. .option-box{
  289. display: flex;
  290. flex-direction: column;
  291. gap: 40rpx;
  292. width: 100%;
  293. &-item{
  294. display: flex;
  295. gap: 20rpx;
  296. align-items: center;
  297. font-size: 32rpx;
  298. padding: 0 40rpx;
  299. }
  300. }
  301. .discount{
  302. height: 130rpx;
  303. display: flex;
  304. align-items: center;
  305. width: 90%;
  306. justify-content: space-between;
  307. padding:0rpx 40rpx 0rpx 40rpx;
  308. // gap: 20rpx;
  309. .discount-image{
  310. width: 36rpx;
  311. height: 36rpx;
  312. border-radius: 10rpx;
  313. }
  314. }
  315. .remark{
  316. display: flex;
  317. align-items: center;
  318. justify-content: space-between;
  319. padding: 20rpx 40rpx;
  320. // background-color: red;
  321. text{
  322. font-size: 32rpx;
  323. font-weight: 500;
  324. }
  325. .remark-textarea{
  326. width: 80%;
  327. height: 180rpx;
  328. // border: 1rpx solid #000;
  329. // border-radius: 10rpx;
  330. // padding: 20rpx;
  331. }
  332. }
  333. .cart-pay{
  334. // background-color: red;
  335. height: 130rpx;
  336. display: flex;
  337. .cart{
  338. width: 30%;
  339. display: flex;
  340. align-items: center;
  341. justify-content: center;
  342. }
  343. .total-section{
  344. width: 30%;
  345. display: flex;
  346. flex-direction: column;
  347. align-items: center;
  348. justify-content: center;
  349. text{
  350. font-size: 28rpx;
  351. &.total-price{
  352. color: #ff0000;
  353. font-size: 32rpx;
  354. font-weight: 500;
  355. }
  356. }
  357. }
  358. .pay{
  359. width: 40%;
  360. background-color: $uni-color;
  361. color: #fff;
  362. text-align: center;
  363. display: flex;
  364. align-items: center;
  365. justify-content: center;
  366. font-size: 32rpx;
  367. }
  368. }
  369. </style>