index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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 (!/^(^[0-9]*$)|(^[\w]+$)/.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. .panel input{
  452. height: 90rpx;
  453. }
  454. /deep/.disabled .uni-radio-input {
  455. background-color: #F8F8F8;
  456. }
  457. form {
  458. font-size: 28rpx;
  459. color: #282828;
  460. }
  461. form input,
  462. form radio-group {
  463. flex: 1;
  464. margin-left: 30rpx;
  465. text-align: right;
  466. }
  467. form input {
  468. font-size: 26rpx;
  469. }
  470. form label {
  471. margin-right: 50rpx;
  472. }
  473. form radio {
  474. margin-right: 8rpx;
  475. }
  476. form checkbox-group {
  477. height: 90rpx;
  478. }
  479. form checkbox {
  480. margin-right: 20rpx;
  481. }
  482. .panel {
  483. padding-right: 30rpx;
  484. padding-left: 30rpx;
  485. background-color: #FFFFFF;
  486. }
  487. .panel~.panel {
  488. margin-top: 14rpx;
  489. }
  490. .panel .acea-row {
  491. height: 90rpx;
  492. }
  493. .panel .acea-row~.acea-row {
  494. border-top: 1rpx solid #EEEEEE;
  495. }
  496. .input-placeholder {
  497. font-size: 26rpx;
  498. color: #BBBBBB;
  499. }
  500. .icon-xiangyou {
  501. margin-left: 25rpx;
  502. font-size: 26rpx;
  503. color: #BFBFBF;
  504. margin-top: 2rpx;
  505. }
  506. .popup {
  507. position: fixed;
  508. bottom: 0;
  509. left: 0;
  510. z-index: 99;
  511. width: 100%;
  512. padding-bottom: 100rpx;
  513. border-top-left-radius: 16rpx;
  514. border-top-right-radius: 16rpx;
  515. background-color: #F5F5F5;
  516. overflow: hidden;
  517. transform: translateY(100%);
  518. transition: 0.3s;
  519. }
  520. .popup.on {
  521. transform: translateY(0);
  522. }
  523. .popup .title {
  524. position: relative;
  525. height: 137rpx;
  526. font-size: 32rpx;
  527. line-height: 137rpx;
  528. text-align: center;
  529. }
  530. .popup scroll-view {
  531. height: 466rpx;
  532. padding-right: 30rpx;
  533. padding-left: 30rpx;
  534. box-sizing: border-box;
  535. }
  536. .popup label {
  537. padding: 35rpx 30rpx;
  538. border-radius: 16rpx;
  539. margin-bottom: 20rpx;
  540. background-color: #FFFFFF;
  541. }
  542. .popup .text {
  543. flex: 1;
  544. min-width: 0;
  545. font-size: 28rpx;
  546. color: #282828;
  547. }
  548. .popup .info {
  549. margin-top: 10rpx;
  550. font-size: 22rpx;
  551. color: #909090;
  552. }
  553. .popup .icon-guanbi {
  554. position: absolute;
  555. top: 50%;
  556. right: 30rpx;
  557. z-index: 2;
  558. transform: translateY(-50%);
  559. font-size: 30rpx;
  560. color: #707070;
  561. cursor: pointer;
  562. }
  563. .popup .text .acea-row {
  564. display: inline-flex;
  565. max-width: 100%;
  566. }
  567. .popup .name {
  568. flex: 1;
  569. overflow: hidden;
  570. white-space: nowrap;
  571. text-overflow: ellipsis;
  572. font-size: 30rpx;
  573. }
  574. .popup .label {
  575. width: 56rpx;
  576. height: 28rpx;
  577. border: 1rpx solid #E93323;
  578. margin-left: 18rpx;
  579. font-size: 20rpx;
  580. line-height: 26rpx;
  581. text-align: center;
  582. color: #E93323;
  583. }
  584. .popup .type {
  585. width: 124rpx;
  586. height: 42rpx;
  587. margin-top: 14rpx;
  588. background-color: #FCF0E0;
  589. font-size: 24rpx;
  590. line-height: 42rpx;
  591. text-align: center;
  592. color: #D67300;
  593. }
  594. .popup .type.special {
  595. background-color: #FDE9E7;
  596. color: #E93323;
  597. }
  598. .button-section {
  599. /* position: fixed;
  600. bottom: 0;
  601. left: 0;
  602. width: 100%; */
  603. padding: 58rpx 30rpx;
  604. }
  605. .button-section .button {
  606. height: 86rpx;
  607. border-radius: 43rpx;
  608. background-color: var(--view-theme);
  609. font-size: 30rpx;
  610. line-height: 86rpx;
  611. color: #FFFFFF;
  612. }
  613. .button-section .navigator {
  614. height: 86rpx;
  615. border: 1rpx solid var(--view-theme);
  616. border-radius: 43rpx;
  617. margin-top: 26rpx;
  618. font-size: 30rpx;
  619. line-height: 86rpx;
  620. text-align: center;
  621. color: var(--view-theme);
  622. }
  623. </style>