index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <div class="app-content">
  3. <block v-if="option.pageStatus == 'recharge'">
  4. <div class="tabs-wrap">充值</div>
  5. </block>
  6. <block v-else>
  7. <app-tabs :tabs="tabs" :currentTab="tabIndex" :isFixed="true" :borderLeft="true" @change="tabChange" itemWidth="50%" />
  8. </block>
  9. <!-- 直接付款 -->
  10. <block v-if="tabIndex == 0">
  11. <div class="logo-wrap">
  12. <div class="logo-img">
  13. <img :src="`${constant.imgUrl}/retail/user/attr-default.png`" alt mode="widthFix" />
  14. </div>
  15. <div class="app-size-30">{{ shopUser.userName }}</div>
  16. </div>
  17. <div class="pay-input-wrap">
  18. <pay-input-module :focus="inpFocus" :num="amount" @focusFn="focusFn" @blurFn="blurFn" @clickKey="clickKeyFn" />
  19. <div class="balance">
  20. <span>账户余额 ¥</span>
  21. <span class="app-size-30">{{ shopUser.userAsset.balance }}</span>
  22. </div>
  23. <!-- 按钮 -->
  24. <div class="btn-wrap">
  25. <button class="button-com red" @click="balancePayFn">余额支付</button>
  26. <button class="button-com green" @click="wexinPayFn">微信支付</button>
  27. </div>
  28. </div>
  29. </block>
  30. <!-- 我要配送 -->
  31. <block v-else>
  32. <app-delivery-module ref="appDelivery" />
  33. </block>
  34. <!-- <button @click="_pay">提交</button> -->
  35. <!-- 支付密码弹窗 -->
  36. <modal-module :show="passwordModal" @cancel="modalCancel" @click="passwordModalClick" :maskClosable="false" title="支付密码" padding="30rpx 30rpx">
  37. <template v-slot:content>
  38. <div class="app-modal-input-wrap">
  39. <div class="inp-list-line">
  40. <!-- <div class="line-label">支付密码</div> -->
  41. <div class="line-input">
  42. <input type="password" v-model="modalForm.payPassword" :adjust-position="false" class="inp-input" />
  43. </div>
  44. </div>
  45. </div>
  46. </template>
  47. </modal-module>
  48. </div>
  49. </template>
  50. <script>
  51. import { mapGetters } from 'vuex'
  52. import AppTabs from '@/components/plugin/tabs'
  53. import PayInputModule from './components/pay-input'
  54. import AppDeliveryModule from '@/components/app-delivery'
  55. // import { getMiniAppUrl } from '@/utils/common'
  56. import wexinPay from '@/utils/pay/wxPay'
  57. import ModalModule from '@/components/plugin/modal'
  58. // api
  59. import { fastPay } from '@/api/pay'
  60. import { recharge } from '@/api/member'
  61. import { getShopUser } from '@/utils/auth'
  62. export default {
  63. name: 'pay',
  64. components: {
  65. AppTabs,
  66. PayInputModule,
  67. AppDeliveryModule,
  68. ModalModule
  69. },
  70. data() {
  71. return {
  72. constant: this.$constant,
  73. inpFocus: false,
  74. // tab
  75. tabIndex: 0,
  76. tabs: [
  77. {
  78. name: '直接付款'
  79. },
  80. {
  81. name: '我要配送'
  82. }
  83. ],
  84. // 初始form
  85. amount: '',
  86. form: {
  87. payWay: 0 // 0微信 1支付宝 2余额
  88. },
  89. // 支付相关 ============
  90. passwordModal: false,
  91. modalForm: {
  92. payPassword: ''
  93. },
  94. appendFrm: {
  95. anonymity: '0', // 是否匿名 0不 1要
  96. sendDistance: '', // 配送距离,根据腾讯js进行计算
  97. // goodsId: '', // 【商城下单特有字段】商品id
  98. // goodsStyleId: '', // 【商城下单特有字段】商品款式id
  99. // goodsNum: '', // 【商城下单特有字段】商品数量
  100. // couponId: '0', // 优惠券id,默认0没有使用优惠券
  101. receiveLat: '', // 收花人纬度
  102. receiveLong: '' // 收花人经度
  103. }
  104. }
  105. },
  106. computed: {
  107. ...mapGetters({ shopUser: 'getShopUser' })
  108. },
  109. onLoad(option) {
  110. // this.option = this.$util.isEmpty(option) || {
  111. // account: 12358,
  112. // shopId: 15680
  113. // }
  114. this.init()
  115. },
  116. methods: {
  117. init() {
  118. // this.$util.getCheckLogin().then(res => {})
  119. getShopUser()
  120. },
  121. _pay() {
  122. if (!this.amount) {
  123. this.$msg('请先输入金额!')
  124. return false
  125. }
  126. let params = {}
  127. let host = null
  128. if (this.option.pageStatus == 'recharge') {
  129. params = {
  130. amount: this.amount
  131. }
  132. host = recharge
  133. } else {
  134. params = {
  135. needSend: this.tabIndex == 0 ? '1' : '0',
  136. prePrice: this.amount
  137. // sourceType: 1,
  138. // shopId: 15680
  139. }
  140. host = fastPay
  141. }
  142. host(params).then(res => {
  143. wexinPay(res.data, this.paySuccess, this.payFail)
  144. // window.location.href = res.data.pay_button.mweb_url
  145. })
  146. },
  147. // tab切换
  148. tabChange(e) {
  149. this.tabIndex = e.index
  150. },
  151. // 点击输入框
  152. focusFn() {
  153. this.inpFocus = true
  154. },
  155. // 失焦
  156. blurFn() {
  157. this.inpFocus = false
  158. },
  159. // 点击键盘
  160. clickKeyFn(val) {
  161. this.amount = val
  162. },
  163. // 微信支付
  164. wexinPayFn() {
  165. this.form.payWay = 0
  166. this._pay()
  167. },
  168. // 余额支付
  169. balancePayFn() {
  170. this.form.payWay = 2
  171. this.passwordModal = true
  172. },
  173. passwordModalClick(e) {
  174. if (e.index === 0) {
  175. this.modalCancel()
  176. } else {
  177. this._pay()
  178. }
  179. },
  180. modalCancel() {
  181. this.passwordModal = false
  182. this.modalForm.payPassword = ''
  183. },
  184. // 支付成功
  185. paySuccess() {
  186. alert('支付成功!')
  187. this.$util.pageTo({
  188. url: '/pages/callback/index',
  189. type: 2,
  190. query: {
  191. pagestatus: 3
  192. // orderSn: this.option.orderSn,
  193. // payDiscountPrice: res.data.discountAmount
  194. }
  195. })
  196. },
  197. payFail() {
  198. alert('支付失败!')
  199. }
  200. }
  201. }
  202. </script>
  203. <style lang="scss">
  204. .app-content {
  205. min-height: 0;
  206. padding-top: 100px;
  207. // padding-bottom: 120px;
  208. }
  209. .tabs-wrap {
  210. position: fixed;
  211. top: 0;
  212. width: 100%;
  213. height: 80px;
  214. line-height: 80px;
  215. text-align: center;
  216. background-color: #fff;
  217. font-size: 30px;
  218. box-shadow: 4px 4px 10px #eee;
  219. }
  220. .logo-wrap {
  221. padding-top: 70px;
  222. padding-bottom: 60px;
  223. text-align: center;
  224. .logo-img {
  225. width: 120px;
  226. margin: 0 auto 20px;
  227. }
  228. }
  229. .pay-input-wrap {
  230. background-color: #fff;
  231. border-top-left-radius: 20px;
  232. border-top-right-radius: 20px;
  233. padding: 50px 80px 28px;
  234. .balance {
  235. margin-top: 30px;
  236. color: $fontColor2;
  237. }
  238. .btn-wrap {
  239. width: 100%;
  240. margin-top: 64px;
  241. .button-com {
  242. display: block;
  243. margin-bottom: 20px;
  244. padding-top: 30px;
  245. padding-bottom: 30px;
  246. }
  247. }
  248. }
  249. </style>