移动系统liao
2025-02-17 557c2711a3e103ebc3d0492344eca9730d5e92b2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<template>
    <view>
        <u-toast ref="uToast" /><u-no-network></u-no-network>
        <u-navbar title="发票设置" safeAreaInsetTop fixed placeholder @leftClick="goNavigateBack"></u-navbar>
 
        <view class="coreshop-bg-white">
            <u--form :model="model" :rules="rules" ref="uForm" errorType="message" labelPosition="top" labelWidth="80">
                <view class="coreshop-padding-10">
                    <u-form-item label="发票类型" prop="typeName" borderBottom>
                        <u-radio-group v-model="model.typeName" placement="column">
                            <u-radio :customStyle="{marginBottom: '8px'}"
                                     @change="radioChange" v-for="(item, index) in radioItems" :key="index" :name="item.name" :label="item.name"></u-radio>
                        </u-radio-group>
                    </u-form-item>
 
                    <u-form-item label="发票抬头" class="cheque" prop="name" borderBottom>
                        <u--input v-model="model.name" placeholder='抬头名称' @input="getCheque" />
                        <view class="cheque-content" v-show="isShow">
                            <view class="tips-item" v-for="(item,index) in chequeLisit" :key="index" @click="chooseCheque(item)">
                                <view class="tips-name">
                                    {{item.name|| ''}}
                                </view>
                                <view class="sub-div">
                                    <view class="tax-no">
                                        {{item.code|| ''}}
                                    </view>
                                    <view class="tips-num">
                                        <view class="num">
                                            {{item.frequency|| ''}}
                                        </view>
                                        人使用过
                                    </view>
                                </view>
                            </view>
                        </view>
                    </u-form-item>
                    <u-form-item label="税务编号" prop="code" v-show="type === '3'" borderBottom>
                        <u--input v-model="model.code" placeholder='纳税人识别号' />
                    </u-form-item>
                    <u-form-item label="发票内容" v-show="type === '3'" borderBottom>
                        <view>明细</view>
                    </u-form-item>
 
                </view>
 
                <view class="coreshop-bottomBox">
                    <button class="coreshop-btn coreshop-btn-square coreshop-btn-w" @click="saveInvoice">保存发票</button>
                    <button class="coreshop-btn coreshop-btn-square coreshop-btn-b" @click="notNeedInvoice">本次不开具发票</button>
                </view>
 
            </u--form>
        </view>
 
        <!-- 登录提示 -->
        <coreshop-login-modal></coreshop-login-modal>
    </view>
</template>
<script>
    export default {
        data() {
            return {
                radioItems: [{
                    name: '个人发票',
                    value: '2'
                },
                {
                    name: '企业发票',
                    value: '3'
                }],
                type: '1', // 发票类型 1不开发票、2个人发票、3公司发票
                model: {
                    typeName: '', // 发票类型 2个人 3企业
                    name: '', // 抬头名称
                    code: '', // 税号
                },
                isShow: false,
                chequeLisit: [],
                rules: {
                    typeName: [
                        {
                            required: true,
                            message: '请选择发票类型或点击不开具',
                            trigger: ['change', 'blur'],
                        }
                    ],
                    name: [
                        {
                            required: true,
                            message: '请输入发票抬头',
                            trigger: ['change', 'blur'],
                        }
                    ],
                    code: [
                        {
                            validator: (rule, value, callback) => {
                                if (this.type === '3' && !this.model.code) {
                                    return false;
                                }
                                return true;
                            },
                            message: '请输入发票税务编号'
                        }
                    ],
                },
            }
        },
        onReady() {
            this.$refs.uForm.setRules(this.rules);
        },
        onLoad() {
            let invoice
            let pages = getCurrentPages()
            let pre = pages[pages.length - 2]
            console.log(pre);
            if (pre != undefined) {
                // #ifdef APP-PLUS || APP-PLUS-NVUE
                invoice = pre.invoice
                // #endif
                // #ifdef MP-WEIXIN
                invoice = pre.$vm.invoice
                // #endif
                // #ifdef MP-ALIPAY || MP-TOUTIAO
                invoice = pre.data.invoice;
                // #endif
                if (invoice && invoice.hasOwnProperty('type') && invoice.type !== '1') {
                    // 发票不是未使用, 展示发票信息
                    this.model.name = invoice.name;
                    this.model.code = invoice.code;
                    this.type = invoice.type;
                    if (invoice.type == 2) {
                        this.model.typeName = this.radioItems[0].name;
                    } else if (invoice.type == 3) {
                        this.model.typeName = this.radioItems[1].name;
                    }
                }
            }
        },
        methods: {
            // 选中某个单选框时,由radio时触发
            radioChange(e) {
                this.radioItems.forEach(item => {
                    if (item.name === e) {
                        this.type = item.value
                    }
                })
            },
            // 不需要发票信息
            notNeedInvoice() {
                let data = {
                    type: '1',
                    name: '',
                    code: ''
                }
                this.setPageData(data)
            },
            // 保存发票信息
            saveInvoice() {
                //if (this.type === '1' || this.type === 1) {
                //    this.$u.toast('请选择发票类型')
                //    return false
                //}
                //if (!this.model.name) {
                //    this.$u.toast('请输入发票抬头')
                //    return false
                //}
                //// 企业类型需要输入税号
                //if (this.type === '3' && !this.model.code) {
                //    this.$u.toast('请输入发票税号信息')
                //    return false
                //}
 
                this.$refs.uForm.validate().then(res => {
                    let data = {
                        type: this.type,
                        name: this.model.name
                    }
                    // 不是企业类型不需要税号
                    data['code'] = this.type === '3' ? this.model.code : ''
                    this.setPageData(data)
                }).catch(errors => {
                    uni.$u.toast('提交的数据校验失败,请输入合法信息!')
                })
 
            },
            // 向上个页面赋值并返回
            setPageData(data) {
                let pages = getCurrentPages(); //当前页
                let beforePage = pages[pages.length - 2]; //上个页面
                if (beforePage != undefined) {
                    // #ifdef MP-ALIPAY || MP-TOUTIAO
                    this.$db.set('userInvoice', data, true);
                    // #endif
                    // #ifdef MP-WEIXIN
                    beforePage.$vm.invoice = data;
                    // #endif
                    // #ifdef APP-PLUS || APP-PLUS-NVUE
                    // beforePage.invoice = data;
                    this.$store.commit('invoice', data)
                    // #endif
                    uni.navigateBack({
                        delta: 1
                    })
                }
            },
            getCheque(event) {
                let name = event;
                if (name != '') {
                    let data = {
                        name: name
                    }
                    this.$u.api.getTaxInfo(data).then(res => {
                        if (res.status) {
                            if (res.data.length != 0) {
                                this.isShow = true
                                this.chequeLisit = res.data
                            } else {
                                // this.isShow = false
                            }
                        } else {
                            this.$u.toast(res.msg)
                        }
                    });
                } else {
                    this.isShow = false
                }
            },
            chooseCheque(item) {
                this.model.name = item.name;
                this.model.code = item.code;
                this.isShow = false;
                this.type = '3';
                this.model.typeName = this.radioItems[1].name;
            }
        }
    }
</script>
<style scoped lang="scss">
    @import "invoice.scss";
</style>