index.vue 17 KB

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