submit_order.vue 11 KB

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