index.vue 14 KB

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