index.vue 6.4 KB

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