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.
zhishifufei_uniapp/pages/store/applyInvoicing.vue

296 lines
7.8 KiB

9 months ago
<template>
<BaseContainer class="apply-invoicing">
<NavBar title="申请开票" />
9 months ago
<view v-if="orderNum" class="order-info info-box">
9 months ago
<view class="info-item flex flex-center-x">
<view class="item-label">订单编号</view>
<view class="item-content">{{ orderNum }}</view>
</view>
<view class="info-item flex flex-center-x">
<view class="item-label">开票金额</view>
<view class="item-content money-content"><text>{{ money }}</text></view>
</view>
</view>
<view class="invoicing-info info-box">
<view class="info-item flex flex-center-x">
<view class="item-label">抬头类型</view>
<view class="item-content">
<radio-group @change="changeRadioType">
<label>
9 months ago
<radio value="1" :checked="invoicingInfo.type === 1" color="#F8473E"/><text>个人</text>
9 months ago
</label>
<label>
9 months ago
<radio value="2" :checked="invoicingInfo.type === 2" color="#F8473E"/><text>企业</text>
9 months ago
</label>
</radio-group>
</view>
</view>
<view class="info-item flex flex-center-x">
<view class="item-label">发票抬头</view>
<view class="item-content">
9 months ago
<input v-if="!orderNum" type="text" v-model="invoicingInfo.invoiceHeader" placeholder="抬头名称" placeholder-class="input-placeholder" />
<picker
v-else
:range="invoiceHeaderArray"
:value="invoiceHeaderIndex"
@change="changeInvoiceHeader"
:style="invoiceHeaderIndex > -1 ? '' : 'color: #CFCFCF;'"
>{{ invoiceHeaderIndex > -1 ? invoiceHeaderArray[invoiceHeaderIndex] : '请选择发票抬头'}}</picker>
9 months ago
</view>
</view>
9 months ago
<template v-if="Number(invoicingInfo.type) === 2">
9 months ago
<view class="info-item flex flex-center-x">
<view class="item-label">税号</view>
<view class="item-content">
9 months ago
<input type="text" v-model="invoicingInfo.dutyParagraph" placeholder="纳税人识别号或社会统一征信代码" placeholder-class="input-placeholder" />
9 months ago
</view>
</view>
<view class="info-item flex flex-center-x">
<view class="item-label">地址</view>
<view class="item-content">
9 months ago
<input type="text" v-model="invoicingInfo.address" placeholder="选填" placeholder-class="input-placeholder" />
9 months ago
</view>
</view>
<view class="info-item flex flex-center-x">
<view class="item-label">开户行</view>
<view class="item-content">
9 months ago
<input type="text" v-model="invoicingInfo.bank" placeholder="选填" placeholder-class="input-placeholder" />
9 months ago
</view>
</view>
</template>
</view>
<view class="footer">
<view class="submit-btn btn" @click="submit">提交申请</view>
9 months ago
<view v-if="orderNum" class="cancel-btn btn" @click="cancel">不开发票</view>
9 months ago
</view>
</BaseContainer>
</template>
<script>
9 months ago
import { addInvoiceHeader, editInvoiceHeader, applyInvoice, getInvoiceHeaderList } from '@/api/store';
9 months ago
export default {
data() {
return {
orderNum: '',
money: '',
9 months ago
headerId: '',
invoiceHeaderIndex: -1,
invoiceHeaderList: [],
invoiceHeaderArray: [],
9 months ago
invoicingInfo: {
9 months ago
type: 1,
9 months ago
invoiceHeader: '',
dutyParagraph: '',
address: '',
bank: '',
},
};
},
onLoad(options) {
console.log(options);
this.orderNum = options.orderNum || '';
this.money = options.money || 0;
9 months ago
if (options.orderNum) {
this.getInvoiceHeaderList();
}
if (options.info) {
const info = JSON.parse(options.info);
this.headerId = info.id;
this.invoicingInfo = {
type: info.header_type,
invoiceHeader: info.invoice_header,
dutyParagraph: info.tax_number,
address: info.address,
bank: info.bank,
}
}
console.log(addInvoiceHeader, editInvoiceHeader, applyInvoice);
9 months ago
},
methods: {
changeRadioType(e) {
console.log(e, this.invoicingInfo.type);
this.invoicingInfo.type = e.detail.value;
9 months ago
this.invoicingInfo.invoiceHeader = '';
this.invoicingInfo.dutyParagraph = '';
this.invoicingInfo.address = '';
this.invoicingInfo.bank = '';
this.invoiceHeaderIndex = -1;
if (this.orderNum && this.invoiceHeaderList.length > 0) {
const arr = [];
this.invoiceHeaderList.forEach(v => {
if (Number(v.header_type) === Number(this.invoicingInfo.type)) {
arr.push(v.invoice_header);
}
});
this.invoiceHeaderArray = arr;
}
9 months ago
},
submit() {
9 months ago
if (!this.invoicingInfo.invoiceHeader) {
return this.$util.showMsg("请填写发票抬头");
}
uni.showLoading({
mask: true,
});
const params = {
order_number: this.orderNum,
invoice_amount: this.money,
header_type: this.invoicingInfo.type,
invoice_header: this.invoicingInfo.invoiceHeader,
tax_number: this.invoicingInfo.dutyParagraph,
address: this.invoicingInfo.address,
bank: this.invoicingInfo.bank,
}
this.commonApi(params);
},
async commonApi(params) {
let response = {};
try{
if (this.orderNum) {
response = await applyInvoice(params);
} else if (this.headerId){
response = await editInvoiceHeader({ id: this.headerId, ...params});
} else {
response = await addInvoiceHeader(params);
}
console.log(response);
uni.hideLoading();
const { data, code, msg } = response;
if (code != 200) {
uni.showToast({
title: msg,
});
} else {
uni.showToast({
title: this.orderNum ? '申请成功!' : (this.headerId ? '修改成功!' : '添加成功!'),
});
setTimeout(() => {
uni.navigateBack();
}, 1000)
}
}catch(e){
uni.hideLoading();
console.log(e);
}
9 months ago
},
cancel() {
uni.navigateBack();
},
9 months ago
changeInvoiceHeader(e) {
this.invoiceHeaderIndex = e.detail.value;
this.invoicingInfo.invoiceHeader = this.invoiceHeaderArray[this.invoiceHeaderIndex];
},
async getInvoiceHeaderList() {
uni.showLoading({
mask: true,
});
try{
const { data, code, msg } = await getInvoiceHeaderList({});
uni.hideLoading();
if (code != 200) {
uni.showToast({
title: msg,
});
} else {
console.log(data);
this.invoiceHeaderList = data.list;
if (data.list.length > 0) {
const arr = [];
data.list.forEach(v => {
if (Number(v.header_type) === Number(this.invoicingInfo.type)) {
arr.push(v.invoice_header);
}
});
this.invoiceHeaderArray = arr;
}
}
}catch(e){
uni.hideLoading();
console.log(e);
}
},
9 months ago
},
};
</script>
<style lang="scss" scoped>
.input-placeholder {
color: #CFCFCF;
font-size: 24rpx;
}
.apply-invoicing {
background: #f5f5f5;
.info-box {
width: 690rpx;
margin: 20rpx auto 0;
background: #fff;
border-radius: 10rpx;
padding: 20rpx 40rpx;
.info-item {
height: 64rpx;
line-height: 64rpx;
color: #999999;
font-size: 26rpx;
.item-label {
width: 130rpx;
margin-right: 40rpx;
}
.item-content {
flex: 1;
color: #000;
&.money-content {
color: #F8473E;
font-size: 22rpx;
text {
font-size: 32rpx;
}
}
::v-deep {
uni-radio-group, {
display: flex;
align-items: center;
justify-content: flex-end;
.uni-radio-input {
width: 34rpx;
height: 34rpx;
}
}
.uni-label-pointer {
display: flex;
align-items: center;
margin-left: 63rpx;
}
input {
text-align: right;
}
9 months ago
uni-picker {
text-align: right;
}
9 months ago
}
}
}
}
.footer {
position: fixed;
left: 30rpx;
width: 690rpx;
bottom: 173rpx;
.btn {
width: 100%;
height: 80rpx;
background: #E5E5E5;
border-radius: 40rpx;
text-align: center;
line-height: 80rpx;
color: #A2A2A2;
font-size: 32rpx;
&.submit-btn {
background: #F8473E;
color: #fff;
margin-bottom: 40rpx;
}
}
}
}
</style>