index.vue 6.6 KB

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