index.vue 17 KB

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