index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <div class="mianBox">
  3. <van-row class="contentBox" v-if="loading">
  4. <van-row>
  5. <van-col span="24" class="logo"><van-image width="75" height="75" :src="require('../img/logo.png')" /></van-col>
  6. <van-col span="24" class="introduce">中国东信智慧园区平台</van-col>
  7. <van-col span="24" class="money">{{data.money}}</van-col>
  8. <van-col span="24" class="order_money">订单金额(元)</van-col>
  9. </van-row>
  10. <div class="pay_wrap">
  11. <van-button class="pay" color="#F22E3C" @tap="pay">支付</van-button>
  12. <button class="pay" open-type="launchApp" app-parameter="appData" @error="launchAppError" v-if="data.userId">返回APP</button>
  13. <!-- <button class="pay" open-type="launchApp" app-parameter="appData" @error="launchAppError" >返回APP<navigator open-type="exit" target="miniProgram" style="margin:30px 0;display: block;">退出程序</navigator></button> -->
  14. </div>
  15. <van-toast id="van-toast" />
  16. <!-- <van-overlay :show="show" @click="show = false" /> -->
  17. </van-row>
  18. </div>
  19. </template>
  20. <script>
  21. import Toast from '../../wxcomponents/vant/weapp/dist/toast/toast';
  22. import { requestPost, requestGet } from '@/utils/user.js';
  23. export default {
  24. data() {
  25. return {
  26. loading:false,
  27. data:{
  28. money:undefined,
  29. openid:null,
  30. app:false,
  31. },
  32. appData:{
  33. errCOde:0,
  34. errStr:null,
  35. extMsg:"未支付",
  36. extraData:"未支付",
  37. openid:null,
  38. transaction:null,
  39. type:"WXLaunchMiniProgramReq.Resp"
  40. }
  41. }
  42. },
  43. onLoad(options) {
  44. //console.log(options)
  45. let _this = this
  46. const data = JSON.parse(options.params)
  47. _this.data = data
  48. uni.getStorage({
  49. key: 'openid',
  50. success: function (res) {
  51. _this.appData.openid = _this.data.openid
  52. if(data.scene){
  53. if(data.scene == "3"){
  54. //console.log("app进入 -->支付页")
  55. _this.data={
  56. money:Number(data.money).toFixed(2),
  57. channelId:data.channelId,
  58. userId:data.userId,
  59. scene:data.scene,
  60. openid:res.data,
  61. app:false,
  62. }
  63. }
  64. }else{
  65. //console.log("微信小程序历史记录进入 -->支付页")
  66. _this.data={
  67. money:data.money,
  68. scene:'2',
  69. channelId:'',
  70. userId:null,
  71. openid:data.openid,
  72. app:false,
  73. }
  74. }
  75. _this.loading = true
  76. _this.data.app = false
  77. _this.pay()
  78. },
  79. fail: function (res) {
  80. },
  81. });
  82. },
  83. methods: {
  84. pay(){
  85. let _this = this
  86. if(_this.data.openid && _this.data.openid != 'null' ){
  87. if(_this.data.userId){//app用户充值
  88. //console.log("app用户充值")
  89. requestGet("dxtop/staff/one",
  90. {
  91. "id":_this.data.userId,
  92. },
  93. ).then(res =>{
  94. if(res[1].data.data){
  95. requestPost("dxtop/order/callUnifiedPay",
  96. {
  97. "money": Number(_this.data.money).toFixed(2),
  98. "topPayType": "W06",
  99. "payType": "2",
  100. "channelId":_this.data.channelId,
  101. "userId":res[1].data.data.sid,
  102. "scene":_this.data.scene,
  103. "openId":_this.data.openid,
  104. }
  105. ).then(res2 => {
  106. if(res2[1].data?.status == "ERROR"){
  107. if(res2[1].data?.code == 500){
  108. if(res2[1].data.msg == "acct参数错误"){
  109. Toast("华为、Android10系统,需要开启微信的“浮窗”和“允许在其他上层应用上打开”这两个权限")
  110. }else{
  111. Toast(res2[1].data.msg)
  112. }
  113. }else{
  114. Toast(res2[1].data.msg)
  115. }
  116. }else{
  117. if(res2[1].data){
  118. let data = JSON.parse(res2[1].data.data)
  119. uni.requestPayment({
  120. timeStamp: data.timeStamp,
  121. nonceStr: data.nonceStr,
  122. package: data.package,
  123. signType: data.signType,
  124. paySign: data.paySign,
  125. success: function (res3) {
  126. //console.log('success:' + JSON.stringify(res));
  127. uni.redirectTo({
  128. url: `../over/index`
  129. });
  130. },
  131. fail: function (err) {
  132. //console.log('fail:' + JSON.stringify(err));
  133. }
  134. });
  135. }
  136. }
  137. }).catch(err =>{
  138. })
  139. }else{
  140. Toast("该用户未暂未录入充值系统...")
  141. }
  142. })
  143. }else{
  144. Toast("请使用'中国东信'APP途径进行充值")
  145. }
  146. }else{
  147. //console.log("去授权页",JSON.stringify(_this.data))
  148. uni.redirectTo({
  149. url: `../login/index?params=${JSON.stringify(this.data)}`
  150. });
  151. }
  152. }
  153. },
  154. onShow(options){
  155. }
  156. }
  157. </script>
  158. <style lang="scss" scoped>
  159. .mianBox{
  160. height: 100%;
  161. width: 100%;
  162. color: #000;
  163. box-sizing: border-box;
  164. background-color: #F2F6FC;
  165. position: fixed;
  166. .contentBox{
  167. width: 100%;
  168. height: auto;
  169. padding: 15px 20px;
  170. box-sizing: border-box;
  171. overflow: hidden;
  172. .logo{
  173. /deep/ .van-image{
  174. margin:0 auto;
  175. display: block;
  176. }
  177. }
  178. .introduce{
  179. text-align: center;
  180. color: #000;
  181. display: block;
  182. /deep/ .van-col{
  183. font-size: 20;
  184. margin-top:20px;
  185. letter-spacing: 2px;
  186. }
  187. }
  188. .money{
  189. text-align: center;
  190. color: #000;
  191. /deep/ .van-col{
  192. font-size: 30px;
  193. margin-top: 10px;
  194. font-weight: 700;
  195. }
  196. }
  197. .order_money{
  198. text-align: center;
  199. color: #ccc;
  200. display: block;
  201. /deep/ .van-col{
  202. font-size: 20;
  203. margin-top:10px;
  204. letter-spacing: 2px;
  205. }
  206. }
  207. /deep/ .van-button{
  208. border-radius: 6px;
  209. width: 100% !important;
  210. margin-top:25px;
  211. letter-spacing: 2px;
  212. font-size: 18px;
  213. height: 50px;
  214. }
  215. .order_wrap{
  216. width:95%;
  217. padding:10px 20px 20px 20px;
  218. box-sizing: border-box;
  219. width:95%;
  220. margin:20px 2.5%;
  221. background-color: #fff;
  222. border-radius: 6px;
  223. box-shadow: 0 2px 12px 0 #ccc;
  224. display: block;
  225. /deep/ .van-col{
  226. font-size: 16px;
  227. color:#ccc;
  228. margin-top:10px;
  229. display: block;
  230. }
  231. /deep/ .left{
  232. text-align: left;
  233. }
  234. /deep/ .right{
  235. text-align: right;
  236. }
  237. }
  238. .pay_wrap{
  239. width:95%;
  240. margin:70px 2.5% 0;
  241. .pay{
  242. height: 50px;
  243. font-size: 18px;
  244. border-radius: 10px;
  245. margin-top:40px;
  246. }
  247. }
  248. }
  249. }
  250. .pay{
  251. background:#F22E3C;
  252. color:#fff;
  253. }
  254. </style>