pay.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. <template>
  2. <view class="pay">
  3. <view class="balance">
  4. <view class="title">
  5. 账户余额(元)
  6. </view>
  7. <view class="money">
  8. {{dBalance}}
  9. </view>
  10. <view class="histroy" @click="goBill">
  11. 余额记录
  12. </view>
  13. </view>
  14. <view class="select_money">
  15. <view class="title">
  16. 充值金额
  17. </view>
  18. <view class="option_money">
  19. <view class="value" :class="currentIndex == index?'current':''" v-for="(item,index) in moneyList" :key="index"
  20. @click="selectMoney(item,index)">
  21. ¥{{item.value}}
  22. </view>
  23. </view>
  24. <view class="for_js">
  25. <text>选择为商户充值</text>
  26. <!-- <span class="select" @click="popup_show = true">去选择 <image src="../../static/identify/more.png" mode=""></image> -->
  27. <view class="select" @click="popup_show = true">
  28. <view class="right" >
  29. <!-- <image :src="$globalData.publicUrl+jsHead" mode="" v-if="jsHead !== ''"></image> -->
  30. {{jsName}}
  31. <image src="../../static/identify/more.png" mode=""></image>
  32. </view>
  33. </view>
  34. </span>
  35. </view>
  36. <view class="title_text">
  37. <span style="color:#2F3437;font-size: 28rpx;">温馨提示:</span>
  38. <span>1 预存的金额和赠送的优惠券均不可提现,转移,转赠</span>
  39. <span>2 预存余额使用范围,只限本平合项目及交通费支付</span>
  40. <!-- 3 优惠券可与预存余额同时使用<br>
  41. 4 每个订单优惠券每次仅使用一张<br>
  42. 5 项目回购与优惠券不能同时使用<br>
  43. 6 赠送优惠券金额均为50元一张<br> -->
  44. </view>
  45. </view>
  46. <!-- <view class="select_money">
  47. <view class="title">
  48. <span>充值对象</span>
  49. <view class="technician" @click="popup_show = true">
  50. <view class="right" >
  51. <image src="../../static/identify/add1.png" mode="" v-if="jsHead == ''"></image>
  52. <image :src="$globalData.publicUrl+jsHead" mode="" v-else></image>
  53. {{jsName}}
  54. <image src="../../static/identify/more.png" mode=""></image>
  55. </view>
  56. </view>
  57. </view>
  58. </view> -->
  59. <view class="pay_btn">
  60. <view class="sub_money">
  61. 充值金额:<text v-if="form.dMoney !== ''">{{form.dMoney}}元</text>
  62. </view>
  63. <view class="btn" @click="submit">
  64. 确认充值
  65. </view>
  66. </view>
  67. <view class="select_technician" v-if="popup_show" @click="cut" >
  68. <view class="select_technician_content" @click.stop>
  69. <view class="head">
  70. <image src="../../static/identify/head.png" mode=""></image>
  71. </view>
  72. <view class="title">
  73. 请选择一位商户充值
  74. </view>
  75. <view class="technician_select">
  76. <view class="address">
  77. <view class="left" @click="show = true">
  78. <image src="../../static/identify/my3.png" mode=""></image>
  79. {{city}}
  80. </view>
  81. <u-select v-model="show" :list="cityList" @confirm="confirm"></u-select>
  82. <view class="right">
  83. <u-search placeholder="请输入商户昵称" v-model="search" :clearabled="true" :show-action="false" @search="getJsList"></u-search>
  84. </view>
  85. </view>
  86. </view>
  87. <view class="technician_box" v-if="jsList.length > 0">
  88. <view class="technician" :class="nowIndex == index?'option_technician':''" v-for="(item,index) in jsList"
  89. :key="index" @click="selectJs(item,index)">
  90. <view class="technician_left">
  91. <image :src="$globalData.publicUrl + item.cPortrait" mode=""></image>
  92. </view>
  93. <view class="technician_center">
  94. <view class="name">
  95. {{item.cNickName}}
  96. </view>
  97. <view class="technician_data">
  98. <!-- <view class="technician_mark">
  99. <image src="../../static/identify/star.png" mode=""></image>
  100. {{item.nStar}}
  101. </view> -->
  102. <view class="technician_num">
  103. 已服务{{item.nNum}}单
  104. </view>
  105. </view>
  106. </view>
  107. <view class="round">
  108. <!-- <span class="real" v-if="nowIndex == index"></span> -->
  109. <!-- <span class="empty" v-else></span> -->
  110. <!-- <image src="../../static/identify/head.png" mode=""></image> -->
  111. <image src="../../static/identify/round.png" mode="" v-if="nowIndex !== index"></image>
  112. <image src="../../static/other/select_round.png" mode="" v-else></image>
  113. </view>
  114. </view>
  115. </view>
  116. <view class="technician_box" v-else>
  117. <view class="null">
  118. <image src="https://www.mescroll.com/img/mescroll-empty.png" mode=""></image>
  119. </view>
  120. </view>
  121. <view class="btn_box">
  122. <!-- <view class="btn" @click="popup_show = false">
  123. 取 消
  124. </view> -->
  125. <view class="btn yes" @click="popup_show = false">
  126. 确 定
  127. </view>
  128. </view>
  129. </view>
  130. </view>
  131. <!-- <view class="pays">
  132. <input type="number" decimal="true" v-model="form.dMoney" placeholder="自定义充值金额(¥)" />
  133. <view>
  134. <view class="paybtn" @click="submit">充值</view>
  135. </view>
  136. <view class="log" @click="goBill">
  137. 账单
  138. </view>
  139. </view> -->
  140. </view>
  141. </template>
  142. <script>
  143. import wx from 'weixin-js-sdk'
  144. import {
  145. pay,
  146. getSignature,
  147. getCityList,
  148. engineer,
  149. getInfo
  150. } from '../../api/index.js'
  151. export default {
  152. data() {
  153. return {
  154. form: {
  155. dMoney: '',
  156. cOpenId: uni.getStorageSync('wx_copenid'),
  157. jsId: ''
  158. },
  159. dBalance: 0.00,
  160. wxconfig: {},
  161. jsId: '',
  162. show: false,
  163. cityList: [],
  164. city: '城市',
  165. jsList: [],
  166. jsName: '去选择',
  167. moneyList: [{
  168. value: 200
  169. },
  170. {
  171. value: 500
  172. },
  173. {
  174. value: 2000
  175. },
  176. {
  177. value: 5000
  178. }
  179. ],
  180. currentIndex: null,
  181. search: '',
  182. popup_show: false,
  183. nowIndex: null,
  184. jsHead: ''
  185. }
  186. },
  187. onLoad() {
  188. wx.checkJsApi({
  189. jsApiList: ['chooseImage'], // 需要检测的JS接口列表,所有JS接口列表见附录2,
  190. success: function(res) {
  191. // 以键值对的形式返回,可用的api值true,不可用为false
  192. // 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
  193. }
  194. });
  195. },
  196. methods: {
  197. cut(){
  198. this.popup_show = false
  199. },
  200. //账户余额
  201. getinfo() {
  202. getInfo().then(res => {
  203. if (res.data.code == 200) {
  204. this.isLogin = true
  205. this.info = res.data.data,
  206. this.dBalance = res.data.data.dBalance.toFixed(2)
  207. }
  208. })
  209. },
  210. //选择商户
  211. selectJs(item, index) {
  212. this.nowIndex = index
  213. this.form.jsId = item.id
  214. this.jsHead = item.cPortrait
  215. this.jsName = item.cName
  216. },
  217. //选择部门
  218. select_address() {
  219. this.show = true
  220. },
  221. selectMoney(item, index) {
  222. this.currentIndex = index
  223. this.form.dMoney = item.value
  224. },
  225. getDeptList() {
  226. let data = {}
  227. // data.city = uni.getStorageSync('selectCity')
  228. data.city = '太原'
  229. data.search = this.search
  230. getCityList().then(res => {
  231. res.data.data.forEach(item => {
  232. this.cityList.push({
  233. label: item.deptName,
  234. value: item.deptId
  235. })
  236. })
  237. })
  238. },
  239. getJsList() {
  240. let data = {}
  241. data.city = this.city
  242. engineer(data).then(res => {
  243. this.jsList = res.data.data.records
  244. })
  245. },
  246. confirm(e) {
  247. this.city = e[0].label
  248. this.getJsList()
  249. },
  250. goBill() {
  251. uni.navigateTo({
  252. url: '/pages/my/bill'
  253. })
  254. },
  255. submit() {
  256. if (this.form.dMoney == 0) {
  257. uni.showToast({
  258. title: '请选择充值金额',
  259. icon: 'none'
  260. })
  261. return
  262. }
  263. let url = 'https://test.baoxianzhanggui.com/fragrance/'
  264. pay(this.form).then(res => {
  265. let payConfig = JSON.parse(res.data.data)
  266. getSignature(url).then(res => {
  267. this.wxconfig = res.data
  268. wx.config({
  269. beta: true,
  270. debug: false,
  271. appId: this.wxconfig.appId, // 公众号ID
  272. // appId: uni.getAppBaseInfo().host.appId, // 公众号ID
  273. timestamp: this.wxconfig.timestamp, // 时间戳,自1970年以来的秒数
  274. nonceStr: this.wxconfig.nonceStr, // 随机串
  275. signature: this.wxconfig.sign, // 微信签名方式
  276. jsApiList: ['getBrandWCPayRequest']
  277. });
  278. var vm = this
  279. wx.invoke(
  280. 'getBrandWCPayRequest', { // 下面参数内容都是后台返回的
  281. 'appId': payConfig.appid, // 公众号名称,由商户传入
  282. 'timeStamp': payConfig.timeStamp, // 时间戳
  283. 'nonceStr': payConfig.nonceStr, // 随机串
  284. 'package': payConfig.package, // 预支付id
  285. 'signType': payConfig.signType, // 微信签名方式
  286. 'paySign': payConfig.paySign, // 微信签名
  287. },
  288. function(res) {
  289. // 使用以上方式判断前端返回,微信团队郑重提示:res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
  290. // JSON.stringify(res);
  291. if (res.err_msg == "get_brand_wcpay_request:ok") {
  292. vm.$message.success(
  293. "支付成功") // 使用alert来弹窗 支付成功 是没有反应的。所以这里改为框架页面的弹窗就好了。注意必须要上这个微信浏览器内置事件外 转this指向才能弹窗
  294. // vm.isDisabledSubmitBtn = false;
  295. vm.getInfo()
  296. } else if (res.err_msg == "get_brand_wcpay_request:cancel") {
  297. uni.showToast({
  298. title: '已取消支付',
  299. icon: 'none'
  300. })
  301. // alert('支付取消');
  302. // vm.isDisabledSubmitBtn = false;
  303. } else {
  304. alert('付款失败');
  305. // vm.isDisabledSubmitBtn = false;
  306. }
  307. })
  308. })
  309. })
  310. },
  311. },
  312. onShow() {
  313. this.getinfo()
  314. this.getDeptList()
  315. }
  316. }
  317. </script>
  318. <style lang="scss" scoped>
  319. .pay {
  320. width: 100%;
  321. height: 100%;
  322. // padding: 32rpx;
  323. box-sizing: border-box;
  324. background: #F8F8F8;
  325. // position: relative;
  326. .balance {
  327. width: 100%;
  328. height: 256rpx;
  329. background: linear-gradient(90deg, #2ADDD2 0%, #22BEB5 100%);
  330. // background: linear-gradient(to right, #35c99d, #27aea7);
  331. padding: 32rpx;
  332. box-sizing: border-box;
  333. color: #fff;
  334. position: relative;
  335. z-index: 1;
  336. .title {
  337. font-size: 32rpx;
  338. color: #FFFFFF;
  339. margin-bottom: 20rpx;
  340. }
  341. .money {
  342. font-size: 56rpx;
  343. color: #FFFFFF;
  344. line-height: 66rpx;
  345. margin-bottom: 20rpx;
  346. }
  347. .histroy {
  348. width: 160rpx;
  349. height: 56rpx;
  350. background: #FFFFFF;
  351. border-radius: 12rpx 0px 0px 12rpx;
  352. font-size: 28rpx;
  353. color: #22BEB5;
  354. box-sizing: border-box;
  355. text-align: center;
  356. line-height: 56rpx;
  357. position: absolute;
  358. top: 76rpx;
  359. right: 0;
  360. // transform: translateY(-50%);
  361. }
  362. }
  363. .select_money {
  364. width: 100%;
  365. background-color: #fff;
  366. padding: 48rpx 32rpx;
  367. box-sizing: border-box;
  368. border-radius: 48rpx;
  369. margin-top: -50rpx;
  370. z-index: 9;
  371. position: absolute;
  372. .title_text {
  373. font-size: 28rpx;
  374. span {
  375. font-size: 26rpx;
  376. color: #666666;
  377. line-height: 30rpx;
  378. display: block;
  379. margin-top: 12rpx;
  380. }
  381. }
  382. .title {
  383. line-height: 45rpx;
  384. .right {
  385. display: flex;
  386. align-items: center;
  387. float: right;
  388. margin-top: -7%;
  389. image {
  390. width: 40rpx;
  391. height: 40rpx;
  392. margin: 0px 10rpx;
  393. }
  394. }
  395. }
  396. .option_money {
  397. display: flex;
  398. justify-content: space-around;
  399. flex-wrap: wrap;
  400. // .title_text {
  401. // font-size: 28rpx;
  402. // }
  403. .value {
  404. // width: 45%;
  405. // height: 100rpx;
  406. // border-radius: 10px;
  407. // background-color: rgb(238,251,251);
  408. width: 321rpx;
  409. height: 108rpx;
  410. background: #FFFFFF;
  411. border-radius: 8rpx;
  412. border: 2rpx solid #EEEEEE;
  413. margin: 12rpx;
  414. display: flex;
  415. justify-content: center;
  416. align-items: center;
  417. font-weight: 700;
  418. box-sizing: border-box;
  419. font-size: 40rpx;
  420. color: #232A24;
  421. line-height: 47rpx;
  422. }
  423. .current {
  424. border: 1px solid #22BFB5;
  425. background: #F2FBFB;
  426. color: #22BFB5;
  427. }
  428. }
  429. .for_js {
  430. display: flex;
  431. justify-content: space-between;
  432. font-size: 30rpx;
  433. color: #2F3437;
  434. // line-height: 35rpx;
  435. margin-top: 22rpx;
  436. margin-bottom: 34rpx;
  437. font-weight: 600;
  438. .select {
  439. font-size: 30rpx;
  440. font-weight: 400;
  441. color: #666666;
  442. display: flex;
  443. align-items: center;
  444. image {
  445. width: 32rpx;
  446. height: 32rpx;
  447. }
  448. .right{
  449. display: flex;
  450. align-items: center;
  451. }
  452. }
  453. }
  454. }
  455. .select_technician {
  456. width: 100%;
  457. height: 100%;
  458. position: absolute;
  459. top: 0;
  460. left: 0;
  461. background: rgba(0, 0, 0, 0.5);
  462. display: flex;
  463. justify-content: center;
  464. align-items: center;
  465. z-index: 999;
  466. .back{
  467. width: 100%;
  468. // height: ;
  469. }
  470. .select_technician_content {
  471. width: 630rpx;
  472. height: 798rpx;
  473. background-color: #fff;
  474. border-radius: 24rpx;
  475. padding: 24rpx 32rpx;
  476. box-sizing: border-box;
  477. display: flex;
  478. flex-direction: column;
  479. position: relative;
  480. z-index: 9999;
  481. .head {
  482. position: absolute;
  483. top: 0;
  484. left: 50%;
  485. transform: translate(-50%,-24rpx);
  486. image {
  487. width: 200rpx;
  488. height: 58rpx;
  489. }
  490. }
  491. .title {
  492. width: 100%;
  493. height: 40rpx;
  494. text-align: center;
  495. font-size: 28rpx;
  496. margin-top: 10rpx;
  497. margin-bottom: 32rpx;
  498. }
  499. .technician_select {
  500. height:64rpx;
  501. margin-bottom: 40rpx;
  502. .address {
  503. height: 100%;
  504. display: flex;
  505. align-items: center;
  506. justify-content: space-between;
  507. .left {
  508. // width: 50%;
  509. display: flex;
  510. align-items: center;
  511. margin-right: 32rpx;
  512. image {
  513. width: 40rpx;
  514. height: 40rpx;
  515. margin-right: 5px;
  516. }
  517. }
  518. .right {
  519. flex: 1;
  520. // width: 100%;
  521. }
  522. }
  523. }
  524. .technician_box {
  525. width: 100%;
  526. flex: 1;
  527. overflow-y: auto;
  528. .null {
  529. width: 100%;
  530. height: 100%;
  531. image {
  532. width: 100%;
  533. // margin-top: 50px;
  534. }
  535. }
  536. .technician {
  537. width: 100%;
  538. height: 80rpx;
  539. border-radius: 10px;
  540. margin-bottom: 10px;
  541. // padding: 0px 10px;
  542. box-sizing: border-box;
  543. display: flex;
  544. justify-content: space-between;
  545. align-items: center;
  546. .technician_left {
  547. width:80rpx;
  548. height: 80rpx;
  549. image {
  550. width: 100%;
  551. height: 100%;
  552. }
  553. }
  554. .technician_center {
  555. width: 60%;
  556. height: 100%;
  557. display: flex;
  558. flex-direction: column;
  559. .name {
  560. font-size: 28rpx;
  561. // margin-top: 8rpx;
  562. margin-bottom: 10rpx;
  563. }
  564. .technician_data {
  565. // height: 100%;
  566. display: flex;
  567. align-items: center;
  568. justify-content: space-between;
  569. .technician_mark {
  570. display: flex;
  571. align-items: center;
  572. image {
  573. width: 20px;
  574. height: 20px;
  575. }
  576. }
  577. .technician_num {
  578. font-size: 26rpx;
  579. color: #333333;
  580. }
  581. }
  582. }
  583. .round {
  584. width: 36rpx;
  585. height: 36rpx;
  586. image{
  587. width: 36rpx;
  588. height: 36rpx;
  589. }
  590. }
  591. }
  592. }
  593. .btn_box {
  594. height: 92rpx;
  595. display: flex;
  596. justify-content: space-around;
  597. align-items: center;
  598. .btn {
  599. width: 510rpx;
  600. height: 68rpx;
  601. text-align: center;
  602. line-height: 68rpx;
  603. border: 1px solid #ccc;
  604. border-radius: 44rpx;
  605. }
  606. .yes {
  607. background: linear-gradient(to right, #35c99d, #27aea7);
  608. color: #fff;
  609. }
  610. }
  611. }
  612. }
  613. .pay_btn {
  614. width: 100%;
  615. height: 124rpx;
  616. background: #FFFFFF;
  617. border-radius: 10px;
  618. position: fixed;
  619. bottom: 0;
  620. left: 0;
  621. padding: 24rpx 32rpx;
  622. box-sizing: border-box;
  623. display: flex;
  624. align-items: center;
  625. justify-content: space-between;
  626. .sub_money {
  627. font-size: 28rpx;
  628. color: #2F3437;
  629. display: flex;
  630. align-items: center;
  631. text {
  632. font-size: 36rpx;
  633. color: #F53E54;
  634. }
  635. }
  636. .btn {
  637. width: 288rpx;
  638. height: 76rpx;
  639. background: linear-gradient(90deg, #1AD7CE 0%, #21C9C1 100%);
  640. border-radius: 106rpx;
  641. font-size: 32rpx;
  642. color: #FFFFFF;
  643. display: flex;
  644. align-items: center;
  645. justify-content: center;
  646. }
  647. }
  648. }
  649. </style>