group-pay.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <view class="flex-common-css iPhone-bottom box-border-box">
  3. <Nav title='提交订单' bgckgroundBox='transparent'></Nav>
  4. <scroll-view :scroll-y="true" class="scroll-view-css" @scrolltolower="scrolltolower">
  5. <view class="p-24 box-border-box bgc-f b-rad-20 mb-20">
  6. <view class="align-items-flex-end flex-justify-space p-b-20 b-b-F9F9F9 mb-20">
  7. <view class="align-items-flex-start">
  8. <image :src="goods_info.cover_img" mode="scaleToFill" class="goods-img mr-18"></image>
  9. <view class="">
  10. <view class="fs-32 w-150 text-overflow-ellipsis-one mb-10">
  11. {{goods_info.title}}
  12. </view>
  13. <view class="mb-10 fs-22 fc-9">
  14. 可用时间:
  15. {{goods_info.usable_time == 1?'24小时可用':goods_info.timeData}}
  16. </view>
  17. <view class="fs-22 fc-9 mb-10">
  18. {{goods_info.is_quota == 0?'不限购':'限购'+ goods_info.quota_num +'张'}} .
  19. {{goods_info.pre_book == 1?'无需预约':'需预约'}}
  20. </view>
  21. <view class="fs-22 fc-9">
  22. 随时退 . 过期自动退
  23. </view>
  24. </view>
  25. </view>
  26. <view class="">
  27. <view class="align-items-center mb-10 flex-justify-end">
  28. <view class="fs-22 fc-9 mr-6 sc-class">
  29. {{goods_info.line_price}}
  30. </view>
  31. <view class="goods_info.price fs-22">
  32. 现价¥<span class="fs-28">{{goods_info.price}}</span>
  33. </view>
  34. </view>
  35. <view class="align-items-center">
  36. <image src="@/static/img/takeout/j.png" mode="" class="j" @click="setNum(1)"></image>
  37. <input type="number" v-model="fromData.number" class="input" @blur='blur' />
  38. <image src="@/static/img/takeout/add.png" mode="" class="j" @click="setNum(2)"></image>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="text-align-center flex-justify-end">
  43. <view class="fs-28 mr-20">
  44. 优惠 <span
  45. class="fc-41ABF5 fs-28">¥{{((Number(goods_info.line_price) - Number(goods_info.price)) * Number(fromData.number)).toFixed(2)}}</span>
  46. </view>
  47. <view class="fs-28">
  48. 小计 <span
  49. class="fc-41ABF5 fs-28 fw-600">¥{{(Number(goods_info.price) * Number(fromData.number)).toFixed(2)}}</span>
  50. </view>
  51. </view>
  52. </view>
  53. </scroll-view>
  54. <view class="but-box align-items-center flex-justify-space bgc-f p-24 box-border-box">
  55. <view class="">
  56. <view class="fs-34 fw-600 fc-41ABF5">
  57. <span class="fs-24 fc-41ABF5 fw-400 mr-12">合计</span><span
  58. class="fs-20 fw-600 fc-41ABF5">¥</span>{{(Number(goods_info.price) * Number(fromData.number)).toFixed(2)}}
  59. </view>
  60. <view class="fc-9">
  61. <span
  62. class="mr-12">共{{fromData.number}}件</span>已优惠¥{{((Number(goods_info.line_price) - Number(goods_info.price)) * Number(fromData.number)).toFixed(2)}}
  63. </view>
  64. </view>
  65. <view class="but bgc-41ABF5 fc-f b-rad-200 text-align-center fs-34" @click="toSave()">
  66. 立即支付
  67. </view>
  68. </view>
  69. </view>
  70. </template>
  71. <script>
  72. import {
  73. groupInfo,
  74. groupCreate
  75. } from '@/api/group.js'
  76. import {
  77. groupPay
  78. } from '@/api/groupOrder.js';
  79. import tools from '@/service/tools';
  80. export default {
  81. components: {},
  82. data() {
  83. return {
  84. fromData: {
  85. id: 0,
  86. shop_id: 0,
  87. number: 1
  88. },
  89. goods_info: {},
  90. usable_time: '',
  91. isAJAX: false
  92. };
  93. },
  94. onLoad(data) {
  95. console.log(data);
  96. if (data) {
  97. this.fromData.id = data.goods_id
  98. this.fromData.shop_id = data.shop_id
  99. this.groupInfo()
  100. }
  101. },
  102. mounted() {},
  103. methods: {
  104. toSave() {
  105. if (this.isAJAX) {
  106. return
  107. }
  108. this.isAJAX = true;
  109. this.fromData.school_id = uni.getStorageSync('school_id');
  110. groupCreate(this.fromData).then((res) => {
  111. if (res.code === 1) {
  112. groupPay({
  113. order_id: res.data.order_id
  114. }).then((ret) => {
  115. if (ret.code === 1) {
  116. uni.requestPayment({
  117. provider: "wxpay", //支付类型-固定值
  118. timeStamp: ret.data.wx_pay.timeStamp + "", // 时间戳(单位:秒)
  119. nonceStr: ret.data.wx_pay.nonceStr, // 随机字符串
  120. package: ret.data.wx_pay.package, // 固定值
  121. signType: ret.data.wx_pay.signType, //固定值
  122. paySign: ret.data.wx_pay.paySign, //签名
  123. success: (ren) => {
  124. this.isAJAX = false;
  125. tools.success("支付成功");
  126. uni.setStorageSync('orderPayType', 3)
  127. setTimeout(() => {
  128. uni.switchTab({
  129. url: "/pages/order/index"
  130. })
  131. }, 1000)
  132. },
  133. fail: (err) => {
  134. this.isAJAX = false;
  135. tools.error("支付失败");
  136. uni.setStorageSync('orderPayType', 3)
  137. setTimeout(() => {
  138. uni.switchTab({
  139. url: "/pages/order/index"
  140. })
  141. }, 1000)
  142. },
  143. });
  144. } else {
  145. this.isAJAX = false;
  146. tools.error("支付失败");
  147. uni.setStorageSync('orderPayType', 3)
  148. setTimeout(() => {
  149. uni.switchTab({
  150. url: "/pages/order/index"
  151. })
  152. }, 1000)
  153. }
  154. })
  155. } else {
  156. this.isAJAX = false;
  157. tools.error(res.msg);
  158. }
  159. })
  160. },
  161. scrolltolower() {
  162. console.log('触底');
  163. },
  164. blur() {
  165. if (this.goods_info.is_quota == 1) {
  166. if (this.fromData.number >= this.goods_info.quota_num) {
  167. tools.error('限购'+ this.goods_info.quota_num + '张')
  168. this.fromData.number = this.goods_info.quota_num
  169. }
  170. }
  171. if (this.fromData.number >= 99) {
  172. tools.error('购买数量最大为99')
  173. this.fromData.number = 99
  174. } else if (this.fromData.number <= 0) {
  175. tools.error('购买数量最少为1')
  176. this.fromData.number = 1
  177. }
  178. },
  179. setNum(num) {
  180. if (num === 1) {
  181. // 减
  182. if (this.fromData.number <= 1) {
  183. tools.error('购买数量最少为1')
  184. return
  185. }
  186. --this.fromData.number
  187. } else {
  188. // 加
  189. if (this.goods_info.is_quota == 1) {
  190. if (this.fromData.number >= this.goods_info.quota_num) {
  191. tools.error('限购'+ this.goods_info.quota_num + '张')
  192. return
  193. } else if (this.fromData.number >= 99) {
  194. tools.error('购买数量已达最大值')
  195. return
  196. }
  197. }
  198. ++this.fromData.number
  199. }
  200. },
  201. setTimeData(timeData) {
  202. let time = ''
  203. let array = ''
  204. timeData.forEach((v, k) => {
  205. v.forEach((i, j) => {
  206. let timeTwo = ''
  207. if (j == 0 || j == 3) {
  208. timeTwo = i + '-'
  209. } else {
  210. timeTwo = i
  211. }
  212. array = array + timeTwo
  213. })
  214. if (timeData.length === k + 1) {
  215. time = time + array + ''
  216. } else {
  217. time = time + array + ' / '
  218. }
  219. array = ''
  220. })
  221. console.log(time);
  222. return time
  223. },
  224. groupInfo() {
  225. groupInfo({
  226. id: this.fromData.id,
  227. shop_id: this.fromData.shop_id
  228. }).then((res) => {
  229. if (res.code === 1) {
  230. if (res.data.usable_time === 2) {
  231. res.data.timeData = this.setTimeData(res.data.usable_time_arr)
  232. }
  233. this.goods_info = res.data
  234. }
  235. })
  236. },
  237. },
  238. }
  239. </script>
  240. <style lang="scss" scoped>
  241. .sc-class {
  242. text-decoration: line-through
  243. }
  244. .goods-img {
  245. width: 120rpx;
  246. height: 120rpx;
  247. border-radius: 20rpx;
  248. }
  249. .but {
  250. width: 40%;
  251. height: 80rpx;
  252. line-height: 80rpx;
  253. }
  254. .w-150 {
  255. width: 340rpx;
  256. }
  257. .j {
  258. width: 40rpx;
  259. height: 40rpx;
  260. }
  261. .input {
  262. max-width: 50rpx;
  263. margin: 0 10rpx;
  264. text-align: center;
  265. }
  266. </style>