save-ticket.vue 8.6 KB

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