You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

353 lines
8.6 KiB

6 months ago
  1. <template>
  2. <view class="app">
  3. <view class="price-box">
  4. <text>支付金额</text>
  5. <text class="price">{{paymoney|toFixed}}</text>
  6. <text v-if="isDefault.isopen&&dikmoney">使用{{usejfnum}}个积分抵扣{{dikmoney|toFixed}}</text>
  7. </view>
  8. <view class="pay-type-list">
  9. <view class="type-item b-b" @click="changePayType(1)">
  10. <text class="icon yticon icon-weixinzhifu"></text>
  11. <view class="con">
  12. <text class="tit">微信支付</text>
  13. <text>推荐使用微信支付</text>
  14. </view>
  15. <label class="radio">
  16. <radio value="1" color="#fa436a" :checked='payType == 1' />
  17. </radio>
  18. </label>
  19. </view>
  20. <view class="type-item" v-if="yue>0" @click="changePayType(2)">
  21. <text class="icon yticon icon-erjiye-yucunkuan"></text>
  22. <view class="con">
  23. <text class="tit">余额(优先)+微信</text>
  24. <text>可用余额 ¥{{yue}}</text>
  25. </view>
  26. <label class="radio">
  27. <radio value="2" color="#fa436a" :checked='payType == 2' />
  28. </radio>
  29. </label>
  30. </view>
  31. <view class="type-item" v-else>
  32. <text class="icon yticon icon-erjiye-yucunkuan"></text>
  33. <view class="con">
  34. <text class="tit">余额混合</text>
  35. <text>可用余额 ¥{{yue}}</text>
  36. </view>
  37. <label class="radio" style="color: #909399;">
  38. 余额不足
  39. </label>
  40. </view>
  41. <view class="type-item">
  42. <view class="icon yticon jifenicon">
  43. <image src="../../static/img/jificon.png"/>
  44. </view>
  45. <view class="con">
  46. <text class="tit">积分抵扣</text>
  47. <text v-if="jifen>lessjifen">
  48. 当前积分{{jifen}}
  49. <text class="moreuse" v-if="morejifen">,最多可使用{{morejifen}}</text>
  50. </text>
  51. <text v-else>当前积分{{jifen}}&nbsp;,{{lessjifen}}可用</text>
  52. </view>
  53. <view class="input switch" v-if="jifen>lessjifen">
  54. <switch color="#f06c7a" :checked="isDefault.isopen" @change="isDefaultChange" />
  55. </view>
  56. </view>
  57. </view>
  58. <view class="shuom">{{zfsmtext}}</view>
  59. <text class="mix-btn" @click="confirm">确认支付</text>
  60. <button style="color:#909399; background-color: white; height: 60rpx; width: 300rpx; text-align: center; font-size: 26rpx; border: 0px solid #ffffff;" plain="true" open-type="share">找人代付</button>
  61. </view>
  62. </template>
  63. <script>
  64. import {throttle} from '@/common/util';
  65. export default {
  66. data() {
  67. return {
  68. payType: 1,
  69. orderInfo: [],
  70. paymoney:0,
  71. dhid:0,
  72. yue:0,
  73. jifen:0,
  74. usejfnum:0,
  75. lessjifen:0,//积分起步数量
  76. morejifen:0,//最多可使用积分,0表示不限制
  77. dikmoney:0,
  78. isDefault:{isopen:false},
  79. zfsmtext:'支付方式优先级是积分抵扣 > 余额 > 微信'
  80. };
  81. },
  82. computed: {
  83. },
  84. onLoad(options) {
  85. this.paymoney=options.paymoney;
  86. this.dhid=options.dhid;
  87. if(options.df==1)
  88. {
  89. uni.login({
  90. success:function(e){
  91. t.daiflogin(e.code);
  92. }
  93. })
  94. }
  95. uni.getStorage({
  96. key:'paymentOrder',
  97. success: (e) => {
  98. //console.log(e,'值?')
  99. let paygoodlist= e.data;
  100. let len = paygoodlist.length;
  101. for(let i=0;i<len;i++){
  102. this.deleteGoods(paygoodlist[i].id)
  103. }
  104. }
  105. })
  106. },
  107. filters: {
  108. toFixed:function(x) {
  109. return parseFloat(x).toFixed(2);
  110. }
  111. },
  112. onShow(){
  113. let getuserinfo=uni.getStorageSync('userinfo');
  114. this.getuserinfo(getuserinfo.uid,getuserinfo.aid);
  115. this.baseinfo('zftip');
  116. },
  117. methods: {
  118. async daiflogin(code){
  119. let logininfo = await this.$api.login({action:'daiflogin',code:code});
  120. if(logininfo.data){
  121. uni.setStorage({
  122. key:'userinfo',
  123. data:logininfo.data,
  124. success: () => {
  125. }
  126. })
  127. }
  128. },
  129. //找人代付
  130. onShareAppMessage(res) {
  131. if (res.from === 'button') {// 来自页面内分享按钮
  132. console.log(res.target)
  133. }
  134. return {
  135. title: '朋友找您代付,需支付'+this.paymoney+'元!',
  136. path: '/pages/pay/pay?dhid='+this.dhid+'&paymoney='+this.paymoney+'&df=1'
  137. }
  138. },
  139. async baseinfo(key) {
  140. let reinfo=await this.$api.baseinfo({action:'baseinfo',key:key});
  141. this.zfsmtext=reinfo.data.info
  142. },
  143. async getuserinfo(uid,aid) {
  144. let reinfo=await this.$api.userinfo({action:'userinfo',uid:uid,dhid:this.dhid,aid:aid});
  145. this.yue=reinfo.data.yue;
  146. this.jifen=reinfo.data.jifen;
  147. this.dikmoney=reinfo.data.dikmoney;
  148. this.lessjifen=reinfo.data.lessjifen;
  149. this.morejifen=reinfo.data.morejifen;
  150. this.usejfnum=reinfo.data.usejfnum;
  151. this.paymoney=reinfo.data.paymoney
  152. },
  153. async wxpay(dhid,openid) {
  154. let getuserinfo=uni.getStorageSync('userinfo');
  155. let reinfo=await this.$api.wxpay({action:'wxpayall',aid:getuserinfo.aid,openid:openid,dhid:dhid,paytype:this.payType,isjifen:this.isDefault.isopen});
  156. //console.log(reinfo,'返回');
  157. if(reinfo.code==1){
  158. uni.requestPayment({
  159. provider: 'wxpay',
  160. timeStamp: reinfo.data.timeStamp,
  161. nonceStr: reinfo.data.nonceStr,
  162. package: reinfo.data.package,
  163. signType: 'MD5',
  164. paySign: reinfo.data.paySign,
  165. success: function (res) {
  166. //console.log('success:' + JSON.stringify(res));
  167. uni.redirectTo({
  168. url: '/pages/pay/paySuccess'
  169. })
  170. },
  171. fail: function (err) {
  172. console.log('fail:' + JSON.stringify(err));
  173. uni.showToast({
  174. title:'已放弃支付',icon:'none'
  175. })
  176. }
  177. });
  178. }else if(reinfo.code==2){
  179. uni.redirectTo({
  180. url: '/pages/pay/paySuccess'
  181. })
  182. }else{
  183. uni.showToast({
  184. title:reinfo.msg,icon:'none'
  185. })
  186. }
  187. },
  188. //选择支付方式
  189. changePayType(type) {
  190. this.payType = type;
  191. if(type==2){
  192. let t=this;
  193. uni.showModal({
  194. title: '支付说明',
  195. showCancel:false,
  196. confirmText:'明白了',
  197. content: t.zfsmtext,
  198. success: function (res) {}
  199. });
  200. }
  201. },
  202. //确认支付
  203. confirm: throttle( function() {
  204. let openid=uni.getStorageSync('userinfo');
  205. this.wxpay(this.dhid,openid['openid'])
  206. }),
  207. //删除本地购物车列表对应商品
  208. deleteGoods(id){
  209. let getcartlist=uni.getStorageSync('cartlist');
  210. let len = getcartlist.length;
  211. for(let i=0;i<len;i++){
  212. if(id==getcartlist[i].id){
  213. getcartlist.splice(i, 1);
  214. break;
  215. }
  216. }
  217. //更新本地储存
  218. uni.setStorageSync('cartlist',getcartlist);
  219. },
  220. isDefaultChange(e){
  221. let t=this;
  222. t.$set(this.isDefault,'isopen',e.detail.value)
  223. if(t.isDefault.isopen&&this.dikmoney<=0){
  224. uni.showModal({
  225. title: '提示',
  226. content: '当前积分不足',
  227. success: function (res) {
  228. if (res.confirm) {
  229. t.$set(t.isDefault,'isopen',false)
  230. //console.log('用户点击确定')
  231. } else if (res.cancel) {
  232. // 手动修改switch的状态,视图会同步更新
  233. t.$set(t.isDefault,'isopen',false)
  234. //console.log('用户点击取消');
  235. }
  236. }
  237. });
  238. }else{
  239. if(this.isDefault.isopen){
  240. this.paymoney-=parseFloat(this.dikmoney*100)/100;
  241. }else{
  242. this.paymoney+=parseFloat(this.dikmoney*100)/100;
  243. }
  244. }
  245. },
  246. }
  247. }
  248. </script>
  249. <style lang='scss'>
  250. .app {
  251. width: 100%;
  252. }
  253. .price-box {
  254. background-color: #fff;
  255. height: 265upx;
  256. display: flex;
  257. flex-direction: column;
  258. justify-content: center;
  259. align-items: center;
  260. font-size: 28upx;
  261. color: #909399;
  262. .price{
  263. font-size: 50upx;
  264. color: #303133;
  265. margin-top: 12upx;
  266. &:before{
  267. content: '¥';
  268. font-size: 40upx;
  269. }
  270. }
  271. }
  272. .pay-type-list {
  273. margin-top: 20upx;
  274. background-color: #fff;
  275. padding-left: 60upx;
  276. .type-item{
  277. height: 120upx;
  278. padding: 20upx 0;
  279. display: flex;
  280. justify-content: space-between;
  281. align-items: center;
  282. padding-right: 60upx;
  283. font-size: 30upx;
  284. position:relative;
  285. }
  286. .icon{
  287. width: 100upx;
  288. font-size: 52upx;
  289. }
  290. .jifenicon{
  291. image{
  292. width: 60upx;
  293. height: 60upx;
  294. }
  295. }
  296. .icon-erjiye-yucunkuan {
  297. color: #fe8e2e;
  298. }
  299. .icon-weixinzhifu {
  300. color: #36cb59;
  301. }
  302. .icon-alipay {
  303. color: #01aaef;
  304. }
  305. .tit{
  306. font-size: $font-lg;
  307. color: $font-color-dark;
  308. margin-bottom: 4upx;
  309. }
  310. .con{
  311. flex: 1;
  312. display: flex;
  313. flex-direction: column;
  314. font-size: $font-sm;
  315. color: $font-color-light;
  316. .moreuse{
  317. margin-left: 5upx;
  318. font-size: 24upx;
  319. color: #909399;
  320. }
  321. }
  322. }
  323. .mix-btn {
  324. display: flex;
  325. align-items: center;
  326. justify-content: center;
  327. width: 630upx;
  328. height: 80upx;
  329. margin: 50upx auto 30upx;
  330. font-size: $font-lg;
  331. color: #fff;
  332. background-color: $base-color;
  333. border-radius: 10upx;
  334. box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  335. }
  336. .shuom{
  337. text-align: center;
  338. font-size: 28upx;
  339. color: #DD524D;
  340. padding: 15upx;
  341. }
  342. </style>