index_20220609123920.vue 6.5 KB

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