pay.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <view>
  3. <!--列表数据-->
  4. <view class="list">
  5. <view class="info">
  6. <view class="order_title">
  7. <text>广安农机农技智慧服务</text>
  8. <view class="zhu" style="margin-top: -2px;"><u-tag text="租" type="success" /></view>
  9. </view>
  10. <view class="order_item" v-for="(item, index) in list" :key="index">
  11. <image :src="ip + item.goods.pic" class="pic" mode="aspectFill"></image>
  12. <view class="con">
  13. <view class="title">
  14. <text>{{ item.goods.title }}</text>
  15. </view>
  16. <view class="price">
  17. <text>¥{{ item.goods.price }}</text>
  18. <text class="day">/天</text>
  19. </view>
  20. </view>
  21. <view class="clear"></view>
  22. </view>
  23. <u-divider style="padding: 10px;">共计{{ list.length }}项服务</u-divider>
  24. </view>
  25. <view class="info">
  26. <view class="form_group hr">
  27. <view class="lable">我的姓名</view>
  28. <input type="text" placeholder="请输入姓名" v-model="item.name" />
  29. </view>
  30. <view class="form_group hr">
  31. <view class="lable">联系电话</view>
  32. <input type="number" placeholder="请输入联系电话" v-model="item.phone" />
  33. </view>
  34. <view class="form_group hr">
  35. <view class="lable">租赁天数</view>
  36. <u-number-box v-model="item.days" :min="1" @change="change"></u-number-box>
  37. </view>
  38. <view class="form_group hr">
  39. <view class="lable">备注信息</view>
  40. <textarea placeholder="备注信息" v-model="item.notes" />
  41. </view>
  42. </view>
  43. <view class="phone">请填写正确的手机号,我们客服人员会和你取得联系</view>
  44. </view>
  45. <view class="footer">
  46. <view class="lfx">
  47. <view class="f">
  48. <view class="hej">
  49. <text class="price">¥{{ item.totalPrice }}</text>
  50. </view>
  51. </view>
  52. <view class="f js" @click="pay()">支付</view>
  53. </view>
  54. </view>
  55. </view>
  56. </template>
  57. <script>
  58. export default {
  59. data() {
  60. return {
  61. ip: this.$http.urls.ip,
  62. list: [],
  63. item: { orderList: [], totalPrice: 0, days: 1, phone: this.$getUser().phone }
  64. };
  65. },
  66. onLoad(e) {
  67. this.list = JSON.parse(e.list);
  68. this.calcul();
  69. },
  70. methods: {
  71. change(e) {
  72. this.calcul();
  73. },
  74. //计算
  75. calcul() {
  76. this.item.totalPrice = 0;
  77. this.list.forEach(item => {
  78. this.item.totalPrice = this.$util.accAdd(this.item.totalPrice, item.goods.price);
  79. });
  80. this.item.totalPrice = this.$util.accMul(this.item.totalPrice, this.item.days);
  81. this.$forceUpdate();
  82. },
  83. //结算
  84. pay() {
  85. let rule = [
  86. { name: 'name', checkType: 'notnull', errorMsg: '请输入姓名' },
  87. { name: 'phone', checkType: 'phoneno', errorMsg: '请输入正确手机号' },
  88. { name: 'days', checkType: 'notnull', errorMsg: '请选择租赁天数' }
  89. ];
  90. if (!this.$verify.check(this.item, rule)) {
  91. uni.showModal({ content: this.$verify.error, showCancel: false });
  92. return;
  93. }
  94. this.item.orderList = [];
  95. this.item.title = '';
  96. this.list.forEach(item => {
  97. this.item.orderList.push({ id: item.id, goodsId: item.goodsId, price: item.goods.price, title: item.goods.title, pic: item.goods.pic });
  98. this.item.title += item.goods.title + ',';
  99. });
  100. this.item.openId = this.$getUser().openId;
  101. this.item.userId = this.$getUser().id;
  102. this.$http.request({
  103. url: this.$http.urls.pay,
  104. method: 'POST',
  105. data: this.item,
  106. success: res => {
  107. if (res.data.code === 200) {
  108. //调起微信支付
  109. wx.requestPayment({
  110. timeStamp: res.data.data.timeStamp,
  111. nonceStr: res.data.data.nonceStr,
  112. package: res.data.data.package,
  113. signType: res.data.data.signType,
  114. paySign: res.data.data.paySign,
  115. success: r => {
  116. uni.redirectTo({ url: '/pages/order/list' });
  117. },
  118. fail: r => {
  119. uni.redirectTo({ url: '/pages/order/list' });
  120. }
  121. });
  122. } else {
  123. uni.showModal({ content: res.data.msg, showCancel: false });
  124. }
  125. }
  126. });
  127. }
  128. }
  129. };
  130. </script>
  131. <style lang="scss">
  132. page {
  133. background-color: $page;
  134. }
  135. .list {
  136. padding: 0px 10px 75px 10px;
  137. .info {
  138. background-color: white;
  139. border-radius: 5px;
  140. margin-top: 10px;
  141. }
  142. .phone {
  143. padding-top: 5px;
  144. font-size: 13px;
  145. color: #838383;
  146. }
  147. }
  148. .footer {
  149. .price {
  150. font-size: 15px;
  151. }
  152. }
  153. </style>