index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <PageWrapper>
  3. <BasicTable @register="registerTable">
  4. <template #toolbar>
  5. <div class="w-2/5 flex">
  6. <Search @search="value => handleSearch('search', value)" placeholder="项目名称/项目编号" />
  7. <a-button @click="showModalFn" class="ml-3"><PlusOutlined />新增项目</a-button>
  8. </div>
  9. </template>
  10. <template #filterDropdown="{ setSelectedKeys, selectedKeys, confirm, clearFilters }">
  11. <div class="p-3">
  12. <a-select
  13. :options="options"
  14. placeholder="按办事处筛选"
  15. @select="value => setSelectedKeys([value])"
  16. allowclear
  17. />
  18. </div>
  19. <div class="pb-3 justify-center flex">
  20. <a-button size="small" @click="() => handleSearch('insideCategoryId', selectedKeys[0], confirm)" class="mr-3"
  21. >确定</a-button
  22. >
  23. <a-button size="small" @click="() => clearFilters()">重置</a-button>
  24. </div>
  25. </template>
  26. </BasicTable>
  27. <BasicModal @register="registerModal" @ok="submitModal">
  28. <BasicForm @register="registerForm" ref="formElRef" />
  29. </BasicModal>
  30. </PageWrapper>
  31. </template>
  32. <script lang="ts">
  33. import { computed, defineComponent, ref } from 'vue'
  34. import { BasicTable, useTable } from '/@/components/Table'
  35. import { BasicModal, useModal } from '/@/components/Modal'
  36. import { BasicForm, FormActionType, FormSchema, useForm } from '/@/components/Form/index'
  37. import { PlusOutlined } from '@ant-design/icons-vue'
  38. import { PageWrapper } from '/@/components/Page'
  39. import { getProjectList } from '/@/api/sys/project'
  40. import { Input, Select } from 'ant-design-vue'
  41. import { getProjectTableColumns } from './tableData'
  42. import { useOfficeStore } from '/@/store/modules/office'
  43. import { ProjectListItem, ProjectListParams, ProjectUpdateOrCreateParams } from '/@/api/sys/model/projectModel'
  44. import { addProject } from '/@/api/sys/project'
  45. import { onMountedOrActivated } from '/@/hooks/core/onMountedOrActivated'
  46. import { useMessage } from '/@/hooks/web/useMessage'
  47. export default defineComponent({
  48. name: 'Workbench',
  49. components: {
  50. PageWrapper,
  51. BasicTable,
  52. Search: Input.Search,
  53. ASelect: Select,
  54. BasicModal,
  55. BasicForm,
  56. PlusOutlined
  57. },
  58. setup() {
  59. const { createMessage } = useMessage()
  60. const formElRef = ref<Nullable<FormActionType>>(null)
  61. const officeStore = useOfficeStore()
  62. const options = computed(() => officeStore.getCategoryOptions)
  63. const staffOptions = computed(() => officeStore.getCategoriedStaff)
  64. const schemas = computed<FormSchema[]>(() => [
  65. {
  66. field: 'code',
  67. component: 'Input',
  68. label: '项目编号',
  69. required: true
  70. },
  71. {
  72. field: 'name',
  73. component: 'Input',
  74. label: '项目名称',
  75. required: true
  76. },
  77. {
  78. field: 'categoryId',
  79. component: 'Select',
  80. label: '销售负责人',
  81. componentProps: {
  82. options,
  83. showArrow: true,
  84. onChange: async (value: string) => {
  85. officeStore.getStaffWithCategoryIdAction({ categoryId: value })
  86. const formRef = formElRef.value
  87. formRef?.setFieldsValue({ staffId: '' })
  88. }
  89. },
  90. colProps: {
  91. span: 15
  92. },
  93. required: true
  94. },
  95. {
  96. field: 'staffId',
  97. component: 'Select',
  98. disabledLabelWidth: true,
  99. componentProps: {
  100. showArrow: true,
  101. options: staffOptions
  102. },
  103. label: '',
  104. colProps: {
  105. span: 8,
  106. offset: 1
  107. }
  108. },
  109. {
  110. field: 'remark',
  111. label: '备注',
  112. component: 'InputTextArea'
  113. }
  114. ])
  115. async function checkOffice() {
  116. if (!officeStore.getOfficesAction.length) {
  117. await officeStore.getOfficesAction()
  118. }
  119. }
  120. const [registerTable, { setTableData, reload }] = useTable({
  121. canResize: true,
  122. title: '项目列表',
  123. rowKey: 'id',
  124. api: getProjectList,
  125. columns: getProjectTableColumns(),
  126. showTableSetting: true
  127. })
  128. const [registerModal, { openModal, setModalProps }] = useModal()
  129. const [registerForm] = useForm({
  130. labelWidth: 120,
  131. schemas,
  132. showActionButtonGroup: false
  133. })
  134. onMountedOrActivated(async () => {
  135. checkOffice()
  136. })
  137. async function handleSearch(key: keyof ProjectListParams, value: string, fn?: Fn) {
  138. if (fn) {
  139. fn()
  140. } else {
  141. const tableData = await getProjectList({ page: 1, pageSize: 10, [key]: value })
  142. setTableData<ProjectListItem>(tableData.items)
  143. }
  144. }
  145. async function showModalFn() {
  146. openModal()
  147. setModalProps({
  148. title: '新增项目',
  149. okText: '确认添加'
  150. })
  151. }
  152. function submitModal() {
  153. formElRef.value?.validate().then((values: ProjectUpdateOrCreateParams) => {
  154. createProject(values)
  155. })
  156. }
  157. async function createProject(values: ProjectUpdateOrCreateParams) {
  158. const newVals = { ...values }
  159. if (values.categoryId) {
  160. newVals.category = options.value.find(item => item.value === values.categoryId)?.label || ''
  161. }
  162. if (values.staffId) {
  163. newVals.staffName = staffOptions.value.find(item => item.value === values.staffId)?.label || ''
  164. }
  165. try {
  166. await addProject(newVals)
  167. } finally {
  168. openModal(false)
  169. reload()
  170. createMessage.success('新建项目成功')
  171. }
  172. }
  173. return {
  174. showModalFn,
  175. registerTable,
  176. options,
  177. handleSearch,
  178. registerModal,
  179. registerForm,
  180. submitModal,
  181. formElRef
  182. }
  183. }
  184. })
  185. </script>