index.vue 16 KB

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