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

348 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.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;">(余额: 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. 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. // console.log(props.item);
  184. },
  185. beforeDestroy() {
  186. uni.$off('updatePickupPoint');
  187. }
  188. }
  189. </script>
  190. <style lang="scss" scoped>
  191. .place-order-title{
  192. font-size: 35rpx;
  193. height: 90rpx;
  194. display: flex;
  195. align-items: center;
  196. justify-content: center;
  197. position: relative;
  198. .number{
  199. color: $uni-color;
  200. }
  201. .text{
  202. color: #000;
  203. }
  204. .place-order-title-image{
  205. width: 100rpx;
  206. height: 50rpx;
  207. }
  208. .place-order-title-close{
  209. position: absolute;
  210. right: 20rpx;
  211. top: 50%;
  212. transform: translateY(-50%);
  213. color: $uni-color-third;
  214. }
  215. }
  216. .place-order-address{
  217. display: flex;
  218. height: 80rpx;
  219. line-height: 80rpx;
  220. align-items: center;
  221. // background-color: red;
  222. gap: 30rpx;
  223. padding-left: 20rpx;
  224. position: relative;
  225. text{
  226. font-size: 32rpx;
  227. font-weight: 500;
  228. }
  229. &-arrow{
  230. position: absolute;
  231. right: 20rpx;
  232. top: 50%;
  233. transform: translateY(-50%);
  234. }
  235. &-content{
  236. display: flex;
  237. flex-direction: column;
  238. justify-content: space-around;
  239. gap: 0rpx;
  240. height: 100%;
  241. // width: 100%;
  242. &-name{
  243. height: 30rpx;
  244. line-height: 30rpx;
  245. }
  246. &-address{
  247. height: 30rpx;
  248. line-height: 30rpx;
  249. width: 90%;
  250. text-overflow: ellipsis; // 三个连着一起才会出现省略号
  251. overflow: hidden;
  252. white-space: nowrap;
  253. }
  254. }
  255. }
  256. .item{
  257. display: flex;
  258. padding: 40rpx;
  259. gap: 40rpx;
  260. &-image{
  261. width: 250rpx;
  262. height: 200rpx;
  263. }
  264. }
  265. .option-box{
  266. display: flex;
  267. flex-direction: column;
  268. gap: 40rpx;
  269. width: 100%;
  270. &-item{
  271. display: flex;
  272. gap: 20rpx;
  273. align-items: center;
  274. font-size: 32rpx;
  275. padding: 0 40rpx;
  276. }
  277. }
  278. .discount{
  279. height: 130rpx;
  280. display: flex;
  281. align-items: center;
  282. width: 90%;
  283. justify-content: space-between;
  284. padding:0rpx 40rpx 0rpx 40rpx;
  285. // gap: 20rpx;
  286. .discount-image{
  287. width: 36rpx;
  288. height: 36rpx;
  289. border-radius: 10rpx;
  290. }
  291. }
  292. .remark{
  293. display: flex;
  294. align-items: center;
  295. justify-content: space-between;
  296. padding: 20rpx 40rpx;
  297. // background-color: red;
  298. text{
  299. font-size: 32rpx;
  300. font-weight: 500;
  301. }
  302. .remark-textarea{
  303. width: 80%;
  304. height: 180rpx;
  305. // border: 1rpx solid #000;
  306. // border-radius: 10rpx;
  307. // padding: 20rpx;
  308. }
  309. }
  310. .cart-pay{
  311. // background-color: red;
  312. height: 130rpx;
  313. display: flex;
  314. .cart{
  315. width: 30%;
  316. display: flex;
  317. align-items: center;
  318. justify-content: center;
  319. }
  320. .pay{
  321. width: 70%;
  322. background-color: $uni-color;
  323. color: #fff;
  324. text-align: center;
  325. display: flex;
  326. align-items: center;
  327. justify-content: center;
  328. font-size: 32rpx;
  329. }
  330. }
  331. </style>