applyFeisui.vue 7.31 KB
<template>
  <view class="invoice-apply">
    <view class="content">
      <!-- 发票信息标题 -->
      <view class="section-header">
        <text class="section-title">发票信息</text>
        <text class="section-hint">请填写开票信息</text>
      </view>

      <!-- 发票类型 -->
      <view class="form-item">
        <text class="label">发票类型</text>
        <view class="type-select">
          <view
            :class="{ active: form.type === '1' }"
            class="type-option"
            @click="form.type = '1'"
          >
            <view class="type-icon">
              <text class="icon-text"></text>
            </view>
            <view class="type-info">
              <text class="type-name">个人</text>
            </view>
          </view>
          <view
            :class="{ active: form.type === '0' }"
            class="type-option"
            @click="form.type = '0'"
          >
            <view class="type-icon enterprise">
              <text class="icon-text"></text>
            </view>
            <view class="type-info">
              <text class="type-name">企业</text>
            </view>
          </view>
        </view>
      </view>

      <!-- 发票抬头 -->
      <view class="form-item column">
        <text class="label">发票抬头</text>
        <input
          v-model="form.name"
          class="input"
          placeholder="请输入公司全称或个人姓名"
        />
        <text class="hint">请确保发票抬头与公司营业执照或个人身份证上的名称一致</text>
      </view>

      <!-- 纳税人识别号(企业才显示) -->
      <view v-if="form.type === '0'" class="form-item column">
        <text class="label">纳税人识别号</text>
        <input
          v-model="form.taxno"
          class="input"
          maxlength="20"
          placeholder="请输入纳税人识别号"
        />
        <text class="hint">企业税务登记证上的号码,一般为 15、18 或 20 位</text>
      </view>

      <!-- 开票金额(只读) -->
      <!-- <view class="form-item">
        <text class="label">开票金额</text>
        <text class="amount">¥ {{ (Number(form.amount || 0)).toFixed(2) }}</text>
      </view> -->
    </view>

    <!-- 提交按钮 -->
    <view class="btn-wrap">
      <view :class="{ loading: submitting }" class="submit-btn" @click="handleSubmit">
        {{ submitting ? '提交中...' : '提交申请' }}
      </view>
    </view>
  </view>
</template>

<script setup>
import {ref, reactive} from 'vue';
import {onLoad} from '@dcloudio/uni-app';
import {outputInvoiceNoFeisui} from '@/common/api.js';

const submitting = ref(false);

// 表单数据
const form = reactive({
  id: '',           // 订单ID
  name: '',          // 发票抬头
  taxno: '',         // 纳税人识别号
  type: '1',         // 发票类型:1=个人 0=企业
  amount: 0          // 金额
});

// 页面加载
onLoad((options) => {
  if (options.id || options.orderId) {
    form.id = options.id || options.orderId;
    form.amount = options.amount || 0;
  }
  console.log('非税开票参数:', options)
});

// 表单验证
const validateForm = () => {
  // 发票抬头校验
  if (!form.name) {
    uni.showToast({title: '请输入发票抬头', icon: 'none'});
    return false;
  }
  if (form.name.length < 2 || form.name.length > 100) {
    uni.showToast({title: '发票抬头长度在2-100个字符之间', icon: 'none'});
    return false;
  }

  // 企业必须填纳税人识别号
  if (form.type === '0' && !form.taxno) {
    uni.showToast({title: '请输入纳税人识别号', icon: 'none'});
    return false;
  }

  // 纳税人识别号格式校验
  if (form.type === '0') {
    const taxReg = /^[A-Z0-9]{15}$|^[A-Z0-9]{18}$|^[A-Z0-9]{20}$/;
    if (!taxReg.test(form.taxno)) {
      uni.showToast({title: '纳税人识别号格式不正确', icon: 'none'});
      return false;
    }
  }

  return true;
};

// 提交非税发票申请
const handleSubmit = async () => {
  if (submitting.value) return;
  if (!validateForm()) return;

  submitting.value = true;
  console.log('提交非税开票表单数据:', form);
  try {
    await outputInvoiceNoFeisui(form);
    uni.showToast({
      title: '开票申请提交成功',
      icon: 'success'
    });
    setTimeout(() => {
      uni.navigateBack();
    }, 1500);
  } catch (error) {
    console.log('非税开票失败:', error);
    submitting.value = false;
  } finally {
    submitting.value = false;
  }
};
</script>

<style lang="scss" scoped>
.invoice-apply {
  min-height: 100vh;
  background: #f5f7fa;
  // padding-bottom: 140rpx;
}

.content {
  padding: 20rpx;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20rpx 0;
  margin-bottom: 10rpx;

  .section-title {
    font-size: 32rpx;
    font-weight: 600;
    color: #303133;
  }

  .section-hint {
    font-size: 24rpx;
    color: #909399;
    padding: 6rpx 16rpx;
    background: #f5f5f5;
    border-radius: 8rpx;
  }
}

.form-item {
  background: #fff;
  padding: 24rpx;
  margin-bottom: 20rpx;
  border-radius: 16rpx;
  border: 1rpx solid #e9ecef;

  &.column {
    display: flex;
    flex-direction: column;
  }

  .label {
    font-size: 28rpx;
    color: #333;
    font-weight: 500;
    margin-bottom: 16rpx;
  }

  .input {
    width: 100%;
    font-size: 28rpx;
    color: #333;
    padding: 0 24rpx;
    box-sizing: border-box;
    background: transparent;
    min-width: 0;
    text-align: left;
    border: 1rpx solid #e4e7ed;
    border-radius: 8rpx;
    height: 80rpx;
    line-height: 80rpx;

    &::placeholder {
      color: #999;
      font-size: 28rpx;
    }
  }

  .hint {
    font-size: 24rpx;
    color: #909399;
    margin-top: 8rpx;
  }

  .amount {
    font-size: 36rpx;
    color: #AD181F;
    font-weight: 600;
  }
}

/* 发票类型选择 */
.type-select {
  display: flex;
  gap: 20rpx;
  margin-top: 10rpx;
}

.type-option {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 20rpx;
  border: 2rpx solid #e4e7ed;
  border-radius: 12rpx;
  background: #faf4f4;
  transition: all 0.3s;

  &.active {
    border-color: #AD181F;
    background: #faf4f4;
  }

  .type-icon {
    width: 60rpx;
    height: 60rpx;
    background: #fbd9d9;
    border-radius: 8rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 16rpx;

    .icon-text {
      font-size: 28rpx;
      font-weight: 600;
      color: #AD181F;
    }

    &.enterprise {
      background: #fbd9d9;

      .icon-text {
        color: #AD181F;
      }
    }
  }

  &.active .type-icon {
    background: #AD181F;

    .icon-text {
      color: #fff;
    }

    &.enterprise {
      background: #AD181F;
    }
  }

  .type-info {
    display: flex;
    flex-direction: column;

    .type-name {
      font-size: 28rpx;
      font-weight: 600;
      color: #303133;
    }
  }
}

/* 提交按钮 */
.btn-wrap {
  width: 100%;
  background-color: #fff;
  padding: 30rpx;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  box-sizing: border-box;
  box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.05);
}

.submit-btn {
  height: 88rpx;
  line-height: 88rpx;
  border-radius: 44rpx;
  width: 100%;
  background: linear-gradient(135deg, #AD181F 0%, #c42a2a 100%);
  color: #fff;
  font-size: 32rpx;
  text-align: center;
  font-weight: 500;

  &.loading {
    background: #c0c4cc;
  }
}
</style>