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

567 lines
12 KiB

1 year ago
11 months ago
11 months ago
11 months ago
1 year ago
11 months ago
11 months ago
11 months ago
11 months ago
1 year ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
1 year ago
11 months ago
11 months ago
1 year ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
1 year ago
11 months ago
11 months ago
11 months ago
1 year ago
11 months ago
11 months ago
11 months ago
1 year ago
11 months ago
11 months ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
11 months ago
11 months ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
11 months ago
11 months ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
11 months ago
1 year ago
11 months ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
11 months ago
1 year ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
1 year ago
11 months ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
1 year ago
11 months ago
1 year ago
  1. <template>
  2. <view class="page">
  3. <!-- 导航栏 -->
  4. <navbar title="确认订单" leftClick @leftClick="$utils.navigateBack" bgColor="#E3441A" color="#fff" />
  5. <view class="bac"></view>
  6. <view class="box">
  7. <!-- 商品详情 -->
  8. <view class="product-item" v-for="item in payOrderProduct" :key="item.id">
  9. <view class="img-box">
  10. <image :src="item.image" mode="aspectFill"></image>
  11. </view>
  12. <view class="server-info">
  13. <view class="server-title">{{ item.title }}</view>
  14. <view class="texture">
  15. 材质{{ item.subText }}
  16. </view>
  17. <view class="stepper">
  18. <uv-number-box button-size="60" v-model="item.num"></uv-number-box>
  19. </view>
  20. <view class="sales-volume">
  21. <view class="desc">已售出 {{ item.payNum }}</view>
  22. </view>
  23. </view>
  24. </view>
  25. <!-- 地址 -->
  26. <view @click="openAddress" class="cell-item">
  27. <view class="cell-item-left">
  28. <image src="@/pages_order/static/createOrder/address.png" mode="widthFix" class="cell-icon"></image>
  29. <view class="user-name">{{ address.name }}</view>
  30. <view class="user-address">{{ address.address }}</view>
  31. </view>
  32. <view class="cell-item-right">
  33. <uv-icon name="arrow-right"></uv-icon>
  34. </view>
  35. </view>
  36. <view class="cell-list">
  37. <uv-radio-group v-model="payMethod">
  38. <view style="width: 710rpx;">
  39. <!-- 账户余额 -->
  40. <view class="cell-item">
  41. <view class="cell-item-left">
  42. <image src="@/pages_order/static/createOrder/account.png" mode="widthFix" class="cell-icon">
  43. </image>
  44. <view class="user-name">账户余额</view>
  45. <view class="descript">(余额: {{ userInfo.money }})</view>
  46. </view>
  47. <view class="cell-item-right">
  48. <uv-radio activeColor="#E3441A"
  49. size="40rpx"
  50. icon-size="30rpx"
  51. :name="1"/>
  52. </view>
  53. </view>
  54. <!-- 微信支付 -->
  55. <view class="cell-item">
  56. <view class="cell-item-left">
  57. <image src="@/pages_order/static/createOrder/wx.png" mode="widthFix" class="cell-icon">
  58. </image>
  59. <view class="user-name">微信支付</view>
  60. <view class="descript"></view>
  61. </view>
  62. <view class="cell-item-right">
  63. <uv-radio
  64. activeColor="#E3441A"
  65. size="40rpx"
  66. icon-size="30rpx"
  67. :name="0"/>
  68. </view>
  69. </view>
  70. </view>
  71. </uv-radio-group>
  72. </view>
  73. <!-- 优惠券 -->
  74. <view @click="openCoupon" class="cell-item">
  75. <view class="cell-item-left">
  76. <image src="@/pages_order/static/createOrder/coupon.png" mode="widthFix" class="cell-icon"></image>
  77. <view class="user-name">优惠券</view>
  78. <view class="descript">({{ coupon.money || 0}})</view>
  79. </view>
  80. <view class="cell-item-right">
  81. <!-- <radio color="#E3441A" :value="2" :checked="coupon.id" /> -->
  82. </view>
  83. </view>
  84. <!-- 提示 -->
  85. <view class="hint"
  86. v-if="payOrderProduct[0] && payOrderProduct[0].orderDetails">
  87. {{ payOrderProduct[0].orderDetails }}
  88. </view>
  89. <!-- 用户协议 -->
  90. <view class="agreement">
  91. <radio color="#E3441A" @click="agreement = !agreement" :checked="agreement" />
  92. 本人已同意<text @click="$refs.popup.open('user_xy')">用户使用协议</text>
  93. </view>
  94. <!-- 下单 -->
  95. <view class="submit">
  96. <view class="price">
  97. <view>
  98. <text style="color: #000;">合计</text>
  99. <text style="font-size: 18px;
  100. font-weight: 600;">{{ totalPrice }}</text>
  101. </view>
  102. </view>
  103. <view class="btn" @click="submit">
  104. 立即支付
  105. </view>
  106. </view>
  107. </view>
  108. <!-- 地址选择 -->
  109. <uv-popup ref="addressPopup" :round="30" style="padding-bottom: 90rpx;">
  110. <addressList ref="addressList" height="60vh" @select="selectAddress" />
  111. <view class="add-btn">
  112. <view @click="$utils.navigateTo('/pages_order/mine/address')" class="button-submit">新增地址</view>
  113. </view>
  114. </uv-popup>
  115. <!-- 优惠券选择-->
  116. <uv-popup ref="couponPopup" :round="30">
  117. <couponList ref="couponList" height="60vh" @select="selectCoupon" />
  118. </uv-popup>
  119. <configPopup ref="popup"></configPopup>
  120. </view>
  121. </template>
  122. <script>
  123. import addressList from '../components/address/addressList.vue'
  124. import couponList from '@/components/couponList/couponList.vue'
  125. import {
  126. mapState
  127. } from 'vuex'
  128. export default {
  129. components: {
  130. addressList,
  131. couponList
  132. },
  133. data() {
  134. return {
  135. address: {
  136. name: '请选择地址',
  137. address: '',
  138. },
  139. addressTotal: 0,
  140. remark: '',
  141. num: 1,
  142. agreement: false,
  143. coupon: {},
  144. payMethod : 0,
  145. }
  146. },
  147. computed: {
  148. totalPrice() {
  149. let price = 0
  150. this.payOrderProduct.forEach(n => {
  151. price += n.price * n.num
  152. })
  153. if (this.coupon.id) {
  154. price -= this.coupon.money
  155. }
  156. return Number(price).toFixed(2)
  157. },
  158. ...mapState(['userInfo', 'payOrderProduct']),
  159. },
  160. onLoad() {
  161. this.$store.commit('getUserInfo')
  162. },
  163. onShow() {
  164. this.getAddressList()
  165. this.getCouponList()
  166. },
  167. methods: {
  168. // 打开
  169. getAddressList() {
  170. // 获取地址列表
  171. this.$refs.addressList.getAddressList().then(res => {
  172. this.addressTotal = res.total
  173. if (this.addressTotal != 0) {
  174. this.address = res.records[0]
  175. }
  176. })
  177. },
  178. //获取优惠券列表
  179. getCouponList() {
  180. this.$refs.couponList.getCouponList()
  181. },
  182. // 打开选择地址
  183. openAddress() {
  184. if (this.addressTotal == 0) {
  185. return uni.navigateTo({
  186. url: '/pages_order/mine/address?type=back'
  187. })
  188. }
  189. this.$refs.addressPopup.open('bottom')
  190. },
  191. // 选择地址
  192. selectAddress(e) {
  193. this.address = e
  194. this.$refs.addressPopup.close()
  195. },
  196. // 打开优惠券选择
  197. openCoupon() {
  198. if (this.addressTotal == 0) {
  199. return uni.navigateTo({
  200. url: '/pages_order/mine/address?type=back'
  201. })
  202. }
  203. this.$refs.couponPopup.open('bottom')
  204. },
  205. // 选择优惠券
  206. selectCoupon(e) {
  207. //判断优惠券限制
  208. let {
  209. useMoney
  210. } = e
  211. let productTotalPrice = 0
  212. this.payOrderProduct.forEach(item => {
  213. productTotalPrice += item.price
  214. })
  215. if (productTotalPrice < useMoney) {
  216. return uni.showToast({
  217. title: `此优惠券需要满${useMoney}使用`,
  218. icon: "none"
  219. })
  220. }
  221. this.coupon = e
  222. this.$refs.couponPopup.close()
  223. },
  224. submit() {
  225. let addressId = this.address.id
  226. if (!addressId) {
  227. uni.showToast({
  228. title: '请选择地址',
  229. icon: 'none'
  230. })
  231. return
  232. }
  233. if (!this.agreement) {
  234. uni.showToast({
  235. title: '请先同意使用协议',
  236. icon: 'none'
  237. })
  238. return
  239. }
  240. let data = {}
  241. let api = ''
  242. // if (this.payOrderProduct[0].shopId || this.payOrderProduct[0].type == 2) { //普通商品
  243. // let list = []
  244. // this.payOrderProduct.forEach(n => {
  245. // list.push({
  246. // num: n.num,
  247. // shopId: n.shopId || n.id,
  248. // })
  249. // })
  250. // data = {
  251. // addressId,
  252. // list: JSON.stringify(list),
  253. // }
  254. // api = 'createSumOrder'
  255. // this.deleteCart(this.payOrderProduct.map(n => n.id).join(','))
  256. // } else { //体验、常规商品
  257. data = {
  258. addressId,
  259. num: this.payOrderProduct[0].num,
  260. shopId: this.payOrderProduct[0].id,
  261. payType : this.payMethod,
  262. }
  263. api = 'createOrder'
  264. // }
  265. if(this.coupon.id){
  266. data.couponId = this.coupon.id
  267. }
  268. this.$api(api, data, res => {
  269. if (res.code == 200) {
  270. if(this.payMethod == 1){
  271. uni.showToast({
  272. title: '下单成功',
  273. icon: 'none'
  274. })
  275. setTimeout(uni.redirectTo, 700, {
  276. url: '/pages/index/order'
  277. })
  278. return
  279. }
  280. uni.requestPaymentWxPay(res)
  281. .then(res => {
  282. uni.showToast({
  283. title: '下单成功',
  284. icon: 'none'
  285. })
  286. setTimeout(uni.redirectTo, 700, {
  287. url: '/pages/index/order'
  288. })
  289. }).catch(n => {
  290. setTimeout(uni.redirectTo, 700, {
  291. url: '/pages/index/order'
  292. })
  293. })
  294. } else if (res.code == 902) {
  295. uni.showModal({
  296. title: res.message,
  297. success(e) {
  298. if (e.confirm) {
  299. uni.redirectTo({
  300. url: '/pages/index/order'
  301. })
  302. }
  303. }
  304. })
  305. }
  306. })
  307. },
  308. // 删除购物车
  309. deleteCart(ids) {
  310. this.$api('deleteCart', {
  311. ids
  312. })
  313. },
  314. }
  315. }
  316. </script>
  317. <style scoped lang="scss">
  318. .page {
  319. .bac {
  320. width: 100%;
  321. height: 100px;
  322. background: $uni-color;
  323. }
  324. .box {
  325. padding: 20rpx;
  326. margin-top: -150rpx;
  327. // 商品详情
  328. .product-item {
  329. display: flex;
  330. flex-wrap: wrap;
  331. align-items: center;
  332. justify-content: space-between;
  333. background: white;
  334. border-radius: 15rpx;
  335. box-sizing: border-box;
  336. padding: 25rpx;
  337. margin: 20rpx 0rpx;
  338. .img-box {
  339. width: 200rpx;
  340. height: 200rpx;
  341. background: #ccc;
  342. border-radius: 10rpx;
  343. overflow: hidden;
  344. image {
  345. width: 100%;
  346. height: 100%;
  347. }
  348. }
  349. .server-info {
  350. width: calc(100% - 200rpx);
  351. box-sizing: border-box;
  352. padding: 10rpx 20rpx;
  353. display: flex;
  354. flex-direction: column;
  355. justify-content: space-around;
  356. .server-title {
  357. font-size: 34rpx;
  358. }
  359. .texture {
  360. color: #B8B8B8;
  361. margin: 10rpx 0rpx;
  362. }
  363. .stepper {
  364. margin-bottom: 10rpx;
  365. &::v-deep .uv-number-box__input {
  366. color: $uni-color !important;
  367. width: 100rpx !important;
  368. }
  369. }
  370. .sales-volume {
  371. display: flex;
  372. align-items: center;
  373. color: #B8B8B8;
  374. font-size: 26rpx;
  375. image {
  376. width: 25rpx;
  377. height: 25rpx;
  378. }
  379. }
  380. }
  381. }
  382. //cell单元格(地址)
  383. .cell-item {
  384. display: flex;
  385. justify-content: space-between;
  386. align-items: center;
  387. background: white;
  388. border-radius: 20rpx;
  389. padding: 20rpx;
  390. box-sizing: border-box;
  391. .cell-item-left {
  392. display: flex;
  393. align-items: center;
  394. width: 90%;
  395. .cell-icon {
  396. width: 40rpx;
  397. }
  398. .user-name,
  399. .user-address {
  400. white-space: nowrap;
  401. overflow: hidden;
  402. text-overflow: ellipsis;
  403. width: 150rpx;
  404. padding-left: 20rpx;
  405. box-sizing: border-box;
  406. }
  407. .descript {
  408. color: #888888;
  409. }
  410. .user-address {
  411. width: calc(100% - 230rpx);
  412. }
  413. }
  414. .cell-item-right {
  415. width: 10%;
  416. display: flex;
  417. justify-content: flex-end;
  418. }
  419. }
  420. .cell-list {
  421. margin: 20rpx 0rpx;
  422. border-radius: 20rpx;
  423. overflow: hidden;
  424. .cell-item {
  425. border-radius: 0rpx;
  426. }
  427. }
  428. // 提示
  429. .hint {
  430. font-size: 26rpx;
  431. margin-top: 80rpx;
  432. color: #BFBFBF;
  433. }
  434. // 用户协议
  435. .agreement {
  436. display: flex;
  437. justify-content: center;
  438. align-items: center;
  439. padding: 10px 0;
  440. .van-checkbox {
  441. margin-right: 5rpx;
  442. }
  443. text {
  444. color: $uni-color;
  445. }
  446. }
  447. // 下单
  448. .submit {
  449. position: fixed;
  450. bottom: 0;
  451. left: 0;
  452. width: 100%;
  453. height: 60px;
  454. background-color: #fff;
  455. display: flex;
  456. justify-content: space-between;
  457. align-items: center;
  458. .price {
  459. color: #F39637;
  460. padding: 0 20px;
  461. }
  462. .btn {
  463. background: $uni-color;
  464. color: white;
  465. width: 120px;
  466. height: 45px;
  467. border-radius: 23px;
  468. font-size: 16px;
  469. display: flex;
  470. justify-content: center;
  471. align-items: center;
  472. }
  473. }
  474. }
  475. //新增地址按钮
  476. .add-btn {
  477. width: 100%;
  478. .button-submit {
  479. display: flex;
  480. align-items: center;
  481. justify-content: center;
  482. width: 596rpx;
  483. height: 90rpx;
  484. background: #E3441A;
  485. border-radius: 46rpx;
  486. margin: 20rpx auto;
  487. font-size: 28rpx;
  488. font-family: PingFang SC, PingFang SC-Regular;
  489. font-weight: 400;
  490. text-align: center;
  491. color: #ffffff;
  492. }
  493. }
  494. }
  495. </style>