sureOrder.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <view class="sure-order">
  3. <view class="order-detail">
  4. <view class="order-title">
  5. <uv-text text="订单详情" :customStyle="{
  6. fontWeight:'bold'
  7. }" size="32"></uv-text>
  8. </view>
  9. <view class="order-content">
  10. <uv-image :src="imageUrl(orderData.rotatingImages) || ''" width="180" height="180" radius="16">
  11. </uv-image>
  12. <view class="order-content-detail">
  13. <uv-text :text="orderData.name" :lines="2" size="28"></uv-text>
  14. <uv-text text="x1" type="content" size="28" :customStyle="{
  15. background:'#eee',
  16. padding:'2rpx 16rpx',
  17. borderRadius:'4rpx',
  18. margin:'10rpx 0'
  19. }"></uv-text>
  20. <uv-text :text="orderData.price" type="error" size="32" mode="price"></uv-text>
  21. </view>
  22. </view>
  23. <view class="order-item">
  24. <uv-text text="优惠券" size="28"></uv-text>
  25. <view class="text-flex"
  26. @tap="$navigateTo('/subPages/workarkPage/coupon/coupon?productLevelId=' + orderData.productLevelId + '&price=' + orderData.price)">
  27. <text class="order-item-icon">-</text>
  28. <uv-text :text="minus" type="error" size="28" mode="price"></uv-text>
  29. <uv-icon name="arrow-right" size="32"></uv-icon>
  30. </view>
  31. </view>
  32. <view class="order-count">
  33. <view class="text-flex">
  34. <uv-text text="合计:" size="28"></uv-text>
  35. <uv-text :text="countPriceData.totalFee" type="error" size="28" mode="price"></uv-text>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="hui-button-box">
  40. <view class="button-flex">
  41. <uv-text :text="countPriceData.totalFee" type="error" size="28" mode="price"></uv-text>
  42. <view class="text-flex">
  43. <uv-text text="-" type="error" size="24"></uv-text>
  44. <uv-text :text="minus" type="error" size="24" mode="price"></uv-text>
  45. </view>
  46. </view>
  47. <uv-button type="primary" text="立即支付" @tap="payment" :disabled="isCount"></uv-button>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import {
  53. getServeById,
  54. countPriceAPI,
  55. createOrder,
  56. getWxPay
  57. } from '@/request/api/workark.js'
  58. export default {
  59. props: {
  60. orderId: {
  61. type: Number,
  62. default: 0
  63. },
  64. },
  65. data() {
  66. return {
  67. orderData: {
  68. price: 0
  69. },
  70. countPriceData: {
  71. productCoupon: [],
  72. totalFee: 0
  73. },
  74. isCount: false,
  75. couponChecked: [],
  76. order: {}
  77. };
  78. },
  79. mounted() {
  80. uni.$on('changeCoupon', this.changeCoupon);
  81. if (this.orderId) this.init();
  82. },
  83. beforeDestroy() {
  84. uni.$off('changeCoupon', this.changeCoupon);
  85. },
  86. computed: {
  87. minus() {
  88. let data = this.countPriceData.productCoupon || [];
  89. let num = 0;
  90. for (var i = 0; i < data.length; i++) {
  91. num += data[i].minus
  92. }
  93. return num;
  94. }
  95. },
  96. methods: {
  97. async init() {
  98. let orderData = await getServeById(this.orderId);
  99. if (!orderData.state) return;
  100. this.orderData = orderData.data;
  101. this.countPrice();
  102. },
  103. imageUrl(data) {
  104. if (!data) return '';
  105. let imgData = JSON.parse(data)[0];
  106. if (!imgData) return '';
  107. return imgData.url;
  108. },
  109. async countPrice() {
  110. this.isCount = true;
  111. let couponIds = this.couponChecked.map(node => node.id).join(',') || -1;
  112. let countPriceData = await countPriceAPI(this.orderData.id, couponIds);
  113. this.isCount = false;
  114. if (!countPriceData.state) return;
  115. this.countPriceData = countPriceData.data;
  116. },
  117. changeCoupon(data) {
  118. this.couponChecked = data;
  119. this.countPrice();
  120. },
  121. async payment() {
  122. uni.showLoading({
  123. title: '订单确认中...'
  124. })
  125. let couponIds = this.couponChecked.map(node => node.id).join(',') || -1;
  126. let orderData = await createOrder(this.orderData.id, this.$store.getters.organization.id, couponIds);
  127. if (orderData.state) {
  128. let wxConfig = await getWxPay(orderData.data.orderNo, uni.getStorageSync('openId'));
  129. uni.requestPayment({
  130. provider: 'wxpay',
  131. timeStamp: wxConfig.data.timeStamp,
  132. nonceStr: wxConfig.data.nonceStr,
  133. package: wxConfig.data.prepayId,
  134. signType: wxConfig.data.signType,
  135. paySign: wxConfig.data.paySign,
  136. success: res => {
  137. this.paymentCallback(orderData.data.id, '支付成功');
  138. },
  139. fail: err => {
  140. this.paymentCallback(orderData.data.id, '未支付');
  141. }
  142. });
  143. }
  144. },
  145. paymentCallback(orderId, status) {
  146. this.$emit('closePopup');
  147. uni.hideLoading();
  148. this.$navigateTo(`/subPages/workarkPage/paymentStatus/paymentStatus?orderId=${orderId}&status=${status}`);
  149. }
  150. },
  151. }
  152. </script>
  153. <style lang="scss">
  154. .sure-order {
  155. padding: 30rpx;
  156. }
  157. .order-detail {
  158. background: #fff;
  159. padding: 30rpx;
  160. border-radius: 16rpx;
  161. }
  162. .order-title {
  163. padding-bottom: 30rpx;
  164. }
  165. .order-content {
  166. display: flex;
  167. }
  168. .order-content-detail {
  169. flex: 1;
  170. width: 0;
  171. margin-left: 30rpx;
  172. }
  173. .order-item {
  174. display: flex;
  175. justify-content: space-between;
  176. align-items: center;
  177. height: 88rpx;
  178. border-bottom: 1px solid $uv-border-color;
  179. margin-bottom: 30rpx;
  180. }
  181. .order-item-icon {
  182. color: $uv-error;
  183. }
  184. .order-count {
  185. display: flex;
  186. justify-content: flex-end;
  187. }
  188. .button-flex {
  189. margin-right: 20rpx;
  190. }
  191. </style>