index.vue 13 KB

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