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

771 lines
19 KiB

10 months ago
10 months ago
8 months ago
10 months ago
10 months ago
8 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
8 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
8 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
8 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
8 months ago
10 months ago
10 months ago
10 months ago
8 months ago
10 months ago
10 months ago
10 months ago
10 months ago
8 months ago
10 months ago
10 months ago
8 months ago
10 months ago
8 months ago
10 months ago
10 months ago
10 months ago
10 months ago
8 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
8 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
8 months ago
10 months ago
  1. <template>
  2. <view class="page">
  3. <!-- 导航栏 -->
  4. <navbar :title="titleMap[type]" leftClick @leftClick="$utils.navigateBack" bgColor="#E3441A" color="#fff" />
  5. <view class="bac"></view>
  6. <view class="box">
  7. <!-- 送礼 -->
  8. <view class="give-type" v-if="type == 'give'">
  9. <view class="tab-box">
  10. <view class="tab-item" :class="{'active': isGive === 1}"
  11. @click="isGive = 1">
  12. <text>单人礼包</text>
  13. <text class="desc">送给1位好友可同时送多件礼品</text>
  14. </view>
  15. <view class="tab-item" :class="{'active': isGive === 2}"
  16. @click="isGive = 2">
  17. <text>多人礼包</text>
  18. <text class="desc">送给多位好友每人1件礼品</text>
  19. </view>
  20. <view class="tab-item" :class="{'active': isGive === 3}"
  21. @click="isGive = 3">
  22. <text>抽奖礼包</text>
  23. <text class="desc">好友抽奖中奖者获得礼品</text>
  24. </view>
  25. </view>
  26. <!-- <view class="tips">
  27. <text>支付后分享给好友收礼</text>
  28. <text class="guide" @click="$refs.popup.open('gift_guide')">指南</text>
  29. </view> -->
  30. </view>
  31. <!-- 多人礼包人数 -->
  32. <view class="cell-item" v-if="type == 'give' && isGive === 2">
  33. <view class="cell-item-left">
  34. <uv-icon name="gift" size="40" color="#E3441A"></uv-icon>
  35. <view class="user-name">礼包份数</view>
  36. </view>
  37. <view class="cell-item-right">
  38. <view class="stepper">
  39. <text class="minus" :class="{disabled: multiNum <= multiMinNum}"
  40. @click="multiNum > multiMinNum && multiNum--">-</text>
  41. <text class="num">{{multiNum}}</text>
  42. <text class="plus" :class="{disabled: multiNum >= multiMaxNum}"
  43. @click="multiNum < multiMaxNum && multiNum++">+</text>
  44. </view>
  45. </view>
  46. </view>
  47. <!-- 抽奖礼包说明 -->
  48. <view class="lucky-box" v-if="type == 'give' && isGive === 3">
  49. <view class="title">抽奖规则</view>
  50. <view class="tips-list">
  51. <view class="tip-item"> 好友参与抽奖</view>
  52. <view class="tip-item"> 系统随机抽取中奖者</view>
  53. <view class="tip-item"> 中奖者填写地址领取礼品</view>
  54. </view>
  55. </view>
  56. <!-- 商品详情 -->
  57. <view class="product-item" v-for="item in payOrderProduct" :key="item.id">
  58. <view class="img-box">
  59. <image :src="item.image" mode="aspectFill"></image>
  60. </view>
  61. <view class="server-info">
  62. <view class="server-title">{{ item.title }}</view>
  63. <view class="texture">
  64. 材质{{ item.subText }}
  65. </view>
  66. <view class="stepper">
  67. <uv-number-box button-size="60" v-model="item.num"></uv-number-box>
  68. </view>
  69. <view class="sales-volume">
  70. <view class="desc">已售出 {{ item.payNum }}</view>
  71. </view>
  72. </view>
  73. </view>
  74. <!-- 地址 -->
  75. <view @click="openAddress" class="cell-item">
  76. <view class="cell-item-left">
  77. <image src="@/pages_order/static/createOrder/address.png" mode="widthFix" class="cell-icon"></image>
  78. <view class="user-name">{{ address.name }}</view>
  79. <view class="user-address">{{ address.address }}</view>
  80. </view>
  81. <view class="cell-item-right">
  82. <uv-icon name="arrow-right"></uv-icon>
  83. </view>
  84. </view>
  85. <view class="cell-list">
  86. <uv-radio-group v-model="payMethod">
  87. <view style="width: 710rpx;">
  88. <!-- 账户余额 -->
  89. <view class="cell-item">
  90. <view class="cell-item-left">
  91. <image src="@/pages_order/static/createOrder/account.png" mode="widthFix" class="cell-icon">
  92. </image>
  93. <view class="user-name">账户余额</view>
  94. <view class="descript">(余额: {{ riceInfo.balance }})</view>
  95. </view>
  96. <view class="cell-item-right">
  97. <uv-radio activeColor="#E3441A"
  98. size="40rpx"
  99. icon-size="30rpx"
  100. :name="1"/>
  101. </view>
  102. </view>
  103. <!-- 微信支付 -->
  104. <view class="cell-item">
  105. <view class="cell-item-left">
  106. <image src="@/pages_order/static/createOrder/wx.png" mode="widthFix" class="cell-icon">
  107. </image>
  108. <view class="user-name">微信支付</view>
  109. <view class="descript"></view>
  110. </view>
  111. <view class="cell-item-right">
  112. <uv-radio
  113. activeColor="#E3441A"
  114. size="40rpx"
  115. icon-size="30rpx"
  116. :name="0"/>
  117. </view>
  118. </view>
  119. </view>
  120. </uv-radio-group>
  121. </view>
  122. <!-- 优惠券 -->
  123. <view @click="openCoupon" class="cell-item">
  124. <view class="cell-item-left">
  125. <image src="@/pages_order/static/createOrder/coupon.png" mode="widthFix" class="cell-icon"></image>
  126. <view class="user-name">优惠券</view>
  127. <view class="descript">({{ coupon.money || 0}})</view>
  128. </view>
  129. <view class="cell-item-right">
  130. <!-- <radio color="#E3441A" :value="2" :checked="coupon.id" /> -->
  131. </view>
  132. </view>
  133. <!-- 提示 -->
  134. <view class="hint"
  135. v-if="payOrderProduct[0] && payOrderProduct[0].orderDetails">
  136. {{ payOrderProduct[0].orderDetails }}
  137. </view>
  138. <!-- 用户协议 -->
  139. <view class="agreement">
  140. <radio color="#E3441A" @click="agreement = !agreement" :checked="agreement" />
  141. 本人已同意<text @click="$refs.popup.open('user_xy')">用户使用协议</text>
  142. </view>
  143. <!-- 下单 -->
  144. <view class="submit">
  145. <view class="price">
  146. <view>
  147. <text style="color: #000;">合计</text>
  148. <text style="font-size: 18px;
  149. font-weight: 600;">{{ totalPrice }}</text>
  150. </view>
  151. </view>
  152. <view class="btn" @click="submit">
  153. 立即支付
  154. </view>
  155. </view>
  156. </view>
  157. <!-- 地址选择 -->
  158. <uv-popup ref="addressPopup" :round="30" style="padding-bottom: 90rpx;">
  159. <addressList ref="addressList" height="60vh" @select="selectAddress" />
  160. <view class="add-btn">
  161. <view @click="$utils.navigateTo('/pages_order/mine/address')" class="button-submit">新增地址</view>
  162. </view>
  163. </uv-popup>
  164. <!-- 优惠券选择-->
  165. <uv-popup ref="couponPopup" :round="30">
  166. <couponList ref="couponList" height="60vh" @select="selectCoupon" />
  167. </uv-popup>
  168. <configPopup ref="popup"></configPopup>
  169. </view>
  170. </template>
  171. <script>
  172. import addressList from '../components/address/addressList.vue'
  173. import couponList from '@/components/couponList/couponList.vue'
  174. import {
  175. mapState
  176. } from 'vuex'
  177. export default {
  178. components: {
  179. addressList,
  180. couponList
  181. },
  182. data() {
  183. return {
  184. address: {
  185. name: '请选择地址',
  186. address: '',
  187. },
  188. addressTotal: 0,
  189. remark: '',
  190. num: 1,
  191. agreement: false,
  192. coupon: {},
  193. payMethod : 0,
  194. isGive : 0,
  195. type : '',
  196. titleMap : {
  197. def : '确认订单',
  198. give : '送礼清单',
  199. },
  200. multiNum: 2, // 多人礼包人数
  201. multiMinNum: 2, // 最小人数
  202. multiMaxNum: 100, // 最大人数
  203. }
  204. },
  205. computed: {
  206. totalPrice() {
  207. let price = 0
  208. this.payOrderProduct.forEach(n => {
  209. price += n.price * n.num
  210. })
  211. if (this.coupon.id) {
  212. price -= this.coupon.money
  213. }
  214. return Number(price).toFixed(2)
  215. },
  216. ...mapState(['userInfo', 'payOrderProduct']),
  217. },
  218. onLoad(args) {
  219. this.type = args.type || 'def'
  220. if(this.type == 'give'){
  221. this.isGive = 1
  222. }
  223. this.$store.commit('getUserInfo')
  224. },
  225. onShow() {
  226. this.getAddressList()
  227. this.getCouponList()
  228. },
  229. methods: {
  230. // 打开
  231. getAddressList() {
  232. // 获取地址列表
  233. this.$refs.addressList.getAddressList().then(res => {
  234. this.addressTotal = res.total
  235. if (this.addressTotal != 0) {
  236. this.address = res.records[0]
  237. }
  238. })
  239. },
  240. //获取优惠券列表
  241. getCouponList() {
  242. this.$refs.couponList.getCouponList()
  243. },
  244. // 打开选择地址
  245. openAddress() {
  246. if (this.addressTotal == 0) {
  247. return uni.navigateTo({
  248. url: '/pages_order/mine/address?type=back'
  249. })
  250. }
  251. this.$refs.addressPopup.open('bottom')
  252. },
  253. // 选择地址
  254. selectAddress(e) {
  255. this.address = e
  256. this.$refs.addressPopup.close()
  257. },
  258. // 打开优惠券选择
  259. openCoupon() {
  260. if (this.addressTotal == 0) {
  261. return uni.navigateTo({
  262. url: '/pages_order/mine/address?type=back'
  263. })
  264. }
  265. this.$refs.couponPopup.open('bottom')
  266. },
  267. // 选择优惠券
  268. selectCoupon(e) {
  269. //判断优惠券限制
  270. let {
  271. useMoney
  272. } = e
  273. let productTotalPrice = 0
  274. this.payOrderProduct.forEach(item => {
  275. productTotalPrice += item.price
  276. })
  277. if (productTotalPrice < useMoney) {
  278. return uni.showToast({
  279. title: `此优惠券需要满${useMoney}使用`,
  280. icon: "none"
  281. })
  282. }
  283. this.coupon = e
  284. this.$refs.couponPopup.close()
  285. },
  286. submit() {
  287. let addressId = this.address.id
  288. if (!addressId) {
  289. uni.showToast({
  290. title: '请选择地址',
  291. icon: 'none'
  292. })
  293. return
  294. }
  295. if (!this.agreement) {
  296. uni.showToast({
  297. title: '请先同意使用协议',
  298. icon: 'none'
  299. })
  300. return
  301. }
  302. let data = {}
  303. let api = ''
  304. // if (this.payOrderProduct[0].shopId || this.payOrderProduct[0].type == 2) { //普通商品
  305. // let list = []
  306. // this.payOrderProduct.forEach(n => {
  307. // list.push({
  308. // num: n.num,
  309. // shopId: n.shopId || n.id,
  310. // })
  311. // })
  312. // data = {
  313. // addressId,
  314. // list: JSON.stringify(list),
  315. // }
  316. // api = 'createSumOrder'
  317. // this.deleteCart(this.payOrderProduct.map(n => n.id).join(','))
  318. // } else { //体验、常规商品
  319. data = {
  320. addressId,
  321. num: this.payOrderProduct[0].num,
  322. shopId: this.payOrderProduct[0].id,
  323. payType : this.payMethod,
  324. isGive : this.isGive,
  325. memberNum : 1,
  326. }
  327. api = 'createOrder'
  328. // }
  329. if(this.coupon.id){
  330. data.couponId = this.coupon.id
  331. }
  332. if(this.isGive == 2){
  333. data.memberNum = this.multiNum
  334. }
  335. this.$api(api, data, res => {
  336. if (res.code == 200) {
  337. if(this.payMethod == 1){
  338. uni.showToast({
  339. title: '下单成功',
  340. icon: 'none'
  341. })
  342. this.paySuccess(res)
  343. return
  344. }
  345. uni.requestPaymentWxPay(res)
  346. .then(res => {
  347. uni.showToast({
  348. title: '下单成功',
  349. icon: 'none'
  350. })
  351. this.paySuccess(res)
  352. }).catch(n => {
  353. setTimeout(uni.redirectTo, 700, {
  354. url: '/pages/index/order'
  355. })
  356. })
  357. }
  358. })
  359. },
  360. paySuccess(res){
  361. if(this.type == 'def'){
  362. setTimeout(uni.redirectTo, 700, {
  363. url: '/pages/index/order'
  364. })
  365. }else{
  366. setTimeout(uni.redirectTo, 700, {
  367. url: `/pages_order/order/instantGift?id=${res.message}`
  368. })
  369. }
  370. },
  371. // 删除购物车
  372. deleteCart(ids) {
  373. this.$api('deleteCart', {
  374. ids
  375. })
  376. },
  377. }
  378. }
  379. </script>
  380. <style scoped lang="scss">
  381. .page {
  382. .bac {
  383. width: 100%;
  384. height: 100px;
  385. background: $uni-color;
  386. }
  387. .give-type {
  388. background: #fff;
  389. border-radius: 20rpx;
  390. padding: 30rpx;
  391. margin-bottom: 20rpx;
  392. .tab-box {
  393. display: flex;
  394. justify-content: space-between;
  395. .tab-item {
  396. width: 30%;
  397. background: #F8F8F8;
  398. border-radius: 20rpx;
  399. padding: 20rpx;
  400. text-align: center;
  401. text {
  402. display: block;
  403. &.desc {
  404. font-size: 24rpx;
  405. color: #999;
  406. margin-top: 10rpx;
  407. }
  408. }
  409. &.active {
  410. background: rgba($uni-color, 0.1);
  411. color: $uni-color;
  412. .desc {
  413. color: $uni-color;
  414. }
  415. }
  416. }
  417. }
  418. .tips {
  419. margin-top: 20rpx;
  420. font-size: 26rpx;
  421. color: #999;
  422. display: flex;
  423. align-items: center;
  424. justify-content: space-between;
  425. .guide {
  426. color: $uni-color;
  427. text-decoration: underline;
  428. }
  429. }
  430. }
  431. .box {
  432. padding: 20rpx;
  433. margin-top: -150rpx;
  434. // 商品详情
  435. .product-item {
  436. display: flex;
  437. flex-wrap: wrap;
  438. align-items: center;
  439. justify-content: space-between;
  440. background: white;
  441. border-radius: 15rpx;
  442. box-sizing: border-box;
  443. padding: 25rpx;
  444. margin: 20rpx 0rpx;
  445. .img-box {
  446. width: 200rpx;
  447. height: 200rpx;
  448. background: #ccc;
  449. border-radius: 10rpx;
  450. overflow: hidden;
  451. image {
  452. width: 100%;
  453. height: 100%;
  454. }
  455. }
  456. .server-info {
  457. width: calc(100% - 200rpx);
  458. box-sizing: border-box;
  459. padding: 10rpx 20rpx;
  460. display: flex;
  461. flex-direction: column;
  462. justify-content: space-around;
  463. .server-title {
  464. font-size: 34rpx;
  465. }
  466. .texture {
  467. color: #B8B8B8;
  468. margin: 10rpx 0rpx;
  469. }
  470. .stepper {
  471. margin-bottom: 10rpx;
  472. &::v-deep .uv-number-box__input {
  473. color: $uni-color !important;
  474. width: 100rpx !important;
  475. }
  476. }
  477. .sales-volume {
  478. display: flex;
  479. align-items: center;
  480. color: #B8B8B8;
  481. font-size: 26rpx;
  482. image {
  483. width: 25rpx;
  484. height: 25rpx;
  485. }
  486. }
  487. }
  488. }
  489. //cell单元格(地址)
  490. .cell-item {
  491. display: flex;
  492. justify-content: space-between;
  493. align-items: center;
  494. background: white;
  495. border-radius: 20rpx;
  496. padding: 20rpx;
  497. box-sizing: border-box;
  498. .cell-item-left {
  499. display: flex;
  500. align-items: center;
  501. width: 90%;
  502. .cell-icon {
  503. width: 40rpx;
  504. }
  505. .user-name,
  506. .user-address {
  507. white-space: nowrap;
  508. overflow: hidden;
  509. text-overflow: ellipsis;
  510. width: 150rpx;
  511. padding-left: 20rpx;
  512. box-sizing: border-box;
  513. }
  514. .descript {
  515. color: #888888;
  516. }
  517. .user-address {
  518. width: calc(100% - 230rpx);
  519. }
  520. }
  521. .cell-item-right {
  522. width: 10%;
  523. display: flex;
  524. justify-content: flex-end;
  525. .stepper {
  526. display: flex;
  527. align-items: center;
  528. text {
  529. display: flex;
  530. align-items: center;
  531. justify-content: center;
  532. width: 44rpx;
  533. height: 44rpx;
  534. &.minus, &.plus {
  535. background: #F8F8F8;
  536. border-radius: 50%;
  537. font-size: 32rpx;
  538. &.disabled {
  539. color: #ccc;
  540. }
  541. }
  542. &.num {
  543. margin: 0 20rpx;
  544. color: $uni-color;
  545. font-size: 28rpx;
  546. }
  547. }
  548. }
  549. }
  550. }
  551. .cell-list {
  552. margin: 20rpx 0rpx;
  553. border-radius: 20rpx;
  554. overflow: hidden;
  555. .cell-item {
  556. border-radius: 0rpx;
  557. }
  558. }
  559. // 提示
  560. .hint {
  561. font-size: 26rpx;
  562. margin-top: 80rpx;
  563. color: #BFBFBF;
  564. }
  565. // 用户协议
  566. .agreement {
  567. display: flex;
  568. justify-content: center;
  569. align-items: center;
  570. padding: 10px 0;
  571. .van-checkbox {
  572. margin-right: 5rpx;
  573. }
  574. text {
  575. color: $uni-color;
  576. }
  577. }
  578. // 下单
  579. .submit {
  580. position: fixed;
  581. bottom: 0;
  582. left: 0;
  583. width: 100%;
  584. height: 60px;
  585. background-color: #fff;
  586. display: flex;
  587. justify-content: space-between;
  588. align-items: center;
  589. .price {
  590. color: #F39637;
  591. padding: 0 20px;
  592. }
  593. .btn {
  594. background: $uni-color;
  595. color: white;
  596. width: 120px;
  597. height: 45px;
  598. border-radius: 23px;
  599. font-size: 16px;
  600. display: flex;
  601. justify-content: center;
  602. align-items: center;
  603. }
  604. }
  605. }
  606. //新增地址按钮
  607. .add-btn {
  608. width: 100%;
  609. .button-submit {
  610. display: flex;
  611. align-items: center;
  612. justify-content: center;
  613. width: 596rpx;
  614. height: 90rpx;
  615. background: #E3441A;
  616. border-radius: 46rpx;
  617. margin: 20rpx auto;
  618. font-size: 28rpx;
  619. font-family: PingFang SC, PingFang SC-Regular;
  620. font-weight: 400;
  621. text-align: center;
  622. color: #ffffff;
  623. }
  624. }
  625. .multi-box, .lucky-box {
  626. background: #fff;
  627. border-radius: 20rpx;
  628. padding: 30rpx;
  629. margin-bottom: 20rpx;
  630. .title {
  631. font-size: 28rpx;
  632. font-weight: 500;
  633. margin-bottom: 20rpx;
  634. }
  635. }
  636. .multi-box {
  637. .stepper {
  638. display: flex;
  639. align-items: center;
  640. justify-content: center;
  641. text {
  642. display: flex;
  643. align-items: center;
  644. justify-content: center;
  645. width: 60rpx;
  646. height: 60rpx;
  647. &.minus, &.plus {
  648. background: #F8F8F8;
  649. border-radius: 50%;
  650. font-size: 36rpx;
  651. &.disabled {
  652. color: #ccc;
  653. }
  654. }
  655. &.num {
  656. margin: 0 40rpx;
  657. color: $uni-color;
  658. font-size: 32rpx;
  659. }
  660. }
  661. }
  662. }
  663. .lucky-box {
  664. .tips-list {
  665. .tip-item {
  666. font-size: 26rpx;
  667. color: #666;
  668. line-height: 2;
  669. }
  670. }
  671. }
  672. }
  673. </style>