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

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