invoice.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <view class="pages">
  3. <view class="" :style="{height: navHeight+'px' }"></view>
  4. <view class="navbar-box">
  5. <u-navbar title="开具发票" :safeAreaInsetTop="true" @leftClick="leftClick" :titleStyle="{color:'#fff'}" leftIconColor="#fff" bgColor="#EF1818"></u-navbar>
  6. </view>
  7. <view class="page-wrap">
  8. <u-tabs
  9. :list="tabsList"
  10. lineColor="#EE0D0D"
  11. :current="tabsCurrent"
  12. :activeStyle="{color:'#EE0D0D','font-weight': '600','font-size':'30rpx'}"
  13. :inactiveStyle="{color:'#7F7F7F'}"
  14. itemStyle="width:50%;box-sizing:border-box;padding:24rpx;"
  15. @click="tabsClick"></u-tabs>
  16. <view class="block-wrap" style="margin-top: 32rpx;">
  17. <view class="form-item">
  18. <view class="til">
  19. <text>*</text>抬头名称
  20. </view>
  21. <u--input placeholder="请输入名称" border="surround" v-model="formData.name" ></u--input>
  22. </view>
  23. <view class="form-item" v-if="tabsCurrent===0">
  24. <view class="til">
  25. <text>*</text>税号
  26. </view>
  27. <u--input placeholder="请输入税号 " border="surround" v-model="formData.creditCode" ></u--input>
  28. </view>
  29. </view>
  30. <view class="block-wrap amount u-flex u-row-between">
  31. <view class="til">发票金额</view>
  32. <view class="con">¥{{invoiceInfo.invoiceAmount}}</view>
  33. </view>
  34. <view class="block-wrap">
  35. <view class="form-item">
  36. <view class="til">
  37. <text>*</text>电子邮箱
  38. </view>
  39. <u--input placeholder="请输入电子邮箱" border="surround" v-model="formData.email" ></u--input>
  40. </view>
  41. </view>
  42. </view>
  43. <view class="page-bottom">
  44. <view class="inner">
  45. <view class="btn active" v-if="cansubmit" @click="submitorder">提交</view>
  46. <view class="btn" @click="$u.toast('请完整填写表单')" v-else>提交</view>
  47. </view>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import { systemInfo } from "@/mixin.js";
  53. export default {
  54. mixins: [systemInfo], // 使用mixin
  55. data() {
  56. return {
  57. staticUrl:this.$commonConfig.staticUrl,
  58. orderId:'',
  59. tabsCurrent:0,
  60. tabsList:[
  61. {name:'企业',status:'0'},
  62. {name:'个人',status:'1'}
  63. ],
  64. invoiceInfo:{},
  65. handlerList:[],
  66. formData:{
  67. name:'',
  68. creditCode :'',
  69. email:''
  70. }
  71. }
  72. },
  73. onShow() {
  74. },
  75. onLoad(page) {
  76. this.orderId = page.id;
  77. this.getSystemInfo();
  78. this.getInvoiceInfo();
  79. },
  80. computed: {
  81. // 是否全选
  82. cansubmit() {
  83. if(this.tabsCurrent===0){
  84. return this.formData.name && this.formData.creditCode && uni.$u.test.email(this.formData.email);
  85. }else{
  86. return this.formData.name && uni.$u.test.email(this.formData.email);
  87. }
  88. },
  89. },
  90. methods: {
  91. leftClick(e){
  92. let pages = getCurrentPages();
  93. if(pages.length==1){
  94. uni.$u.route('/pages/index/index')
  95. }else{
  96. uni.navigateBack()
  97. };
  98. },
  99. tabsClick(item){
  100. this.tabsCurrent = item.index;
  101. // console.log('item',item);
  102. this.setDefault();
  103. },
  104. getInvoiceInfo(){
  105. this.$u.api.getInvoiceInfo({orderId:this.orderId}).then(res=>{
  106. // console.log('res',res);
  107. this.invoiceInfo = res.data;
  108. this.handlerList = res.data.handlerList||[];
  109. this.setDefault();
  110. }).catch(err=>{
  111. console.log('getInvoiceInfo',err);
  112. })
  113. },
  114. setDefault(){
  115. if(this.handlerList.length>0){
  116. let handlerType1 = this.handlerList.find(handler => handler.handlerType === 1) || {};//个人
  117. let handlerType2 = this.handlerList.find(handler => handler.handlerType === 2) || {};//企业
  118. if(this.tabsCurrent===0){//企业
  119. this.formData.name = handlerType2.name||null;
  120. this.formData.creditCode = handlerType2.creditCode||null;
  121. this.formData.email = handlerType2.email||null;
  122. }else{
  123. this.formData.name = handlerType1.name||null;
  124. this.formData.email = handlerType1.email||null;
  125. }
  126. }
  127. },
  128. submitorder(){
  129. let params = {
  130. orderId:this.orderId,
  131. invoiceAmount:this.invoiceInfo.invoiceAmount,
  132. invoiceHandler:{
  133. handlerType:this.tabsCurrent===0?2:1,
  134. name:this.formData.name,
  135. email:this.formData.email,
  136. // mobile:this.formData.mobile
  137. }
  138. };
  139. if(this.tabsCurrent===0){//企业
  140. params.invoiceHandler.creditCode = this.formData.creditCode
  141. }
  142. this.$u.api.submitInvoice(params).then(res=>{
  143. uni.$u.toast(res.msg)
  144. // uni.navigateBack()
  145. setTimeout(()=>{
  146. uni.redirectTo({
  147. url: `/center/orderdetails?id=${this.orderId}`
  148. })
  149. },1500)
  150. }).catch(err=>{
  151. console.log('submitorder',err);
  152. })
  153. }
  154. }
  155. }
  156. </script>
  157. <style>
  158. page{background-color: #F7F7F9;}
  159. </style>
  160. <style lang="scss" scoped>
  161. .block-wrap{
  162. background-color: #fff;
  163. border-radius: 16rpx;
  164. padding: 22rpx 32rpx 30rpx;
  165. margin-bottom: 24rpx;
  166. .form-item{
  167. margin-bottom: 22rpx;
  168. .til{
  169. font-size: 28rpx;
  170. font-family: PingFangSC, PingFang SC;
  171. font-weight: 400;
  172. color: #333;
  173. margin-bottom: 12rpx;
  174. text{
  175. color: #EF0E0E;
  176. }
  177. }
  178. }
  179. &.amount{
  180. padding: 26rpx 32rpx;
  181. .til{
  182. margin-bottom: 0;
  183. }
  184. .con{
  185. font-size: 28rpx;
  186. font-family: SourceHanSansCN, SourceHanSansCN;
  187. font-weight: bold;
  188. color: #EF0E0E;
  189. }
  190. }
  191. }
  192. .page-bottom{
  193. $height:98rpx;
  194. position: relative;
  195. z-index: 1001;
  196. height: $height;
  197. padding: 24rpx 20rpx;
  198. .inner{
  199. position: fixed;
  200. background-color: transparent;
  201. height: $height;
  202. left: 0;
  203. right: 0;
  204. bottom: 0;
  205. padding: 24rpx 20rpx;
  206. // box-shadow: 0rpx -4rpx 12rpx 0rpx rgba(215,215,215,0.5);
  207. .btn{
  208. font-size: 28rpx;
  209. height: 100%;
  210. line-height: $height;
  211. border-radius: 50rpx;
  212. padding: 0 50rpx;
  213. background-color: #eee;
  214. color: #333;
  215. text-align: center;
  216. &.active{
  217. background: linear-gradient(90deg, #FF7979 0%, #ED0000 100%);
  218. color: #fff;
  219. }
  220. }
  221. }
  222. }
  223. </style>