index.vue 16 KB

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