index.vue 16 KB

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