save-ticket.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <template>
  2. <view class="save-order-box iPhone-bottom flex-common-css box-border-box">
  3. <view class="bg-box"></view>
  4. <Nav title='提交订单' bgckgroundBox='transparent'></Nav>
  5. <view class="scroll-view-css box-border-box p-24">
  6. <view class="box-card box-border-box mb-20 bgc-f">
  7. <view class="box-input align-items-center box-border-box p-b-20 mb-20">
  8. <view class="fs-28 fw-600 w158">姓名</view>
  9. <input v-model="fromData.name" type="text" placeholder="请输入姓名">
  10. </view>
  11. <view class="box-input align-items-center box-border-box p-b-20 mb-20">
  12. <view class="fs-28 fw-600 w158">手机号</view>
  13. <input v-model="fromData.phone" type="number" placeholder="请输入手机号">
  14. <view class="fs-28 fc-41ABF5 code-box" @click="getCode()">{{codeText}}{{isCode?'s':''}}</view>
  15. </view>
  16. <view class="box-input align-items-center box-border-box p-b-20 mb-20">
  17. <view class="fs-28 fw-600 w158">验证码</view>
  18. <input v-model="fromData.code" type="number" placeholder="请输入验证码">
  19. </view>
  20. <view class="box-input align-items-center box-border-box p-b-20 mb-20">
  21. <view class="fs-28 fw-600 w158">联系地址</view>
  22. <input v-model="fromData.address" type="text" placeholder="请输入联系地址(选填)">
  23. </view>
  24. </view>
  25. <view class="box-card box-border-box mb-20 bgc-f">
  26. <view class="box-top box-border-box flex-justify-space">
  27. <view class="box-left display-flex">
  28. <image :src="goodsData.cover_img" mode="aspectFill"></image>
  29. <view class="w336 fs-28 fw-400">{{goodsData.title||''}}</view>
  30. </view>
  31. <view class="box-right">
  32. <view class="fs-32 fw-600 text-align-right mb-12">¥{{goodsData.price||''}}</view>
  33. <view class="display-flex align-items-center">
  34. <!-- <view class="right-only-right-red fw-500 text-align-center fs-36 fc-f" @click="setNum(1)">-
  35. </view> -->
  36. <image class="wh-44" @click="setNum(1)" src="@/static/img/takeout/j.png" mode=""></image>
  37. <view class="right-only-right-2 text-align-center fs-28 fw-400">{{fromData.number}}</view>
  38. <image class="wh-44" src="@/static/img/takeout/add.png" @click="setNum(2)" mode=""></image>
  39. <!-- <view class="right-only-right-add fw-500 text-align-center fs-36 fc-f" @click="setNum(2)">+
  40. </view> -->
  41. </view>
  42. </view>
  43. </view>
  44. <view class="box-buttom text-align-right">
  45. <span class="fs-28 fc-9 fw-400">共{{fromData.number}}件,</span>
  46. <span class="fs-28 fc-0 fw-400">合计¥</span>
  47. <span
  48. class="fs-44 fc-0 fw-b">{{goodsData.price?(Number(goodsData.price)*fromData.number).toFixed(2):''}}</span>
  49. </view>
  50. </view>
  51. <view class="box-card box-border-box mb-20 bgc-f flex-justify-space">
  52. <view class="fs-28 fw-600 w158">备注</view>
  53. <input v-model="fromData.note" class="text-align-right" type="text" placeholder="请填写你的备注">
  54. </view>
  55. <view class="box-card box-border-box mb-20 bgc-f flex-justify-space">
  56. <view class="fs-28 fw-600 w158">支付方式</view>
  57. <view class="wx-box display-flex">
  58. <image src="@/static/img/common/wx-zf.png" mode="scaleToFill"></image>
  59. <view class="fs-28 fw-400 ml-10">微信支付</view>
  60. </view>
  61. </view>
  62. </view>
  63. <view class="bottom-box box-border-box p-24">
  64. <view class="flex-justify-space">
  65. <view class="align-items-flex-end box-1">
  66. <span class="fs-28 fc-f fw-600">¥</span>
  67. <span
  68. class="fs-44 fc-f fw-600">{{goodsData.price?(Number(goodsData.price)*fromData.number).toFixed(2):''}}</span>
  69. </view>
  70. <view class="text-align-center box-2 fs-32 fc-f fw-600" @click="toSave()">立即支付</view>
  71. </view>
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. import {
  77. ticketOrderFoster
  78. } from '@/api/ticket.js'
  79. import {
  80. getCode
  81. } from '@/api/common.js'
  82. import {
  83. ticketCreate,
  84. ticketPay
  85. } from '@/api/ticket.js';
  86. import tools from "@/service/tools";
  87. export default {
  88. data() {
  89. return {
  90. isCode: false,
  91. codeText: '获取验证码',
  92. fromData: {
  93. name: '',
  94. id: '',
  95. phone: '',
  96. school_id: '',
  97. code: '',
  98. note: '',
  99. address: '',
  100. number: 1,
  101. },
  102. isAJAX: false,
  103. goodsData: {},
  104. }
  105. },
  106. onLoad(e) {
  107. if (e.goodsData) {
  108. let obj = JSON.parse(decodeURIComponent(e.goodsData));
  109. this.goodsData = obj;
  110. this.fromData.id = obj.id;
  111. }
  112. },
  113. mounted() {
  114. this.ticketOrderFoster()
  115. },
  116. methods: {
  117. ticketOrderFoster() {
  118. ticketOrderFoster().then((res) => {
  119. if (res.code == 1) {
  120. console.log(res);
  121. this.fromData.address = res.data.address
  122. this.fromData.name = res.data.name
  123. this.fromData.phone = res.data.phone
  124. }
  125. })
  126. },
  127. getCode() {
  128. if (this.isCode) {
  129. return
  130. }
  131. this.isCode = true;
  132. getCode({
  133. phone: this.fromData.phone,
  134. send_type: 'ticket_order'
  135. }).then((res) => {
  136. if (res.code === 1) {
  137. this.codeText = 60;
  138. let timer = setInterval(() => {
  139. this.codeText -= 1;
  140. if (this.codeText <= 0) {
  141. clearInterval(timer);
  142. this.isCode = false;
  143. this.codeText = '获取验证码'
  144. }
  145. }, 1000);
  146. } else {
  147. this.isCode = false;
  148. tools.error('获取验证码失败,请稍后重试')
  149. }
  150. })
  151. },
  152. setNum(type) {
  153. if (type == 1) {
  154. if (this.fromData.number <= 1) {
  155. return
  156. } else {
  157. this.fromData.number -= 1;
  158. }
  159. } else {
  160. this.fromData.number += 1;
  161. }
  162. },
  163. toSave() {
  164. if (this.isAJAX) {
  165. return
  166. }
  167. this.isAJAX = true;
  168. this.fromData.school_id = uni.getStorageSync('school_id');
  169. ticketCreate(this.fromData).then((res) => {
  170. if (res.code === 1) {
  171. ticketPay({
  172. order_id: res.data.order_id
  173. }).then((ret) => {
  174. if (ret.code === 1) {
  175. uni.requestPayment({
  176. provider: "wxpay", //支付类型-固定值
  177. timeStamp: ret.data.wx_pay.timeStamp + "", // 时间戳(单位:秒)
  178. nonceStr: ret.data.wx_pay.nonceStr, // 随机字符串
  179. package: ret.data.wx_pay.package, // 固定值
  180. signType: ret.data.wx_pay.signType, //固定值
  181. paySign: ret.data.wx_pay.paySign, //签名
  182. success: (ren) => {
  183. tools.success("支付成功");
  184. this.isAJAX = false;
  185. setTimeout(() => {
  186. uni.switchTab({
  187. url: "/pages/order/index"
  188. })
  189. uni.setStorageSync('orderPayType', 4)
  190. }, 1000)
  191. },
  192. fail: (err) => {
  193. this.isAJAX = false;
  194. tools.error("支付失败");
  195. setTimeout(() => {
  196. uni.switchTab({
  197. url: "/pages/order/index"
  198. })
  199. uni.setStorageSync('orderPayType', 4)
  200. }, 1000)
  201. },
  202. });
  203. } else {
  204. this.isAJAX = false;
  205. tools.error("支付失败");
  206. setTimeout(() => {
  207. uni.switchTab({
  208. url: "/pages/order/index"
  209. })
  210. uni.setStorageSync('orderPayType', 4)
  211. }, 1000)
  212. }
  213. })
  214. } else {
  215. this.isAJAX = false;
  216. tools.error(res.msg);
  217. }
  218. })
  219. },
  220. },
  221. }
  222. </script>
  223. <style scoped lang="scss">
  224. .wh-44 {
  225. width: 44rpx;
  226. height: 44rpx;
  227. }
  228. .save-order-box {
  229. position: relative;
  230. .right-only-right-red {
  231. width: 44rpx;
  232. height: 44rpx;
  233. line-height: 40rpx;
  234. border-radius: 12rpx;
  235. border: 1rpx solid #41ABF5;
  236. color: #41ABF5;
  237. }
  238. .right-only-right-add {
  239. width: 44rpx;
  240. height: 44rpx;
  241. line-height: 40rpx;
  242. background: linear-gradient(117deg, #57CAFF 0%, #41ABF5 100%);
  243. border-radius: 12rpx;
  244. }
  245. .right-only-right-2 {
  246. min-width: 50rpx;
  247. }
  248. .bg-box {
  249. width: 100%;
  250. height: 448rpx;
  251. filter: blur(80rpx);
  252. background: linear-gradient(to right, rgba(176, 252, 250, 0.6), rgba(249, 246, 224, 0.87), rgba(249, 246, 224, 0.87));
  253. position: absolute;
  254. top: 0;
  255. left: 0;
  256. z-index: -1;
  257. }
  258. .bottom-box {
  259. background-color: #fff;
  260. .box-1 {
  261. flex: 1;
  262. height: 100rpx;
  263. background: #333;
  264. border-radius: 200rpx 0rpx 0rpx 200rpx;
  265. box-sizing: border-box;
  266. padding-left: 32rpx;
  267. padding-bottom: 20rpx;
  268. }
  269. .box-2 {
  270. width: 200rpx;
  271. height: 100rpx;
  272. line-height: 100rpx;
  273. background: #41ABF5;
  274. border-radius: 0rpx 200rpx 200rpx 0rpx;
  275. text-align: center;
  276. }
  277. }
  278. .box-card {
  279. width: 100%;
  280. min-height: 88rpx;
  281. border-radius: 20rpx;
  282. padding: 24rpx 24rpx 0 24rpx;
  283. .box-top {
  284. padding-bottom: 24rpx;
  285. border-bottom: 2rpx solid #F9F9F9;
  286. margin-bottom: 24rpx;
  287. .box-left {
  288. image {
  289. width: 108rpx;
  290. height: 108rpx;
  291. border-radius: 8rpx;
  292. margin-right: 16rpx;
  293. }
  294. .w336 {
  295. width: 336rpx;
  296. }
  297. }
  298. }
  299. .box-buttom {
  300. padding-bottom: 24rpx;
  301. }
  302. }
  303. .box-input {
  304. border-bottom: 2rpx solid #F9F9F9;
  305. position: relative;
  306. .w158 {
  307. width: 158rpx;
  308. }
  309. input {
  310. font-size: 28rpx;
  311. }
  312. .code-box {
  313. position: absolute;
  314. right: 0;
  315. top: 0;
  316. }
  317. }
  318. .wx-box {
  319. image {
  320. width: 40rpx;
  321. height: 40rpx;
  322. }
  323. }
  324. }
  325. </style>