金诚优选前端代码
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.

371 lines
9.3 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <template>
  2. <view>
  3. <lf-nav title="支付收银台" :showIcon="true" bgColor="#fff"></lf-nav>
  4. <view class="content">
  5. <view class="card lf-flex-column lf-row-center">
  6. <view class="lf-font-28 lf-color-222">需要支付</view>
  7. <view class="lf-m-t-10 lf-m-b-10">
  8. <text class="symbol"></text>
  9. <text class="price">{{ amount }}</text>
  10. </view>
  11. <view class="tips">
  12. <view>剩余支付时间</view>
  13. <view>
  14. <!-- <countdown-timer :time="time" :autoStart="true" @finish="dateFinish">
  15. <template v-slot="{minute, second}">
  16. <view class="lf-flex">
  17. <view>{{ minute >= 10 ? minute : "0" + minute }}</view>
  18. <view>:</view>
  19. <view>{{ second >= 10 ? second : "0" + second }}</view>
  20. </view>
  21. </template>
  22. </countdown-timer> -->
  23. <countdown-time minute="5" second="0" :showDay="false" :showHour="false">
  24. </countdown-time>
  25. </view>
  26. </view>
  27. </view>
  28. <view class="card lf-row-between" v-for="(item, index) in pay_list" :key="index">
  29. <view>
  30. <text class="lf-iconfont" :class="item.icon"></text>
  31. <text class="lf-m-l-10 lf-font-28 lf-color-222">{{ item.name }}</text>
  32. </view>
  33. <radio-group @change="checkChange($event, index)">
  34. <radio :checked="item.checked"></radio>
  35. </radio-group>
  36. </view>
  37. </view>
  38. <view class="fixed-btn" hover-class="lf-opacity" @click="confirm">立即支付</view>
  39. <view class="fixed-agreement">购买须知</view>
  40. <lf-pay-password v-if="show_pw" @comfirm="payComfirm" title="请输入支付密码"></lf-pay-password>
  41. </view>
  42. </template>
  43. <script>
  44. import countdownTime from '@/components/uni-countdown/uni-countdown.vue';
  45. import lfPayPassword from '@/components/lf-payPassword/lf-payPassword.vue'
  46. export default {
  47. components: {
  48. countdownTime,
  49. lfPayPassword
  50. },
  51. data(){
  52. return {
  53. pay_list: [{
  54. name: '余额支付',
  55. icon: 'icon--',
  56. type: 'balance',
  57. checked: false
  58. },{
  59. name: '微信支付',
  60. icon: 'icon--1',
  61. type: 'wx_lite',
  62. checked: true
  63. }],
  64. time: new Date('2021/09/8 14:15:00').getTime() - new Date('2021/09/8 14:10:00').getTime(),
  65. is_date_finish: false,
  66. amount: '',
  67. order_no: '',
  68. token: '',
  69. balance_sum: 0,
  70. show_pw: false,
  71. user_pw: ''
  72. }
  73. },
  74. onLoad(options){
  75. this.token = this.$cookieStorage.get('user_token');
  76. this.amount = options.amount;
  77. this.order_no = options.order_no;
  78. this.getBalanceSum();
  79. },
  80. methods: {
  81. // 获取余额
  82. getBalanceSum(){
  83. this.$http.get({
  84. api: 'api/users/balance/sum',
  85. header: {
  86. Authorization: this.token
  87. }
  88. }).then(res => {
  89. this.balance_sum = res.data.data.sum;
  90. })
  91. },
  92. // 改变支付方式
  93. checkChange(event, current){
  94. let list = this.pay_list.map((item, index) => {
  95. if(index == current){
  96. item.checked = true;
  97. }else{
  98. item.checked = false;
  99. }
  100. return item;
  101. })
  102. this.pay_list = list;
  103. },
  104. // 倒计时结束
  105. dateFinish(){
  106. console.log("倒计时结束");
  107. this.is_date_finish = true;
  108. this.$msg('订单超时', {icon: 'error'}).then(() => {
  109. this.$toBack();
  110. })
  111. },
  112. // 支付密码输入完成
  113. payComfirm(event){
  114. this.user_pw = event;
  115. this.show_pw = false;
  116. this.confirm();
  117. },
  118. // 支付
  119. confirm(){
  120. if(this.is_date_finish) return this.$msg('订单超时未支付');
  121. let channel = '';
  122. this.pay_list.map(item => {
  123. if(item.checked){
  124. channel = item.type;
  125. }
  126. })
  127. if(channel == 'balance' && !this.user_pw){
  128. this.show_pw = true;
  129. return;
  130. }
  131. this.getOpenid().then(res => {
  132. var data = {
  133. channel: 'wx_lite',
  134. openid: res,
  135. order_no: this.order_no,
  136. balance: 0
  137. };
  138. if(channel == 'balance'){
  139. data.pay_pwd = this.user_pw;
  140. data.balance = Number(this.amount);
  141. data.channel = 'wx_lite';
  142. }
  143. this.$http.post({
  144. api: `api/shopping/order/charge`,
  145. data: data,
  146. header: {
  147. Authorization: this.token
  148. }
  149. }).then(res => {
  150. console.log("-------------------", res)
  151. res = res.data;
  152. if (res.status) {
  153. // this.formId = e.detail.formId || '';
  154. if (res.data.name == 'balance') {
  155. this.balanceCharge();
  156. } else {
  157. this.newcharge(true, res.data.charge);
  158. }
  159. } else {
  160. this.newcharge(false, res.message);
  161. }
  162. })
  163. }).catch(() => {
  164. this.setData({
  165. loading: false
  166. });
  167. wx.showModal({
  168. content: '支付失败',
  169. showCancel: false
  170. });
  171. });
  172. },
  173. // 获取openid
  174. getOpenid() {
  175. return new Promise((resolve, reject) => {
  176. wx.login({
  177. success: res => {
  178. this.$http.get({
  179. api: `api/oauth/miniprogram/openid`,
  180. data: {
  181. code: res.code
  182. }
  183. }).then(res => {
  184. res = res.data;
  185. resolve(res.data.openid);
  186. }).catch(() => {
  187. reject('获取openid失败');
  188. });
  189. },
  190. fail: () => {
  191. wx.showModal({
  192. content: "接口请求失败",
  193. showCancel: false
  194. });
  195. }
  196. });
  197. });
  198. },
  199. // 新版支付
  200. newcharge(success, charge) {
  201. if (success) {
  202. var that = this;
  203. if (charge.pay_scene == 'test') {
  204. wx.showModal({
  205. content: '不支持模拟支付',
  206. showCancel: false
  207. });
  208. this.setData({
  209. loading: false
  210. });
  211. } else {
  212. wx.requestPayment({
  213. "timeStamp": charge.credential.wechat.timeStamp,
  214. "nonceStr": charge.credential.wechat.nonceStr,
  215. "package": charge.credential.wechat.package,
  216. "signType": charge.credential.wechat.signType,
  217. "paySign": charge.credential.wechat.paySign,
  218. success: res => {
  219. if (res.errMsg == 'requestPayment:ok') {
  220. this.setData({
  221. loading: false
  222. });
  223. // wx.redirectTo({
  224. // url: `/pages/store/success/success?order_no=${that.order_no}&amount=${that.amount}&channel=${that.channel}&formId=${this.formId}` //&charge_id=${charge.charge_id} charge_id 支付测试使用
  225. // });
  226. uni.redirectTo({
  227. url: '/pages/aboutpay/paystate?payState=1&amount='+ that.amount
  228. })
  229. } else {
  230. wx.showModal({
  231. content: '调用支付失败!',
  232. showCancel: false
  233. });
  234. }
  235. },
  236. fail: err => {
  237. this.setData({
  238. loading: false
  239. });
  240. if (err.errMsg == 'requestPayment:fail cancel') {
  241. // wx.redirectTo({
  242. // url: `/pages/order/detail/detail?no=${that.order_no}`
  243. // });
  244. uni.redirectTo({
  245. url: '/pages/order/index/onlineorder'
  246. })
  247. } else {
  248. wx.showModal({
  249. content: '调用支付失败!',
  250. showCancel: false
  251. });
  252. }
  253. }
  254. });
  255. }
  256. } else {
  257. this.setData({
  258. loading: false
  259. });
  260. wx.showModal({
  261. content: charge || '请求支付失败,请重试!',
  262. showCancel: false
  263. });
  264. this.user_pw = '';
  265. }
  266. },
  267. // 纯余额支付
  268. balanceCharge() {
  269. this.setData({
  270. loading: false
  271. });
  272. // wx.redirectTo({
  273. // url: `/pages/store/success/success?order_no=${this.order_no}&amount=${this.amount}&channel=${this.channel}&formId=${this.formId}`
  274. // });
  275. uni.redirectTo({
  276. url: '/pages/aboutpay/paystate?payState=1&amount='+ this.amount
  277. })
  278. },
  279. setData: function (obj) {
  280. let that = this;
  281. let keys = [];
  282. let val, data;
  283. Object.keys(obj).forEach(function (key) {
  284. keys = key.split('.');
  285. val = obj[key];
  286. data = that.$data;
  287. keys.forEach(function (key2, index) {
  288. if (index + 1 == keys.length) {
  289. that.$set(data, key2, val);
  290. } else {
  291. if (!data[key2]) {
  292. that.$set(data, key2, {});
  293. }
  294. }
  295. data = data[key2];
  296. });
  297. });
  298. }
  299. }
  300. }
  301. </script>
  302. <style>
  303. page{
  304. background-color: #F8F8F8;
  305. }
  306. </style>
  307. <style lang="scss" scoped="scoped">
  308. .content{
  309. padding: 30rpx 32rpx;
  310. width: 750rpx;
  311. height: max-content;
  312. box-sizing: border-box;
  313. .card{
  314. width: 100%;
  315. height: max-content;
  316. padding: 30rpx 40rpx;
  317. background-color: #FFFFFF;
  318. border-radius: 20rpx;
  319. &:nth-child(n+2){
  320. margin-top: 30rpx;
  321. }
  322. .symbol{
  323. color: #15716E;
  324. font-size: 32rpx;
  325. }
  326. .price{
  327. font-size: 72rpx;
  328. color: #15716E;
  329. font-weight: bold;
  330. }
  331. .tips{
  332. font-size: 24rpx;
  333. color: #FF9D9D;
  334. display: flex;
  335. align-items: center;
  336. }
  337. }
  338. }
  339. .fixed-agreement {
  340. position: fixed;
  341. bottom: 5vh;
  342. font-size: 28rpx;
  343. color: #15716E;
  344. left: calc(50% - 84rpx);
  345. width: 168rpx;
  346. }
  347. .fixed-btn{
  348. position: fixed;
  349. bottom: 10vh;
  350. left: calc(50% - 275rpx);
  351. width: 550rpx;
  352. height: 100rpx;
  353. background-color: #15716E;
  354. color: #FFFFFF;
  355. text-align: center;
  356. line-height: 100rpx;
  357. font-size: 32rpx;
  358. border-radius: 50rpx;
  359. }
  360. </style>