index.vue 14 KB

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