index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <script setup lang="ts">
  2. import AForm from '@/components/AForm/index.vue'
  3. import { FormConfigType } from '@/components/AForm/type'
  4. import { ToolbarConfigType } from '@/components/AToolbar/type'
  5. import { ColumnConfigType } from '@/components/ATable/type'
  6. import { StrAnyObj, StrAnyObjArr } from '@/typings'
  7. import { useHandleData } from '@/utils/useHandleData'
  8. import {
  9. getPageApi,
  10. getDetailApi,
  11. addApi,
  12. editApi,
  13. deleteApi,
  14. excelExportApi
  15. } from '@/api/business/capital/transactions'
  16. import { getPageApi as getCapitalAccountPageApi } from '@/api/business/capital/account'
  17. import { getPageApi as getCorporationPageApi } from '@/api/business/corporation/corporation'
  18. const queryRef = ref<InstanceType<typeof AForm>>()
  19. const formRef = ref<InstanceType<typeof AForm>>()
  20. const showQuery = ref<boolean>(true)
  21. const selectKeys = ref<string[]>([])
  22. const pageTotal = ref<number>(0)
  23. const queryData = ref<StrAnyObj>({ pageNum: 1, pageSize: 10 })
  24. const tableData = ref<StrAnyObjArr>([])
  25. const formData = ref<StrAnyObj>({ type: 1 })
  26. const dialogTitle = ref<string>('')
  27. const dialogVisible = ref<boolean>(false)
  28. const queryConfig: FormConfigType[] = [
  29. {
  30. type: 'select',
  31. prop: 'corporationId',
  32. label: '归属公司',
  33. keyName: 'id',
  34. labelName: 'name',
  35. async option() {
  36. const data = await getCorporationPageApi({ searchAll: true })
  37. return data.records
  38. }
  39. },
  40. {
  41. type: 'select',
  42. prop: 'capitalAccountId',
  43. label: '资金账号',
  44. keyName: 'id',
  45. labelName: 'accountAlias',
  46. async option() {
  47. const data = await getCapitalAccountPageApi({ searchAll: true })
  48. return data.records
  49. }
  50. },
  51. {
  52. type: 'datePicker',
  53. prop: 'tradingTime',
  54. label: '交易时间',
  55. datePickerType: 'daterange',
  56. defaultTime: [new Date(0, 0, 0, 0, 0, 0), new Date(0, 0, 0, 23, 59, 59)]
  57. },
  58. {
  59. type: 'select',
  60. prop: 'type',
  61. label: '交易类型',
  62. option: [
  63. {
  64. key: 1,
  65. label: '收入'
  66. },
  67. {
  68. key: 0,
  69. label: '支出'
  70. }
  71. ]
  72. },
  73. {
  74. type: 'select',
  75. prop: 'targetType',
  76. label: '对方类型',
  77. dict: 'target_type'
  78. }
  79. ]
  80. const toolbarConfig: ToolbarConfigType[] = [
  81. {
  82. common: 'search',
  83. click() {
  84. queryData.value.pageNum = 1
  85. getPage()
  86. }
  87. },
  88. {
  89. common: 'reset',
  90. click() {
  91. queryRef.value?.resetFields()
  92. getPage()
  93. }
  94. },
  95. {
  96. common: 'add',
  97. click() {
  98. dialogVisible.value = true
  99. dialogTitle.value = '新增'
  100. }
  101. },
  102. {
  103. common: 'delete',
  104. disabled() {
  105. return selectKeys.value.length == 0
  106. },
  107. click() {
  108. handleRemove(selectKeys.value)
  109. }
  110. },
  111. {
  112. text: '导出',
  113. icon: 'Download',
  114. type: 'primary',
  115. click() {
  116. excelExportApi(queryData.value).then(() => {
  117. ElMessage.success('导出成功')
  118. })
  119. }
  120. }
  121. ]
  122. const columnConfig: ColumnConfigType[] = [
  123. {
  124. prop: 'corporationName',
  125. label: '归属公司'
  126. },
  127. {
  128. prop: 'accountAlias',
  129. label: '资金账号'
  130. },
  131. {
  132. prop: 'tradingTime',
  133. label: '交易时间'
  134. },
  135. {
  136. prop: 'type',
  137. label: '交易类型',
  138. formatter(row) {
  139. return row.type == 1 ? '收入' : '支出'
  140. }
  141. },
  142. {
  143. prop: 'amount',
  144. label: '交易金额'
  145. },
  146. {
  147. prop: 'targetType',
  148. label: '对方类型',
  149. dict: 'target_type'
  150. },
  151. {
  152. prop: 'targetAccountName',
  153. label: '对方账户名'
  154. },
  155. {
  156. prop: 'targetDepositBank',
  157. label: '对方开户银行'
  158. },
  159. {
  160. prop: 'targetAccount',
  161. label: '对方账号'
  162. },
  163. {
  164. prop: 'remark',
  165. label: '摘要',
  166. showOverflowTooltip: true
  167. },
  168. {
  169. width: 250,
  170. handleConfig: [
  171. {
  172. common: 'update',
  173. click(row) {
  174. dialogVisible.value = true
  175. dialogTitle.value = '编辑'
  176. getDetailApi({ id: row.id }).then((resp: StrAnyObj) => {
  177. formData.value = resp
  178. })
  179. }
  180. },
  181. {
  182. common: 'delete',
  183. click(row) {
  184. handleRemove([row.id])
  185. }
  186. }
  187. ]
  188. }
  189. ]
  190. const formConfig: FormConfigType[] = [
  191. {
  192. type: 'select',
  193. prop: 'capitalAccountId',
  194. label: '资金账号',
  195. keyName: 'id',
  196. labelName: 'accountAlias',
  197. async option() {
  198. const data = await getCapitalAccountPageApi({ searchAll: true })
  199. return data.records
  200. },
  201. rule: [{ required: true, message: '资金账号不能为空', trigger: 'blur' }]
  202. },
  203. {
  204. type: 'datePicker',
  205. prop: 'tradingTime',
  206. label: '交易时间',
  207. datePickerType: 'datetime',
  208. format: 'YYYY-MM-DD hh:mm:ss',
  209. valueFormat: 'YYYY-MM-DD hh:mm:ss',
  210. defaultTime: new Date(),
  211. rule: [{ required: true, message: '交易时间不能为空', trigger: 'blur' }]
  212. },
  213. {
  214. type: 'radio',
  215. prop: 'type',
  216. label: '交易类型',
  217. option: [
  218. {
  219. key: 1,
  220. label: '收入'
  221. },
  222. {
  223. key: 0,
  224. label: '支出'
  225. }
  226. ],
  227. rule: [{ required: true, message: '交易类型不能为空', trigger: 'blur' }]
  228. },
  229. {
  230. type: 'inputNumber',
  231. prop: 'amount',
  232. label: '交易金额',
  233. min: 0.01,
  234. precision: 2,
  235. rule: [{ required: true, message: '交易金额不能为空', trigger: 'blur' }]
  236. },
  237. {
  238. type: 'select',
  239. prop: 'targetType',
  240. label: '对方类型',
  241. dict: 'target_type',
  242. rule: [{ required: true, message: '对方类型不能为空', trigger: 'blur' }]
  243. },
  244. {
  245. type: 'input',
  246. prop: 'targetAccountName',
  247. label: '对方账户名'
  248. },
  249. {
  250. type: 'input',
  251. prop: 'targetDepositBank',
  252. label: '对方开户银行'
  253. },
  254. {
  255. type: 'input',
  256. prop: 'targetAccount',
  257. label: '对方账号'
  258. },
  259. {
  260. type: 'input',
  261. prop: 'remark',
  262. itemType: 'textarea',
  263. rows: 5,
  264. label: '摘要'
  265. }
  266. ]
  267. onMounted(() => {
  268. getPage()
  269. })
  270. function getPage() {
  271. getPageApi(queryData.value).then((resp) => {
  272. tableData.value = resp.records
  273. pageTotal.value = resp.total
  274. })
  275. }
  276. function tableSelectionChange(item: StrAnyObjArr) {
  277. selectKeys.value = item.map((item) => item.id)
  278. }
  279. function formSubmit() {
  280. formRef.value?.validate(() => {
  281. if (formData.value.id) {
  282. editApi(formData.value).then(() => {
  283. dialogVisible.value = false
  284. ElMessage.success('修改成功')
  285. getPage()
  286. })
  287. } else {
  288. addApi(formData.value).then(() => {
  289. dialogVisible.value = false
  290. ElMessage.success('新增成功')
  291. getPage()
  292. })
  293. }
  294. })
  295. }
  296. function formClosed() {
  297. formRef.value?.resetFields()
  298. }
  299. function handleRemove(idList: string[]) {
  300. useHandleData('是否确认删除?', () => {
  301. deleteApi({ idList }).then(() => {
  302. ElMessage.success('删除成功')
  303. getPage()
  304. })
  305. })
  306. }
  307. </script>
  308. <template>
  309. <div>
  310. <el-card v-if="showQuery">
  311. <a-form ref="queryRef" v-model="queryData" :config="queryConfig" :span="6"> </a-form>
  312. </el-card>
  313. <a-table
  314. selection
  315. :data="tableData"
  316. :page-total="pageTotal"
  317. :toolbar-config="toolbarConfig"
  318. :column-config="columnConfig"
  319. v-model:showQuery="showQuery"
  320. v-model:page-num="queryData.pageNum"
  321. v-model:page-size="queryData.pageSize"
  322. @page-num-change="getPage"
  323. @page-size-change="getPage"
  324. @selection-change="tableSelectionChange"
  325. >
  326. </a-table>
  327. <a-dialog
  328. v-model="dialogVisible"
  329. :title="dialogTitle"
  330. @submit="formSubmit"
  331. @closed="formClosed"
  332. >
  333. <a-form ref="formRef" v-model="formData" :config="formConfig" :span="24"> </a-form>
  334. </a-dialog>
  335. </div>
  336. </template>