index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  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. case 'delivery_type':
  156. case 'store_id':
  157. case 'store_name':
  158. case 'product_id':
  159. this.urlQuery += `${this.urlQuery ? '&' : '?'}${key}=${options[key]}`;
  160. break;
  161. case 'from':
  162. this.from = options[key];
  163. break;
  164. case 'header_type':
  165. this.header_type = options[key];
  166. break;
  167. case 'id':
  168. this.id = options[key];
  169. this.getInvoiceDetail();
  170. break;
  171. case 'specialInvoice':
  172. if (options[key] === 'false') {
  173. this.specialInvoice = false;
  174. }
  175. break;
  176. }
  177. }
  178. if (options.order_id)
  179. this.order_id = options.order_id
  180. const invoiceItem = this.invoiceTypeList.find(item => item.value === this.type);
  181. this.typeName = invoiceItem.name;
  182. },
  183. onShow() {
  184. uni.removeStorageSync('form_type_cart');
  185. },
  186. methods: {
  187. // 获取发票数据
  188. getInvoiceDetail() {
  189. uni.showLoading({
  190. title: '加载中'
  191. });
  192. invoiceDetail(this.id).then(res => {
  193. uni.hideLoading();
  194. this.header_type = res.data.header_type.toString();
  195. this.type = res.data.type.toString();
  196. const invoiceItem = this.invoiceTypeList.find(item => item.value === this.type);
  197. this.typeName = invoiceItem.name;
  198. this.name = res.data.name;
  199. this.drawer_phone = res.data.drawer_phone;
  200. this.email = res.data.email;
  201. this.duty_number = res.data.duty_number;
  202. this.bank = res.data.bank;
  203. this.card_number = res.data.card_number;
  204. this.address = res.data.address;
  205. this.tell = res.data.tell;
  206. this.is_default = res.data.is_default ? [''] : [];
  207. }).catch(err => {
  208. uni.showToast({
  209. title: err,
  210. icon: 'none'
  211. });
  212. });
  213. },
  214. // 保存
  215. formSubmit(e) {
  216. const formData = e.detail.value;
  217. formData.type = this.type;
  218. if (formData.header_type === '1') {
  219. if (!formData.name) {
  220. return uni.showToast({
  221. title: '请输入需要开具发票的姓名',
  222. icon: 'none'
  223. });
  224. }
  225. if (!formData.drawer_phone) {
  226. return uni.showToast({
  227. title: '请输入您的手机号',
  228. icon: 'none'
  229. });
  230. }
  231. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(formData.drawer_phone)) {
  232. return uni.showToast({
  233. title: '请正确输入您的手机号',
  234. icon: 'none'
  235. });
  236. }
  237. if (!formData.email) {
  238. return uni.showToast({
  239. title: '请输入您的联系邮箱',
  240. icon: 'none'
  241. });
  242. }
  243. if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(formData.email)) {
  244. return uni.showToast({
  245. title: '请正确输入您的联系邮箱',
  246. icon: 'none'
  247. });
  248. }
  249. }
  250. if (formData.header_type === '2') {
  251. if (formData.type === '1') {
  252. if (!formData.name) {
  253. return uni.showToast({
  254. title: '请输入需要开具发票的企业名称',
  255. icon: 'none'
  256. });
  257. }
  258. if (!formData.duty_number) {
  259. return uni.showToast({
  260. title: '请输入纳税人识别号',
  261. icon: 'none'
  262. });
  263. }
  264. if (!/[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}/.test(formData.duty_number)) {
  265. return uni.showToast({
  266. title: '请正确输入纳税人识别号',
  267. icon: 'none'
  268. });
  269. }
  270. if (!formData.drawer_phone) {
  271. return uni.showToast({
  272. title: '请输入您的手机号',
  273. icon: 'none'
  274. });
  275. }
  276. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(formData.drawer_phone)) {
  277. return uni.showToast({
  278. title: '请正确输入您的手机号',
  279. icon: 'none'
  280. });
  281. }
  282. if (!formData.email) {
  283. return uni.showToast({
  284. title: '请输入您的联系邮箱',
  285. icon: 'none'
  286. });
  287. }
  288. if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(formData.email)) {
  289. return uni.showToast({
  290. title: '请正确输入您的联系邮箱',
  291. icon: 'none'
  292. });
  293. }
  294. }
  295. if (formData.type === '2') {
  296. if (!formData.name) {
  297. return uni.showToast({
  298. title: '请输入需要开具发票的企业名称',
  299. icon: 'none'
  300. });
  301. }
  302. if (!formData.duty_number) {
  303. return uni.showToast({
  304. title: '请输入纳税人识别号',
  305. icon: 'none'
  306. });
  307. }
  308. if (!/[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}/.test(formData.duty_number)) {
  309. return uni.showToast({
  310. title: '请正确输入纳税人识别号',
  311. icon: 'none'
  312. });
  313. }
  314. if (!formData.drawer_phone) {
  315. return uni.showToast({
  316. title: '请输入您的手机号',
  317. icon: 'none'
  318. });
  319. }
  320. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(formData.drawer_phone)) {
  321. return uni.showToast({
  322. title: '请正确输入您的手机号',
  323. icon: 'none'
  324. });
  325. }
  326. if (!formData.email) {
  327. return uni.showToast({
  328. title: '请输入您的联系邮箱',
  329. icon: 'none'
  330. });
  331. }
  332. if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(formData.email)) {
  333. return uni.showToast({
  334. title: '请正确输入您的联系邮箱',
  335. icon: 'none'
  336. });
  337. }
  338. if (!formData.bank) {
  339. return uni.showToast({
  340. title: '请输入您的开户银行',
  341. icon: 'none'
  342. });
  343. }
  344. if (!formData.card_number) {
  345. return uni.showToast({
  346. title: '请输入您的银行账号',
  347. icon: 'none'
  348. });
  349. }
  350. if (!/^\d{16}|\d{19}$/.test(formData.card_number)) {
  351. return uni.showToast({
  352. title: '请正确输入您的银行账号',
  353. icon: 'none'
  354. });
  355. }
  356. if (!formData.address) {
  357. return uni.showToast({
  358. title: '请输入您所在的企业地址',
  359. icon: 'none'
  360. });
  361. }
  362. if (!formData.tell) {
  363. return uni.showToast({
  364. title: '请输入您的企业电话',
  365. icon: 'none'
  366. });
  367. }
  368. }
  369. }
  370. formData.is_default = formData.is_default.length;
  371. formData.id = this.id;
  372. uni.showLoading({
  373. title: '保存中'
  374. });
  375. invoiceSave(formData).then(res => {
  376. let that = this;
  377. uni.showToast({
  378. title: res.msg,
  379. icon: 'success',
  380. success() {
  381. switch (that.from) {
  382. case 'order_confirm':
  383. let name = '';
  384. name += formData.header_type == 1 ? '个人' : '企业';
  385. name += formData.type == 1 ? '普通' : '专用';
  386. name += '发票';
  387. if (that.id) {
  388. uni.navigateTo({
  389. url: `/pages/goods/order_confirm/index${that.urlQuery}&invoice_id=${that.id}&invoice_name=${name}`
  390. })
  391. } else {
  392. uni.navigateTo({
  393. url: `/pages/goods/order_confirm/index${that.urlQuery}&invoice_id=${res.data.id}&invoice_name=${name}`
  394. })
  395. }
  396. break;
  397. case 'order_details':
  398. if (that.id) {
  399. uni.navigateTo({
  400. url: `/pages/goods/order_details/index?order_id=${that.order_id}&invoice_id=${that.id}`
  401. })
  402. } else {
  403. uni.navigateTo({
  404. url: `/pages/goods/order_details/index?order_id=${that.order_id}&invoice_id=${res.data.id}`
  405. })
  406. }
  407. break;
  408. default:
  409. uni.navigateTo({
  410. url: '/pages/users/user_invoice_list/index?from=invoice_form'
  411. });
  412. break;
  413. }
  414. }
  415. });
  416. }).catch(err => {
  417. uni.showToast({
  418. title: err,
  419. icon: 'none'
  420. });
  421. });
  422. },
  423. // 调起发票类型弹窗
  424. callType() {
  425. this.popupType = true;
  426. },
  427. // 选择发票类型
  428. changeType(e) {
  429. const type = e.detail.value,
  430. invoiceItem = this.invoiceTypeList.find(item => item.value === type);
  431. if (type === '2' && this.header_type === '1') {
  432. this.header_type = '2';
  433. }
  434. this.typeName = invoiceItem.name;
  435. this.type = type;
  436. this.popupType = false;
  437. },
  438. // 关闭发票弹窗
  439. closeType() {
  440. this.popupType = false;
  441. },
  442. // 选择抬头类型
  443. changeTitleType(e) {
  444. this.header_type = e.detail.value;
  445. this.type = '1';
  446. }
  447. }
  448. }
  449. </script>
  450. <style scoped>
  451. /deep/.disabled .uni-radio-input {
  452. background-color: #F8F8F8;
  453. }
  454. form {
  455. font-size: 28rpx;
  456. color: #282828;
  457. }
  458. form input,
  459. form radio-group {
  460. flex: 1;
  461. margin-left: 30rpx;
  462. text-align: right;
  463. }
  464. form input {
  465. font-size: 26rpx;
  466. }
  467. form label {
  468. margin-right: 50rpx;
  469. }
  470. form radio {
  471. margin-right: 8rpx;
  472. }
  473. form checkbox-group {
  474. height: 90rpx;
  475. }
  476. form checkbox {
  477. margin-right: 20rpx;
  478. }
  479. .panel {
  480. padding-right: 30rpx;
  481. padding-left: 30rpx;
  482. background-color: #FFFFFF;
  483. }
  484. .panel~.panel {
  485. margin-top: 14rpx;
  486. }
  487. .panel .acea-row {
  488. height: 90rpx;
  489. }
  490. .panel .acea-row~.acea-row {
  491. border-top: 1rpx solid #EEEEEE;
  492. }
  493. .input-placeholder {
  494. font-size: 26rpx;
  495. color: #BBBBBB;
  496. }
  497. .icon-xiangyou {
  498. margin-left: 25rpx;
  499. font-size: 26rpx;
  500. color: #BFBFBF;
  501. margin-top: 2rpx;
  502. }
  503. .popup {
  504. position: fixed;
  505. bottom: 0;
  506. left: 0;
  507. z-index: 99;
  508. width: 100%;
  509. padding-bottom: 100rpx;
  510. border-top-left-radius: 16rpx;
  511. border-top-right-radius: 16rpx;
  512. background-color: #F5F5F5;
  513. overflow: hidden;
  514. transform: translateY(100%);
  515. transition: 0.3s;
  516. }
  517. .popup.on {
  518. transform: translateY(0);
  519. }
  520. .popup .title {
  521. position: relative;
  522. height: 137rpx;
  523. font-size: 32rpx;
  524. line-height: 137rpx;
  525. text-align: center;
  526. }
  527. .popup scroll-view {
  528. height: 466rpx;
  529. padding-right: 30rpx;
  530. padding-left: 30rpx;
  531. box-sizing: border-box;
  532. }
  533. .popup label {
  534. padding: 35rpx 30rpx;
  535. border-radius: 16rpx;
  536. margin-bottom: 20rpx;
  537. background-color: #FFFFFF;
  538. }
  539. .popup .text {
  540. flex: 1;
  541. min-width: 0;
  542. font-size: 28rpx;
  543. color: #282828;
  544. }
  545. .popup .info {
  546. margin-top: 10rpx;
  547. font-size: 22rpx;
  548. color: #909090;
  549. }
  550. .popup .icon-guanbi {
  551. position: absolute;
  552. top: 50%;
  553. right: 30rpx;
  554. z-index: 2;
  555. transform: translateY(-50%);
  556. font-size: 30rpx;
  557. color: #707070;
  558. cursor: pointer;
  559. }
  560. .popup .text .acea-row {
  561. display: inline-flex;
  562. max-width: 100%;
  563. }
  564. .popup .name {
  565. flex: 1;
  566. overflow: hidden;
  567. white-space: nowrap;
  568. text-overflow: ellipsis;
  569. font-size: 30rpx;
  570. }
  571. .popup .label {
  572. width: 56rpx;
  573. height: 28rpx;
  574. border: 1rpx solid #E93323;
  575. margin-left: 18rpx;
  576. font-size: 20rpx;
  577. line-height: 26rpx;
  578. text-align: center;
  579. color: #E93323;
  580. }
  581. .popup .type {
  582. width: 124rpx;
  583. height: 42rpx;
  584. margin-top: 14rpx;
  585. background-color: #FCF0E0;
  586. font-size: 24rpx;
  587. line-height: 42rpx;
  588. text-align: center;
  589. color: #D67300;
  590. }
  591. .popup .type.special {
  592. background-color: #FDE9E7;
  593. color: #E93323;
  594. }
  595. .button-section {
  596. /* position: fixed;
  597. bottom: 0;
  598. left: 0;
  599. width: 100%; */
  600. padding: 58rpx 30rpx;
  601. }
  602. .button-section .button {
  603. height: 86rpx;
  604. border-radius: 43rpx;
  605. background-color: var(--view-theme);
  606. font-size: 30rpx;
  607. line-height: 86rpx;
  608. color: #FFFFFF;
  609. }
  610. .button-section .navigator {
  611. height: 86rpx;
  612. border: 1rpx solid var(--view-theme);
  613. border-radius: 43rpx;
  614. margin-top: 26rpx;
  615. font-size: 30rpx;
  616. line-height: 86rpx;
  617. text-align: center;
  618. color: var(--view-theme);
  619. }
  620. </style>