建材商城系统20241014
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.

803 lines
20 KiB

  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.name }}</view>
  63. <view class="texture">
  64. 材质{{ item.material }}
  65. </view>
  66. <view class="stepper">
  67. <uv-number-box button-size="60" v-model="item.selectNum"
  68. :max="item.num"></uv-number-box>
  69. </view>
  70. <view class="sales-volume">
  71. <view class="desc">已售出 {{ item.payNum }}</view>
  72. </view>
  73. </view>
  74. </view>
  75. <!-- 地址 -->
  76. <view @click="openAddress" class="cell-item">
  77. <view class="cell-item-left">
  78. <image src="@/pages_order/static/createOrder/address.png" mode="widthFix" class="cell-icon"></image>
  79. <view class="user-name">{{ address.name }}</view>
  80. <view class="user-address">{{ address.address }}</view>
  81. </view>
  82. <view class="cell-item-right">
  83. <uv-icon name="arrow-right"></uv-icon>
  84. </view>
  85. </view>
  86. <!-- 备注 -->
  87. <!-- <view class="cell-item">
  88. <view class="cell-item-left">
  89. <image src="@/pages_order/static/createOrder/coupon.png" mode="widthFix" class="cell-icon"></image>
  90. <view class="user-name">备注</view>
  91. </view>
  92. <view class="cell-item-right remark-input">
  93. <uv-textarea v-model="remark" border="none" height="40rpx" placeholder="请输入订单备注信息" :count="false" :auto-height="false" />
  94. </view>
  95. </view> -->
  96. <view class="cell-list">
  97. <uv-radio-group v-model="payMethod">
  98. <view style="width: 710rpx;">
  99. <!-- 账户余额 -->
  100. <view class="cell-item">
  101. <view class="cell-item-left">
  102. <image src="@/pages_order/static/createOrder/account.png" mode="widthFix" class="cell-icon">
  103. </image>
  104. <view class="user-name">账户余额</view>
  105. <view class="descript">(余额: {{ userInfo.price }})</view>
  106. </view>
  107. <view class="cell-item-right">
  108. <uv-radio activeColor="#E3441A"
  109. size="40rpx"
  110. icon-size="30rpx"
  111. :name="0"/>
  112. </view>
  113. </view>
  114. <!-- 微信支付 -->
  115. <view class="cell-item">
  116. <view class="cell-item-left">
  117. <image src="@/pages_order/static/createOrder/wx.png" mode="widthFix" class="cell-icon">
  118. </image>
  119. <view class="user-name">微信支付</view>
  120. <view class="descript"></view>
  121. </view>
  122. <view class="cell-item-right">
  123. <uv-radio
  124. activeColor="#E3441A"
  125. size="40rpx"
  126. icon-size="30rpx"
  127. :name="1"/>
  128. </view>
  129. </view>
  130. </view>
  131. </uv-radio-group>
  132. </view>
  133. <!-- 优惠券 -->
  134. <!-- <view @click="openCoupon" class="cell-item">
  135. <view class="cell-item-left">
  136. <image src="@/pages_order/static/createOrder/coupon.png" mode="widthFix" class="cell-icon"></image>
  137. <view class="user-name">优惠券</view>
  138. <view class="descript">({{ coupon.money || 0}})</view>
  139. </view>
  140. <view class="cell-item-right">
  141. <radio color="#E3441A" :value="2" :checked="coupon.id" />
  142. </view>
  143. </view> -->
  144. <!-- 提示 -->
  145. <view class="hint"
  146. v-if="payOrderProduct[0] && payOrderProduct[0].orderDetails">
  147. {{ payOrderProduct[0].orderDetails }}
  148. </view>
  149. <!-- 用户协议 -->
  150. <view class="agreement">
  151. <radio color="#E3441A" @click="agreement = !agreement" :checked="agreement" />
  152. 本人已同意<text @click="$refs.popup.open('user_xy')">用户使用协议</text>
  153. </view>
  154. <!-- 下单 -->
  155. <view class="submit">
  156. <view class="price">
  157. <view>
  158. <text style="color: #000;">合计</text>
  159. <text style="font-size: 18px;
  160. font-weight: 600;">{{ totalPrice }}</text>
  161. </view>
  162. </view>
  163. <view class="btn" @click="submit">
  164. 立即支付
  165. </view>
  166. </view>
  167. </view>
  168. <!-- 地址选择 -->
  169. <uv-popup ref="addressPopup" :round="30" style="padding-bottom: 90rpx;">
  170. <addressList ref="addressList" height="60vh" @select="selectAddress" />
  171. <view class="add-btn">
  172. <view @click="$utils.navigateTo('/pages_order/mine/address?type=back')" class="button-submit">新增地址</view>
  173. </view>
  174. </uv-popup>
  175. <!-- 优惠券选择-->
  176. <!-- <uv-popup ref="couponPopup" :round="30">
  177. <couponList ref="couponList" height="60vh" @select="selectCoupon" />
  178. </uv-popup> -->
  179. <configPopup ref="popup"></configPopup>
  180. <!-- <kefu></kefu> -->
  181. </view>
  182. </template>
  183. <script>
  184. import addressList from '../components/address/addressList.vue'
  185. // import couponList from '@/components/couponList/couponList.vue'
  186. import {
  187. mapState
  188. } from 'vuex'
  189. export default {
  190. components: {
  191. addressList,
  192. // couponList
  193. },
  194. data() {
  195. return {
  196. address: {
  197. name: '请选择地址',
  198. address: '',
  199. },
  200. addressTotal: 0,
  201. remark: '',
  202. agreement: false,
  203. coupon: {},
  204. payMethod : 1,
  205. isGive : 0,
  206. type : '',
  207. titleMap : {
  208. def : '确认订单',
  209. give : '送礼清单',
  210. },
  211. multiNum: 2, // 多人礼包人数
  212. multiMinNum: 2, // 最小人数
  213. multiMaxNum: 100, // 最大人数
  214. }
  215. },
  216. computed: {
  217. totalPrice() {
  218. let price = 0
  219. this.payOrderProduct.forEach(n => {
  220. price += n.price * (n.selectNum || 1)
  221. })
  222. if (this.coupon.id) {
  223. price -= this.coupon.money
  224. }
  225. return Number(price).toFixed(2)
  226. },
  227. ...mapState(['userInfo', 'payOrderProduct']),
  228. },
  229. onLoad(args) {
  230. this.type = args.type || 'def'
  231. if(this.type == 'give'){
  232. this.isGive = 1
  233. }
  234. this.$store.commit('getUserInfo')
  235. },
  236. onShow() {
  237. this.getAddressList()
  238. // this.getCouponList()
  239. },
  240. methods: {
  241. // 打开
  242. getAddressList() {
  243. // 获取地址列表
  244. this.$refs.addressList.getAddressList().then(res => {
  245. this.addressTotal = res.total
  246. if (this.addressTotal != 0) {
  247. this.address = res.records[0]
  248. }
  249. })
  250. },
  251. //获取优惠券列表
  252. getCouponList() {
  253. this.$refs.couponList.getCouponList()
  254. },
  255. // 打开选择地址
  256. openAddress() {
  257. if (this.addressTotal == 0) {
  258. return uni.navigateTo({
  259. url: '/pages_order/mine/address?type=back'
  260. })
  261. }
  262. this.$refs.addressPopup.open('bottom')
  263. },
  264. // 选择地址
  265. selectAddress(e) {
  266. this.address = e
  267. this.$refs.addressPopup.close()
  268. },
  269. // 打开优惠券选择
  270. openCoupon() {
  271. if (this.addressTotal == 0) {
  272. return uni.navigateTo({
  273. url: '/pages_order/mine/address?type=back'
  274. })
  275. }
  276. this.$refs.couponPopup.open('bottom')
  277. },
  278. // 选择优惠券
  279. selectCoupon(e) {
  280. //判断优惠券限制
  281. let {
  282. useMoney
  283. } = e
  284. let productTotalPrice = 0
  285. this.payOrderProduct.forEach(item => {
  286. productTotalPrice += item.price
  287. })
  288. if (productTotalPrice < useMoney) {
  289. return uni.showToast({
  290. title: `此优惠券需要满${useMoney}使用`,
  291. icon: "none"
  292. })
  293. }
  294. this.coupon = e
  295. this.$refs.couponPopup.close()
  296. },
  297. submit() {
  298. let addressId = this.address.id
  299. if (!addressId) {
  300. uni.showToast({
  301. title: '请选择地址',
  302. icon: 'none'
  303. })
  304. return
  305. }
  306. if (!this.agreement) {
  307. uni.showToast({
  308. title: '请先同意使用协议',
  309. icon: 'none'
  310. })
  311. return
  312. }
  313. let data = {}
  314. let api = ''
  315. // if(this.type != 'give'){
  316. // let list = []
  317. // this.payOrderProduct.forEach(n => {
  318. // list.push({
  319. // num: n.selectNum || 1,
  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 = 'createOrder'
  330. // this.deleteCart(this.payOrderProduct.map(n => n.id).join(','))
  331. // } else {
  332. data = {
  333. addressId,
  334. num: this.payOrderProduct[0].selectNum || 1,
  335. productId: 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 == 0){
  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>