handpos-client 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "handpos-client",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "手持POS",
5
5
  "main": "src/index.js",
6
6
  "directories": {
@@ -1,199 +1,233 @@
1
- <template>
2
- <div>
3
- <div class="mhead">
4
- <ul>
5
- <li>
6
- <text>垃圾费缴费</text>
7
- </li>
8
- </ul>
9
- </div>
10
- <div class="body">
11
- <div class="container contentpanel auto">
12
- <div class="row buypanel">
13
- <div class="buyform">
14
- <h3 style="color: red;">订单信息</h3>
15
- <div>
16
- <h4>缴费类型:垃圾费</h4>
17
- </div>
18
- <div>
19
- <h4>账期:{{garbageInfo.accountperiod}}</h4>
20
- </div>
21
- <div>
22
- <h4>支付金额:{{garbageInfo.money}} &nbsp;&nbsp;元</h4>
23
- </div>
24
- </div>
25
- <div class="horizontal" height="auto">
26
- <h3 style="color: red;">请选择支付方式</h3>
27
- <table width="60%" border="0" cellspacing="0" cellpadding="0" align="center">
28
- <tbody>
29
- <tr>
30
- <td align="center" v-if='payBtn1.show' class="col-xs-4 weixin">
31
- <div @click='pay("1")'>
32
- <img :src="btn1Path" alt=""/>
33
- </div>
34
- </td>
35
- <td align="center" v-if='payBtn2.show' class="col-xs-4 alipay" >
36
- <div @click='pay("2")'>
37
- <img :src="btn2Path " alt=""/>
38
- </div>
39
- </td>
40
- <td align="center" v-if='payBtn3.show' class="col-xs-4 unionpay">
41
- <div @click='pay("3")'>
42
- <img :src="btn3Path" alt=""/>
43
- </div>
44
- </td>
45
- </tr>
46
- </tbody>
47
- </table>
48
- </div>
49
- </div>
50
- </div>
51
- </div>
52
- <div class="foot" @click="back('toMain')">
53
- <text>返回</text>
54
- </div>
55
- </div>
56
- </template>
57
- <script>
58
- import Vue from 'vue'
59
- export default {
60
- title: '选择支付方式',
61
- data() {
62
- return {
63
- btn1Path: '',
64
- btn2Path: '',
65
- btn3Path: '',
66
- payBtn1: {
67
- show: false,
68
- path: "",
69
- method: "",
70
- pay_way: "",
71
- payment: ""
72
- },
73
- payBtn2: {
74
- show: false,
75
- path: "",
76
- method: "",
77
- pay_way: "",
78
- payment: ""
79
- },
80
- payBtn3: {
81
- show: false,
82
- path: "",
83
- method: "",
84
- pay_way: "",
85
- payment: ""
86
- },
87
- garbageInfo: {
88
- accountperiod: '',
89
- money: 0,
90
- list: []
91
- },
92
- payInfo: {
93
- pay_way: '',
94
- f_payment: '',
95
- url: '',
96
- f_serial_id: ''
97
- },
98
- resolve: undefined,
99
- reject: undefined,
100
- obj: undefined
101
- }
102
- },
103
- methods: {
104
- // 格式化日期显示
105
- formatDate(dateStr) {
106
- if (!dateStr) return ''
107
- const parts = dateStr.split('-')
108
- if (parts.length === 2) {
109
- return `${parts[0]}年${parts[1]}月`
110
- }
111
- return dateStr
112
- },
113
-
114
- back(para) {
115
- this.obj.resolve(false)
116
- this.$back(para)
117
- },
118
-
119
- getQR() {
120
- this.obj.getQR()
121
- },
122
-
123
- async pay (str) {
124
- if (!this.handClick) {
125
- this.handClick = true
126
-
127
- // 垃圾费不需要读卡验证,直接进行支付
128
- if (str === '1') {
129
- this.payInfo.pay_way = this.payBtn1.pay_way
130
- this.payInfo.f_payment = this.payBtn1.payment
131
- this.payMethod(this.payBtn1.unionPayAlias, this.payBtn1.method)
132
- } else if (str === '2') {
133
- this.payInfo.pay_way = this.payBtn2.pay_way
134
- this.payInfo.f_payment = this.payBtn2.payment
135
- this.payMethod(this.payBtn2.unionPayAlias, this.payBtn2.method)
136
- } else {
137
- this.payInfo.pay_way = this.payBtn3.pay_way
138
- this.payInfo.f_payment = this.payBtn3.payment
139
- this.payMethod(this.payBtn3.unionPayAlias, this.payBtn3.method)
140
- }
141
- }
142
- },
143
-
144
- payMethod(unionPayAlias, payMethod) {
145
- if (payMethod === 'qrcode') {
146
- this.getQR()
147
- } else if (payMethod === 'card') {
148
- this.cardPay(unionPayAlias)
149
- } else {
150
- this.$showNewMessage('提示', `未知支付方式:${payMethod},请联系管理员`, ['confirm'], 'newmgs')
151
- }
152
- },
153
-
154
- cardPay(unionPayAlias) {
155
- let attach = this.obj.getAttach()
156
- let money = Vue.PosUtil.yuan2fen(this.garbageInfo.money)
157
- //测试环境支付金额统一改为1分
158
- if (Vue.PosUtil.posParam.isTest) {
159
- money = 1
160
- }
161
- attach.f_revenue = Vue.PosUtil.posParam.revenue
162
- attach.money = money
163
- try {
164
- HostApp.__this__ = this
165
- HostApp.pay({
166
- data: attach,
167
- callback: 'javascript:HostApp.__this__.toSuccess();'
168
- }, unionPayAlias)
169
- } catch (e) {
170
- console.log('e', e)
171
- }
172
- },
173
-
174
- // 垃圾费支付成功处理
175
- toSuccess() {
176
- this.$showNewMessage('提示', '垃圾费缴费成功!', ['confirm'], 'newmgs', () => {
177
- this.$back('toMain')
178
- })
179
- }
180
- },
181
-
182
- ready() {
183
- // 从路由参数获取垃圾费信息
184
- this.garbageInfo = this.garbage
185
-
186
- // 设置服务对象里的组件对象
187
- if (this.obj) {
188
- this.obj.setComponents(this)
189
- }
190
-
191
- this.payBtn1 = this.$PosUtil.posParam.PayBtn1
192
- this.payBtn2 = this.$PosUtil.posParam.PayBtn2
193
- this.payBtn3 = this.$PosUtil.posParam.PayBtn3
194
- this.btn1Path = require(`../image/${this.payBtn1.path}`)
195
- this.btn2Path = require(`../image/${this.payBtn2.path}`)
196
- this.btn3Path = require(`../image/${this.payBtn3.path}`)
197
- }
198
- }
199
- </script>
1
+ <template>
2
+ <div>
3
+ <div class="mhead">
4
+ <ul>
5
+ <li>
6
+ <text>垃圾费缴费</text>
7
+ </li>
8
+ </ul>
9
+ </div>
10
+ <div class="body">
11
+ <div class="container contentpanel auto">
12
+ <div class="row buypanel">
13
+ <div class="buyform">
14
+ <h3 style="color: red;">订单信息</h3>
15
+ <div>
16
+ <h4>缴费类型:垃圾费</h4>
17
+ </div>
18
+ <div>
19
+ <h4>账期:{{garbageInfo.accountperiod}}</h4>
20
+ </div>
21
+ <div>
22
+ <h4>支付金额:{{garbageInfo.money}} &nbsp;&nbsp;元</h4>
23
+ </div>
24
+ </div>
25
+ <div class="horizontal" height="auto">
26
+ <h3 style="color: red;">请选择支付方式</h3>
27
+ <table width="60%" border="0" cellspacing="0" cellpadding="0" align="center">
28
+ <tbody>
29
+ <tr>
30
+ <td align="center" v-if='payBtn1.show' class="col-xs-4 weixin">
31
+ <div @click='pay("1")'>
32
+ <img :src="btn1Path" alt=""/>
33
+ </div>
34
+ </td>
35
+ <td align="center" v-if='payBtn2.show' class="col-xs-4 alipay" >
36
+ <div @click='pay("2")'>
37
+ <img :src="btn2Path " alt=""/>
38
+ </div>
39
+ </td>
40
+ <td align="center" v-if='payBtn3.show' class="col-xs-4 unionpay">
41
+ <div @click='pay("3")'>
42
+ <img :src="btn3Path" alt=""/>
43
+ </div>
44
+ </td>
45
+ </tr>
46
+ </tbody>
47
+ </table>
48
+ </div>
49
+ </div>
50
+ </div>
51
+ </div>
52
+ <div class="foot" @click="back('toMain')">
53
+ <text>返回</text>
54
+ </div>
55
+ </div>
56
+ </template>
57
+ <script>
58
+ import Vue from 'vue'
59
+ import * as util from '../../service/util.js'
60
+ export default {
61
+ title: '选择支付方式',
62
+ data() {
63
+ return {
64
+ btn1Path: '',
65
+ btn2Path: '',
66
+ btn3Path: '',
67
+ payBtn1: {
68
+ show: false,
69
+ path: "",
70
+ method: "",
71
+ pay_way: "",
72
+ payment: ""
73
+ },
74
+ payBtn2: {
75
+ show: false,
76
+ path: "",
77
+ method: "",
78
+ pay_way: "",
79
+ payment: ""
80
+ },
81
+ payBtn3: {
82
+ show: false,
83
+ path: "",
84
+ method: "",
85
+ pay_way: "",
86
+ payment: ""
87
+ },
88
+ garbageInfo: {
89
+ accountperiod: '',
90
+ money: 0,
91
+ list: []
92
+ },
93
+ payInfo: {
94
+ pay_way: '',
95
+ f_payment: '',
96
+ url: '',
97
+ f_serial_id: ''
98
+ },
99
+ resolve: undefined,
100
+ reject: undefined,
101
+ obj: undefined
102
+ }
103
+ },
104
+ methods: {
105
+ // 格式化日期显示
106
+ formatDate(dateStr) {
107
+ if (!dateStr) return ''
108
+ const parts = dateStr.split('-')
109
+ if (parts.length === 2) {
110
+ return `${parts[0]}年${parts[1]}月`
111
+ }
112
+ return dateStr
113
+ },
114
+
115
+ back(para) {
116
+ this.obj.resolve(false)
117
+ this.$back(para)
118
+ },
119
+
120
+ getQR() {
121
+ this.obj.getQR()
122
+ },
123
+
124
+ async pay (str) {
125
+ if (!this.handClick) {
126
+ this.handClick = true
127
+
128
+ // 垃圾费不需要读卡验证,直接进行支付
129
+ if (str === '1') {
130
+ this.payInfo.pay_way = this.payBtn1.pay_way
131
+ this.payInfo.f_payment = this.payBtn1.payment
132
+ this.payMethod(this.payBtn1.unionPayAlias, this.payBtn1.method)
133
+ } else if (str === '2') {
134
+ this.payInfo.pay_way = this.payBtn2.pay_way
135
+ this.payInfo.f_payment = this.payBtn2.payment
136
+ this.payMethod(this.payBtn2.unionPayAlias, this.payBtn2.method)
137
+ } else {
138
+ this.payInfo.pay_way = this.payBtn3.pay_way
139
+ this.payInfo.f_payment = this.payBtn3.payment
140
+ this.payMethod(this.payBtn3.unionPayAlias, this.payBtn3.method)
141
+ }
142
+ }
143
+ },
144
+
145
+ payMethod(unionPayAlias, payMethod) {
146
+ if (payMethod === 'qrcode') {
147
+ this.getQR()
148
+ } else if (payMethod === 'card') {
149
+ this.cardPay(unionPayAlias)
150
+ } else {
151
+ this.$showNewMessage('提示', `未知支付方式:${payMethod},请联系管理员`, ['confirm'], 'newmgs')
152
+ }
153
+ },
154
+
155
+ cardPay(unionPayAlias) {
156
+ let attach = this.obj.getAttach()
157
+ let money = Vue.PosUtil.yuan2fen(this.garbageInfo.money)
158
+ //测试环境支付金额统一改为1分
159
+ if (Vue.PosUtil.posParam.isTest) {
160
+ money = 1
161
+ }
162
+ attach.f_revenue = Vue.PosUtil.posParam.revenue
163
+ attach.money = money
164
+ try {
165
+ HostApp.__this__ = this
166
+ HostApp.pay({
167
+ data: attach,
168
+ callback: 'javascript:HostApp.__this__.toSuccess();'
169
+ }, unionPayAlias)
170
+ } catch (e) {
171
+ console.log('e', e)
172
+ }
173
+ },
174
+ print(){
175
+ try {
176
+ let num = 0.00
177
+ this.garbage.list.forEach(item=>{
178
+ num += item.f_money
179
+ })
180
+ let bigNum = util.numberToChinese(num)
181
+ let date = util.getDate()
182
+ let printContent = []
183
+ let textHead = {type: 3, text: '山西华新科莱天然气有限公司垃圾费收费单', fontsize: 3, isbold: true, align: 'center'}
184
+ printContent.push(textHead)
185
+ printContent.push({type: 4, value: 2, unit: 'line'})
186
+ printContent.push({type: 3, text: '收费日期:' + date, fontsize: 2, isbold: false, align: 'left'})
187
+ printContent.push({type: 3, text: '用户编号:' + this.userInfo.f_userinfo_code, fontsize: 2, isbold: false, align: 'left'})
188
+ printContent.push({type: 3, text: '用户姓名:' + this.userInfo.f_user_name, fontsize: 2, isbold: false, align: 'left'})
189
+ printContent.push({type: 3, text: '用气地址:' + this.userInfo.f_address, fontsize: 2, isbold: false, align: 'left'})
190
+ printContent.push({type: 3, text: '收费项目:' + '垃圾费', fontsize: 2, isbold: false, align: 'left'})
191
+ printContent.push({type: 3, text: '垃圾处理费:' + num, fontsize: 2, isbold: false, align: 'left'})
192
+ printContent.push({type: 3, text: '实收金额(大写):' + bigNum, fontsize: 2, isbold: false, align: 'left'})
193
+ printContent.push({type: 3, text: '打票时间:' + date, fontsize: 2, isbold: false, align: 'left'})
194
+ printContent.push({type: 3, text: '收费员:' + Vue.user.name || Vue.PosUtil.Sn, fontsize: 2, isbold: false, align: 'left'})
195
+ printContent.push({type: 4, value: 4, unit: 'line'})
196
+ this.$AndroidPlugin.print(printContent)
197
+ }catch (e) {
198
+ this.$showNewMessage('错误', '收费打印单失败。')
199
+ }
200
+ this.$back('toMain')
201
+ },
202
+
203
+ // 垃圾费支付成功处理
204
+ toSuccess() {
205
+ this.$showNewMessage('错误', '垃圾费缴费成功!是否打印收费单?', ['confirm', 'cancel'], 'newmgs')
206
+ .then((res) => {
207
+ if (res === 'confirm') {
208
+ this.print()
209
+ } else {
210
+ this.$back('toMain')
211
+ }
212
+ })
213
+ }
214
+ },
215
+
216
+ ready() {
217
+ // 从路由参数获取垃圾费信息
218
+ this.garbageInfo = this.garbage
219
+
220
+ // 设置服务对象里的组件对象
221
+ if (this.obj) {
222
+ this.obj.setComponents(this)
223
+ }
224
+
225
+ this.payBtn1 = this.$PosUtil.posParam.PayBtn1
226
+ this.payBtn2 = this.$PosUtil.posParam.PayBtn2
227
+ this.payBtn3 = this.$PosUtil.posParam.PayBtn3
228
+ this.btn1Path = require(`../image/${this.payBtn1.path}`)
229
+ this.btn2Path = require(`../image/${this.payBtn2.path}`)
230
+ this.btn3Path = require(`../image/${this.payBtn3.path}`)
231
+ }
232
+ }
233
+ </script>
@@ -1,47 +1,47 @@
1
- <template>
2
- <div>
3
- <div class="mhead">
4
- <ul>
5
- <li>
6
- <text>自助缴费机</text>
7
- </li>
8
- </ul>
9
- </div>
10
- <div class="body" style="background: #f0f0f0;padding: 20%;margin: 0 auto">
11
- <div>
12
- <h5>请插好燃气卡,等待自动读卡</h5>
13
- <img src="../image/readCard.gif">
14
- </div>
15
- </div>
16
- <div class="foot" @click="back('toMain')">
17
- <text>返回</text>
18
- </div>
19
- </div>
20
- </template>
21
-
22
- <script>
23
- import CheckCard from '../../service/CheckCard'
24
- import GetCardInfo from '../../service/GetCardInfo'
25
- import Vue from 'vue'
26
- export default {
27
- title: '读卡',
28
- name: 'CardMain',
29
- data () {
30
- return {
31
- }
32
- },
33
- methods: {
34
- back(param) {
35
- this.$back(param)
36
- }
37
- },
38
- ready () {
39
- // 用户进入该组件后,轮询检查卡,如果检查到卡就读卡并查询卡信息后返回用户档案
40
- let service = [new CheckCard(this), new GetCardInfo(this)]
41
- service = this.$PosUtil.buildLinked(service)
42
- Vue.eventBack(service)
43
- }
44
- }
45
- </script>
46
- <style>
47
- </style>
1
+ <template>
2
+ <div>
3
+ <div class="mhead">
4
+ <ul>
5
+ <li>
6
+ <text>自助缴费机</text>
7
+ </li>
8
+ </ul>
9
+ </div>
10
+ <div class="body" style="background: #f0f0f0;padding: 20%;margin: 0 auto">
11
+ <div>
12
+ <h5>请插好燃气卡,等待自动读卡</h5>
13
+ <img src="../image/readCard.gif">
14
+ </div>
15
+ </div>
16
+ <div class="foot" @click="back('toMain')">
17
+ <text>返回</text>
18
+ </div>
19
+ </div>
20
+ </template>service
21
+
22
+ <script>
23
+ import CheckCard from '../../service/CheckCard'
24
+ import GetCardInfo from '../../service/GetCardInfo'
25
+ import Vue from 'vue'
26
+ export default {
27
+ title: '读卡',
28
+ name: 'CardMain',
29
+ data () {
30
+ return {
31
+ }
32
+ },
33
+ methods: {
34
+ back(param) {
35
+ this.$back(param)
36
+ }
37
+ },
38
+ ready () {
39
+ // 用户进入该组件后,轮询检查卡,如果检查到卡就读卡并查询卡信息后返回用户档案
40
+ let service = [new CheckCard(this), new GetCardInfo(this)]
41
+ service = this.$PosUtil.buildLinked(service)
42
+ Vue.eventBack(service)
43
+ }
44
+ }
45
+ </script>
46
+ <style>
47
+ </style>
@@ -1,103 +1,111 @@
1
- import Vue from 'vue'
2
-
3
- /**
4
- * @author GaoChengLong
5
- * @date 2018/12/7 16:38
6
- * 轮询检测卡并且读卡获取卡信息
7
- */
8
- export default class CheckCard {
9
-
10
- constructor(components) {
11
- this.self = components
12
- // 助记执行次数
13
- this.count = 0
14
- // 承诺函数助记符
15
- this.resolve = null
16
- // 拒绝函数助记符
17
- this.reject = null
18
- // 计时器
19
- this.timeOut = null
20
- }
21
-
22
- doAction() {
23
- return new Promise((resolve, reject) => {
24
- this.resolve = resolve
25
- this.reject = reject
26
- let obj = this
27
- this.timeOut = window.setInterval(() => {
28
- obj.checkCard(obj)
29
- }, 1000)
30
- })
31
- }
32
-
33
- commit() {
34
-
35
- }
36
-
37
- rollback() {
38
- this.self.cardInfo = {}
39
- this.self.userInfo = {}
40
- }
41
-
42
- // 检测是否有卡
43
- async checkCard(obj) {
44
- if (obj.count === 0) {
45
- obj.self.$showAlert('正在检查卡槽是否有卡', 'success', 2000)
46
- }
47
- if (obj.count % 10 === 0 && obj.count !== 0) {
48
- // 关闭定时器
49
- clearInterval(obj.timeOut)
50
- // 弹出框,如果点确定则退出到主界面,如果点取消则继续轮询
51
- obj.errorInfo('未检测到卡,请检查卡槽是否有卡或异物!', obj.resolve)
52
- } else if (obj.count % 2 === 0) {
53
- this.self.$closeAlert()
54
- let ret = await Vue.AndroidPlugin.hasCard(obj.count)
55
- if (ret) {
56
- // 关闭定时器
57
- clearInterval(obj.timeOut)
58
- obj.readCard()
59
- }
60
- obj.count++
61
- } else {
62
- obj.count++
63
- }
64
- }
65
-
66
- async readCard() {
67
- // this指针被指向CheckCard
68
- this.self.$showAlert('正在读卡,请稍后', 'success', 1000)
69
- // 清空cardInfo缓存
70
- this.self.cardInfo = {}
71
- this.self.userInfo = {}
72
- let jo = await Vue.AndroidPlugin.read()
73
- this.self.$closeAlert()
74
- if (jo.code === 200) {
75
- this.self.cardInfo = jo.msg
76
- // 读卡成功,已成功拿到卡信息,现在开始执行下一个服务
77
- this.resolve(true)
78
- } else if (jo.code === 500) {
79
- this.errorInfo(jo.msg + ',请检查卡是否插好!')
80
- } else {
81
- this.errorInfo('调用读卡器失败,请联系管理员!')
82
- }
83
- }
84
-
85
- /**
86
- * 错误提示框,点确定则返回到主界面,点取消则继续执行轮询
87
- * */
88
- errorInfo(msg) {
89
- this.count = 0
90
- this.self.$showNewMessage('错误', msg + '(点击\'确定\'返回主页,点击\'取消\'继续读卡)', ['confirm', 'cancel'], 'newmgs')
91
- .then((res) => {
92
- if (res === 'confirm') {
93
- this.self.back()
94
- this.resolve(false)
95
- } else {
96
- let obj = this
97
- this.timeOut = window.setInterval(() => {
98
- obj.checkCard(obj)
99
- }, 1000)
100
- }
101
- })
102
- }
103
- }
1
+ import Vue from 'vue'
2
+
3
+ /**
4
+ * @author GaoChengLong
5
+ * @date 2018/12/7 16:38
6
+ * 轮询检测卡并且读卡获取卡信息
7
+ */
8
+ export default class CheckCard {
9
+
10
+ constructor(components) {
11
+ this.self = components
12
+ // 助记执行次数
13
+ this.count = 0
14
+ // 承诺函数助记符
15
+ this.resolve = null
16
+ // 拒绝函数助记符
17
+ this.reject = null
18
+ // 计时器
19
+ this.timeOut = null
20
+ }
21
+
22
+ doAction() {
23
+ return new Promise((resolve, reject) => {
24
+ this.resolve = resolve
25
+ this.reject = reject
26
+ let obj = this
27
+ this.timeOut = window.setInterval(() => {
28
+ obj.checkCard(obj)
29
+ }, 1000)
30
+ })
31
+ }
32
+
33
+ commit() {
34
+
35
+ }
36
+
37
+ rollback() {
38
+ this.self.cardInfo = {}
39
+ this.self.userInfo = {}
40
+ }
41
+
42
+ // 检测是否有卡
43
+ async checkCard(obj) {
44
+ if (obj.count === 0) {
45
+ if (Vue.phoneBuild){
46
+ obj.self.$showMessage('正在检查卡槽是否有卡', 'success', 1000)
47
+ }else {
48
+ obj.self.$showAlert('正在检查卡槽是否有卡', 'success', 2000)
49
+ }
50
+ }
51
+ if (obj.count % 10 === 0 && obj.count !== 0) {
52
+ // 关闭定时器
53
+ clearInterval(obj.timeOut)
54
+ // 弹出框,如果点确定则退出到主界面,如果点取消则继续轮询
55
+ obj.errorInfo('未检测到卡,请检查卡槽是否有卡或异物!', obj.resolve)
56
+ } else if (obj.count % 2 === 0) {
57
+ this.self.$closeAlert()
58
+ let ret = await Vue.AndroidPlugin.hasCard(obj.count)
59
+ if (ret) {
60
+ // 关闭定时器
61
+ clearInterval(obj.timeOut)
62
+ obj.readCard()
63
+ }
64
+ obj.count++
65
+ } else {
66
+ obj.count++
67
+ }
68
+ }
69
+
70
+ async readCard() {
71
+ // this指针被指向CheckCard
72
+ if (Vue.phoneBuild){
73
+ this.self.$showMessage('正在读卡,请稍后', 'success', 1000)
74
+ }else {
75
+ this.self.$showAlert('正在读卡,请稍后', 'success', 1000)
76
+ }
77
+ // 清空cardInfo缓存
78
+ this.self.cardInfo = {}
79
+ this.self.userInfo = {}
80
+ let jo = await Vue.AndroidPlugin.read()
81
+ this.self.$closeAlert()
82
+ if (jo.code === 200) {
83
+ this.self.cardInfo = jo.msg
84
+ // 读卡成功,已成功拿到卡信息,现在开始执行下一个服务
85
+ this.resolve(true)
86
+ } else if (jo.code === 500) {
87
+ this.errorInfo(jo.msg + ',请检查卡是否插好!')
88
+ } else {
89
+ this.errorInfo('调用读卡器失败,请联系管理员!')
90
+ }
91
+ }
92
+
93
+ /**
94
+ * 错误提示框,点确定则返回到主界面,点取消则继续执行轮询
95
+ * */
96
+ errorInfo(msg) {
97
+ this.count = 0
98
+ this.self.$showNewMessage('错误', msg + '(点击\'确定\'返回主页,点击\'取消\'继续读卡)', ['confirm', 'cancel'], 'newmgs')
99
+ .then((res) => {
100
+ if (res === 'confirm') {
101
+ this.self.back()
102
+ this.resolve(false)
103
+ } else {
104
+ let obj = this
105
+ this.timeOut = window.setInterval(() => {
106
+ obj.checkCard(obj)
107
+ }, 1000)
108
+ }
109
+ })
110
+ }
111
+ }
@@ -0,0 +1,86 @@
1
+ export function numberToChinese(num) {
2
+ if (isNaN(num)) return '输入无效';
3
+
4
+ const chineseNums = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
5
+ const chineseUnits = ['', '拾', '', '佰', '', '仟', '', '万', '', '亿', '', '兆'];
6
+ const decimalUnits = ['角', '分'];
7
+
8
+ // 限制最多两位小数,并四舍五入
9
+ num = Math.round(num * 100) / 100;
10
+
11
+ // 拆分为整数部分和小数部分
12
+ let integerPart = Math.floor(num);
13
+ let decimalPart = Math.round((num - integerPart) * 100);
14
+
15
+ // 处理整数部分
16
+ function convertInteger(n) {
17
+ if (n === 0) return '零';
18
+ let result = '';
19
+ let unitIndex = 0;
20
+ let needZero = false;
21
+
22
+ while (n > 0) {
23
+ const digit = n % 10;
24
+ if (digit !== 0) {
25
+ if (needZero) {
26
+ result = '零' + result;
27
+ needZero = false;
28
+ }
29
+ if (unitIndex === 2 || unitIndex === 6 || unitIndex === 10) {
30
+ // 万、亿、兆位
31
+ result = chineseUnits[unitIndex] + result;
32
+ } else if (unitIndex > 0) {
33
+ result = chineseUnits[unitIndex - 1] + result;
34
+ }
35
+ result = chineseNums[digit] + result;
36
+ } else {
37
+ if (result !== '' && !needZero) {
38
+ needZero = true;
39
+ }
40
+ }
41
+ n = Math.floor(n / 10);
42
+ unitIndex += 2; // 每次跳过单位占位(如:个、十、百、千...)
43
+ }
44
+
45
+ // 补充“元”
46
+ result += '元';
47
+ return result;
48
+ }
49
+
50
+ // 处理小数部分
51
+ function convertDecimal(d) {
52
+ if (d === 0) return '整';
53
+ let result = '';
54
+ const jiao = Math.floor(d / 10);
55
+ const fen = d % 10;
56
+ if (jiao > 0) {
57
+ result += chineseNums[jiao] + '角';
58
+ }
59
+ if (fen > 0) {
60
+ result += chineseNums[fen] + '分';
61
+ }
62
+ return result;
63
+ }
64
+
65
+ let result = '';
66
+
67
+ if (integerPart === 0 && decimalPart > 0) {
68
+ result = '零元' + convertDecimal(decimalPart);
69
+ } else {
70
+ result = convertInteger(integerPart) + convertDecimal(decimalPart);
71
+ }
72
+
73
+ return result;
74
+ }
75
+
76
+
77
+ export function getDate() {
78
+ let dt = new Date()
79
+ let month = dt.getMonth()+1
80
+ let date = dt.getDate()
81
+ let hour = dt.getHours()
82
+ let min = dt.getMinutes()
83
+ let sec = dt.getSeconds()
84
+ return dt.getFullYear() + '-' + (month<10? '0'+ month : month) + '-' + (date<10? '0'+ date : date)
85
+ + ' ' + (hour<10? '0'+ hour : hour) + ':' + (min<10? '0'+ min : min) + ':' + (sec<10? '0'+ sec : sec)
86
+ }