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. _this.loading = true
  81. },
  82. });
  83. },
  84. methods: {
  85. pay(){
  86. let _this = this
  87. if(_this.data.openid && _this.data.openid != 'null' ){
  88. if(_this.data.userId){//app用户充值
  89. //console.log("app用户充值")
  90. requestGet("dxtop/staff/one",
  91. {
  92. "id":_this.data.userId,
  93. },
  94. ).then(res =>{
  95. if(res[1].data.data){
  96. requestPost("dxtop/order/callUnifiedPay",
  97. {
  98. "money": Number(_this.data.money).toFixed(2),
  99. "topPayType": "W06",
  100. "payType": "2",
  101. "channelId":_this.data.channelId,
  102. "userId":res[1].data.data.sid,
  103. "scene":_this.data.scene,
  104. "openId":_this.data.openid,
  105. }
  106. ).then(res2 => {
  107. if(res2[1].data?.status == "ERROR"){
  108. if(res2[1].data?.code == 500){
  109. if(res2[1].data.msg == "acct参数错误"){
  110. Toast("华为、Android10系统,需要开启微信的“浮窗”和“允许在其他上层应用上打开”这两个权限")
  111. }else{
  112. Toast(res2[1].data.msg)
  113. }
  114. }else{
  115. Toast(res2[1].data.msg)
  116. }
  117. }else{
  118. if(res2[1].data){
  119. let data = JSON.parse(res2[1].data.data)
  120. uni.requestPayment({
  121. timeStamp: data.timeStamp,
  122. nonceStr: data.nonceStr,
  123. package: data.package,
  124. signType: data.signType,
  125. paySign: data.paySign,
  126. success: function (res3) {
  127. //console.log('success:' + JSON.stringify(res));
  128. uni.redirectTo({
  129. url: `../over/index`
  130. });
  131. },
  132. fail: function (err) {
  133. //console.log('fail:' + JSON.stringify(err));
  134. }
  135. });
  136. }
  137. }
  138. }).catch(err =>{
  139. })
  140. }else{
  141. Toast("该用户未暂未录入充值系统...")
  142. }
  143. })
  144. }else{
  145. Toast("请使用'中国东信'APP途径进行充值")
  146. }
  147. }else{
  148. //console.log("去授权页",JSON.stringify(_this.data))
  149. uni.redirectTo({
  150. url: `../login/index?params=${JSON.stringify(this.data)}`
  151. });
  152. }
  153. }
  154. },
  155. onShow(options){
  156. }
  157. }
  158. </script>
  159. <style lang="scss" scoped>
  160. .mianBox{
  161. height: 100%;
  162. width: 100%;
  163. color: #000;
  164. box-sizing: border-box;
  165. background-color: #F2F6FC;
  166. position: fixed;
  167. .contentBox{
  168. width: 100%;
  169. height: auto;
  170. padding: 15px 20px;
  171. box-sizing: border-box;
  172. overflow: hidden;
  173. .logo{
  174. /deep/ .van-image{
  175. margin:0 auto;
  176. display: block;
  177. }
  178. }
  179. .introduce{
  180. text-align: center;
  181. color: #000;
  182. display: block;
  183. /deep/ .van-col{
  184. font-size: 20;
  185. margin-top:20px;
  186. letter-spacing: 2px;
  187. }
  188. }
  189. .money{
  190. text-align: center;
  191. color: #000;
  192. /deep/ .van-col{
  193. font-size: 30px;
  194. margin-top: 10px;
  195. font-weight: 700;
  196. }
  197. }
  198. .order_money{
  199. text-align: center;
  200. color: #ccc;
  201. display: block;
  202. /deep/ .van-col{
  203. font-size: 20;
  204. margin-top:10px;
  205. letter-spacing: 2px;
  206. }
  207. }
  208. /deep/ .van-button{
  209. border-radius: 6px;
  210. width: 100% !important;
  211. margin-top:25px;
  212. letter-spacing: 2px;
  213. font-size: 18px;
  214. height: 50px;
  215. }
  216. .order_wrap{
  217. width:95%;
  218. padding:10px 20px 20px 20px;
  219. box-sizing: border-box;
  220. width:95%;
  221. margin:20px 2.5%;
  222. background-color: #fff;
  223. border-radius: 6px;
  224. box-shadow: 0 2px 12px 0 #ccc;
  225. display: block;
  226. /deep/ .van-col{
  227. font-size: 16px;
  228. color:#ccc;
  229. margin-top:10px;
  230. display: block;
  231. }
  232. /deep/ .left{
  233. text-align: left;
  234. }
  235. /deep/ .right{
  236. text-align: right;
  237. }
  238. }
  239. .pay_wrap{
  240. width:95%;
  241. margin:70px 2.5% 0;
  242. .pay{
  243. height: 50px;
  244. font-size: 18px;
  245. border-radius: 10px;
  246. margin-top:40px;
  247. }
  248. }
  249. }
  250. }
  251. .pay{
  252. background:#F22E3C;
  253. color:#fff;
  254. }
  255. </style>