123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653 |
- <template>
- <!-- 添加新发票 -->
- <view :style="colorStyle">
- <form @submit="formSubmit">
- <view class="panel">
- <view class="acea-row row-middle">
- <view>抬头类型</view>
- <radio-group name="header_type" @change="changeTitleType">
- <label>
- <radio class="disabled" value="1" :checked="header_type === '1'" /><text>个人</text>
- </label>
- <label>
- <radio value="2" :checked="header_type === '2'" /><text>企业</text>
- </label>
- </radio-group>
- </view>
- <view class="acea-row row-middle">
- <view>发票类型</view>
- <input name="type" :value="type === '2' && header_type === '2' ? '增值税电子专用发票' : '增值税电子普通发票'" disabled
- @click="callType" />
- <text class="iconfont icon-xiangyou"></text>
- </view>
- <view class="acea-row row-middle">
- <view>发票抬头</view>
- <input name="name" :value="name" :placeholder="header_type === '1' ? '需要开具发票的姓名' : '需要开具发票的企业名称'" />
- </view>
- <view v-show="header_type === '2'" class="acea-row row-middle">
- <view>税号</view>
- <input name="duty_number" :value="duty_number" placeholder="纳税人识别号" />
- </view>
- <view class="acea-row row-middle">
- <view>手机号</view>
- <input name="drawer_phone" :value="drawer_phone" placeholder="您的手机号" />
- </view>
- <view class="acea-row row-middle">
- <view>邮箱</view>
- <input name="email" :value="email" placeholder="您的联系邮箱" />
- </view>
- </view>
- <view v-show="type === '2'" class="panel">
- <view class="acea-row row-middle">
- <view>开户银行</view>
- <input name="bank" :value="bank" placeholder="您的开户银行" />
- </view>
- <view class="acea-row row-middle">
- <view>银行账号</view>
- <input name="card_number" :value="card_number" placeholder="您的银行账号" />
- </view>
- <view class="acea-row row-middle">
- <view>企业地址</view>
- <input name="address" :value="address" placeholder="您所在的企业地址" />
- </view>
- <view class="acea-row row-middle">
- <view>企业电话</view>
- <input name="tell" :value="tell" placeholder="您的企业电话" />
- </view>
- </view>
- <checkbox-group class="acea-row row-middle panel" name="is_default">
- <label>
- <checkbox :checked="is_default.length !== 0" /><text>设置为默认抬头</text>
- </label>
- </checkbox-group>
- <view class="button-section">
- <button class="button" form-type="submit">保存</button>
- <navigator class="navigator" :url="backUrl" hover-class="none">取消</navigator>
- </view>
- </form>
- <view :class="{ mask: popupType }"></view>
- <view class="popup" :class="{ on: popupType }">
- <view class="title">发票类型选择<text class="iconfont icon-guanbi" @click="closeType"></text></view>
- <scroll-view scroll-y="true">
- <radio-group name="invoice-type" @change="changeType">
- <template v-for="item in invoiceTypeList">
- <label v-if="item.value === '1' || item.value === '2' && specialInvoice" :key="item.type"
- class="acea-row row-middle">
- <view class="text">
- <view>{{ item.name }}</view>
- <view class="info">{{ item.info }}</view>
- </view>
- <radio :value="item.value" :checked="item.value === type" />
- </label>
- </template>
- </radio-group>
- </scroll-view>
- </view>
- <home v-if="navigation"></home>
- </view>
- </template>
- <script>
- import home from '@/components/home';
- import {
- invoiceSave,
- invoiceDetail
- } from '@/api/user.js';
- import colors from '@/mixins/color.js';
- export default {
- components: {
- home
- },
- mixins: [colors],
- data() {
- return {
- invoiceTypeList: [{
- name: '增值税电子普通发票',
- value: '1',
- info: '纸质发票开出后将以邮寄形式交付'
- },
- {
- name: '增值税电子专用发票',
- value: '2',
- info: '纸质发票开出后将以邮寄形式交付'
- }
- ],
- id: '', // 修改时为必须参数
- header_type: '1', // 抬头类型1: 个人2: 企业
- type: '1', // 发票类型1:普通2:专用
- drawer_phone: '', // 开票人手机号
- name: '', // 名称(发票抬头)
- duty_number: '', // 税号(个人为非必需,企业是必需参数)
- tell: '', // 公司注册电话
- address: '', // 注册地址
- bank: '', // 开户行
- card_number: '', // 银行卡号
- is_default: [], // 是否默认
- email: '', // 邮箱
- popupType: false,
- typeName: '',
- urlQuery: '',
- from: '',
- specialInvoice: true,
- order_id: ''
- };
- },
- computed: {
- backUrl() {
- switch (this.from) {
- case 'order_confirm':
- return `/pages/goods/order_confirm/index${this.urlQuery}`;
- break;
- default:
- return '/pages/users/user_invoice_list/index?from=invoice_form';
- break;
- }
- }
- },
- onLoad(options) {
- for (let key in options) {
- switch (key) {
- case 'couponTitle':
- case 'new':
- case 'cartId':
- case 'pinkId':
- case 'couponId':
- case 'addressId':
- case 'delivery_type':
- case 'store_id':
- case 'store_name':
- case 'product_id':
- this.urlQuery += `${this.urlQuery ? '&' : '?'}${key}=${options[key]}`;
- break;
- case 'from':
- this.from = options[key];
- break;
- case 'header_type':
- this.header_type = options[key];
- break;
- case 'id':
- this.id = options[key];
- this.getInvoiceDetail();
- break;
- case 'specialInvoice':
- if (options[key] === 'false') {
- this.specialInvoice = false;
- }
- break;
- }
- }
- if (options.order_id)
- this.order_id = options.order_id
- const invoiceItem = this.invoiceTypeList.find(item => item.value === this.type);
- this.typeName = invoiceItem.name;
- },
- onShow() {
- uni.removeStorageSync('form_type_cart');
- },
- methods: {
- // 获取发票数据
- getInvoiceDetail() {
- uni.showLoading({
- title: '加载中'
- });
- invoiceDetail(this.id).then(res => {
- uni.hideLoading();
- this.header_type = res.data.header_type.toString();
- this.type = res.data.type.toString();
- const invoiceItem = this.invoiceTypeList.find(item => item.value === this.type);
- this.typeName = invoiceItem.name;
- this.name = res.data.name;
- this.drawer_phone = res.data.drawer_phone;
- this.email = res.data.email;
- this.duty_number = res.data.duty_number;
- this.bank = res.data.bank;
- this.card_number = res.data.card_number;
- this.address = res.data.address;
- this.tell = res.data.tell;
- this.is_default = res.data.is_default ? [''] : [];
- }).catch(err => {
- uni.showToast({
- title: err,
- icon: 'none'
- });
- });
- },
- // 保存
- formSubmit(e) {
- const formData = e.detail.value;
- formData.type = this.type;
- if (formData.header_type === '1') {
- if (!formData.name) {
- return uni.showToast({
- title: '请输入需要开具发票的姓名',
- icon: 'none'
- });
- }
- if (!formData.drawer_phone) {
- return uni.showToast({
- title: '请输入您的手机号',
- icon: 'none'
- });
- }
- if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(formData.drawer_phone)) {
- return uni.showToast({
- title: '请正确输入您的手机号',
- icon: 'none'
- });
- }
- if (!formData.email) {
- return uni.showToast({
- title: '请输入您的联系邮箱',
- icon: 'none'
- });
- }
- if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(formData.email)) {
- return uni.showToast({
- title: '请正确输入您的联系邮箱',
- icon: 'none'
- });
- }
- }
- if (formData.header_type === '2') {
- if (formData.type === '1') {
- if (!formData.name) {
- return uni.showToast({
- title: '请输入需要开具发票的企业名称',
- icon: 'none'
- });
- }
- if (!formData.duty_number) {
- return uni.showToast({
- title: '请输入纳税人识别号',
- icon: 'none'
- });
- }
- if (!/[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}/.test(formData.duty_number)) {
- return uni.showToast({
- title: '请正确输入纳税人识别号',
- icon: 'none'
- });
- }
- if (!formData.drawer_phone) {
- return uni.showToast({
- title: '请输入您的手机号',
- icon: 'none'
- });
- }
- if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(formData.drawer_phone)) {
- return uni.showToast({
- title: '请正确输入您的手机号',
- icon: 'none'
- });
- }
- if (!formData.email) {
- return uni.showToast({
- title: '请输入您的联系邮箱',
- icon: 'none'
- });
- }
- if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(formData.email)) {
- return uni.showToast({
- title: '请正确输入您的联系邮箱',
- icon: 'none'
- });
- }
- }
- if (formData.type === '2') {
- if (!formData.name) {
- return uni.showToast({
- title: '请输入需要开具发票的企业名称',
- icon: 'none'
- });
- }
- if (!formData.duty_number) {
- return uni.showToast({
- title: '请输入纳税人识别号',
- icon: 'none'
- });
- }
- if (!/[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}/.test(formData.duty_number)) {
- return uni.showToast({
- title: '请正确输入纳税人识别号',
- icon: 'none'
- });
- }
- if (!formData.drawer_phone) {
- return uni.showToast({
- title: '请输入您的手机号',
- icon: 'none'
- });
- }
- if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(formData.drawer_phone)) {
- return uni.showToast({
- title: '请正确输入您的手机号',
- icon: 'none'
- });
- }
- if (!formData.email) {
- return uni.showToast({
- title: '请输入您的联系邮箱',
- icon: 'none'
- });
- }
- if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(formData.email)) {
- return uni.showToast({
- title: '请正确输入您的联系邮箱',
- icon: 'none'
- });
- }
- if (!formData.bank) {
- return uni.showToast({
- title: '请输入您的开户银行',
- icon: 'none'
- });
- }
- if (!formData.card_number) {
- return uni.showToast({
- title: '请输入您的银行账号',
- icon: 'none'
- });
- }
- if (!/^\d{16}|\d{19}$/.test(formData.card_number)) {
- return uni.showToast({
- title: '请正确输入您的银行账号',
- icon: 'none'
- });
- }
- if (!formData.address) {
- return uni.showToast({
- title: '请输入您所在的企业地址',
- icon: 'none'
- });
- }
- if (!formData.tell) {
- return uni.showToast({
- title: '请输入您的企业电话',
- icon: 'none'
- });
- }
- }
- }
- formData.is_default = formData.is_default.length;
- formData.id = this.id;
- uni.showLoading({
- title: '保存中'
- });
- invoiceSave(formData).then(res => {
- let that = this;
- uni.showToast({
- title: res.msg,
- icon: 'success',
- success() {
- switch (that.from) {
- case 'order_confirm':
- let name = '';
- name += formData.header_type == 1 ? '个人' : '企业';
- name += formData.type == 1 ? '普通' : '专用';
- name += '发票';
- if (that.id) {
- uni.navigateTo({
- url: `/pages/goods/order_confirm/index${that.urlQuery}&invoice_id=${that.id}&invoice_name=${name}`
- })
- } else {
- uni.navigateTo({
- url: `/pages/goods/order_confirm/index${that.urlQuery}&invoice_id=${res.data.id}&invoice_name=${name}`
- })
- }
- break;
- case 'order_details':
- if (that.id) {
- uni.navigateTo({
- url: `/pages/goods/order_details/index?order_id=${that.order_id}&invoice_id=${that.id}`
- })
- } else {
- uni.navigateTo({
- url: `/pages/goods/order_details/index?order_id=${that.order_id}&invoice_id=${res.data.id}`
- })
- }
- break;
- default:
- uni.navigateTo({
- url: '/pages/users/user_invoice_list/index?from=invoice_form'
- });
- break;
- }
- }
- });
- }).catch(err => {
- uni.showToast({
- title: err,
- icon: 'none'
- });
- });
- },
- // 调起发票类型弹窗
- callType() {
- this.popupType = true;
- },
- // 选择发票类型
- changeType(e) {
- const type = e.detail.value,
- invoiceItem = this.invoiceTypeList.find(item => item.value === type);
- if (type === '2' && this.header_type === '1') {
- this.header_type = '2';
- }
- this.typeName = invoiceItem.name;
- this.type = type;
- this.popupType = false;
- },
- // 关闭发票弹窗
- closeType() {
- this.popupType = false;
- },
- // 选择抬头类型
- changeTitleType(e) {
- this.header_type = e.detail.value;
- this.type = '1';
- }
- }
- }
- </script>
- <style scoped>
- /deep/.disabled .uni-radio-input {
- background-color: #F8F8F8;
- }
- form {
- font-size: 28rpx;
- color: #282828;
- }
- form input,
- form radio-group {
- flex: 1;
- margin-left: 30rpx;
- text-align: right;
- }
- form input {
- font-size: 26rpx;
- }
- form label {
- margin-right: 50rpx;
- }
- form radio {
- margin-right: 8rpx;
- }
- form checkbox-group {
- height: 90rpx;
- }
- form checkbox {
- margin-right: 20rpx;
- }
- .panel {
- padding-right: 30rpx;
- padding-left: 30rpx;
- background-color: #FFFFFF;
- }
- .panel~.panel {
- margin-top: 14rpx;
- }
- .panel .acea-row {
- height: 90rpx;
- }
- .panel .acea-row~.acea-row {
- border-top: 1rpx solid #EEEEEE;
- }
- .input-placeholder {
- font-size: 26rpx;
- color: #BBBBBB;
- }
- .icon-xiangyou {
- margin-left: 25rpx;
- font-size: 26rpx;
- color: #BFBFBF;
- margin-top: 2rpx;
- }
- .popup {
- position: fixed;
- bottom: 0;
- left: 0;
- z-index: 99;
- width: 100%;
- padding-bottom: 100rpx;
- border-top-left-radius: 16rpx;
- border-top-right-radius: 16rpx;
- background-color: #F5F5F5;
- overflow: hidden;
- transform: translateY(100%);
- transition: 0.3s;
- }
- .popup.on {
- transform: translateY(0);
- }
- .popup .title {
- position: relative;
- height: 137rpx;
- font-size: 32rpx;
- line-height: 137rpx;
- text-align: center;
- }
- .popup scroll-view {
- height: 466rpx;
- padding-right: 30rpx;
- padding-left: 30rpx;
- box-sizing: border-box;
- }
- .popup label {
- padding: 35rpx 30rpx;
- border-radius: 16rpx;
- margin-bottom: 20rpx;
- background-color: #FFFFFF;
- }
- .popup .text {
- flex: 1;
- min-width: 0;
- font-size: 28rpx;
- color: #282828;
- }
- .popup .info {
- margin-top: 10rpx;
- font-size: 22rpx;
- color: #909090;
- }
- .popup .icon-guanbi {
- position: absolute;
- top: 50%;
- right: 30rpx;
- z-index: 2;
- transform: translateY(-50%);
- font-size: 30rpx;
- color: #707070;
- cursor: pointer;
- }
- .popup .text .acea-row {
- display: inline-flex;
- max-width: 100%;
- }
- .popup .name {
- flex: 1;
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- font-size: 30rpx;
- }
- .popup .label {
- width: 56rpx;
- height: 28rpx;
- border: 1rpx solid #E93323;
- margin-left: 18rpx;
- font-size: 20rpx;
- line-height: 26rpx;
- text-align: center;
- color: #E93323;
- }
- .popup .type {
- width: 124rpx;
- height: 42rpx;
- margin-top: 14rpx;
- background-color: #FCF0E0;
- font-size: 24rpx;
- line-height: 42rpx;
- text-align: center;
- color: #D67300;
- }
- .popup .type.special {
- background-color: #FDE9E7;
- color: #E93323;
- }
- .button-section {
- /* position: fixed;
- bottom: 0;
- left: 0;
- width: 100%; */
- padding: 58rpx 30rpx;
- }
- .button-section .button {
- height: 86rpx;
- border-radius: 43rpx;
- background-color: var(--view-theme);
- font-size: 30rpx;
- line-height: 86rpx;
- color: #FFFFFF;
- }
- .button-section .navigator {
- height: 86rpx;
- border: 1rpx solid var(--view-theme);
- border-radius: 43rpx;
- margin-top: 26rpx;
- font-size: 30rpx;
- line-height: 86rpx;
- text-align: center;
- color: var(--view-theme);
- }
- </style>
|