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

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