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

335 lines
10 KiB

  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.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;">(余额: 0)
  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">
  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. },
  115. methods: {
  116. // 添加open方法,用于外部调用打开弹窗
  117. open() {
  118. this.$refs.popup.open();
  119. },
  120. // 添加close方法,用于关闭弹窗
  121. close(){
  122. this.$refs.popup.close();
  123. },
  124. // 添加change方法,用于处理弹窗状态变化
  125. change(e) {
  126. console.log('弹窗状态变化:', e);
  127. // 可以在这里添加弹窗打开或关闭后的逻辑处理
  128. },
  129. // 跳转到取餐点选择页面
  130. gotoPickupPoint() {
  131. this.$utils.navigateTo('/pages_order/location/pickupPoint')
  132. },
  133. // 获取并监听取餐点选择事件
  134. listenPickupPoint() {
  135. const pickupPointStr = uni.getStorageSync('selectedPickupPoint');
  136. if (pickupPointStr) {
  137. this.pickupPoint = JSON.parse(pickupPointStr);
  138. }
  139. uni.$on('updatePickupPoint', (point) => {
  140. this.pickupPoint = point;
  141. })
  142. },
  143. // 创建订单
  144. createOrder(){
  145. this.$api('createOrder', {
  146. priceAll: this.priceAll,
  147. pricePay: this.priceAll - 0,
  148. pricePreferential: 0,
  149. payType: this.payMethod,
  150. }, res => {
  151. if (res.code === 200) {
  152. uni.requestPaymentWxPay(res)
  153. .then(e => {
  154. uni.showToast({
  155. title: '下单成功',
  156. icon: 'none'
  157. })
  158. // this.paySuccess(res)
  159. }).catch(n => {
  160. setTimeout(uni.redirectTo, 700, {
  161. url: '/pages/index/order'
  162. })
  163. })
  164. }
  165. })
  166. }
  167. },
  168. mounted(){
  169. this.listenPickupPoint();
  170. },
  171. beforeDestroy() {
  172. uni.$off('updatePickupPoint');
  173. }
  174. }
  175. </script>
  176. <style lang="scss" scoped>
  177. .place-order-title{
  178. font-size: 35rpx;
  179. height: 90rpx;
  180. display: flex;
  181. align-items: center;
  182. justify-content: center;
  183. position: relative;
  184. .number{
  185. color: $uni-color;
  186. }
  187. .text{
  188. color: #000;
  189. }
  190. .place-order-title-image{
  191. width: 100rpx;
  192. height: 50rpx;
  193. }
  194. .place-order-title-close{
  195. position: absolute;
  196. right: 20rpx;
  197. top: 50%;
  198. transform: translateY(-50%);
  199. color: $uni-color-third;
  200. }
  201. }
  202. .place-order-address{
  203. display: flex;
  204. height: 80rpx;
  205. line-height: 80rpx;
  206. align-items: center;
  207. // background-color: red;
  208. gap: 30rpx;
  209. padding-left: 20rpx;
  210. position: relative;
  211. text{
  212. font-size: 32rpx;
  213. font-weight: 500;
  214. }
  215. &-arrow{
  216. position: absolute;
  217. right: 20rpx;
  218. top: 50%;
  219. transform: translateY(-50%);
  220. }
  221. &-content{
  222. display: flex;
  223. flex-direction: column;
  224. justify-content: space-around;
  225. gap: 0rpx;
  226. height: 100%;
  227. // width: 100%;
  228. &-name{
  229. height: 30rpx;
  230. line-height: 30rpx;
  231. }
  232. &-address{
  233. height: 30rpx;
  234. line-height: 30rpx;
  235. width: 90%;
  236. text-overflow: ellipsis; // 三个连着一起才会出现省略号
  237. overflow: hidden;
  238. white-space: nowrap;
  239. }
  240. }
  241. }
  242. .item{
  243. display: flex;
  244. padding: 40rpx;
  245. gap: 40rpx;
  246. &-image{
  247. width: 250rpx;
  248. height: 200rpx;
  249. }
  250. }
  251. .option-box{
  252. display: flex;
  253. flex-direction: column;
  254. gap: 40rpx;
  255. width: 100%;
  256. &-item{
  257. display: flex;
  258. gap: 20rpx;
  259. align-items: center;
  260. font-size: 32rpx;
  261. padding: 0 40rpx;
  262. }
  263. }
  264. .discount{
  265. height: 130rpx;
  266. display: flex;
  267. align-items: center;
  268. width: 90%;
  269. justify-content: space-between;
  270. padding:0rpx 40rpx 0rpx 40rpx;
  271. // gap: 20rpx;
  272. .discount-image{
  273. width: 36rpx;
  274. height: 36rpx;
  275. border-radius: 10rpx;
  276. }
  277. }
  278. .remark{
  279. display: flex;
  280. align-items: center;
  281. justify-content: space-between;
  282. padding: 20rpx 40rpx;
  283. // background-color: red;
  284. text{
  285. font-size: 32rpx;
  286. font-weight: 500;
  287. }
  288. .remark-textarea{
  289. width: 80%;
  290. height: 180rpx;
  291. // border: 1rpx solid #000;
  292. // border-radius: 10rpx;
  293. // padding: 20rpx;
  294. }
  295. }
  296. .cart-pay{
  297. // background-color: red;
  298. height: 130rpx;
  299. display: flex;
  300. .cart{
  301. width: 30%;
  302. display: flex;
  303. align-items: center;
  304. justify-content: center;
  305. }
  306. .pay{
  307. width: 70%;
  308. background-color: $uni-color;
  309. color: #fff;
  310. text-align: center;
  311. display: flex;
  312. align-items: center;
  313. justify-content: center;
  314. font-size: 32rpx;
  315. }
  316. }
  317. </style>