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

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