<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>
|