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

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