index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. <template>
  2. <!-- 添加新发票 -->
  3. <view :style="colorStyle">
  4. <form @submit="formSubmit">
  5. <view class="panel">
  6. <view class="acea-row row-middle">
  7. <view>抬头类型</view>
  8. <radio-group name="header_type" @change="changeTitleType">
  9. <label>
  10. <radio class="disabled" value="1" :checked="header_type === '1'" /><text>个人</text>
  11. </label>
  12. <label>
  13. <radio value="2" :checked="header_type === '2'" /><text>企业</text>
  14. </label>
  15. </radio-group>
  16. </view>
  17. <view class="acea-row row-middle">
  18. <view>发票类型</view>
  19. <input name="type" :value="type === '2' && header_type === '2' ? '增值税电子专用发票' : '增值税电子普通发票'" disabled
  20. @click="callType" />
  21. <text class="iconfont icon-xiangyou"></text>
  22. </view>
  23. <view class="acea-row row-middle">
  24. <view>发票抬头</view>
  25. <input name="name" :value="name" :placeholder="header_type === '1' ? '需要开具发票的姓名' : '需要开具发票的企业名称'" />
  26. </view>
  27. <view v-show="header_type === '2'" class="acea-row row-middle">
  28. <view>税号</view>
  29. <input name="duty_number" :value="duty_number" placeholder="纳税人识别号" />
  30. </view>
  31. <view class="acea-row row-middle">
  32. <view>手机号</view>
  33. <input name="drawer_phone" :value="drawer_phone" placeholder="您的手机号" />
  34. </view>
  35. <view class="acea-row row-middle">
  36. <view>邮箱</view>
  37. <input name="email" :value="email" placeholder="您的联系邮箱" />
  38. </view>
  39. </view>
  40. <view v-show="type === '2'" class="panel">
  41. <view class="acea-row row-middle">
  42. <view>开户银行</view>
  43. <input name="bank" :value="bank" placeholder="您的开户银行" />
  44. </view>
  45. <view class="acea-row row-middle">
  46. <view>银行账号</view>
  47. <input name="card_number" :value="card_number" placeholder="您的银行账号" />
  48. </view>
  49. <view class="acea-row row-middle">
  50. <view>企业地址</view>
  51. <input name="address" :value="address" placeholder="您所在的企业地址" />
  52. </view>
  53. <view class="acea-row row-middle">
  54. <view>企业电话</view>
  55. <input name="tell" :value="tell" placeholder="您的企业电话" />
  56. </view>
  57. </view>
  58. <checkbox-group class="acea-row row-middle panel" name="is_default">
  59. <label>
  60. <checkbox :checked="is_default.length !== 0" /><text>设置为默认抬头</text>
  61. </label>
  62. </checkbox-group>
  63. <view class="button-section">
  64. <button class="button" form-type="submit">保存</button>
  65. <navigator class="navigator" :url="backUrl" hover-class="none">取消</navigator>
  66. </view>
  67. </form>
  68. <view :class="{ mask: popupType }"></view>
  69. <view class="popup" :class="{ on: popupType }">
  70. <view class="title">发票类型选择<text class="iconfont icon-guanbi" @click="closeType"></text></view>
  71. <scroll-view scroll-y="true">
  72. <radio-group name="invoice-type" @change="changeType">
  73. <template v-for="item in invoiceTypeList">
  74. <label v-if="item.value === '1' || item.value === '2' && specialInvoice" :key="item.type"
  75. class="acea-row row-middle">
  76. <view class="text">
  77. <view>{{ item.name }}</view>
  78. <view class="info">{{ item.info }}</view>
  79. </view>
  80. <radio :value="item.value" :checked="item.value === type" />
  81. </label>
  82. </template>
  83. </radio-group>
  84. </scroll-view>
  85. </view>
  86. <home v-if="navigation"></home>
  87. </view>
  88. </template>
  89. <script>
  90. import home from '@/components/home';
  91. import {
  92. invoiceSave,
  93. invoiceDetail
  94. } from '@/api/user.js';
  95. import colors from '@/mixins/color.js';
  96. export default {
  97. components: {
  98. home
  99. },
  100. mixins: [colors],
  101. data() {
  102. return {
  103. invoiceTypeList: [{
  104. name: '增值税电子普通发票',
  105. value: '1',
  106. info: '纸质发票开出后将以邮寄形式交付'
  107. },
  108. {
  109. name: '增值税电子专用发票',
  110. value: '2',
  111. info: '纸质发票开出后将以邮寄形式交付'
  112. }
  113. ],
  114. id: '', // 修改时为必须参数
  115. header_type: '1', // 抬头类型1: 个人2: 企业
  116. type: '1', // 发票类型1:普通2:专用
  117. drawer_phone: '', // 开票人手机号
  118. name: '', // 名称(发票抬头)
  119. duty_number: '', // 税号(个人为非必需,企业是必需参数)
  120. tell: '', // 公司注册电话
  121. address: '', // 注册地址
  122. bank: '', // 开户行
  123. card_number: '', // 银行卡号
  124. is_default: [], // 是否默认
  125. email: '', // 邮箱
  126. popupType: false,
  127. typeName: '',
  128. urlQuery: '',
  129. from: '',
  130. specialInvoice: true,
  131. order_id: ''
  132. };
  133. },
  134. computed: {
  135. backUrl() {
  136. switch (this.from) {
  137. case 'order_confirm':
  138. return `/pages/goods/order_confirm/index${this.urlQuery}`;
  139. break;
  140. default:
  141. return '/pages/users/user_invoice_list/index?from=invoice_form';
  142. break;
  143. }
  144. }
  145. },
  146. onLoad(options) {
  147. for (let key in options) {
  148. switch (key) {
  149. case 'couponTitle':
  150. case 'new':
  151. case 'cartId':
  152. case 'pinkId':
  153. case 'couponId':
  154. case 'addressId':
  155. this.urlQuery += `${this.urlQuery ? '&' : '?'}${key}=${options[key]}`;
  156. break;
  157. case 'from':
  158. this.from = options[key];
  159. break;
  160. case 'header_type':
  161. this.header_type = options[key];
  162. break;
  163. case 'id':
  164. this.id = options[key];
  165. this.getInvoiceDetail();
  166. break;
  167. case 'specialInvoice':
  168. if (options[key] === 'false') {
  169. this.specialInvoice = false;
  170. }
  171. break;
  172. }
  173. }
  174. if (options.order_id)
  175. this.order_id = options.order_id
  176. const invoiceItem = this.invoiceTypeList.find(item => item.value === this.type);
  177. this.typeName = invoiceItem.name;
  178. },
  179. onShow() {
  180. uni.removeStorageSync('form_type_cart');
  181. },
  182. methods: {
  183. // 获取发票数据
  184. getInvoiceDetail() {
  185. uni.showLoading({
  186. title: '加载中'
  187. });
  188. invoiceDetail(this.id).then(res => {
  189. uni.hideLoading();
  190. this.header_type = res.data.header_type.toString();
  191. this.type = res.data.type.toString();
  192. const invoiceItem = this.invoiceTypeList.find(item => item.value === this.type);
  193. this.typeName = invoiceItem.name;
  194. this.name = res.data.name;
  195. this.drawer_phone = res.data.drawer_phone;
  196. this.email = res.data.email;
  197. this.duty_number = res.data.duty_number;
  198. this.bank = res.data.bank;
  199. this.card_number = res.data.card_number;
  200. this.address = res.data.address;
  201. this.tell = res.data.tell;
  202. this.is_default = res.data.is_default ? [''] : [];
  203. }).catch(err => {
  204. uni.showToast({
  205. title: err,
  206. icon: 'none'
  207. });
  208. });
  209. },
  210. // 保存
  211. formSubmit(e) {
  212. const formData = e.detail.value;
  213. formData.type = this.type;
  214. if (formData.header_type === '1') {
  215. if (!formData.name) {
  216. return uni.showToast({
  217. title: '请输入需要开具发票的姓名',
  218. icon: 'none'
  219. });
  220. }
  221. if (!formData.drawer_phone) {
  222. return uni.showToast({
  223. title: '请输入您的手机号',
  224. icon: 'none'
  225. });
  226. }
  227. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(formData.drawer_phone)) {
  228. return uni.showToast({
  229. title: '请正确输入您的手机号',
  230. icon: 'none'
  231. });
  232. }
  233. if (!formData.email) {
  234. return uni.showToast({
  235. title: '请输入您的联系邮箱',
  236. icon: 'none'
  237. });
  238. }
  239. if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(formData.email)) {
  240. return uni.showToast({
  241. title: '请正确输入您的联系邮箱',
  242. icon: 'none'
  243. });
  244. }
  245. }
  246. if (formData.header_type === '2') {
  247. if (formData.type === '1') {
  248. if (!formData.name) {
  249. return uni.showToast({
  250. title: '请输入需要开具发票的企业名称',
  251. icon: 'none'
  252. });
  253. }
  254. if (!formData.duty_number) {
  255. return uni.showToast({
  256. title: '请输入纳税人识别号',
  257. icon: 'none'
  258. });
  259. }
  260. if (!/[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}/.test(formData.duty_number)) {
  261. return uni.showToast({
  262. title: '请正确输入纳税人识别号',
  263. icon: 'none'
  264. });
  265. }
  266. if (!formData.drawer_phone) {
  267. return uni.showToast({
  268. title: '请输入您的手机号',
  269. icon: 'none'
  270. });
  271. }
  272. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(formData.drawer_phone)) {
  273. return uni.showToast({
  274. title: '请正确输入您的手机号',
  275. icon: 'none'
  276. });
  277. }
  278. if (!formData.email) {
  279. return uni.showToast({
  280. title: '请输入您的联系邮箱',
  281. icon: 'none'
  282. });
  283. }
  284. if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(formData.email)) {
  285. return uni.showToast({
  286. title: '请正确输入您的联系邮箱',
  287. icon: 'none'
  288. });
  289. }
  290. }
  291. if (formData.type === '2') {
  292. if (!formData.name) {
  293. return uni.showToast({
  294. title: '请输入需要开具发票的企业名称',
  295. icon: 'none'
  296. });
  297. }
  298. if (!formData.duty_number) {
  299. return uni.showToast({
  300. title: '请输入纳税人识别号',
  301. icon: 'none'
  302. });
  303. }
  304. if (!/[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}/.test(formData.duty_number)) {
  305. return uni.showToast({
  306. title: '请正确输入纳税人识别号',
  307. icon: 'none'
  308. });
  309. }
  310. if (!formData.drawer_phone) {
  311. return uni.showToast({
  312. title: '请输入您的手机号',
  313. icon: 'none'
  314. });
  315. }
  316. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(formData.drawer_phone)) {
  317. return uni.showToast({
  318. title: '请正确输入您的手机号',
  319. icon: 'none'
  320. });
  321. }
  322. if (!formData.email) {
  323. return uni.showToast({
  324. title: '请输入您的联系邮箱',
  325. icon: 'none'
  326. });
  327. }
  328. if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(formData.email)) {
  329. return uni.showToast({
  330. title: '请正确输入您的联系邮箱',
  331. icon: 'none'
  332. });
  333. }
  334. if (!formData.bank) {
  335. return uni.showToast({
  336. title: '请输入您的开户银行',
  337. icon: 'none'
  338. });
  339. }
  340. if (!formData.card_number) {
  341. return uni.showToast({
  342. title: '请输入您的银行账号',
  343. icon: 'none'
  344. });
  345. }
  346. if (!/^\d{16}|\d{19}$/.test(formData.card_number)) {
  347. return uni.showToast({
  348. title: '请正确输入您的银行账号',
  349. icon: 'none'
  350. });
  351. }
  352. if (!formData.address) {
  353. return uni.showToast({
  354. title: '请输入您所在的企业地址',
  355. icon: 'none'
  356. });
  357. }
  358. if (!formData.tell) {
  359. return uni.showToast({
  360. title: '请输入您的企业电话',
  361. icon: 'none'
  362. });
  363. }
  364. }
  365. }
  366. formData.is_default = formData.is_default.length;
  367. formData.id = this.id;
  368. uni.showLoading({
  369. title: '保存中'
  370. });
  371. invoiceSave(formData).then(res => {
  372. let that = this;
  373. uni.showToast({
  374. title: res.msg,
  375. icon: 'success',
  376. success() {
  377. switch (that.from) {
  378. case 'order_confirm':
  379. let name = '';
  380. name += formData.header_type == 1 ? '个人' : '企业';
  381. name += formData.type == 1 ? '普通' : '专用';
  382. name += '发票';
  383. if (that.id) {
  384. uni.navigateTo({
  385. url: `/pages/goods/order_confirm/index${that.urlQuery}&invoice_id=${that.id}&invoice_name=${name}`
  386. })
  387. } else {
  388. uni.navigateTo({
  389. url: `/pages/goods/order_confirm/index${that.urlQuery}&invoice_id=${res.data.id}&invoice_name=${name}`
  390. })
  391. }
  392. break;
  393. case 'order_details':
  394. if (that.id) {
  395. uni.navigateTo({
  396. url: `/pages/goods/order_details/index?order_id=${that.order_id}&invoice_id=${that.id}`
  397. })
  398. } else {
  399. uni.navigateTo({
  400. url: `/pages/goods/order_details/index?order_id=${that.order_id}&invoice_id=${res.data.id}`
  401. })
  402. }
  403. break;
  404. default:
  405. uni.navigateTo({
  406. url: '/pages/users/user_invoice_list/index?from=invoice_form'
  407. });
  408. break;
  409. }
  410. }
  411. });
  412. }).catch(err => {
  413. uni.showToast({
  414. title: err,
  415. icon: 'none'
  416. });
  417. });
  418. },
  419. // 调起发票类型弹窗
  420. callType() {
  421. this.popupType = true;
  422. },
  423. // 选择发票类型
  424. changeType(e) {
  425. const type = e.detail.value,
  426. invoiceItem = this.invoiceTypeList.find(item => item.value === type);
  427. if (type === '2' && this.header_type === '1') {
  428. this.header_type = '2';
  429. }
  430. this.typeName = invoiceItem.name;
  431. this.type = type;
  432. this.popupType = false;
  433. },
  434. // 关闭发票弹窗
  435. closeType() {
  436. this.popupType = false;
  437. },
  438. // 选择抬头类型
  439. changeTitleType(e) {
  440. this.header_type = e.detail.value;
  441. this.type = '1';
  442. }
  443. }
  444. }
  445. </script>
  446. <style scoped>
  447. /deep/.disabled .uni-radio-input {
  448. background-color: #F8F8F8;
  449. }
  450. form {
  451. font-size: 28rpx;
  452. color: #282828;
  453. }
  454. form input,
  455. form radio-group {
  456. flex: 1;
  457. margin-left: 30rpx;
  458. text-align: right;
  459. }
  460. form input {
  461. font-size: 26rpx;
  462. }
  463. form label {
  464. margin-right: 50rpx;
  465. }
  466. form radio {
  467. margin-right: 8rpx;
  468. }
  469. form checkbox-group {
  470. height: 90rpx;
  471. }
  472. form checkbox {
  473. margin-right: 20rpx;
  474. }
  475. .panel {
  476. padding-right: 30rpx;
  477. padding-left: 30rpx;
  478. background-color: #FFFFFF;
  479. }
  480. .panel~.panel {
  481. margin-top: 14rpx;
  482. }
  483. .panel .acea-row {
  484. height: 90rpx;
  485. }
  486. .panel .acea-row~.acea-row {
  487. border-top: 1rpx solid #EEEEEE;
  488. }
  489. .input-placeholder {
  490. font-size: 26rpx;
  491. color: #BBBBBB;
  492. }
  493. .icon-xiangyou {
  494. margin-left: 25rpx;
  495. font-size: 26rpx;
  496. color: #BFBFBF;
  497. margin-top: 2rpx;
  498. }
  499. .popup {
  500. position: fixed;
  501. bottom: 0;
  502. left: 0;
  503. z-index: 99;
  504. width: 100%;
  505. padding-bottom: 100rpx;
  506. border-top-left-radius: 16rpx;
  507. border-top-right-radius: 16rpx;
  508. background-color: #F5F5F5;
  509. overflow: hidden;
  510. transform: translateY(100%);
  511. transition: 0.3s;
  512. }
  513. .popup.on {
  514. transform: translateY(0);
  515. }
  516. .popup .title {
  517. position: relative;
  518. height: 137rpx;
  519. font-size: 32rpx;
  520. line-height: 137rpx;
  521. text-align: center;
  522. }
  523. .popup scroll-view {
  524. height: 466rpx;
  525. padding-right: 30rpx;
  526. padding-left: 30rpx;
  527. box-sizing: border-box;
  528. }
  529. .popup label {
  530. padding: 35rpx 30rpx;
  531. border-radius: 16rpx;
  532. margin-bottom: 20rpx;
  533. background-color: #FFFFFF;
  534. }
  535. .popup .text {
  536. flex: 1;
  537. min-width: 0;
  538. font-size: 28rpx;
  539. color: #282828;
  540. }
  541. .popup .info {
  542. margin-top: 10rpx;
  543. font-size: 22rpx;
  544. color: #909090;
  545. }
  546. .popup .icon-guanbi {
  547. position: absolute;
  548. top: 50%;
  549. right: 30rpx;
  550. z-index: 2;
  551. transform: translateY(-50%);
  552. font-size: 30rpx;
  553. color: #707070;
  554. cursor: pointer;
  555. }
  556. .popup .text .acea-row {
  557. display: inline-flex;
  558. max-width: 100%;
  559. }
  560. .popup .name {
  561. flex: 1;
  562. overflow: hidden;
  563. white-space: nowrap;
  564. text-overflow: ellipsis;
  565. font-size: 30rpx;
  566. }
  567. .popup .label {
  568. width: 56rpx;
  569. height: 28rpx;
  570. border: 1rpx solid #E93323;
  571. margin-left: 18rpx;
  572. font-size: 20rpx;
  573. line-height: 26rpx;
  574. text-align: center;
  575. color: #E93323;
  576. }
  577. .popup .type {
  578. width: 124rpx;
  579. height: 42rpx;
  580. margin-top: 14rpx;
  581. background-color: #FCF0E0;
  582. font-size: 24rpx;
  583. line-height: 42rpx;
  584. text-align: center;
  585. color: #D67300;
  586. }
  587. .popup .type.special {
  588. background-color: #FDE9E7;
  589. color: #E93323;
  590. }
  591. .button-section {
  592. /* position: fixed;
  593. bottom: 0;
  594. left: 0;
  595. width: 100%; */
  596. padding: 58rpx 30rpx;
  597. }
  598. .button-section .button {
  599. height: 86rpx;
  600. border-radius: 43rpx;
  601. background-color: var(--view-theme);
  602. font-size: 30rpx;
  603. line-height: 86rpx;
  604. color: #FFFFFF;
  605. }
  606. .button-section .navigator {
  607. height: 86rpx;
  608. border: 1rpx solid var(--view-theme);
  609. border-radius: 43rpx;
  610. margin-top: 26rpx;
  611. font-size: 30rpx;
  612. line-height: 86rpx;
  613. text-align: center;
  614. color: var(--view-theme);
  615. }
  616. </style>