index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <div class="invoices-layout">
  3. <div class="invoice-header">
  4. <label class="check-con" @click="type='geren'">
  5. <span class="check-box">
  6. <span class="checkbox-inner" :class="{'checkbox-inner-checked':type==='geren'}"></span>
  7. </span>
  8. <span>个人</span>
  9. </label>
  10. <label class="check-con" @click="type='qiye'">
  11. <span class="check-box">
  12. <span class="checkbox-inner" :class="{'checkbox-inner-checked':type==='qiye'}"></span>
  13. </span>
  14. <span>企业</span>
  15. </label>
  16. </div>
  17. <div class="address-input-con" v-if="type==='qiye'">
  18. <div class="address-input-item">
  19. <div class="address-sub">
  20. <div class="top-title">抬头名称</div>
  21. <div class="ant-input" >
  22. <input @blur="blurHandle" v-model="tempInvoice3.title" type="text" placeholder="请输入发票抬头" />
  23. </div>
  24. </div>
  25. </div>
  26. <div class="address-input-item">
  27. <div class="address-sub">
  28. <div class="top-title">税号</div>
  29. <div class="ant-input" >
  30. <input @blur="blurHandle" v-model="tempInvoice3.code" type="text" placeholder="请输入税务登记号" />
  31. </div>
  32. </div>
  33. </div>
  34. <div class="address-input-item">
  35. <div class="address-sub">
  36. <div class="top-title">地址</div>
  37. <div class="ant-input" >
  38. <input @blur="blurHandle" v-model="tempInvoice3.organizedAddress" type="text" placeholder="公司地址" />
  39. </div>
  40. </div>
  41. </div>
  42. <div class="address-input-item">
  43. <div class="address-sub">
  44. <div class="top-title">电话号码</div>
  45. <div class="ant-input" >
  46. <input @blur="blurHandle" v-model="tempInvoice3.registerPhone" type="text" placeholder="公司电话号码" />
  47. </div>
  48. </div>
  49. </div>
  50. <div class="address-input-item">
  51. <div class="address-sub">
  52. <div class="top-title">开户银行</div>
  53. <div class="ant-input" >
  54. <input @blur="blurHandle" v-model="tempInvoice3.bankName" type="text" placeholder="开户银行" />
  55. </div>
  56. </div>
  57. </div>
  58. <div class="address-input-item">
  59. <div class="address-sub">
  60. <div class="top-title">银行账户</div>
  61. <div class="ant-input" >
  62. <input @blur="blurHandle" v-model="tempInvoice3.bankAccount" type="text" placeholder="银行账户" />
  63. </div>
  64. </div>
  65. </div>
  66. <button @click="saveInvoice" type="submit" class="ant-btn ant-btn-primary">
  67. <span>保 存</span>
  68. </button>
  69. <button type="submit" class="ant-btn ant-btn-primary cancel" @click="$emit('closeInvoice', true)">
  70. <span>取 消</span>
  71. </button>
  72. </div>
  73. <div class="address-input-con" v-else>
  74. <div class="address-input-item">
  75. <div class="address-sub">
  76. <div class="top-title">抬头名称</div>
  77. <div class="ant-input" >
  78. <input @blur="blurHandle" v-model="tempInvoice2.title" type="text" placeholder="发票抬头" />
  79. </div>
  80. </div>
  81. </div>
  82. <div class="address-input-item">
  83. <div class="address-sub">
  84. <div class="top-title">税号</div>
  85. <div class="ant-input" >
  86. <input @blur="blurHandle" v-model="tempInvoice2.code" type="text" placeholder="税务登记号" />
  87. </div>
  88. </div>
  89. </div>
  90. <button @click="saveInvoice" type="submit" class="ant-btn ant-btn-primary">
  91. <span>保 存</span>
  92. </button>
  93. <button type="submit" class="ant-btn ant-btn-primary cancel" @click="$emit('closeInvoice', true)">
  94. <span>取 消</span>
  95. </button>
  96. </div>
  97. </div>
  98. </template>
  99. <script>
  100. var cloneObj = function (obj) {
  101. var newObj = {}
  102. if (obj instanceof Array) {
  103. newObj = []
  104. }
  105. for (var key in obj) {
  106. var val = obj[key] || ''
  107. newObj[key] = typeof val === 'object' ? cloneObj(val) : val
  108. }
  109. return newObj
  110. }
  111. export default {
  112. props: ['invoice', 'invoicet', 'token'],
  113. computed: {
  114. tempInvoice2: function () {
  115. return cloneObj(this.invoice)
  116. },
  117. tempInvoice3: function () {
  118. return cloneObj(this.invoicet)
  119. }
  120. },
  121. data () {
  122. return {
  123. type: 'geren'
  124. }
  125. },
  126. methods: {
  127. blurHandle () {
  128. },
  129. saveInvoice () {
  130. let isObject = function (obj) {
  131. return JSON.stringify(obj) === '{}' ? '' : obj
  132. }
  133. let params = {}
  134. if (this.type === 'geren') {
  135. params = {
  136. invoiceType: 2,
  137. title: this.tempInvoice2.title,
  138. code: this.tempInvoice2.code
  139. }
  140. } else {
  141. let {title, code, organizedAddress, registerPhone, bankName, bankAccount} = this.tempInvoice3
  142. params = {
  143. invoiceType: 3,
  144. title,
  145. code,
  146. organizedAddress,
  147. registerPhone,
  148. bankName,
  149. bankAccount
  150. }
  151. }
  152. let test = Object.keys(params)
  153. for (let i = 0; i < test.length; i++) {
  154. if (!isObject(params[test[i]])) {
  155. return this.$toast.show('warn', '信息填写不完整')
  156. }
  157. }
  158. this.$http
  159. .post('user/invoice/save', params, {
  160. headers: {
  161. token: this.token
  162. }
  163. })
  164. .then(data => {
  165. let res = data.data
  166. if (res.code !== 0) return
  167. this.$emit('closeInvoice', true)
  168. let type = this.type === 'geren' ? 2 : 3
  169. this.$store.dispatch('getInvoice', {
  170. type: type,
  171. params: {
  172. invoiceType: type
  173. }
  174. })
  175. })
  176. }
  177. }
  178. }
  179. </script>
  180. <style lang="scss" scoped>
  181. @import "./style.scss";
  182. </style>