sh-view 2.0.7 → 2.1.0

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.
@@ -1,195 +1,195 @@
1
- export default {
2
- props: {
3
- redit: { type: Boolean },
4
- rkey: { type: String },
5
- rname: { type: String },
6
- rdata: {
7
- type: Object,
8
- default() {
9
- return {}
10
- }
11
- },
12
- rprops: {
13
- type: Object,
14
- default() {
15
- return {}
16
- }
17
- },
18
- rparams: {
19
- type: Object,
20
- default() {
21
- return {}
22
- }
23
- }
24
- },
25
- data() {
26
- return {
27
- renderValue: null
28
- }
29
- },
30
- computed: {
31
- rsize() {
32
- return this.rprops.size || this.rparams.$table?.props?.size || this.rparams.$form?.props?.size
33
- },
34
- rform() {
35
- return this.rparams.$form
36
- },
37
- reditmode() {
38
- return this.rparams.$table?.props?.editConfig?.mode
39
- },
40
- isEditAll() {
41
- return !this.rform && this.reditmode === 'all'
42
- },
43
- moneyUnitText() {
44
- let moneyUnitConstants = [
45
- { value: 1, label: '元' },
46
- { value: 1000, label: '千元' },
47
- { value: 10000, label: '万元' }
48
- ]
49
- let moneyConstant = moneyUnitConstants.find(item => item.value === this.rprops.moneyUnit)
50
- return moneyConstant && moneyConstant.label
51
- },
52
- billGroups() {
53
- let { billStart = '分', billEnd = '亿' } = this.rprops
54
- let cnGroups = [
55
- { shortText: '兆', fullText: '兆', value: '' },
56
- { shortText: '千', fullText: '千亿', value: '' },
57
- { shortText: '百', fullText: '百亿', value: '' },
58
- { shortText: '十', fullText: '十亿', value: '' },
59
- { shortText: '亿', fullText: '亿', value: '' },
60
- { shortText: '千', fullText: '千万', value: '' },
61
- { shortText: '百', fullText: '百万', value: '' },
62
- { shortText: '十', fullText: '十万', value: '' },
63
- { shortText: '万', fullText: '万', value: '' },
64
- { shortText: '千', fullText: '千', value: '' },
65
- { shortText: '百', fullText: '百', value: '' },
66
- { shortText: '十', fullText: '十', value: '' },
67
- { shortText: '元', fullText: '元', value: '' },
68
- { shortText: '角', fullText: '角', value: '' },
69
- { shortText: '分', fullText: '分', value: '' },
70
- { shortText: '毫', fullText: '毫', value: '' },
71
- { shortText: '厘', fullText: '厘', value: '' }
72
- ]
73
- let startIndex = cnGroups.findIndex(cn => cn.fullText === billEnd)
74
- let endIndex = cnGroups.findIndex(cn => cn.fullText === billStart)
75
- return cnGroups.slice(startIndex, endIndex)
76
- },
77
- getBillClass() {
78
- return bil => {
79
- return {
80
- basic: bil.fullText === '元',
81
- commafy: ['千', '百万', '十亿', '兆'].includes(bil.fullText)
82
- }
83
- }
84
- },
85
- renderText() {
86
- let keyValue = this.$vUtils.get(this.rdata, this.rkey)
87
- let { rtext } = this.formatValueFun(keyValue)
88
- return rtext
89
- }
90
- },
91
- methods: {
92
- // 输入框变化
93
- async vxeInputChange({ value, $event }) {
94
- if (!this.rform) {
95
- this.setTableValue(value)
96
- }
97
- },
98
- // 输入框变化回调
99
- async vxeChangeCallBack({ value, $event }) {
100
- if (this.rform) {
101
- this.setFormValue(value)
102
- } else {
103
- this.setTableValue(value)
104
- }
105
- },
106
- // radio 变化回调
107
- async vxeRadioCallBack({ label, $event }) {
108
- if (this.rform) {
109
- this.setFormValue(label)
110
- } else {
111
- this.setTableValue(label)
112
- }
113
- },
114
- // check变化回调
115
- async vxeCheckCallBack({ checklist, checked, label, $event }) {
116
- if (this.rform) {
117
- this.setFormValue(checklist)
118
- } else {
119
- this.setTableValue(checklist)
120
- }
121
- },
122
- // 输入框失去焦点回调
123
- async vxeBlurCallback({ value, $event }) {
124
- if (this.rform) {
125
- this.setFormValue(value)
126
- } else {
127
- this.setTableValue(value)
128
- }
129
- },
130
- // form回调赋值
131
- setFormValue(value) {
132
- if (['$vMoney'].includes(this.rname) && value !== '') value = this.$vUtils.multiply(value, this.rprops.moneyUnit || 1)
133
- let { rvalue } = this.formatValueFun(value, true)
134
- let { data, $form } = this.rparams
135
- this.$vUtils.set(data, this.rkey, rvalue)
136
- $form.context.emit('edit-closed', this.rparams, this)
137
- },
138
- // table回调赋值
139
- setTableValue(value) {
140
- if (['$vMoney'].includes(this.rname) && value !== '') value = this.$vUtils.multiply(value, this.rprops.moneyUnit || 1)
141
- const { row, column } = this.rparams
142
- const { model } = column
143
- model.change = true
144
- model.value = value
145
- },
146
- // 格式化值formatValue
147
- formatValueFun(value, editable) {
148
- let rObj = this.$vUtils.formatRender(value, this.rkey, this.rdata, this.rname, this.rprops, this, editable)
149
- this.renderValue = ['$vMoney'].includes(this.rname) ? rObj.rtext : rObj.rvalue
150
- return rObj
151
- },
152
- // 格式化底部值
153
- getFooterData(qianfen = true) {
154
- let { $table, items, itemIndex, column } = this.rparams
155
- let tableData = $table.reactData.tableData
156
- let { rname, rprops, rfooter, property } = column
157
- let { digits, moneyUnit, commafy, type, calculate } = rprops
158
- let footerValue = items[itemIndex]
159
- if (rfooter) {
160
- let caculateObj = rfooter[items[rfooter.index || 0]]
161
- if (caculateObj && (rname === '$vMoney' || (['number', 'float', 'integer'].includes(type) && calculate))) {
162
- let tableColumnData = this.$vUtils.mapTree(tableData, row => row[property])
163
- let { computeType, result, typeObj } = caculateObj
164
- switch (computeType) {
165
- case 'subTotal':
166
- footerValue = this.$vUtils.sum(tableColumnData)
167
- break
168
- case 'allTotal':
169
- footerValue = typeObj[property] || result
170
- break
171
- case 'mean':
172
- footerValue = this.$vUtils.mean(tableColumnData)
173
- break
174
- default:
175
- footerValue = result
176
- break
177
- }
178
- if (rname === '$vMoney') footerValue = this.$vUtils.truncate(this.$vUtils.divide(footerValue, moneyUnit), digits)
179
- if (qianfen && commafy) footerValue = this.$vUtils.commafy(footerValue, { digits })
180
- }
181
- }
182
- return footerValue
183
- },
184
- // 获取单据值
185
- getBillValue(index, total = false) {
186
- let value = total ? this.getFooterData(false) : this.renderValue
187
- if (!value) return ''
188
- let fullValue = this.$vUtils.formatMoneyPad(value)
189
- let fullList = fullValue.replace('.', '').split('')
190
- return fullList[index]
191
- }
192
- },
193
- created() {},
194
- activated() {}
195
- }
1
+ export default {
2
+ props: {
3
+ redit: { type: Boolean },
4
+ rkey: { type: String },
5
+ rname: { type: String },
6
+ rdata: {
7
+ type: Object,
8
+ default() {
9
+ return {}
10
+ }
11
+ },
12
+ rprops: {
13
+ type: Object,
14
+ default() {
15
+ return {}
16
+ }
17
+ },
18
+ rparams: {
19
+ type: Object,
20
+ default() {
21
+ return {}
22
+ }
23
+ }
24
+ },
25
+ data() {
26
+ return {
27
+ renderValue: null
28
+ }
29
+ },
30
+ computed: {
31
+ rsize() {
32
+ return this.rprops.size || this.rparams.$table?.props?.size || this.rparams.$form?.props?.size
33
+ },
34
+ rform() {
35
+ return this.rparams.$form
36
+ },
37
+ reditmode() {
38
+ return this.rparams.$table?.props?.editConfig?.mode
39
+ },
40
+ isEditAll() {
41
+ return !this.rform && this.reditmode === 'all'
42
+ },
43
+ moneyUnitText() {
44
+ let moneyUnitConstants = [
45
+ { value: 1, label: '元' },
46
+ { value: 1000, label: '千元' },
47
+ { value: 10000, label: '万元' }
48
+ ]
49
+ let moneyConstant = moneyUnitConstants.find(item => item.value === this.rprops.moneyUnit)
50
+ return moneyConstant && moneyConstant.label
51
+ },
52
+ billGroups() {
53
+ let { billStart = '分', billEnd = '亿' } = this.rprops
54
+ let cnGroups = [
55
+ { shortText: '兆', fullText: '兆', value: '' },
56
+ { shortText: '千', fullText: '千亿', value: '' },
57
+ { shortText: '百', fullText: '百亿', value: '' },
58
+ { shortText: '十', fullText: '十亿', value: '' },
59
+ { shortText: '亿', fullText: '亿', value: '' },
60
+ { shortText: '千', fullText: '千万', value: '' },
61
+ { shortText: '百', fullText: '百万', value: '' },
62
+ { shortText: '十', fullText: '十万', value: '' },
63
+ { shortText: '万', fullText: '万', value: '' },
64
+ { shortText: '千', fullText: '千', value: '' },
65
+ { shortText: '百', fullText: '百', value: '' },
66
+ { shortText: '十', fullText: '十', value: '' },
67
+ { shortText: '元', fullText: '元', value: '' },
68
+ { shortText: '角', fullText: '角', value: '' },
69
+ { shortText: '分', fullText: '分', value: '' },
70
+ { shortText: '毫', fullText: '毫', value: '' },
71
+ { shortText: '厘', fullText: '厘', value: '' }
72
+ ]
73
+ let startIndex = cnGroups.findIndex(cn => cn.fullText === billEnd)
74
+ let endIndex = cnGroups.findIndex(cn => cn.fullText === billStart)
75
+ return cnGroups.slice(startIndex, endIndex)
76
+ },
77
+ getBillClass() {
78
+ return bil => {
79
+ return {
80
+ basic: bil.fullText === '元',
81
+ commafy: ['千', '百万', '十亿', '兆'].includes(bil.fullText)
82
+ }
83
+ }
84
+ },
85
+ renderText() {
86
+ let keyValue = this.$vUtils.get(this.rdata, this.rkey)
87
+ let { rtext } = this.formatValueFun(keyValue)
88
+ return rtext
89
+ }
90
+ },
91
+ methods: {
92
+ // 输入框变化
93
+ async vxeInputChange({ value, $event }) {
94
+ if (!this.rform) {
95
+ this.setTableValue(value)
96
+ }
97
+ },
98
+ // 输入框变化回调
99
+ async vxeChangeCallBack({ value, $event }) {
100
+ if (this.rform) {
101
+ this.setFormValue(value)
102
+ } else {
103
+ this.setTableValue(value)
104
+ }
105
+ },
106
+ // radio 变化回调
107
+ async vxeRadioCallBack({ label, $event }) {
108
+ if (this.rform) {
109
+ this.setFormValue(label)
110
+ } else {
111
+ this.setTableValue(label)
112
+ }
113
+ },
114
+ // check变化回调
115
+ async vxeCheckCallBack({ checklist, checked, label, $event }) {
116
+ if (this.rform) {
117
+ this.setFormValue(checklist)
118
+ } else {
119
+ this.setTableValue(checklist)
120
+ }
121
+ },
122
+ // 输入框失去焦点回调
123
+ async vxeBlurCallback({ value, $event }) {
124
+ if (this.rform) {
125
+ this.setFormValue(value)
126
+ } else {
127
+ this.setTableValue(value)
128
+ }
129
+ },
130
+ // form回调赋值
131
+ setFormValue(value) {
132
+ if (['$vMoney'].includes(this.rname) && value !== '') value = this.$vUtils.multiply(value, this.rprops.moneyUnit || 1)
133
+ let { rvalue } = this.formatValueFun(value, true)
134
+ let { data, $form } = this.rparams
135
+ this.$vUtils.set(data, this.rkey, rvalue)
136
+ $form.context.emit('edit-closed', this.rparams, this)
137
+ },
138
+ // table回调赋值
139
+ setTableValue(value) {
140
+ if (['$vMoney'].includes(this.rname) && value !== '') value = this.$vUtils.multiply(value, this.rprops.moneyUnit || 1)
141
+ const { row, column } = this.rparams
142
+ const { model } = column
143
+ model.change = true
144
+ model.value = value
145
+ },
146
+ // 格式化值formatValue
147
+ formatValueFun(value, editable) {
148
+ let rObj = this.$vUtils.formatRender(value, this.rkey, this.rdata, this.rname, this.rprops, this, editable)
149
+ this.renderValue = ['$vMoney'].includes(this.rname) ? rObj.rtext : rObj.rvalue
150
+ return rObj
151
+ },
152
+ // 格式化底部值
153
+ getFooterData(qianfen = true) {
154
+ let { $table, items, itemIndex, column } = this.rparams
155
+ let tableData = $table.reactData.tableData
156
+ let { rname, rprops, rfooter, property } = column
157
+ let { digits, moneyUnit, commafy, type, calculate } = rprops
158
+ let footerValue = items[itemIndex]
159
+ if (rfooter) {
160
+ let caculateObj = rfooter[items[rfooter.index || 0]]
161
+ if (caculateObj && (rname === '$vMoney' || (['number', 'float', 'integer'].includes(type) && calculate))) {
162
+ let tableColumnData = this.$vUtils.mapTree(tableData, row => row[property])
163
+ let { computeType, result, typeObj } = caculateObj
164
+ switch (computeType) {
165
+ case 'subTotal':
166
+ footerValue = this.$vUtils.sum(tableColumnData)
167
+ break
168
+ case 'allTotal':
169
+ footerValue = typeObj[property] || result
170
+ break
171
+ case 'mean':
172
+ footerValue = this.$vUtils.mean(tableColumnData)
173
+ break
174
+ default:
175
+ footerValue = result
176
+ break
177
+ }
178
+ if (rname === '$vMoney') footerValue = this.$vUtils.truncate(this.$vUtils.divide(footerValue, moneyUnit), digits)
179
+ if (qianfen && commafy) footerValue = this.$vUtils.commafy(footerValue, { digits })
180
+ }
181
+ }
182
+ return footerValue
183
+ },
184
+ // 获取单据值
185
+ getBillValue(index, total = false) {
186
+ let value = total ? this.getFooterData(false) : this.renderValue
187
+ if (!value) return ''
188
+ let fullValue = this.$vUtils.formatMoneyPad(value)
189
+ let fullList = fullValue.replace('.', '').split('')
190
+ return fullList[index]
191
+ }
192
+ },
193
+ created() {},
194
+ activated() {}
195
+ }