invoice.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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 select-invoice-line" v-if="tabsCurrent===0" @click="selectInvoiceLine">
  18. <view class="til">
  19. <text>*</text>申请类型
  20. </view>
  21. <!-- <u--input placeholder="请选择申请类型" readonly border="surround" v-model="invoiceLineName" ></u--input> -->
  22. <view class="item-value">
  23. <text>{{invoiceLineName}}</text>
  24. </view>
  25. </view>
  26. <u-picker :show="showInvoiceLine" :columns="invoiceLineList" keyName="label" :immediateChange="true" @cancel="cancelInvoiceLine" @confirm="confirmInvoiceLine" ></u-picker>
  27. <view class="form-item">
  28. <view class="til">
  29. <text>*</text>抬头名称
  30. </view>
  31. <u--input placeholder="请输入名称" border="surround" v-model="formData.name" ></u--input>
  32. </view>
  33. <view class="form-item" v-if="tabsCurrent===0">
  34. <view class="til">
  35. <text>*</text>税号
  36. </view>
  37. <u--input placeholder="请输入税号 " border="surround" v-model="formData.creditCode" ></u--input>
  38. </view>
  39. </view>
  40. <view class="block-wrap amount u-flex u-row-between">
  41. <view class="til">发票金额</view>
  42. <view class="con">¥{{invoiceInfo.invoiceAmount}}</view>
  43. </view>
  44. <view class="block-wrap">
  45. <view class="form-item">
  46. <view class="til">
  47. <text>*</text>电子邮箱
  48. </view>
  49. <u--input placeholder="请输入电子邮箱" border="surround" v-model="formData.email" ></u--input>
  50. </view>
  51. <view class="form-item remake">
  52. <view class="til">
  53. 发票备注
  54. </view>
  55. <u--input placeholder="此内容会回显至电子发票的备注中,请谨慎填写" border="surround" v-model="formData.remark" ></u--input>
  56. </view>
  57. </view>
  58. </view>
  59. <view class="page-bottom">
  60. <view class="inner">
  61. <view class="btn active" v-if="cansubmit" @click="submitorder">提交</view>
  62. <view class="btn" @click="$u.toast('请完整填写表单')" v-else>提交</view>
  63. </view>
  64. </view>
  65. </view>
  66. </template>
  67. <script>
  68. import { systemInfo } from "@/mixin.js";
  69. export default {
  70. mixins: [systemInfo], // 使用mixin
  71. data() {
  72. return {
  73. staticUrl:this.$commonConfig.staticUrl,
  74. orderId:'',
  75. tabsCurrent:0,
  76. tabsList:[
  77. {name:'企业',status:'0'},
  78. {name:'个人',status:'1'}
  79. ],
  80. invoiceInfo:{},
  81. handlerList:[],
  82. formData:{
  83. name:'',
  84. creditCode :'',
  85. email:'',
  86. remark:''
  87. },
  88. invoiceLine:'',
  89. showInvoiceLine:false,
  90. invoiceLineName:'',
  91. invoiceLineList:[[{label:'数电专票',id:'bs'},{label:'数电普票',id:'pc'}]]
  92. }
  93. },
  94. onShow() {
  95. },
  96. onLoad(page) {
  97. this.orderId = page.id;
  98. this.invoiceLine = page.invoiceLine;
  99. this.getSystemInfo();
  100. this.getInvoiceInfo();
  101. },
  102. computed: {
  103. // 是否全选
  104. cansubmit() {
  105. if(this.tabsCurrent===0){
  106. return this.formData.name && this.formData.creditCode && uni.$u.test.email(this.formData.email)&& this.invoiceLineName;
  107. }else{
  108. return this.formData.name && uni.$u.test.email(this.formData.email);
  109. }
  110. },
  111. },
  112. methods: {
  113. leftClick(e){
  114. let pages = getCurrentPages();
  115. if(pages.length==1){
  116. uni.$u.route('/pages/index/index')
  117. }else{
  118. uni.navigateBack()
  119. };
  120. },
  121. tabsClick(item){
  122. this.tabsCurrent = item.index;
  123. // console.log('item',item);
  124. this.setDefault();
  125. },
  126. selectInvoiceLine(){
  127. this.showInvoiceLine = true;
  128. console.log('showInvoiceLine');
  129. },
  130. getInvoiceInfo(){
  131. this.$u.api.getInvoiceInfo({orderId:this.orderId}).then(res=>{
  132. // console.log('res',res);
  133. this.invoiceInfo = res.data;
  134. this.handlerList = res.data.handlerList||[];
  135. this.setDefault();
  136. }).catch(err=>{
  137. console.log('getInvoiceInfo',err);
  138. })
  139. },
  140. setDefault(){
  141. if(this.handlerList.length>0){
  142. let handlerType1 = this.handlerList.find(handler => handler.handlerType === 1) || {};//个人
  143. let handlerType2 = this.handlerList.find(handler => handler.handlerType === 2) || {};//企业
  144. if(this.tabsCurrent===0){//企业
  145. this.formData.name = handlerType2.name||null;
  146. this.formData.creditCode = handlerType2.creditCode||null;
  147. this.formData.email = handlerType2.email||null;
  148. this.formData.invoiceLine = this.invoiceLine||null;
  149. this.formData.remark = handlerType2.invoiceRemark||null;
  150. if(this.formData.invoiceLine=='bs'){
  151. this.invoiceLineName = '数电专票'
  152. }else if(this.formData.invoiceLine=='pc'){
  153. this.invoiceLineName = '数电普票'
  154. }
  155. }else{
  156. this.formData.name = handlerType1.name||null;
  157. this.formData.email = handlerType1.email||null;
  158. this.formData.remark = handlerType1.invoiceRemark||null;
  159. }
  160. }
  161. },
  162. cancelInvoiceLine(){
  163. this.showInvoiceLine = false;
  164. },
  165. confirmInvoiceLine(e){
  166. this.showInvoiceLine = false;
  167. console.log('confirmInvoiceLine id',e.value[0].id);
  168. console.log('confirmInvoiceLine label',e.value[0].label);
  169. this.formData.invoiceLine = e.value[0].id;
  170. this.invoiceLineName = e.value[0].label;
  171. },
  172. submitorder(){
  173. let params = {
  174. orderId:this.orderId,
  175. invoiceAmount:this.invoiceInfo.invoiceAmount,
  176. remark:this.formData.remark,
  177. invoiceHandler:{
  178. handlerType:this.tabsCurrent===0?2:1,
  179. name:this.formData.name,
  180. email:this.formData.email,
  181. // mobile:this.formData.mobile
  182. },
  183. invoiceSource:1,//开票来源;0-小程序 1-团购H5 2-线下
  184. };
  185. if(this.tabsCurrent===0){//企业
  186. params.invoiceHandler.creditCode = this.formData.creditCode;
  187. params.invoiceLine = this.formData.invoiceLine;
  188. }
  189. this.$u.api.submitInvoice(params).then(res=>{
  190. uni.$u.toast(res.msg)
  191. // uni.navigateBack()
  192. setTimeout(()=>{
  193. uni.redirectTo({
  194. url: `/center/orderdetails?id=${this.orderId}`
  195. })
  196. },1500)
  197. }).catch(err=>{
  198. console.log('submitorder',err);
  199. })
  200. }
  201. }
  202. }
  203. </script>
  204. <style>
  205. page{background-color: #F7F7F9;}
  206. </style>
  207. <style lang="scss" scoped>
  208. .block-wrap{
  209. background-color: #fff;
  210. border-radius: 16rpx;
  211. padding: 22rpx 32rpx 30rpx;
  212. margin-bottom: 24rpx;
  213. .form-item{
  214. margin-bottom: 22rpx;
  215. .til{
  216. font-size: 28rpx;
  217. font-family: PingFangSC, PingFang SC;
  218. font-weight: 400;
  219. color: #333;
  220. margin-bottom: 12rpx;
  221. text{
  222. color: #EF0E0E;
  223. }
  224. }
  225. ::v-deep .input-placeholder{
  226. color: #EF0E0E!important;
  227. font-size: 24rpx;
  228. }
  229. }
  230. &.amount{
  231. padding: 26rpx 32rpx;
  232. .til{
  233. margin-bottom: 0;
  234. }
  235. .con{
  236. font-size: 28rpx;
  237. font-family: SourceHanSansCN, SourceHanSansCN;
  238. font-weight: bold;
  239. color: #EF0E0E;
  240. }
  241. }
  242. }
  243. .page-bottom{
  244. $height:98rpx;
  245. position: relative;
  246. z-index: 1001;
  247. height: $height;
  248. padding: 24rpx 20rpx;
  249. .inner{
  250. position: fixed;
  251. background-color: transparent;
  252. height: $height;
  253. left: 0;
  254. right: 0;
  255. bottom: 0;
  256. padding: 24rpx 20rpx;
  257. // box-shadow: 0rpx -4rpx 12rpx 0rpx rgba(215,215,215,0.5);
  258. .btn{
  259. font-size: 28rpx;
  260. height: 100%;
  261. line-height: $height;
  262. border-radius: 50rpx;
  263. padding: 0 50rpx;
  264. background-color: #eee;
  265. color: #333;
  266. text-align: center;
  267. &.active{
  268. background: linear-gradient(90deg, #FF7979 0%, #ED0000 100%);
  269. color: #fff;
  270. }
  271. }
  272. }
  273. }
  274. .item-value{
  275. border: 1px solid rgb(218, 219, 222);
  276. display: flex;
  277. align-items: center;
  278. border-radius: 8rpx;
  279. height: 38px;
  280. padding-left: 10px;
  281. }
  282. </style>