submit_order.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <view class="content">
  3. <!-- 支付剩余时间 -->
  4. <view class="break_time">
  5. 交易剩余时间<uv-count-down :time="new Date(allTime).getTime() + 15 * 60 * 1000 - new Date().getTime()" format="mm:ss" @change="change" @finish="finish(countDownTime,allTime)"></uv-count-down>
  6. </view>
  7. <!-- <uv-count-down :time="56687" format="mm:ss" @finish="finish(countDownTime)"></uv-count-down> -->
  8. <!-- <view class="break_time">交易剩余时间15:00</view> -->
  9. <view class="break_money">¥{{countMoney}}</view>
  10. <!-- 住房信息 -->
  11. <view class="zhufang">住房信息</view>
  12. <view class="two_all">
  13. <view class="select-time">
  14. <view class="select-time-one">
  15. <text class="select-list-time">{{startTime}}
  16. <text class="select-list">{{startWeek}}</text>
  17. </text>
  18. </view>
  19. <view class="select-center">
  20. <view class="select-line1"></view>
  21. <view class="select-circle">{{ruzhu_num}}晚</view>
  22. <view class="select-line2"></view>
  23. </view>
  24. <view class="select-time-one">
  25. <text class="select-list-time">{{endTime}}
  26. <text class="select-list">{{endWeek}}</text>
  27. </text>
  28. </view>
  29. </view>
  30. <!-- 房型信息 -->
  31. <view class="select_name">{{roomName}}</view>
  32. <view class="select_type" v-if="roomType==1">全日房</view>
  33. <view class="select_type" v-else-if="roomType==2">钟点房</view>
  34. <view class="select_detail">
  35. {{roomArea}}㎡
  36. <text style="margin-left: 20px;">{{roomConfiguration}}</text>
  37. <!-- <text style="margin-left: 20px;">窗户位于走廊/窗户较小</text> -->
  38. </view>
  39. </view>
  40. <!-- 支付方式 -->
  41. <view class="pay-way">支付方式</view>
  42. <view class="pay-list">
  43. <view class="iconweixin"></view>
  44. <view class="item">微信支付</view>
  45. <label class="radio">
  46. <radio value="" color="rgba(0, 97, 255, 1)" :checked="pay_way == '微信支付'" :disabled="money <= 0" />
  47. </radio>
  48. </label>
  49. </view>
  50. <!-- 确认支付 -->
  51. <view class="quwer" @click="queZhifu1">确认支付</view>
  52. </view>
  53. </template>
  54. <script>
  55. import {
  56. getorderdetail,
  57. quxiaoorder,
  58. getorderpay,
  59. getchapay
  60. } from '../../utils/api_hotel.js'
  61. export default {
  62. data() {
  63. return {
  64. orderId:'',//订单id
  65. startTime:'',//到店日期
  66. endTime:'',//离店日期
  67. startWeek:'',// 默认入店日
  68. endWeek:'',// 默认离店
  69. ruzhu_num:1,//入住夜晚
  70. pay_way: '微信支付',
  71. roomName:'',
  72. roomType:1,
  73. roomArea:'',
  74. roomConfiguration:'',//房间配置
  75. countMoney:'',
  76. countDownTime:null,
  77. allTime:'',
  78. orderNumber:'', //订单号
  79. houseNumberId:'', //房间号id
  80. money:'',
  81. appId: "", //公众号ID,由商户传入
  82. timeStamp: "", //时间戳,自1970年以来的秒数
  83. nonceStr: "", //随机串
  84. package: "",
  85. signType: "", //微信签名方式:
  86. paySign:'',
  87. }
  88. },
  89. onLoad(option) {
  90. this.orderId=option.houseOrderId
  91. },
  92. onShow() {
  93. this.getorderXiang()
  94. },
  95. methods: {
  96. // 截取 url中的code方法
  97. handleUrlCode() {
  98. var url = location.href; //获取打开的公众号的路径
  99. var theRequest = new Object();
  100. if (url.indexOf('?') != -1) {
  101. var str = url.substr(url.indexOf('?') + 1);
  102. var strs = str.split('&');
  103. for (var i = 0; i < strs.length; i++) {
  104. var items = strs[i].split('=');
  105. if(strs[i].split('=')[0]=='code'){
  106. var code=strs[i].split('=')[1]
  107. }
  108. theRequest[strs[i].split('=')[0]] = strs[i].split('=')[1];
  109. theRequest[i] = strs[i].split('=')[1];
  110. localStorage.setItem('code',code)
  111. }
  112. // alert(code+'p')
  113. }
  114. },
  115. // 订单详情
  116. getorderXiang() {
  117. this.payMount=0
  118. let _self = this
  119. var data="?houseOrderId="+this.orderId
  120. getorderdetail(data).then((res) => {
  121. if (res.success) {
  122. this.roomName=res.data.roomNumber
  123. this.roomType=res.data.house.roomType
  124. this.roomArea=res.data.house.roomArea
  125. this.roomConfiguration=res.data.house.roomConfiguration
  126. this.countMoney=res.data.houseOrder.payPrice
  127. this.ruzhu_num=res.data.houseOrder.liveDay
  128. this.startTime=(res.data.houseOrder.reserveLiveTime).substring(5,10)
  129. this.endTime=(res.data.houseOrder.reserveLeaveTime).substring(5,10)
  130. this.startWeek=this.getweekday(res.data.houseOrder.reserveLiveTime)
  131. this.endWeek=this.getweekday(res.data.houseOrder.reserveLeaveTime)
  132. this.orderNumber=res.data.houseOrder.orderNumber //订单号
  133. this.houseNumberId=res.data.houseOrder.houseNumberId //房间号id
  134. // 兼容ios部分系统转换时间格式
  135. this.allTime = res.data.houseOrder.createTime.replace(/-/g, '/')
  136. this.countDownTime = new Date(this.allTime).getTime() + 15 * 60 * 1000 - new Date().getTime()
  137. return;
  138. } else {
  139. console.log('订单详情获取失败')
  140. }
  141. }).catch((err) => {
  142. this.$message.error(err.message)
  143. });
  144. },
  145. // 计算指定时间是周几
  146. getweekday(date){
  147. // date例如:'2022-03-05'
  148. var weekArray = new Array("周日","周一", "周二", "周三", "周四", "周五", "周六")
  149. var weeka = weekArray[new Date(date).getDay()]
  150. return weeka
  151. },
  152. //确认支付
  153. queZhifu1(){
  154. if(localStorage.getItem('code')=='undefined'){
  155. uni.navigateTo({
  156. url:'/pages/huoquCode/huoquCode'
  157. })
  158. return
  159. }
  160. let _self = this
  161. var data={
  162. "usersId": localStorage.getItem('usersId'),
  163. "houseOrderId": this.orderId,//订单号idlocalStorage.getItem('orderId')
  164. "totalPrice":this.countMoney //支付金额
  165. }
  166. getorderpay(data).then((res) => {
  167. // alert(res.message+res.code)
  168. if (res.success) {
  169. _self.appId=res.data.appId
  170. _self.timeStamp=res.data.timeStamp
  171. _self.nonceStr=res.data.nonceStr
  172. _self.package=res.data.packageVal
  173. _self.signType=res.data.signType
  174. _self.paySign=res.data.paySign
  175. _self.onBridgeReady();
  176. } else if(res.code=='500'){
  177. uni.navigateTo({
  178. url:'/pages/huoquCode/huoquCode'
  179. })
  180. // uni.showModal({
  181. // content:res.message
  182. // })
  183. }
  184. }).catch((err) => {
  185. uni.navigateTo({
  186. url:'/pages/huoquCode/huoquCode'
  187. })
  188. });
  189. },
  190. onBridgeReady() {
  191. WeixinJSBridge.invoke('getBrandWCPayRequest', {
  192. "appId": this.appId, //公众号ID,由商户传入
  193. "timeStamp": this.timeStamp, //时间戳,自1970年以来的秒数
  194. "nonceStr": this.nonceStr, //随机串
  195. "package": this.package,
  196. "signType": this.signType, //微信签名方式:
  197. "paySign": this.paySign //微信签名
  198. },
  199. function(res) {
  200. // alert('p1'+res.err_msg)
  201. if (res.err_msg == "get_brand_wcpay_request:ok") {
  202. // alert('pp')
  203. uni.navigateTo({
  204. url:'/pages/my_orderlist/my_orderlist?Inv=3'
  205. })
  206. // 使用以上方式判断前端返回,微信团队郑重提示:
  207. //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
  208. }else{
  209. this.chapayIf()
  210. }
  211. });
  212. },
  213. //查询是否支付成功
  214. chapayIf(){
  215. var data={
  216. "outTradeNo": this.orderNumber,//订单号id
  217. }
  218. getchapay(data).then((res) => {
  219. if (res.success) {
  220. if(res.data.tradeState=="SUCCESS"){
  221. uni.showModal({
  222. content:'支付成功',
  223. success: (res) => {
  224. uni.navigateTo({
  225. url:'/pages/my_orderlist/my_orderlist?Inv=3'
  226. })
  227. },
  228. })
  229. }else{
  230. uni.showModal({
  231. content:res.data.tradeStateDesc
  232. })
  233. }
  234. // return;
  235. } else {
  236. }
  237. }).catch((err) => {
  238. uni.showModal({
  239. content:err.message
  240. })
  241. });
  242. },
  243. // 倒计时结束回调
  244. finish(countDownTime,item) {
  245. // alert('倒计时结束'+item)
  246. // if(item==)
  247. this.quxiaoorder()
  248. },
  249. // 取消订单
  250. quxiaoorder(){
  251. let _self = this
  252. // this.$axios.defaults.headers.common['token'] = localStorage.getItem('token');
  253. // this.$axios.defaults.headers.common['user_head'] = localStorage.getItem('user_head');
  254. // this.$axios.defaults.headers.common['Content-Type'] ='application/json'
  255. var data={
  256. "usersId": localStorage.getItem('usersId'),
  257. "orderNumber": this.orderNumber, //订单号
  258. "houseNumberId": this.houseNumberId, //房间号id
  259. }
  260. quxiaoorder(data).then((res) => {
  261. if (res.success) {
  262. uni.showModal({
  263. content:'支付超时,请重新订房',
  264. success: (res) => {
  265. uni.switchTab({
  266. url:'/pages/index/index'
  267. })
  268. },
  269. fail: (e) => {
  270. // uni.switchTab({
  271. // url:'/pages/index/index'
  272. // })
  273. },
  274. })
  275. // return;
  276. } else {
  277. }
  278. }).catch((err) => {
  279. uni.showModal({
  280. content:err.message
  281. })
  282. });
  283. }
  284. }
  285. }
  286. </script>
  287. <style>
  288. @import url("./css/submit_order.css");
  289. </style>