index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. <template>
  2. <view :style="viewColor">
  3. <view class="add_invoicing" :class="invoice.invoice==true?'on':''">
  4. <view class='title'>选择发票<text class='iconfont icon-guanbi' @tap='close'></text></view>
  5. <form @submit="formSubmit" report-submit="true">
  6. <view class="panel">
  7. <view v-if="receipt_title_type == '1'" class="acea-row row-middle">
  8. <view>发票类型</view>
  9. <input name="receipt_type" :value="typeName" disabled="true" />
  10. </view>
  11. <view v-if="receipt_title_type == '2'" class="acea-row row-middle">
  12. <view>发票类型</view>
  13. <input name="receipt_type" :value="typeName" disabled="true" @click="callType" />
  14. <text class="iconfont icon-xiangyou"></text>
  15. </view>
  16. <view class="acea-row row-middle">
  17. <view>抬头类型</view>
  18. <radio-group name="receipt_title_type" @change="changeHeader">
  19. <label>
  20. <radio value="1" :checked="receipt_title_type == '1' ? true : false" /><text>个人</text>
  21. </label>
  22. <label>
  23. <radio value="2" :checked="receipt_title_type == '2' ? true : false" /><text>企业</text>
  24. </label>
  25. </radio-group>
  26. </view>
  27. <view class="acea-row row-middle">
  28. <view>发票抬头</view>
  29. <input name="receipt_title" :value="receipt_title" :maxlength="20" placeholder="需要开具发票的企业名称"/>
  30. <text class="iconfont icon-xiangyou" @click="callTitle" ></text>
  31. </view>
  32. <view v-show="receipt_title_type == '2'" class="acea-row row-middle">
  33. <view>税号</view>
  34. <input name="duty_paragraph" :value="duty_paragraph" placeholder="纳税人识别号" />
  35. </view>
  36. <view class="acea-row row-middle">
  37. <view>邮箱</view>
  38. <input name="email" :value="email" placeholder="您的联系邮箱" />
  39. </view>
  40. </view>
  41. <view v-show="receipt_title_type == '2' && receipt_type == '2'" class="panel">
  42. <view class="acea-row row-middle">
  43. <view>开户银行</view>
  44. <input name="bank_name" :value="bank_name" placeholder="您的开户银行" />
  45. </view>
  46. <view class="acea-row row-middle">
  47. <view>银行账号</view>
  48. <input name="bank_code" :value="bank_code" placeholder="您的银行账号" />
  49. </view>
  50. <view class="acea-row row-middle">
  51. <view>企业地址</view>
  52. <input name="address" :value="address" placeholder="您所在的企业地址" />
  53. </view>
  54. <view class="acea-row row-middle">
  55. <view>企业电话</view>
  56. <input name="tel" :value="tel" placeholder="您的企业电话" />
  57. </view>
  58. </view>
  59. <view class="btn-wrap">
  60. <button form-type="submit">提交申请</button>
  61. <button class="back" @tap="noInvoice">不开发票</button>
  62. </view>
  63. </form>
  64. <view :class="{ mask: popupType || popupTitle }"></view>
  65. <view class="popup" :class="{ on: popupType }">
  66. <view class="title">发票类型选择<text class="iconfont icon-guanbi" @click="closeType"></text></view>
  67. <scroll-view scroll-y="true">
  68. <radio-group name="invoice-type" @change="changeType">
  69. <label v-for="item in invoiceTypeList" :key="item.type" class="acea-row row-middle">
  70. <view class="text">
  71. <view>{{ item.name }}</view>
  72. <view class="info">{{ item.info }}</view>
  73. </view>
  74. <radio :value="item.type" :checked="receipt_type == item.type ? true : false" />
  75. </label>
  76. </radio-group>
  77. </scroll-view>
  78. <button @tap="closeType">确定</button>
  79. </view>
  80. <view class="popup" :class="{ on: popupTitle }">
  81. <view class="title">抬头选择<text class="iconfont icon-guanbi" @click="closeTitle"></text></view>
  82. <scroll-view scroll-y="true">
  83. <radio-group name="invoice-title" @change="changeTitle">
  84. <template v-for="item in invoiceList">
  85. <label :key="item.user_receipt_id" class="acea-row row-middle">
  86. <view class="text">
  87. <view class="acea-row row-middle">
  88. <view class="name">{{ item.receipt_title }}</view>
  89. <view v-if="item.is_default" class="label">默认</view>
  90. </view>
  91. <view class="type" :class="{ special: item.receipt_type == '2'}">{{ item.receipt_type == 1 ? '普通发票' : '专用发票'}}</view>
  92. </view>
  93. <radio :value="item.user_receipt_id" :checked="item.user_receipt_id == invoice_id ? true : false" />
  94. </label>
  95. </template>
  96. </radio-group>
  97. </scroll-view>
  98. <button @tap="addTitle">添加新的抬头</button>
  99. </view>
  100. </view>
  101. <view class='mask' catchtouchmove="true" :hidden='invoice.invoice==false' @tap='close'></view>
  102. </view>
  103. </template>
  104. <script>
  105. // +----------------------------------------------------------------------
  106. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  107. // +----------------------------------------------------------------------
  108. // | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
  109. // +----------------------------------------------------------------------
  110. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  111. // +----------------------------------------------------------------------
  112. // | Author: CRMEB Team <admin@crmeb.com>
  113. // +----------------------------------------------------------------------
  114. import { invoiceDefault, invoice, invoiceDetail } from '@/api/user.js';
  115. import { mapGetters } from "vuex";
  116. export default {
  117. props: {
  118. invoice: {
  119. type: Object,
  120. default: function() {
  121. return {
  122. invoice: false,
  123. mer_id: 0,
  124. };
  125. }
  126. }
  127. },
  128. computed: { ...mapGetters(['viewColor'])},
  129. data() {
  130. return {
  131. id: '',
  132. receipt_title_type: '1',
  133. receipt_type: '1',
  134. drawer_phone: '',
  135. receipt_title: '',
  136. duty_paragraph: '',
  137. tel: '',
  138. address: '',
  139. bank_name: '',
  140. bank_code: '',
  141. is_default: 0,
  142. email: '',
  143. isDefault: [],
  144. typeName: '增值税电子普通发票',
  145. popupType: false,
  146. popupTitle: false,
  147. invoiceTypeList: [{
  148. type: '1',
  149. name: '增值税电子普通发票',
  150. info: '默认发送至所提供的电子邮件'
  151. },
  152. {
  153. type: '2',
  154. name: '增值税专用发票',
  155. info: '纸质发票开出后将以邮寄形式交付'
  156. }
  157. ],
  158. special_invoice: true,
  159. invoice_func: true,
  160. invoiceList: [],
  161. invoice_checked: '',
  162. invoice_id: '',
  163. order_id: '',
  164. news: '',
  165. cartId: '',
  166. pinkId: '',
  167. couponId: '',
  168. addressId: '',
  169. invoiceData: {},
  170. formvalidate: false
  171. }
  172. },
  173. watch: {
  174. },
  175. onLoad(option) {
  176. this.news = option.news;
  177. this.cartId = option.cartId;
  178. this.pinkId = option.pinkId;
  179. this.couponId = option.couponId;
  180. this.addressId = option.addressId;
  181. if (option.special_invoice == 'false') {
  182. this.$set(this, 'special_invoice', false);
  183. }
  184. },
  185. onShow(){
  186. this.getInvoiceDefault();
  187. this.popupTitle = false;
  188. },
  189. methods: {
  190. getInvoiceList() {
  191. let params = {
  192. // receipt_title_type: this.receipt_title_type,
  193. // receipt_type: this.receipt_type
  194. }
  195. invoice().then(res => {
  196. for (let i = 0; i < res.data.length; i++) {
  197. res.data[i].user_receipt_id = res.data[i].user_receipt_id.toString();
  198. if (res.data[i].is_default) {
  199. this.invoice_id = res.data[i].user_receipt_id;
  200. }
  201. }
  202. this.$set(this, 'invoiceList', res.data);
  203. }).catch(err => {
  204. this.$util.Tips({
  205. title: err
  206. });
  207. });
  208. },
  209. getInvoiceDefault() {
  210. let params = {
  211. is_default: 1,
  212. // receipt_title_type: this.receipt_title_type,
  213. // receipt_type: this.receipt_type
  214. }
  215. invoice(params).then(res => {
  216. let data = res.data[0];
  217. this.typeName = data.receipt_type == '1' ? '增值税电子普通发票' : '增值税专用发票'
  218. this.receipt_title_type = data.receipt_title_type;
  219. this.receipt_type = data.receipt_type ;
  220. this.receipt_title = data.receipt_title;
  221. // this.drawer_phone = res.data.drawer_phone;
  222. this.email = data.email;
  223. this.duty_paragraph = data.duty_paragraph;
  224. this.bank_name = data.bank_name;
  225. this.bank_code = data.bank_code;
  226. this.address = data.address;
  227. this.tel = data.tel;
  228. // this.is_default = data.is_default;
  229. this.invoice_id = data.user_receipt_id.toString();
  230. }).catch(err => {});
  231. },
  232. getInvoiceDetail(id){
  233. invoiceDetail(id).then(res => {
  234. uni.hideLoading();
  235. this.receipt_title_type = res.data.receipt_title_type;
  236. this.receipt_type = res.data.receipt_type;
  237. this.typeName = this.receipt_type == '1' ? '增值税电子普通发票' : '增值税专用发票'
  238. this.receipt_title = res.data.receipt_title;
  239. // this.drawer_phone = res.data.drawer_phone;
  240. this.email = res.data.email;
  241. this.duty_paragraph = res.data.duty_paragraph;
  242. this.bank_name = res.data.bank_name;
  243. this.bank_code = res.data.bank_code;
  244. this.address = res.data.address;
  245. this.tel = res.data.tel;
  246. this.is_default = res.data.is_default;
  247. }).catch(err => {
  248. uni.hideLoading();
  249. this.$util.Tips({
  250. title: err
  251. });
  252. });
  253. },
  254. close: function() {
  255. if(this.formvalidate){
  256. this.$emit('changeInvoiceClose',this.invoiceData)
  257. }else{
  258. this.$emit('changeInvoiceClose','');
  259. }
  260. },
  261. noInvoice: function(){
  262. uni.setStorage({
  263. key:'invoice_Data',
  264. data:{},
  265. success: function(){}
  266. })
  267. this.$emit('changeInvoiceClose','');
  268. },
  269. callType() {
  270. this.popupType = true;
  271. },
  272. changeType(e) {
  273. this.receipt_type = e.detail.value;
  274. this.typeName = this.invoiceTypeList.find(value => {
  275. return value.type == this.receipt_type;
  276. }).name;
  277. },
  278. closeType() {
  279. this.popupType = false;
  280. },
  281. callTitle() {
  282. this.popupTitle = true;
  283. },
  284. changeTitle(e) {
  285. this.invoice_id = e.detail.value.toString();
  286. this.getInvoiceDetail(e.detail.value)
  287. this.popupTitle = false;
  288. },
  289. addTitle() {
  290. this.popupType = false;
  291. this.popupTitle = false;
  292. uni.navigateTo({
  293. url: '/pages/users/user_invoice_form/index?mer_id='+this.invoice.mer_id
  294. });
  295. },
  296. closeTitle() {
  297. this.popupTitle = false;
  298. },
  299. changeHeader(e) {
  300. this.receipt_title_type = e.detail.value;
  301. if(e.detail.value == 1){
  302. this.receipt_type = 1;
  303. this.typeName = '增值税电子普通发票'
  304. }
  305. this.receipt_type
  306. },
  307. changeDefault(e) {
  308. this.is_default = e.detail.value.length ? 1 : 0;
  309. },
  310. // 提交发票数据
  311. formSubmit(e) {
  312. let that = this,
  313. value = e.detail.value;
  314. if (!value.receipt_title_type) return that.$util.Tips({
  315. title: '请填写发票抬头'
  316. });
  317. if (!value.email) return that.$util.Tips({
  318. title: '请填写邮箱'
  319. });
  320. if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(value.email)) return that.$util.Tips({
  321. title: '请输入正确的邮箱'
  322. });
  323. if(value.receipt_title_type == 2){
  324. if (!value.duty_paragraph) return that.$util.Tips({
  325. title: '请填写税号'
  326. });
  327. if(value.receipt_type == '增值税专用发票'){
  328. if (!value.bank_name) return that.$util.Tips({
  329. title: '请填写开户行'
  330. });
  331. if (!value.bank_code) return that.$util.Tips({
  332. title: '请填写银行账号'
  333. });
  334. if (!value.address) return that.$util.Tips({
  335. title: '请填写企业地址'
  336. });
  337. if (!value.tel) return that.$util.Tips({
  338. title: '请填写企业电话'
  339. });
  340. if(!/^(\d{9}|\d{14}|\d{18})$/.test(value.bank_code)){
  341. return this.$util.Tips({
  342. title: '请输入正确的银行账号'
  343. });
  344. }
  345. if(!/(^(\d{3,4})?\d{7,8})$|(13[0-9]{9})/.test(value.tel)){
  346. return this.$util.Tips({
  347. title: '请输入正确的电话号码'
  348. });
  349. }
  350. }
  351. }
  352. that.formvalidate = true;
  353. value.mer_id = that.invoice.mer_id;
  354. value.receipt_type = that.receipt_type;
  355. that.invoiceData = value
  356. uni.setStorage({
  357. key:'invoice_Data',
  358. data: [that.invoiceData],
  359. success: function(){
  360. }
  361. })
  362. that.$emit('changeInvoiceClose',that.invoiceData)
  363. }
  364. }
  365. }
  366. </script>
  367. <style scoped>
  368. .add_invoicing{
  369. position: fixed;
  370. bottom: 0;
  371. width: 100%;
  372. left: 0;
  373. background-color: #fff;
  374. z-index: 77;
  375. border-radius: 16rpx 16rpx 0 0;
  376. padding-bottom: 20rpx;
  377. transform: translate3d(0, 100%, 0);
  378. transition: all .3s cubic-bezier(.25, .5, .5, .9);
  379. }
  380. .add_invoicing.on {
  381. transform: translate3d(0, 0, 0);
  382. }
  383. .add_invoicing .title {
  384. font-size: 32rpx;
  385. font-weight: bold;
  386. text-align: center;
  387. height: 123rpx;
  388. line-height: 123rpx;
  389. position: relative;
  390. }
  391. .add_invoicing .title .iconfont {
  392. position: absolute;
  393. right: 30rpx;
  394. color: #8a8a8a;
  395. font-size: 35rpx;
  396. }
  397. form {
  398. font-size: 28rpx;
  399. color: #282828;
  400. }
  401. form input,
  402. form radio-group {
  403. flex: 1;
  404. text-align: right;
  405. }
  406. form input {
  407. font-size: 26rpx;
  408. }
  409. form label {
  410. margin-right: 50rpx;
  411. }
  412. form radio {
  413. margin-right: 8rpx;
  414. }
  415. form checkbox-group {
  416. height: 90rpx;
  417. }
  418. form checkbox {
  419. margin-right: 20rpx;
  420. }
  421. /deep/radio .uni-radio-input.uni-radio-input-checked {
  422. border: 1px solid var(--view-theme) !important;
  423. background-color: var(--view-theme) !important
  424. }
  425. form button {
  426. height: 76rpx;
  427. border-radius: 38rpx;
  428. margin: 16rpx 30rpx;
  429. background-color: var(--view-theme);
  430. font-size: 30rpx;
  431. line-height: 76rpx;
  432. color: #FFFFFF;
  433. }
  434. .panel {
  435. padding-right: 30rpx;
  436. padding-left: 30rpx;
  437. background-color: #FFFFFF;
  438. }
  439. .panel~.panel {
  440. margin-top: 14rpx;
  441. }
  442. .panel .acea-row {
  443. height: 90rpx;
  444. }
  445. .panel .acea-row~.acea-row {
  446. border-top: 1rpx solid #EEEEEE;
  447. }
  448. .input-placeholder {
  449. font-size: 26rpx;
  450. color: #BBBBBB;
  451. }
  452. .icon-xiangyou {
  453. margin-left: 25rpx;
  454. font-size: 18rpx;
  455. color: #BFBFBF;
  456. }
  457. .btn-wrap {
  458. width: 100%;
  459. padding: 8px 16px;
  460. border-top: 1px solid #F5F5F5;
  461. }
  462. .btn-wrap .back {
  463. border: 1rpx solid var(--view-theme);
  464. background: none;
  465. color: var(--view-theme);
  466. }
  467. .popup {
  468. position: fixed;
  469. bottom: 0;
  470. left: 0;
  471. z-index: 99;
  472. width: 100%;
  473. padding-bottom: 100rpx;
  474. border-top-left-radius: 16rpx;
  475. border-top-right-radius: 16rpx;
  476. background-color: #F5F5F5;
  477. overflow: hidden;
  478. transform: translateY(100%);
  479. transition: 0.3s;
  480. }
  481. .popup.on {
  482. transform: translateY(0);
  483. }
  484. .popup .title {
  485. position: relative;
  486. height: 137rpx;
  487. font-size: 32rpx;
  488. line-height: 137rpx;
  489. text-align: center;
  490. }
  491. .popup scroll-view {
  492. height: 466rpx;
  493. padding-right: 30rpx;
  494. padding-left: 30rpx;
  495. box-sizing: border-box;
  496. }
  497. .popup label {
  498. padding: 35rpx 30rpx;
  499. border-radius: 16rpx;
  500. margin-bottom: 20rpx;
  501. background-color: #FFFFFF;
  502. }
  503. .popup .text {
  504. flex: 1;
  505. min-width: 0;
  506. font-size: 28rpx;
  507. color: #282828;
  508. }
  509. .popup .info {
  510. margin-top: 10rpx;
  511. font-size: 22rpx;
  512. color: #909090;
  513. }
  514. .popup .icon-guanbi {
  515. position: absolute;
  516. top: 50%;
  517. right: 30rpx;
  518. z-index: 2;
  519. transform: translateY(-50%);
  520. font-size: 30rpx;
  521. color: #707070;
  522. cursor: pointer;
  523. }
  524. .popup button {
  525. height: 86rpx;
  526. border-radius: 43rpx;
  527. margin-right: 30rpx;
  528. margin-left: 30rpx;
  529. background-color: var(--view-theme);
  530. font-size: 30rpx;
  531. line-height: 86rpx;
  532. color: #FFFFFF;
  533. }
  534. .popup .text .acea-row {
  535. display: inline-flex;
  536. max-width: 100%;
  537. }
  538. .popup .name {
  539. flex: 1;
  540. overflow: hidden;
  541. white-space: nowrap;
  542. text-overflow: ellipsis;
  543. font-size: 30rpx;
  544. }
  545. .popup .label {
  546. width: 56rpx;
  547. height: 28rpx;
  548. border: 1rpx solid #E93323;
  549. margin-left: 18rpx;
  550. font-size: 20rpx;
  551. line-height: 26rpx;
  552. text-align: center;
  553. color: #E93323;
  554. }
  555. .popup .type {
  556. width: 124rpx;
  557. height: 42rpx;
  558. margin-top: 14rpx;
  559. background-color: #FCF0E0;
  560. font-size: 24rpx;
  561. line-height: 42rpx;
  562. text-align: center;
  563. color: #D67300;
  564. }
  565. .popup .type.special {
  566. background-color: #FDE9E7;
  567. color: #E93323;
  568. }
  569. </style>