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

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