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

366 lines
11 KiB

5 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"></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 ? userInfo.balance.toFixed(2) : 0 }})</text>
  57. </text>
  58. <uv-radio activeColor="#019245" size="40rpx" name="1" />
  59. </view>
  60. </view>
  61. </uv-radio-group>
  62. <uv-gap height="20rpx" bgColor="#F7F7F7" />
  63. <!-- 优惠 -->
  64. <view class="discount">
  65. <text style="font-size: 35rpx;">优惠</text>
  66. <view style="display: flex; align-items: center; gap: 20rpx">
  67. <image src="@/static/image/券.webp" mode="aspectFill" class="discount-image" />
  68. <text>新用户立减</text>
  69. <text style="color: red;">-2</text>
  70. </view>
  71. </view>
  72. <uv-gap height="20rpx" bgColor="#F7F7F7" />
  73. <!-- 备注 -->
  74. <view class="remark">
  75. <text style="align-self: start;">备注</text>
  76. <textarea class="remark-textarea" placeholder="请输入您需要备注的内容" v-model="remark" />
  77. </view>
  78. <!-- 购物车与支付 -->
  79. <view class="cart-pay">
  80. <view class="cart" @click="$emit('addCart')">
  81. <uv-icon name="shopping-cart-fill" size="60rpx" color="#019245" label="加入购物车" labelPos="bottom"
  82. labelSize="25rpx" />
  83. </view>
  84. <view class="pay" @tap="createOrder">
  85. 立即支付
  86. </view>
  87. </view>
  88. </view>
  89. </uv-popup>
  90. </view>
  91. </template>
  92. <script>
  93. import { mapState } from 'vuex'
  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. ...mapState(['userInfo']),
  112. priceAll () {
  113. return this.item.price * this.value
  114. },
  115. goodss () {
  116. return `${this.item.id},${this.value},${this.priceAll};`
  117. }
  118. },
  119. methods: {
  120. // 添加open方法,用于外部调用打开弹窗
  121. open() {
  122. this.$refs.popup.open();
  123. },
  124. // 添加close方法,用于关闭弹窗
  125. close(){
  126. this.$refs.popup.close();
  127. },
  128. // 添加change方法,用于处理弹窗状态变化
  129. change(e) {
  130. console.log('弹窗状态变化:', e);
  131. // 可以在这里添加弹窗打开或关闭后的逻辑处理
  132. },
  133. // 跳转到取餐点选择页面
  134. gotoPickupPoint() {
  135. this.$utils.navigateTo('/pages_order/location/pickupPoint')
  136. },
  137. // 获取并监听取餐点选择事件
  138. listenPickupPoint() {
  139. const pickupPointStr = uni.getStorageSync('selectedPickupPoint');
  140. if (pickupPointStr) {
  141. this.pickupPoint = JSON.parse(pickupPointStr);
  142. }
  143. uni.$on('updatePickupPoint', (point) => {
  144. this.pickupPoint = point;
  145. })
  146. },
  147. // 创建订单
  148. createOrder(){
  149. if (!this.pickupPoint) {
  150. uni.showToast({
  151. title: '请选择取餐地点',
  152. icon: 'error'
  153. })
  154. return
  155. }
  156. if (this.payMethod == '1' && this.userInfo.balance < this.priceAll) {
  157. uni.showToast({
  158. title: '余额不足',
  159. icon: 'error'
  160. })
  161. return
  162. }
  163. uni.showLoading({
  164. title: '下单中...'
  165. })
  166. this.$api('createOrder', {
  167. priceAll: this.priceAll,
  168. pricePay: this.priceAll - 0,
  169. pricePreferential: 0,
  170. payType: this.payMethod,
  171. leaderId: this.pickupPoint.id,
  172. goodss: this.goodss,
  173. remark: this.remark
  174. }, res => {
  175. uni.hideLoading()
  176. if (res.code === 200) {
  177. if (this.payMethod == '0') {
  178. uni.requestPaymentWxPay(res)
  179. .catch(n => {
  180. setTimeout(uni.redirectTo, 700, {
  181. url: '/pages/index/order'
  182. })
  183. })
  184. }else {
  185. uni.showToast({
  186. title: '下单成功',
  187. icon: 'success'
  188. })
  189. setTimeout(uni.redirectTo, 700, {
  190. url: '/pages/index/order'
  191. })
  192. }
  193. }
  194. })
  195. }
  196. },
  197. mounted(){
  198. this.listenPickupPoint();
  199. console.log(123123);
  200. console.log('111', this.userInfo.balance);
  201. },
  202. beforeDestroy() {
  203. uni.$off('updatePickupPoint');
  204. }
  205. }
  206. </script>
  207. <style lang="scss" scoped>
  208. .place-order-title{
  209. font-size: 35rpx;
  210. height: 90rpx;
  211. display: flex;
  212. align-items: center;
  213. justify-content: center;
  214. position: relative;
  215. .number{
  216. color: $uni-color;
  217. }
  218. .text{
  219. color: #000;
  220. }
  221. .place-order-title-image{
  222. width: 100rpx;
  223. height: 50rpx;
  224. }
  225. .place-order-title-close{
  226. position: absolute;
  227. right: 20rpx;
  228. top: 50%;
  229. transform: translateY(-50%);
  230. color: $uni-color-third;
  231. }
  232. }
  233. .place-order-address{
  234. display: flex;
  235. height: 80rpx;
  236. line-height: 80rpx;
  237. align-items: center;
  238. // background-color: red;
  239. gap: 30rpx;
  240. padding-left: 20rpx;
  241. position: relative;
  242. text{
  243. font-size: 32rpx;
  244. font-weight: 500;
  245. }
  246. &-arrow{
  247. position: absolute;
  248. right: 20rpx;
  249. top: 50%;
  250. transform: translateY(-50%);
  251. }
  252. &-content{
  253. display: flex;
  254. flex-direction: column;
  255. justify-content: space-around;
  256. gap: 0rpx;
  257. height: 100%;
  258. // width: 100%;
  259. &-name{
  260. height: 30rpx;
  261. line-height: 30rpx;
  262. }
  263. &-address{
  264. height: 30rpx;
  265. line-height: 30rpx;
  266. width: 90%;
  267. text-overflow: ellipsis; // 三个连着一起才会出现省略号
  268. overflow: hidden;
  269. white-space: nowrap;
  270. }
  271. }
  272. }
  273. .item{
  274. display: flex;
  275. padding: 40rpx;
  276. gap: 40rpx;
  277. &-image{
  278. width: 250rpx;
  279. height: 200rpx;
  280. }
  281. }
  282. .option-box{
  283. display: flex;
  284. flex-direction: column;
  285. gap: 40rpx;
  286. width: 100%;
  287. &-item{
  288. display: flex;
  289. gap: 20rpx;
  290. align-items: center;
  291. font-size: 32rpx;
  292. padding: 0 40rpx;
  293. }
  294. }
  295. .discount{
  296. height: 130rpx;
  297. display: flex;
  298. align-items: center;
  299. width: 90%;
  300. justify-content: space-between;
  301. padding:0rpx 40rpx 0rpx 40rpx;
  302. // gap: 20rpx;
  303. .discount-image{
  304. width: 36rpx;
  305. height: 36rpx;
  306. border-radius: 10rpx;
  307. }
  308. }
  309. .remark{
  310. display: flex;
  311. align-items: center;
  312. justify-content: space-between;
  313. padding: 20rpx 40rpx;
  314. // background-color: red;
  315. text{
  316. font-size: 32rpx;
  317. font-weight: 500;
  318. }
  319. .remark-textarea{
  320. width: 80%;
  321. height: 180rpx;
  322. // border: 1rpx solid #000;
  323. // border-radius: 10rpx;
  324. // padding: 20rpx;
  325. }
  326. }
  327. .cart-pay{
  328. // background-color: red;
  329. height: 130rpx;
  330. display: flex;
  331. .cart{
  332. width: 30%;
  333. display: flex;
  334. align-items: center;
  335. justify-content: center;
  336. }
  337. .pay{
  338. width: 70%;
  339. background-color: $uni-color;
  340. color: #fff;
  341. text-align: center;
  342. display: flex;
  343. align-items: center;
  344. justify-content: center;
  345. font-size: 32rpx;
  346. }
  347. }
  348. </style>