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

392 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
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.clickContinue = true;
  128. this.confirm();
  129. },
  130. // 支付
  131. confirm() {
  132. if (this.clickContinue == true) {
  133. this.clickContinue = false;
  134. if (this.is_date_finish) return this.$msg('订单超时未支付');
  135. let channel = '';
  136. this.pay_list.map(item => {
  137. if (item.checked) {
  138. channel = item.type;
  139. }
  140. })
  141. if (channel == 'balance' && !this.user_pw) {
  142. this.show_pw = true;
  143. return;
  144. }
  145. this.getOpenid().then(res => {
  146. var data = {
  147. channel: 'wx_lite',
  148. openid: res,
  149. order_no: this.order_no,
  150. balance: 0
  151. };
  152. if (channel == 'balance') {
  153. data.pay_pwd = this.user_pw;
  154. data.balance = Number(this.amount);
  155. data.channel = 'wx_lite';
  156. }
  157. this.$http.post({
  158. api: `api/shopping/order/charge`,
  159. data: data,
  160. header: {
  161. Authorization: this.token
  162. }
  163. }).then(res => {
  164. res = res.data;
  165. if (res.status) {
  166. // this.formId = e.detail.formId || '';
  167. if (res.data.name == 'balance') {
  168. this.balanceCharge();
  169. } else {
  170. this.newcharge(true, res.data.charge);
  171. }
  172. } else {
  173. this.newcharge(false, res.message);
  174. this.show_pw = false;
  175. }
  176. this.clickContinue = true;
  177. })
  178. }).catch(() => {
  179. this.clickContinue = true;
  180. this.show_pw = false;
  181. this.setData({
  182. loading: false
  183. });
  184. wx.showModal({
  185. content: '支付失败',
  186. showCancel: false
  187. });
  188. });
  189. }
  190. },
  191. // 获取openid
  192. getOpenid() {
  193. return new Promise((resolve, reject) => {
  194. wx.login({
  195. success: res => {
  196. this.$http.get({
  197. api: `api/oauth/miniprogram/openid`,
  198. data: {
  199. code: res.code
  200. }
  201. }).then(res => {
  202. res = res.data;
  203. resolve(res.data.openid);
  204. }).catch(() => {
  205. reject('获取openid失败');
  206. });
  207. },
  208. fail: () => {
  209. wx.showModal({
  210. content: "接口请求失败",
  211. showCancel: false
  212. });
  213. }
  214. });
  215. });
  216. },
  217. // 新版支付
  218. newcharge(success, charge) {
  219. if (success) {
  220. var that = this;
  221. if (charge.pay_scene == 'test') {
  222. wx.showModal({
  223. content: '不支持模拟支付',
  224. showCancel: false
  225. });
  226. this.setData({
  227. loading: false
  228. });
  229. } else {
  230. wx.requestPayment({
  231. "timeStamp": charge.credential.wechat.timeStamp,
  232. "nonceStr": charge.credential.wechat.nonceStr,
  233. "package": charge.credential.wechat.package,
  234. "signType": charge.credential.wechat.signType,
  235. "paySign": charge.credential.wechat.paySign,
  236. success: res => {
  237. if (res.errMsg == 'requestPayment:ok') {
  238. this.setData({
  239. loading: false
  240. });
  241. // wx.redirectTo({
  242. // 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 支付测试使用
  243. // });
  244. uni.redirectTo({
  245. url: '/pages/aboutpay/paystate?payState=1&amount=' + that
  246. .amount
  247. })
  248. } else {
  249. wx.showModal({
  250. content: '调用支付失败!',
  251. showCancel: false
  252. });
  253. }
  254. },
  255. fail: err => {
  256. this.setData({
  257. loading: false
  258. });
  259. if (err.errMsg == 'requestPayment:fail cancel') {
  260. // wx.redirectTo({
  261. // url: `/pages/order/detail/detail?no=${that.order_no}`
  262. // });
  263. uni.redirectTo({
  264. url: '/pages/order/index/onlineorder'
  265. })
  266. } else {
  267. wx.showModal({
  268. content: '调用支付失败!',
  269. showCancel: false
  270. });
  271. }
  272. }
  273. });
  274. }
  275. } else {
  276. this.setData({
  277. loading: false
  278. });
  279. wx.showModal({
  280. content: charge || '请求支付失败,请重试!',
  281. showCancel: false
  282. });
  283. this.user_pw = '';
  284. }
  285. },
  286. // 纯余额支付
  287. balanceCharge() {
  288. this.setData({
  289. loading: false
  290. });
  291. // wx.redirectTo({
  292. // url: `/pages/store/success/success?order_no=${this.order_no}&amount=${this.amount}&channel=${this.channel}&formId=${this.formId}`
  293. // });
  294. uni.redirectTo({
  295. url: '/pages/aboutpay/paystate?payState=1&amount=' + this.amount
  296. })
  297. },
  298. setData: function(obj) {
  299. let that = this;
  300. let keys = [];
  301. let val, data;
  302. Object.keys(obj).forEach(function(key) {
  303. keys = key.split('.');
  304. val = obj[key];
  305. data = that.$data;
  306. keys.forEach(function(key2, index) {
  307. if (index + 1 == keys.length) {
  308. that.$set(data, key2, val);
  309. } else {
  310. if (!data[key2]) {
  311. that.$set(data, key2, {});
  312. }
  313. }
  314. data = data[key2];
  315. });
  316. });
  317. }
  318. }
  319. }
  320. </script>
  321. <style>
  322. page {
  323. background-color: #F8F8F8;
  324. }
  325. </style>
  326. <style lang="scss" scoped="scoped">
  327. .content {
  328. padding: 30rpx 32rpx;
  329. width: 750rpx;
  330. height: max-content;
  331. box-sizing: border-box;
  332. .card {
  333. width: 100%;
  334. height: max-content;
  335. padding: 30rpx 40rpx;
  336. background-color: #FFFFFF;
  337. border-radius: 20rpx;
  338. &:nth-child(n+2) {
  339. margin-top: 30rpx;
  340. }
  341. .symbol {
  342. color: #15716E;
  343. font-size: 32rpx;
  344. }
  345. .price {
  346. font-size: 72rpx;
  347. color: #15716E;
  348. font-weight: bold;
  349. }
  350. .tips {
  351. font-size: 24rpx;
  352. color: #FF9D9D;
  353. display: flex;
  354. align-items: center;
  355. }
  356. }
  357. }
  358. .fixed-agreement {
  359. position: fixed;
  360. bottom: 5vh;
  361. font-size: 28rpx;
  362. color: #15716E;
  363. left: calc(50% - 84rpx);
  364. width: 168rpx;
  365. }
  366. .fixed-btn {
  367. position: fixed;
  368. bottom: 10vh;
  369. left: calc(50% - 275rpx);
  370. width: 550rpx;
  371. height: 100rpx;
  372. background-color: #15716E;
  373. color: #FFFFFF;
  374. text-align: center;
  375. line-height: 100rpx;
  376. font-size: 32rpx;
  377. border-radius: 50rpx;
  378. }
  379. </style>