pay.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <view>
  3. <hx-navbar title="支付订单" :backgroundColor="[241,241,241]"></hx-navbar>
  4. <view class="head">
  5. <view class="row" >
  6. <text v-if="countdownStr">支付剩余时间 {{countdownStr}}</text>
  7. <text v-else>重新提交订单</text>
  8. </view>
  9. <view class="row pricebox pt-8">
  10. <text class="fh">¥</text>
  11. <text class="txt1">{{orderInfo.money}}</text>
  12. </view>
  13. <view class="row pt-4" @click="doOrder">
  14. <text>{{orderInfo.store_name}}</text>
  15. <text v-if="orderInfo.store_community">({{orderInfo.store_community}})</text>
  16. <text>订单详情</text>
  17. <i class="hxicon-right"></i>
  18. </view>
  19. </view>
  20. <view class="container">
  21. <radio-group @change="payChange" class="list-box">
  22. <block v-for="(item,i) in payData" :key="i">
  23. <view class="flex-rl list-item">
  24. <view class="left">
  25. <view class="iconbox" :style="'background-color:' + item.icon_color">
  26. <i :class="item.icon" ></i>
  27. </view>
  28. </view>
  29. <view class="b-b right">
  30. <view class="tit-box">
  31. <text class="tit">{{item.name}}</text>
  32. </view>
  33. <radio :value="item.id" color="#ffc107" :checked="item.default == 1" />
  34. </view>
  35. </view>
  36. </block>
  37. </radio-group>
  38. </view>
  39. <view class="btn" @click="submitPay">
  40. <text>确认支付</text>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. export default {
  46. onLoad(option) {
  47. let that = this
  48. //获取订单id
  49. if(option.id){
  50. }
  51. },
  52. onReady(){
  53. let that = this
  54. that.orderInfo = {
  55. //订单id
  56. order_id: "LQL20200410134",
  57. //金额
  58. money: 206.2,
  59. //门店名称
  60. store_name: "小太阳红旗商店",
  61. //门店地标
  62. store_community: "玫瑰园店",
  63. //订单创建时间
  64. create_date: "2020-04-10 18:08:56",
  65. //订单有效期
  66. expiration_date: "2021-04-12 20:06:56"
  67. }
  68. that.countdown();
  69. for (let i in this.payData){
  70. if(this.payData[i].default == 1){
  71. this.payType = this.payData[i].id
  72. }
  73. }
  74. },
  75. data() {
  76. return {
  77. countdownStr: "00:00",
  78. //订单信息
  79. orderInfo:{},
  80. //默认支付方式
  81. payType:"wxpay",
  82. // 支付方式
  83. payData: [{
  84. id: "wxpay",
  85. name: "微信支付",
  86. icon: "hxicon-weixinzhifu",
  87. icon_color: "#09bb07",
  88. default: 0,
  89. },
  90. {
  91. id: "alipay",
  92. name: "支付宝支付",
  93. icon: "hxicon-zhifubaozhifu",
  94. icon_color: "#08a0e9",
  95. default: 1
  96. }],
  97. }
  98. },
  99. methods: {
  100. payChange(event){
  101. this.payType = event.target.value
  102. },
  103. doOrder(){
  104. //查看订单
  105. uni.showModal({
  106. content: '这是查看订单的事件',
  107. showCancel: false,
  108. confirmColor: "#999",
  109. success: function (res) {
  110. }
  111. });
  112. },
  113. //倒计时
  114. countdown(){
  115. var go_time=new Date((this.orderInfo.expiration_date).replace(/-/g, '/'));
  116. var now_time=new Date();
  117. if(!go_time.getTime()){
  118. return
  119. }
  120. var alltime =go_time.getTime() -now_time.getTime (); //剩余的时间(毫秒)
  121. if(alltime <= 0){
  122. this.countdownStr = ""
  123. this.showPrompt()
  124. return
  125. }
  126. var haoscend =alltime%1000; //毫秒
  127. //console.log(haoscend);
  128. var scend = parseInt ((alltime/1000)%60 )
  129. //console.log(scend);
  130. var minute =parseInt((alltime/1000/60)%60 )
  131. // console.log(minute);
  132. var hour =parseInt((alltime/1000/60/60)%24 )
  133. if(scend<10){
  134. scend = "0" + scend
  135. }
  136. if(minute<10){
  137. minute = "0" + minute
  138. }
  139. let str = minute +":"+scend;
  140. if(hour>0){
  141. str = hour + ':' + str
  142. }
  143. this.countdownStr = str
  144. setTimeout (this.countdown ,1000);
  145. },
  146. //显示弹窗
  147. showPrompt(){
  148. uni.showModal({
  149. content: '支付超时,请重新下单',
  150. showCancel: false,
  151. confirmText: "重新下单",
  152. confirmColor: "#999",
  153. success: function (res) {
  154. if (res.confirm) {
  155. }
  156. }
  157. });
  158. },
  159. //确认支付
  160. submitPay(){
  161. if(this.countdownStr == ''){
  162. this.showPrompt()
  163. return
  164. }
  165. // #ifdef APP-PLUS
  166. uni.requestPayment({
  167. provider: this.payType,
  168. orderInfo: 'orderInfo', //微信、支付宝订单数据
  169. success: function (res) {
  170. console.log('success:' + JSON.stringify(res));
  171. },
  172. fail: function (err) {
  173. console.log('fail:' + JSON.stringify(err));
  174. }
  175. });
  176. //#endif
  177. // #ifdef MP-WEIXIN
  178. //微信小程序
  179. uni.requestPayment({
  180. provider: 'wxpay',
  181. timeStamp: String(Date.now()),
  182. nonceStr: 'A1B2C3D4E5',
  183. package: 'prepay_id=wx20180101abcdefg',
  184. signType: 'MD5',
  185. paySign: '',
  186. success: function (res) {
  187. console.log('success:' + JSON.stringify(res));
  188. },
  189. fail: function (err) {
  190. console.log('fail:' + JSON.stringify(err));
  191. }
  192. });
  193. // #endif
  194. }
  195. }
  196. }
  197. </script>
  198. <style lang="scss">
  199. page{
  200. background-color: #f1f1f1;
  201. }
  202. .pt-8{
  203. margin-top: 8px;
  204. }
  205. .pt-4{
  206. margin-top: 4px;
  207. }
  208. .flex-rl{
  209. display: flex;
  210. flex-direction: row;
  211. justify-content: space-between;
  212. }
  213. .head{
  214. display: flex;
  215. flex-direction: column;
  216. justify-content: center;
  217. padding: 30px 15px;
  218. .row{
  219. display: flex;
  220. flex-direction: row;
  221. justify-content: center;
  222. font-size: 12px;
  223. color: #888;
  224. .fh{
  225. font-size: 16px;
  226. font-weight: bold;
  227. color: #000;
  228. }
  229. .txt1{
  230. font-size: 34px;
  231. font-weight: bold;
  232. color: #000;
  233. }
  234. [class*="hxicon-"]{
  235. position: relative;
  236. top: 3px;
  237. margin-left: 3px;
  238. }
  239. }
  240. .pricebox{
  241. display: flex;
  242. flex-direction: row;
  243. align-items: baseline;
  244. }
  245. }
  246. .container{
  247. margin: 15px;
  248. border-radius: 10px;
  249. background-color: #fff;
  250. overflow: hidden;
  251. padding: 0 8px 0 14px;
  252. .list-box{
  253. display: flex;
  254. flex-direction: column;
  255. .list-item{
  256. display: flex;
  257. flex-direction: row;
  258. align-items: center;
  259. height: 50px;
  260. .left{
  261. display: flex;
  262. flex-direction: row;
  263. align-items: center;
  264. .iconbox{
  265. display: flex;
  266. flex-direction: row;
  267. justify-content: center;
  268. align-items: center;
  269. height: 24px;
  270. width: 24px;
  271. border-radius: 4px;
  272. [class*="hxicon-"]{
  273. font-size: 22px;
  274. color: #fff;
  275. }
  276. }
  277. }
  278. .right{
  279. display: flex;
  280. flex-direction: row;
  281. align-items: center;
  282. flex: 1;
  283. height: 100%;
  284. .tit-box{
  285. flex: 1;
  286. .tit{
  287. font-size: 16px;
  288. color: #333;
  289. margin-left: 6px;
  290. }
  291. }
  292. }
  293. }
  294. }
  295. }
  296. .btn{
  297. position: fixed;
  298. display: flex;
  299. flex-direction: row;
  300. justify-content: center;
  301. align-items: center;
  302. border-radius: 10px;
  303. overflow: hidden;
  304. bottom: 15px;
  305. left: 15px;
  306. right: 15px;
  307. height: 45px;
  308. font-size: 16px;
  309. font-weight: bold;
  310. color: #333;
  311. background: linear-gradient(45deg, #ffd900, #ffc107);
  312. }
  313. </style>