index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <template>
  2. <div class="app-content pay-wrap">
  3. <!-- 我要配送 -->
  4. <!-- <block v-else> -->
  5. <div class="delivery-wrap" v-if="!$util.isEmpty(orderShop)">
  6. <div class="shop-logo-wrap" v-if="!$util.isEmpty(orderShop)">
  7. <div class="logo-img">
  8. <img :src="orderShop.merchant.smallLogoUrl | default_img" alt mode="widthFix" />
  9. </div>
  10. </div>
  11. <div class="module-com pay-input-wrap">
  12. <pay-input-module :focus="inpFocus" :num="amount" @focusFn="focusFn" @blurFn="blurFn" @clickKey="clickKeyFn" />
  13. <div class="balance" v-if="!$util.isEmpty(shopUser) && shopUser.userAsset.balance && shopUser.userAsset.balance != '0.00'">
  14. <span>账户余额 ¥</span>
  15. <span class="app-size-30">{{ shopUser.userAsset.balance }}</span>
  16. </div>
  17. </div>
  18. <!-- 查看更多 -->
  19. <div class="view-more" :class="{'open' : tabIndex == 1}" @click="tabIndex = tabIndex == 0 ? 1 : 0">
  20. <button type="primary" size="mini" plain="true">{{ tabIndex == 0 ? '点我填写收花人' : '收起' }}</button>
  21. </div>
  22. <!-- 查看更多 -->
  23. <block v-if="tabIndex == 1">
  24. <app-delivery-module ref="appDelivery" :anonymous="true" />
  25. </block>
  26. <!-- 可选优惠 -->
  27. <div class="module-com discount-wrap" v-if="!$util.isEmpty(discountArr)">
  28. <div class="module-tit">可选优惠</div>
  29. <div class="module-det">
  30. <app-coupon-sel ref="couponSel" :price="amount" :discountArr="['member', 'coupon']" />
  31. </div>
  32. </div>
  33. <!-- 按钮 -->
  34. <div class="btn-wrap">
  35. <button v-if="!$util.isEmpty(shopUser) && shopUser.userAsset.balance && shopUser.userAsset.balance != '0.00'" class="button-com red" @click="balancePayFn">余额支付</button>
  36. <button class="button-com green" v-if="isWxMiniapp()" @click="wexinPayFn">微信支付</button>
  37. <button class="button-com red" v-else @click="aliPayFn">支付宝支付</button>
  38. </div>
  39. </div>
  40. <!-- </block> -->
  41. <!-- 支付密码弹窗 -->
  42. <modal-module :show="passwordModal" @cancel="modalCancel" @click="passwordModalClick" :maskClosable="false" title="支付密码" padding="30rpx 30rpx">
  43. <template v-slot:content>
  44. <div class="app-modal-input-wrap">
  45. <div class="inp-list-line">
  46. <!-- <div class="line-label">支付密码</div> -->
  47. <div class="line-input">
  48. <input type="password" v-model="modalForm.payPassword" :adjust-position="false" class="inp-input" />
  49. </div>
  50. </div>
  51. </div>
  52. </template>
  53. </modal-module>
  54. <!-- 阿里支付 -->
  55. <div class="al-pay" v-html="aliPayHtml" ref="alipayWap"></div>
  56. <!-- 未设置支付密码弹窗 -->
  57. <alert-module :show="setPassModal" btnText="去设置" btnColor="#FF2842" padding="66rpx 24rpx 66rpx 24rpx" @click="hideAlert">
  58. <div class="go-login-module">
  59. <div>暂未设置密码,去设置密码!</div>
  60. </div>
  61. </alert-module>
  62. </div>
  63. </template>
  64. <script>
  65. import { mapGetters } from 'vuex'
  66. import AppTabs from '@/components/plugin/tabs'
  67. import PayInputModule from './components/pay-input'
  68. import AppDeliveryModule from '@/components/app-delivery'
  69. import wexinPay from '@/utils/pay/wxPay'
  70. import ModalModule from '@/components/plugin/modal'
  71. import AppCouponSel from '@/components/app-coupon-sel'
  72. import AlertModule from '@/components/plugin/alert'
  73. import { isWxMiniapp } from '@/utils/common'
  74. import { share } from '@/mixins'
  75. import { fastPay } from '@/api/pay'
  76. import { recharge } from '@/api/member'
  77. import { getOrderShop } from '@/utils/config'
  78. export default {
  79. name: 'pay',
  80. components: {
  81. AppTabs,
  82. PayInputModule,
  83. AppDeliveryModule,
  84. ModalModule,
  85. AppCouponSel,
  86. AlertModule
  87. },
  88. mixins: [share],
  89. data() {
  90. return {
  91. constant: this.$constant,
  92. inpFocus: false,
  93. tabIndex: 0,
  94. tabs: [
  95. {
  96. name: '直接付款'
  97. },
  98. {
  99. name: '我要配送'
  100. }
  101. ],
  102. amount: '',
  103. form: {
  104. payWay: 0 // 0微信 1支付宝 2余额
  105. },
  106. aliPayHtml: '',
  107. passwordModal: false,
  108. modalForm: {
  109. payPassword: ''
  110. },
  111. appendFrm: {
  112. sendDistance: '', // 配送距离,根据腾讯js进行计算
  113. receiveLat: '', // 收花人纬度
  114. receiveLong: '' // 收花人经度
  115. },
  116. payCallData: null,
  117. // 优惠折扣
  118. discountArr: false,
  119. // 未设置密码
  120. setPassModal: false
  121. }
  122. },
  123. computed: {
  124. ...mapGetters({ orderShop: 'getOrderShop' }),
  125. ...mapGetters({ shopUser: 'getShopUser' })
  126. },
  127. onLoad(option) {
  128. // #ifdef H5
  129. this.specialInit()
  130. // #endif
  131. },
  132. mounted() {},
  133. methods: {
  134. isWxMiniapp(){
  135. return isWxMiniapp()
  136. },
  137. init(){
  138. this.specialInit();
  139. },
  140. specialInit() {
  141. // #ifdef H5
  142. // 微信二次分享
  143. let href = window.location.href
  144. if (href.indexOf('from=singlemessage') > 0) {
  145. location.href = `${this.$constant.formal}/#/pages/pay/index${this.$util.parse(this.option)}`
  146. return false
  147. }
  148. // #endif
  149. if (this.option.pageType) {
  150. this.tabIndex = parseInt(this.option.pageType)
  151. }
  152. getOrderShop(true).then(res => {
  153. this.inpFocus = true
  154. uni.setNavigationBarTitle({
  155. title: `您正在向【${res.shop.merchantName} ${res.shop.shopName}】付款`
  156. })
  157. this.$refs.couponSel._getUserDiscount().then(status => {
  158. this.discountArr = status
  159. })
  160. // 设置分享
  161. let shareParams = {
  162. title: `点我付款`, // 分享标题
  163. desc: '享随机优惠,最高20元', // 分享内容
  164. imgUrl: `${this.$constant.imgUrl}/retail/pay.jpg`,
  165. // #ifdef H5
  166. pagePath: `${this.$constant.formal}/#/pages/pay/index?account=${res.shop.id}&store=0&sourceType=3`,
  167. // #endif
  168. // #ifndef H5
  169. pagePath: `/pages/pay/index?account=${res.shop.id}&store=0&sourceType=3`
  170. // #endif
  171. }
  172. // this.jweixinFn(shareParams)
  173. })
  174. },
  175. _pay() {
  176. if (!this.amount) {
  177. this.$msg('请先输入金额!')
  178. return false
  179. }
  180. let params = {}
  181. let host = null
  182. if (this.option.pageStatus == 'recharge') {
  183. params = {
  184. amount: this.amount
  185. }
  186. host = recharge
  187. } else {
  188. params = {
  189. needSend: this.tabIndex == 0 ? '0' : '1',
  190. prePrice: this.amount,
  191. payWay: this.form.payWay,
  192. payPassword:this.modalForm.payPassword
  193. }
  194. if (this.tabIndex == 1) {
  195. let deliveryForm = this.$refs.appDelivery.form ? this.$refs.appDelivery.form : {}
  196. let deliveryRegion = this.$refs.appDelivery.region ? this.$refs.appDelivery.region : {}
  197. params = {
  198. ...params,
  199. ...deliveryForm,
  200. ...deliveryRegion
  201. }
  202. }
  203. if (this.option.store) {
  204. params.store = this.option.store
  205. }
  206. if (this.option.sourceType) {
  207. params.sourceType = this.option.sourceType
  208. }
  209. if (!this.$util.isEmpty(this.discountArr)) {
  210. params.couponId = this.$refs.couponSel.couponId
  211. }
  212. host = fastPay
  213. }
  214. host(params).then(res => {
  215. this.payCallData = res.data
  216. //错误返回判断
  217. if(res.code == 0){
  218. this.$msg(res.msg)
  219. return false
  220. }
  221. if (this.form.payWay == 0) {
  222. wexinPay(res.data, this.paySuccess, this.payFail)
  223. } else if (this.form.payWay == 1) {
  224. this.aliPayHtml = res
  225. this.$nextTick(() => {
  226. this.$refs.alipayWap.children[0].submit()
  227. })
  228. } else {
  229. this.paySuccess()
  230. }
  231. })
  232. },
  233. // tab切换
  234. tabChange(e) {
  235. this.tabIndex = e.index
  236. this.inpFocus = true
  237. },
  238. // 点击输入框
  239. focusFn() {
  240. this.inpFocus = true
  241. },
  242. // 失焦
  243. blurFn() {
  244. this.inpFocus = false
  245. },
  246. // 点击键盘
  247. clickKeyFn(val) {
  248. this.amount = val
  249. },
  250. // 支付宝支付
  251. aliPayFn() {
  252. this.form.payWay = 1
  253. this._pay()
  254. },
  255. // 微信支付
  256. wexinPayFn() {
  257. this.form.payWay = 0
  258. this._pay()
  259. },
  260. // 暂未设置密码
  261. hideAlert() {
  262. this.$util.pageTo('/pages/user/password')
  263. },
  264. // 余额支付
  265. balancePayFn() {
  266. if (!this.$util.isEmpty(this.shopUser) && this.shopUser.hasPayPwd == 0) {
  267. this.setPassModal = true
  268. } else {
  269. this.form.payWay = 2
  270. this.passwordModal = true
  271. }
  272. },
  273. passwordModalClick(e) {
  274. if (e.index === 0) {
  275. this.modalCancel()
  276. } else {
  277. this._pay()
  278. }
  279. },
  280. modalCancel() {
  281. this.passwordModal = false
  282. this.modalForm.payPassword = ''
  283. },
  284. // 支付成功
  285. paySuccess() {
  286. this.$util.pageTo({
  287. url: '/pages/callback/index',
  288. type: 2,
  289. query: {
  290. pageStatus: 3,
  291. orderSn:this.payCallData.orderSn,
  292. totalPrice:this.payCallData.totalPrice,
  293. id: this.payCallData.orderId,
  294. ...this.params
  295. }
  296. })
  297. },
  298. payFail() {
  299. }
  300. }
  301. }
  302. </script>
  303. <style lang="scss">
  304. .app-content {
  305. min-height: calc(100vh - 20px);
  306. padding-top: 20px;
  307. }
  308. .tabs-wrap {
  309. position: fixed;
  310. top: 0;
  311. width: 100%;
  312. height: 80px;
  313. line-height: 80px;
  314. text-align: center;
  315. background-color: #fff;
  316. font-size: 30px;
  317. box-shadow: 4px 4px 10px #eee;
  318. }
  319. .pay-wrap {
  320. .logo-wrap {
  321. padding-top: 70px;
  322. padding-bottom: 60px;
  323. text-align: center;
  324. .logo-img {
  325. width: 120px;
  326. margin: 0 auto 20px;
  327. border-radius: 50%;
  328. img {
  329. border-radius: 50%;
  330. }
  331. }
  332. }
  333. .pay-input-wrap {
  334. background-color: #fff;
  335. border-top-left-radius: 20px;
  336. border-top-right-radius: 20px;
  337. padding: 50px 80px 28px;
  338. margin-bottom: 0 !important;
  339. .balance {
  340. margin-top: 30px;
  341. color: $fontColor2;
  342. }
  343. .btn-wrap {
  344. width: 100%;
  345. margin-top: 64px;
  346. .button-com {
  347. display: block;
  348. margin-bottom: 20px;
  349. padding-top: 30px;
  350. padding-bottom: 30px;
  351. }
  352. }
  353. }
  354. }
  355. // 我要配送
  356. .delivery-wrap {
  357. .module-com {
  358. margin-bottom: 20px;
  359. background-color: #fff;
  360. .module-tit {
  361. padding: 20px 18px;
  362. font-size: 28px;
  363. font-weight: 600;
  364. border-bottom: 1px solid $borderColor;
  365. }
  366. .module-det {
  367. padding: 0 30px;
  368. }
  369. }
  370. // 金额
  371. .pay-input-wrap {
  372. padding: 50px 36px 38px;
  373. .balance {
  374. margin-top: 30px;
  375. color: $fontColor2;
  376. }
  377. }
  378. .shop-logo-wrap {
  379. padding-bottom: 20px;
  380. @include disFlex(center, center);
  381. .logo-img {
  382. width: 120px;
  383. border-radius: 50%;
  384. margin: 10px auto;
  385. // margin-right: 20px;
  386. img {
  387. border-radius: 50%;
  388. }
  389. }
  390. }
  391. // 可选优惠
  392. .discount-wrap {
  393. .module-det {
  394. padding-top: 20px;
  395. padding-bottom: 20px;
  396. }
  397. }
  398. // 匿名派送
  399. .none-name-delivery {
  400. // padding-left: 30px;
  401. padding: 26px 30px;
  402. // margin-top: 40px;
  403. margin-bottom: 20px;
  404. background-color: #fff;
  405. .none-name-text {
  406. margin-left: 14px;
  407. color: $fontColor2;
  408. }
  409. }
  410. // 按钮
  411. .btn-wrap {
  412. width: calc(100% - 60px);
  413. margin: 64px auto 0;
  414. padding-bottom: 20px;
  415. .button-com {
  416. display: block;
  417. margin-bottom: 20px;
  418. padding-top: 30px;
  419. padding-bottom: 30px;
  420. &:last-child {
  421. margin-bottom: 0;
  422. }
  423. }
  424. }
  425. // 查看更多
  426. .view-more {
  427. width: 100%;
  428. // padding-top: 10px;
  429. padding-bottom: 20px;
  430. margin-bottom: 20px;
  431. font-size: 28px;
  432. @include disFlex(center, center);
  433. background-color: #fff;
  434. color: #3385ff;
  435. .view-more-text {
  436. margin-right: 14px;
  437. }
  438. i {
  439. font-size: 30px;
  440. font-weight: 600;
  441. }
  442. &.open {
  443. i {
  444. transform: rotate(180deg);
  445. }
  446. }
  447. }
  448. }
  449. </style>