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

536 lines
11 KiB

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