InvoiceForm.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  2. <member-base :show="false"><view class="div container member-invoice-form">
  3. <view class="div common-header-wrap">
  4. <view :style="'height:'+navHeight+'px'"></view>
  5. <view class="common-header-holder"></view>
  6. <view class="common-header-fixed">
  7. <title-header />
  8. <uni-nav-bar :title="getTitle" class="common-header" left-icon="back" @clickLeft="goBack()">
  9. </uni-nav-bar>
  10. </view>
  11. </view>
  12. <view class="div main-content">
  13. <flex-line :show-border="true">
  14. <text class="span">发票类型</text>
  15. <view class="div" slot="right">
  16. <radio-group @change="radioChange">
  17. <label v-for="(item, index) in invoice_state_options" :key="index">
  18. <radio :value="item.value" :checked="invoice.invoice_state==item.value" />
  19. <text>{{item.label}}</text>
  20. </label>
  21. </radio-group>
  22. </view>
  23. </flex-line>
  24. <view>
  25. <view v-if="invoice.invoice_state=='1'">
  26. <flex-line class="field-line" :show-border="true"><text class="span field-name">发票抬头</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="invoice.invoice_title" /></view></flex-line>
  27. <flex-line class="field-line" :show-border="true"><text class="span field-name">纳税人识别号</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="invoice.invoice_code" /></view></flex-line>
  28. <flex-line class="field-line" :show-border="true"><text class="span field-name">发票内容</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="invoice.invoice_content" /></view></flex-line>
  29. </view>
  30. <view v-if="invoice.invoice_state=='2'">
  31. <flex-line class="field-line" :show-border="true"><text class="span field-name">单位名称</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="invoice.invoice_company" /></view></flex-line>
  32. <flex-line class="field-line" :show-border="true"><text class="span field-name">纳税人识别号</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="invoice.invoice_company_code" /></view></flex-line>
  33. <flex-line class="field-line" :show-border="true"><text class="span field-name">注册地址</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="invoice.invoice_reg_addr" /></view></flex-line>
  34. <flex-line class="field-line" :show-border="true"><text class="span field-name">注册电话</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="invoice.invoice_reg_phone" /></view></flex-line>
  35. <flex-line class="field-line" :show-border="true"><text class="span field-name">开户银行</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="invoice.invoice_reg_bname" /></view></flex-line>
  36. <flex-line class="field-line" :show-border="true"><text class="span field-name">银行帐户</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="invoice.invoice_reg_baccount" /></view></flex-line>
  37. </view>
  38. </view>
  39. <view class="div pt-10 pb-10"><view class="div common-btn ds-button-large" @click="submit">{{getSumitTitle}}</view></view>
  40. </view>
  41. </view></member-base>
  42. </template>
  43. <script>
  44. import {getFontSize} from '@/util/common'
  45. import TitleHeader from '../../TitleHeader'
  46. import MemberBase from '../MemberBase'
  47. import { getInvoiceInfo, addInvoice, editInvoice } from '../../../api/memberInvoice'
  48. import flexLine from '../../flexLine'
  49. export default {
  50. name: 'InvoiceForm',
  51. mounted(){
  52. // #ifdef MP-WEIXIN
  53. this.navHeight = uni.getMenuButtonBoundingClientRect().top
  54. // #endif
  55. },
  56. data(){
  57. return {
  58. navHeight: 0,
  59. action:'',
  60. isFromCheckout:0,
  61. goBackLevel:0,
  62. invoice_state_options: [
  63. {
  64. label: '普通发票',
  65. value: '1'
  66. },
  67. {
  68. label: '增值税专用发票',
  69. value: '2'
  70. }
  71. ],
  72. invoice_id: 0,
  73. invoice: {
  74. invoice_state: '1',
  75. invoice_title: '',
  76. invoice_code: '',
  77. invoice_content: '',
  78. invoice_company: '',
  79. invoice_company_code: '',
  80. invoice_reg_addr: '',
  81. invoice_reg_phone: '',
  82. invoice_reg_bname: '',
  83. invoice_reg_baccount: ''
  84. }
  85. }
  86. },
  87. components:{
  88. TitleHeader,
  89. MemberBase,
  90. flexLine
  91. },
  92. onLoad: function (option) {
  93. this.isFromCheckout = option.isFromCheckout
  94. this.goBackLevel=option.goBackLevel
  95. this.action=option.action
  96. if (!this.isAddMode) {
  97. this.invoice_id = option.invoice_id
  98. getInvoiceInfo(this.invoice_id).then(res => {
  99. this.invoice.invoice_state = res.result.invoice_state
  100. this.invoice.invoice_title = res.result.invoice_title
  101. this.invoice.invoice_code = res.result.invoice_code
  102. this.invoice.invoice_content = res.result.invoice_content
  103. this.invoice.invoice_company = res.result.invoice_company
  104. this.invoice.invoice_company_code = res.result.invoice_company_code
  105. this.invoice.invoice_reg_addr = res.result.invoice_reg_addr
  106. this.invoice.invoice_reg_phone = res.result.invoice_reg_phone
  107. this.invoice.invoice_reg_bname = res.result.invoice_reg_bname
  108. this.invoice.invoice_reg_baccount = res.result.invoice_reg_baccount
  109. }).catch(function (error) {
  110. uni.showToast({icon:'none',title: error.message})
  111. })
  112. }
  113. },
  114. computed:{
  115. fontSize(){
  116. return getFontSize()
  117. },
  118. isAddMode () {
  119. let mode = this.action
  120. // add: 添加地址,edit: 编辑地址
  121. if (mode === 'add') {
  122. return true
  123. } else {
  124. return false
  125. }
  126. },
  127. getTitle () {
  128. if (this.isAddMode) {
  129. return '新增发票'
  130. } else {
  131. return '修改发票'
  132. }
  133. },
  134. getSumitTitle () {
  135. let isFromCheckout = this.isFromCheckout
  136. if (isFromCheckout) {
  137. return '保存并使用'
  138. } else {
  139. return '保存'
  140. }
  141. }
  142. },
  143. methods: {
  144. radioChange(e){
  145. this.invoice.invoice_state=e.detail.value
  146. },
  147. goBack () {
  148. uni.navigateBack({delta:1})
  149. },
  150. submit () {
  151. // 普通发票
  152. if (this.invoice.invoice_state === '1') {
  153. if (this.invoice.invoice_title === '') {
  154. uni.showToast({icon:'none',title: '请填写发票抬头'})
  155. return
  156. }
  157. if (this.invoice.invoice_code === '') {
  158. uni.showToast({icon:'none',title: '请填写纳税人识别号'})
  159. return
  160. }
  161. if (this.invoice.invoice_content === '') {
  162. uni.showToast({icon:'none',title: '请填写发票内容'})
  163. return
  164. }
  165. }
  166. // 专用发票
  167. if (this.invoice.invoice_state === '2') {
  168. if (this.invoice.invoice_company === '') {
  169. uni.showToast({icon:'none',title: '请填写单位名称'})
  170. return
  171. }
  172. if (this.invoice.invoice_company_code === '') {
  173. uni.showToast({icon:'none',title: '请填写纳税人识别号'})
  174. return
  175. }
  176. if (this.invoice.invoice_reg_addr === '') {
  177. uni.showToast({icon:'none',title: '请填写注册地址'})
  178. return
  179. }
  180. if (this.invoice.invoice_reg_phone === '') {
  181. uni.showToast({icon:'none',title: '请填写注册电话'})
  182. return
  183. }
  184. if (this.invoice.invoice_reg_bname === '') {
  185. uni.showToast({icon:'none',title: '请填写开户银行'})
  186. return
  187. }
  188. if (this.invoice.invoice_reg_baccount === '') {
  189. uni.showToast({icon:'none',title: '请填写银行帐户'})
  190. return
  191. }
  192. }
  193. if (this.isAddMode) {
  194. uni.showLoading({ title: '加载中' })
  195. addInvoice(this.invoice).then(
  196. (response) => {
  197. uni.hideLoading()
  198. this.updateSelectedInvoice()
  199. }, (error) => {
  200. uni.hideLoading()
  201. uni.showToast({icon:'none',title: error.message})
  202. })
  203. } else {
  204. uni.showLoading({ title: '加载中' })
  205. editInvoice(this.invoice, this.invoice_id).then(
  206. (response) => {
  207. uni.hideLoading()
  208. this.updateSelectedInvoice()
  209. }, (error) => {
  210. uni.hideLoading()
  211. uni.showToast({icon:'none',title: error.message})
  212. })
  213. }
  214. },
  215. updateSelectedInvoice () {
  216. uni.navigateBack({delta:1})
  217. }
  218. }
  219. }
  220. </script>
  221. <style lang="scss">
  222. .member-invoice-form{
  223. .mint-radiolist {
  224. display: flex;
  225. .mint-cell {
  226. flex: 1;
  227. .mint-radio-input:checked + .mint-radio-core {
  228. background-color: $primaryColor !important;
  229. border-color: $primaryColor !important;
  230. }
  231. &:after{display: none}
  232. }
  233. }
  234. }
  235. </style>
  236. <style lang="scss" scoped>
  237. .main-content{background: #fff;padding:0 $pageSpace}
  238. </style>