index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <!-- 发票管理 -->
  2. <template>
  3. <v-card class="card-box pa-5">
  4. <CtTable
  5. :items="items"
  6. :headers="headers"
  7. :loading="false"
  8. :elevation="0"
  9. :isTools="true"
  10. :showPage="true"
  11. :total="total"
  12. :page-info="query"
  13. @pageHandleChange="handleChangePage"
  14. @add="handle"
  15. @edit="handle"
  16. @del="handleDelete"
  17. >
  18. </CtTable>
  19. </v-card>
  20. <CtDialog :visible="show" :widthType="3" titleClass="text-h6" :title="editId ? '编辑发票抬头' : '新增发票抬头'" @close="handleClose" @submit="handleSubmit">
  21. <CtForm ref="CtFormRef" :items="formItems">
  22. <template #certificationTip>
  23. <div style="color:var(--color-999); font-size: 13px;margin-left: 108px;" class="mb-5">
  24. <v-icon color="primary" size="20" class="mr-1">mdi-check-circle-outline</v-icon>
  25. <span>企业实名认证账号,可开具普票和企业专票</span>
  26. <span>
  27. <span>查看</span>
  28. </span>
  29. </div>
  30. </template>
  31. <template #invoiceHeaderTip v-if="invoiceHeaderTip">
  32. <div style="color:var(--color-999); font-size: 13px;" class="d-flex mr-10">
  33. <v-icon color="primary" class="mr-1 mt-1">mdi-shield-check</v-icon>
  34. <div>相关法律规定,专票抬头与实名认证主体必须一致, 若需开具其他主体专票,请变更企业实名认证</div>
  35. </div>
  36. </template>
  37. </CtForm>
  38. </CtDialog>
  39. </template>
  40. <script setup>
  41. defineOptions({ name: 'invoiceHeader'})
  42. import { nextTick, ref } from 'vue'
  43. import { getEnterpriseBusiness } from '@/api/enterprise'
  44. import { getInvoiceTitlePage, createInvoiceTitle, updateInvoiceTitle, deleteInvoiceTitle } from '@/api/recruit/enterprise/member/invoice'
  45. import Snackbar from '@/plugins/snackbar'
  46. import Confirm from '@/plugins/confirm'
  47. import { useI18n } from '@/hooks/web/useI18n'
  48. import { checkUSCI, checkBankNo, checkBankName, checkAddress } from '@/utils/validate'
  49. const { t } = useI18n()
  50. const total = ref(0)
  51. const items = ref([])
  52. const headers = [
  53. { title: '抬头类型', key: 'category', sortable: false, value: item => item.category === 0 ? '个人' : '企业' },
  54. { title: '发票类型', key: 'type', sortable: false, value: item => item.type === 0 ? '增值税普通发票' : '增值税专用发票' },
  55. { title: '发票抬头', key: 'title', sortable: false },
  56. { title: '纳税人识别号', key: 'code', sortable: false },
  57. { title: '基本开户银行', key: 'enterpriseBankTitle', sortable: false },
  58. { title: '基本银行账号', key: 'enterpriseBankNo', sortable: false },
  59. { title: '企业注册地址', key: 'enterpriseAddress', sortable: false },
  60. { title: '企业注册电话', key: 'enterprisePhone', sortable: false },
  61. { title: '操作', key: 'actions', sortable: false }
  62. ]
  63. const query = ref({
  64. pageNo: 1,
  65. pageSize: 10
  66. })
  67. const CtFormRef = ref()
  68. const show = ref(false)
  69. const editId = ref(null)
  70. const editInfo = ref(null)
  71. const personKeys = ['category', 'type', 'title']
  72. const enterpriseKeys = ['category', 'type', 'certificationTip', 'invoiceHeaderTip', 'title', 'code', 'enterpriseBankTitle', 'enterpriseBankNo', 'enterpriseAddress', 'enterprisePhone']
  73. // 抬头类型
  74. const handleChangeCategory = (categoryType = 0) => { // 0: 个人, 1: 企业
  75. formItems.value.options = []
  76. const keyArr = categoryType ? enterpriseKeys : personKeys
  77. const arr = keyArr.map(key => {
  78. const optionsItem = { ...optionsBase[key] }
  79. if (categoryType === 0) { // 个人
  80. invoiceHeaderTip.value = false
  81. if (optionsItem.key === 'type') optionsItem.items = [optionsItem.items[0]]
  82. if (optionsItem.key === 'title') {
  83. optionsItem.value = '个人'
  84. optionsItem.disabled = true
  85. }
  86. } else { // 企业
  87. if (optionsItem.key === 'category') optionsItem.value = 1
  88. if (editInfo.value) {
  89. if (editInfo.value[key]) optionsItem.value = editInfo.value[key]
  90. } else {
  91. if (business.value[key]) optionsItem.value = business.value[key]
  92. }
  93. }
  94. return optionsItem
  95. })
  96. nextTick(() => {
  97. formItems.value.options = arr
  98. })
  99. }
  100. const invoiceHeaderTip = ref(false)
  101. const handleChangeType = (isVerified) => {
  102. invoiceHeaderTip.value = isVerified
  103. formItems.value.options.forEach(e => {
  104. if (business.value[e.key]) e.value = business.value[e.key] // business.value
  105. if (e.key === 'title') e.disabled = isVerified
  106. if (e.rulesBaseLabel) {
  107. e.label = isVerified ? `${e.rulesBaseLabel} *` : e.rulesBaseLabel
  108. e.rules = isVerified ? [v => !!v || `请输入${e.rulesBaseLabel}`, ...e.rules] : []
  109. }
  110. })
  111. }
  112. const optionsBase = {
  113. category: {
  114. type: 'ifRadio',
  115. key: 'category',
  116. value: 0,
  117. label: '抬头类型 *',
  118. width: 90,
  119. items: [
  120. { label: '个人', value: 0 },
  121. { label: '企业', value: 1 }
  122. ],
  123. change: handleChangeCategory
  124. },
  125. type: {
  126. type: 'ifRadio',
  127. key: 'type',
  128. value: 0,
  129. label: '发票类型 *',
  130. width: 90,
  131. hideDetails: true,
  132. items: [
  133. { label: '增值税普通发票', value: 0 },
  134. { label: '增值税专用发票', value: 1 }
  135. ],
  136. change: handleChangeType
  137. },
  138. title: {
  139. type: 'text',
  140. key: 'title',
  141. value: '',
  142. label: '发票抬头 *',
  143. rules: [v => !!v || '请输入发票抬头'],
  144. },
  145. code: {
  146. type: 'text',
  147. key: 'code',
  148. value: '',
  149. label: '纳税人识别号 *',
  150. outlined: true,
  151. rules: [
  152. value => {
  153. if (value && checkUSCI(value)) return true
  154. return '纳税人识别号'
  155. }
  156. ]
  157. },
  158. enterpriseBankTitle: {
  159. type: 'text',
  160. key: 'enterpriseBankTitle',
  161. value: null,
  162. label: '基本开户银行',
  163. placeholder: '请填写开户许可证上的开户银行',
  164. rulesBaseLabel: '基本开户银行',
  165. outlined: true,
  166. rules: [
  167. value => {
  168. if (!value || (value && checkBankName(value))) return true
  169. return '请输入正确的开户银行'
  170. }
  171. ]
  172. },
  173. enterpriseBankNo: {
  174. type: 'number',
  175. key: 'enterpriseBankNo',
  176. value: null,
  177. label: '基本银行账号',
  178. placeholder: '请填写开户许可证上的银行账号',
  179. rulesBaseLabel: '基本银行账号',
  180. outlined: true,
  181. rules: [
  182. value => {
  183. if (!value || (value && checkBankNo(value))) return true
  184. return '请输入正确的银行账号'
  185. }
  186. ]
  187. },
  188. enterpriseAddress: {
  189. type: 'text',
  190. key: 'enterpriseAddress',
  191. value: null,
  192. label: '企业注册地址',
  193. placeholder: '请填写开户许可证上的企业注册地址',
  194. rulesBaseLabel: '企业注册地址',
  195. outlined: true,
  196. rules: [
  197. value => {
  198. if (!value || (value && checkAddress(value))) return true
  199. return '请输入正确的注册地址'
  200. }
  201. ]
  202. },
  203. enterprisePhone: {
  204. type: 'phoneNumber',
  205. key: 'enterprisePhone',
  206. value: null,
  207. label: '企业注册电话',
  208. placeholder: '请填写开户许可证上的企业注册电话',
  209. rulesBaseLabel: '企业注册电话',
  210. outlined: true,
  211. },
  212. certificationTip: {
  213. slotName: 'certificationTip',
  214. },
  215. invoiceHeaderTip: {
  216. slotName: 'invoiceHeaderTip',
  217. },
  218. }
  219. const formItems = ref({ options: [] })
  220. // 获取列表
  221. const getList =async () => {
  222. const res = await getInvoiceTitlePage(query.value)
  223. items.value = res.list
  224. total.value = res.total
  225. }
  226. getList()
  227. const handleChangePage = (e) => {
  228. query.value.pageNo = e
  229. getList()
  230. }
  231. // 获取企业工商信息
  232. const business = ref({})
  233. const getEnterpriseBusinessInfo = async () => {
  234. const data = await getEnterpriseBusiness()
  235. if (!data || !Object.keys(data).length) return
  236. // console.log(1, 'business', data)
  237. business.value = {
  238. title: data.name,
  239. code: data.code,
  240. enterpriseAddress: data.address,
  241. }
  242. }
  243. getEnterpriseBusinessInfo()
  244. // 新增 编辑
  245. const handle = (item) => {
  246. editId.value = item?.id || null
  247. editInfo.value = item || null
  248. handleChangeCategory(item?.category || 0)
  249. handleChangeType(item?.type || 0)
  250. show.value = true
  251. }
  252. // 删除
  253. const handleDelete = ({ id }) => {
  254. Confirm(t('common.confirmTitle'), '是否确定删除此抬头信息?').then(async () => {
  255. await deleteInvoiceTitle(id)
  256. Snackbar.success(t('common.delMsg'))
  257. getList()
  258. })
  259. }
  260. // 新增、编辑提交
  261. const handleClose = () => {
  262. show.value = false
  263. editId.value = null
  264. }
  265. const { userId } = JSON.parse(localStorage.getItem('accountInfo'))
  266. const handleSubmit = async () => {
  267. const { valid } = await CtFormRef.value.formRef.validate()
  268. if (!valid || !userId) return
  269. const obj = {
  270. userId
  271. }
  272. formItems.value.options.forEach(item => {
  273. obj[item.key] = item.value
  274. })
  275. if (obj.type === undefined || obj.type === null || obj.type === '') return Snackbar.warning('请选择发票类型')
  276. if (editId.value) obj.id = editId.value
  277. const api = editId.value ? updateInvoiceTitle : createInvoiceTitle
  278. await api(obj)
  279. Snackbar.success(editId.value ? t('common.editSuccessMsg') : t('common.addMsg'))
  280. handleClose()
  281. getList()
  282. }
  283. </script>
  284. <style scoped lang="scss">
  285. </style>