敢为人鲜小程序前端代码仓库
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.

349 lines
10 KiB

4 weeks 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.orderNum }}</text><text>人下单</text>
  8. <view class="place-order-title-close" @click="close">
  9. <uv-icon name="close" size="40rpx"></uv-icon>
  10. </view>
  11. </view>
  12. <!-- 选择取餐地点 -->
  13. <view class="place-order-address" @click="gotoPickupPoint">
  14. <uv-icon name="map-fill" color="#019245" size="55rpx">
  15. </uv-icon>
  16. <text style="font-size: 42rpx;" v-show="!pickupPoint">
  17. 请选择取餐地点
  18. </text>
  19. <view v-if="pickupPoint" class="place-order-address-content">
  20. <view class="place-order-address-content-name">
  21. {{ pickupPoint.name }}{{ pickupPoint.phone }}
  22. </view>
  23. <view class="place-order-address-content-address"> {{ pickupPoint.area }} {{ pickupPoint.address }} </view>
  24. </view>
  25. <view class="place-order-address-arrow">
  26. <uv-icon name="arrow-right" size="40rpx">
  27. </uv-icon>
  28. </view>
  29. </view>
  30. <uv-gap height="20rpx" bgColor="#F7F7F7" />
  31. <!-- 货品信息 -->
  32. <view class="item">
  33. <image :src="item.image" mode="aspectFill" class="item-image"></image>
  34. <view style="font-size: 36rpx;">
  35. <view>{{ item.name }}</view>
  36. <view style="color: red; ">{{ item.price }}</view>
  37. <view style="margin-top: 30rpx;">
  38. <uv-number-box v-model="value" button-size="36"></uv-number-box>
  39. </view>
  40. </view>
  41. </view>
  42. <!-- 选项框 -->
  43. <uv-radio-group v-model="payMethod">
  44. <view class="option-box" >
  45. <view class="option-box-item">
  46. <uv-icon name="weixin-circle-fill" size="70rpx" color="#019245" />
  47. <text style="flex: 1;">
  48. 微信支付
  49. </text>
  50. <uv-radio activeColor="#019245" size="40rpx" name="0" />
  51. </view>
  52. <view class="option-box-item">
  53. <uv-icon name="red-packet" size="70rpx" color="#019245" />
  54. <text style="flex: 1;">
  55. 账户余额
  56. <text style="color: gray; margin-left: 20rpx;">(余额: {{ userInfo.balance.toFixed(2) }})
  57. </text>
  58. </text>
  59. <uv-radio activeColor="#019245" size="40rpx" name="1" />
  60. </view>
  61. </view>
  62. </uv-radio-group>
  63. <uv-gap height="20rpx" bgColor="#F7F7F7" />
  64. <!-- 优惠 -->
  65. <view class="discount">
  66. <text style="font-size: 35rpx;">优惠</text>
  67. <view style="display: flex; align-items: center; gap: 20rpx">
  68. <image src="@/static/image/券.webp" mode="aspectFill" class="discount-image" />
  69. <text>新用户立减</text>
  70. <text style="color: red;">-2</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="pay" @tap="createOrder">
  86. 立即支付
  87. </view>
  88. </view>
  89. </view>
  90. </uv-popup>
  91. </view>
  92. </template>
  93. <script>
  94. export default {
  95. name: 'placeOrder',
  96. data() {
  97. return {
  98. value: 1,
  99. payMethod: '0',
  100. pickupPoint: null,
  101. remark: '',
  102. }
  103. },
  104. props: {
  105. item: {
  106. type: Object,
  107. default: () => {}
  108. }
  109. },
  110. computed: {
  111. priceAll () {
  112. return this.item.price * this.value
  113. },
  114. goodss () {
  115. return `${this.item.id},${this.value},${this.priceAll};`
  116. }
  117. },
  118. methods: {
  119. // 添加open方法,用于外部调用打开弹窗
  120. open() {
  121. this.$refs.popup.open();
  122. },
  123. // 添加close方法,用于关闭弹窗
  124. close(){
  125. this.$refs.popup.close();
  126. },
  127. // 添加change方法,用于处理弹窗状态变化
  128. change(e) {
  129. console.log('弹窗状态变化:', e);
  130. // 可以在这里添加弹窗打开或关闭后的逻辑处理
  131. },
  132. // 跳转到取餐点选择页面
  133. gotoPickupPoint() {
  134. this.$utils.navigateTo('/pages_order/location/pickupPoint')
  135. },
  136. // 获取并监听取餐点选择事件
  137. listenPickupPoint() {
  138. const pickupPointStr = uni.getStorageSync('selectedPickupPoint');
  139. if (pickupPointStr) {
  140. this.pickupPoint = JSON.parse(pickupPointStr);
  141. }
  142. uni.$on('updatePickupPoint', (point) => {
  143. this.pickupPoint = point;
  144. })
  145. },
  146. // 创建订单
  147. createOrder(){
  148. uni.showLoading({
  149. title: '下单中...'
  150. })
  151. this.$api('createOrder', {
  152. priceAll: this.priceAll,
  153. pricePay: this.priceAll - 0,
  154. pricePreferential: 0,
  155. payType: this.payMethod,
  156. leaderId: this.pickupPoint.id,
  157. goodss: this.goodss
  158. }, res => {
  159. uni.hideLoading()
  160. if (res.code === 200) {
  161. if (this.payMethod == '0') {
  162. uni.requestPaymentWxPay(res)
  163. .catch(n => {
  164. setTimeout(uni.redirectTo, 700, {
  165. url: '/pages/index/order'
  166. })
  167. })
  168. }else {
  169. uni.showToast({
  170. title: '下单成功',
  171. icon: 'success'
  172. })
  173. setTimeout(uni.redirectTo, 700, {
  174. url: '/pages/index/order'
  175. })
  176. }
  177. }
  178. })
  179. }
  180. },
  181. mounted(){
  182. this.listenPickupPoint();
  183. },
  184. onShow(){
  185. console.log('onShow');
  186. },
  187. beforeDestroy() {
  188. uni.$off('updatePickupPoint');
  189. }
  190. }
  191. </script>
  192. <style lang="scss" scoped>
  193. .place-order-title{
  194. font-size: 35rpx;
  195. height: 90rpx;
  196. display: flex;
  197. align-items: center;
  198. justify-content: center;
  199. position: relative;
  200. .number{
  201. color: $uni-color;
  202. }
  203. .text{
  204. color: #000;
  205. }
  206. .place-order-title-image{
  207. width: 100rpx;
  208. height: 50rpx;
  209. }
  210. .place-order-title-close{
  211. position: absolute;
  212. right: 20rpx;
  213. top: 50%;
  214. transform: translateY(-50%);
  215. color: $uni-color-third;
  216. }
  217. }
  218. .place-order-address{
  219. display: flex;
  220. height: 80rpx;
  221. line-height: 80rpx;
  222. align-items: center;
  223. // background-color: red;
  224. gap: 30rpx;
  225. padding-left: 20rpx;
  226. position: relative;
  227. text{
  228. font-size: 32rpx;
  229. font-weight: 500;
  230. }
  231. &-arrow{
  232. position: absolute;
  233. right: 20rpx;
  234. top: 50%;
  235. transform: translateY(-50%);
  236. }
  237. &-content{
  238. display: flex;
  239. flex-direction: column;
  240. justify-content: space-around;
  241. gap: 0rpx;
  242. height: 100%;
  243. // width: 100%;
  244. &-name{
  245. height: 30rpx;
  246. line-height: 30rpx;
  247. }
  248. &-address{
  249. height: 30rpx;
  250. line-height: 30rpx;
  251. width: 90%;
  252. text-overflow: ellipsis; // 三个连着一起才会出现省略号
  253. overflow: hidden;
  254. white-space: nowrap;
  255. }
  256. }
  257. }
  258. .item{
  259. display: flex;
  260. padding: 40rpx;
  261. gap: 40rpx;
  262. &-image{
  263. width: 250rpx;
  264. height: 200rpx;
  265. }
  266. }
  267. .option-box{
  268. display: flex;
  269. flex-direction: column;
  270. gap: 40rpx;
  271. width: 100%;
  272. &-item{
  273. display: flex;
  274. gap: 20rpx;
  275. align-items: center;
  276. font-size: 32rpx;
  277. padding: 0 40rpx;
  278. }
  279. }
  280. .discount{
  281. height: 130rpx;
  282. display: flex;
  283. align-items: center;
  284. width: 90%;
  285. justify-content: space-between;
  286. padding:0rpx 40rpx 0rpx 40rpx;
  287. // gap: 20rpx;
  288. .discount-image{
  289. width: 36rpx;
  290. height: 36rpx;
  291. border-radius: 10rpx;
  292. }
  293. }
  294. .remark{
  295. display: flex;
  296. align-items: center;
  297. justify-content: space-between;
  298. padding: 20rpx 40rpx;
  299. // background-color: red;
  300. text{
  301. font-size: 32rpx;
  302. font-weight: 500;
  303. }
  304. .remark-textarea{
  305. width: 80%;
  306. height: 180rpx;
  307. // border: 1rpx solid #000;
  308. // border-radius: 10rpx;
  309. // padding: 20rpx;
  310. }
  311. }
  312. .cart-pay{
  313. // background-color: red;
  314. height: 130rpx;
  315. display: flex;
  316. .cart{
  317. width: 30%;
  318. display: flex;
  319. align-items: center;
  320. justify-content: center;
  321. }
  322. .pay{
  323. width: 70%;
  324. background-color: $uni-color;
  325. color: #fff;
  326. text-align: center;
  327. display: flex;
  328. align-items: center;
  329. justify-content: center;
  330. font-size: 32rpx;
  331. }
  332. }
  333. </style>