|
@@ -0,0 +1,227 @@
|
|
|
+<template>
|
|
|
+ <div class="w-50vw">
|
|
|
+ <basic-form @register="register" @submit="handleSubmit" />
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+<script lang="ts">
|
|
|
+ import { defineComponent, computed, unref, watch, PropType } from 'vue'
|
|
|
+ import { BasicForm, FormSchema, useForm } from '/@/components/Form/index'
|
|
|
+ import { ProjectStatusEnum } from '/@/enums/statusEnum'
|
|
|
+ import { useOfficeStore } from '/@/store/modules/office'
|
|
|
+ import { ProjectListItem, ProjectDetailParams } from '/@/api/sys/model/projectModel'
|
|
|
+ import { onMountedOrActivated } from '/@/hooks/core/onMountedOrActivated'
|
|
|
+ import { updateProject } from '/@/api/sys/project'
|
|
|
+ import { useMessage } from '/@/hooks/web/useMessage'
|
|
|
+ const schemas: FormSchema[] = [
|
|
|
+ {
|
|
|
+ field: 'status',
|
|
|
+ component: 'RadioGroup',
|
|
|
+ label: '状态',
|
|
|
+
|
|
|
+ componentProps: {
|
|
|
+ options: [
|
|
|
+ {
|
|
|
+ label: '正常',
|
|
|
+ value: ProjectStatusEnum.NORMAL
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '停用',
|
|
|
+ value: ProjectStatusEnum.STOP
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'createName',
|
|
|
+ component: 'Input',
|
|
|
+ label: '创建者',
|
|
|
+ componentProps: {
|
|
|
+ disabled: true
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'code',
|
|
|
+ component: 'Input',
|
|
|
+ label: '项目编号',
|
|
|
+
|
|
|
+ componentProps: {
|
|
|
+ disabled: true
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'name',
|
|
|
+ component: 'Input',
|
|
|
+ label: '项目名称',
|
|
|
+
|
|
|
+ required: true
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'insideCategoryId',
|
|
|
+ component: 'Select',
|
|
|
+ componentProps: {
|
|
|
+ showArrow: true
|
|
|
+ },
|
|
|
+ label: '所在办事处',
|
|
|
+
|
|
|
+ required: true
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'categoryId',
|
|
|
+ component: 'Select',
|
|
|
+ label: '销售负责人',
|
|
|
+ componentProps: {
|
|
|
+ showArrow: true
|
|
|
+ },
|
|
|
+ colProps: {
|
|
|
+ span: 14
|
|
|
+ },
|
|
|
+ required: true
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'staffId',
|
|
|
+ component: 'Select',
|
|
|
+ disabledLabelWidth: true,
|
|
|
+ componentProps: {
|
|
|
+ showArrow: true
|
|
|
+ },
|
|
|
+ label: '',
|
|
|
+ colProps: {
|
|
|
+ span: 8,
|
|
|
+ offset: 2
|
|
|
+ },
|
|
|
+ required: true
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'remark',
|
|
|
+ component: 'InputTextArea',
|
|
|
+ label: '备注'
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ export default defineComponent({
|
|
|
+ components: {
|
|
|
+ BasicForm
|
|
|
+ },
|
|
|
+ props: {
|
|
|
+ info: {
|
|
|
+ type: Object as PropType<ProjectListItem>,
|
|
|
+ required: true
|
|
|
+ }
|
|
|
+ },
|
|
|
+ emits: ['updateInfo:info'],
|
|
|
+ setup(props, { emit }) {
|
|
|
+ const info = computed({
|
|
|
+ get: () => props.info,
|
|
|
+ set: value => emit('updateInfo:info', value)
|
|
|
+ })
|
|
|
+
|
|
|
+ const { createMessage } = useMessage()
|
|
|
+ const officeStore = useOfficeStore()
|
|
|
+ const options = computed(() => officeStore.getCategoryOptions)
|
|
|
+ const staffOptions = computed(() => officeStore.getCategoriedStaff)
|
|
|
+
|
|
|
+ const [register, { updateSchema, setFieldsValue, removeSchemaByFiled, appendSchemaByField }] = useForm({
|
|
|
+ labelWidth: 120,
|
|
|
+ schemas,
|
|
|
+ actionColOptions: {
|
|
|
+ flex: '280px',
|
|
|
+ span: 14
|
|
|
+ },
|
|
|
+ submitButtonOptions: {
|
|
|
+ text: '确认修改'
|
|
|
+ }
|
|
|
+ })
|
|
|
+ async function checkOffice() {
|
|
|
+ if (!officeStore.getOfficesAction.length) {
|
|
|
+ await officeStore.getOfficesAction()
|
|
|
+ }
|
|
|
+ if (props.info.categoryId) {
|
|
|
+ await officeStore.getStaffWithCategoryIdAction({ categoryId: props.info.categoryId })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ onMountedOrActivated(async () => {
|
|
|
+ await checkOffice()
|
|
|
+ await updateSchema([
|
|
|
+ {
|
|
|
+ field: 'insideCategoryId',
|
|
|
+ component: 'Select',
|
|
|
+ label: '所在办事处',
|
|
|
+ componentProps: { options, showArrow: true },
|
|
|
+ required: true
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'categoryId',
|
|
|
+ component: 'Select',
|
|
|
+ label: '销售负责人',
|
|
|
+ componentProps: {
|
|
|
+ options,
|
|
|
+ showArrow: true,
|
|
|
+ onChange: (value: string) => {
|
|
|
+ officeStore.getStaffWithCategoryIdAction({ categoryId: value })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ colProps: {
|
|
|
+ span: 14
|
|
|
+ },
|
|
|
+ required: true
|
|
|
+ }
|
|
|
+ ])
|
|
|
+ await setFieldsValue({ ...unref(info) })
|
|
|
+ })
|
|
|
+ watch(staffOptions, async newStaffOtpions => {
|
|
|
+ await removeSchemaByFiled('staffId')
|
|
|
+ await appendSchemaByField(
|
|
|
+ {
|
|
|
+ field: 'staffId',
|
|
|
+ component: 'Select',
|
|
|
+ label: '',
|
|
|
+ componentProps: {
|
|
|
+ showArrow: true,
|
|
|
+ options: newStaffOtpions
|
|
|
+ },
|
|
|
+ disabledLabelWidth: true,
|
|
|
+ colProps: {
|
|
|
+ span: 8,
|
|
|
+ offset: 2
|
|
|
+ },
|
|
|
+ required: true
|
|
|
+ },
|
|
|
+ 'categoryId'
|
|
|
+ )
|
|
|
+ })
|
|
|
+ const handleOnSave = async (values: {
|
|
|
+ name: string
|
|
|
+ insideCategoryId: string
|
|
|
+ categoryId: string
|
|
|
+ staffId: string
|
|
|
+ remark: string
|
|
|
+ status: string
|
|
|
+ }) => {
|
|
|
+ const newVal: ProjectDetailParams = {
|
|
|
+ ...values,
|
|
|
+ id: props.info.id,
|
|
|
+ insideCategory: '',
|
|
|
+ category: '',
|
|
|
+ staffName: ''
|
|
|
+ }
|
|
|
+ if (values.insideCategoryId) {
|
|
|
+ newVal.insideCategory = options.value.find(item => item.value === values.insideCategoryId)?.label || ''
|
|
|
+ }
|
|
|
+ if (values.categoryId) {
|
|
|
+ newVal.category = options.value.find(item => item.value === values.categoryId)?.label || ''
|
|
|
+ }
|
|
|
+ if (values.staffId) {
|
|
|
+ newVal.staffName = staffOptions.value.find(item => item.value === values.staffId)?.label || ''
|
|
|
+ }
|
|
|
+ await updateProject(newVal)
|
|
|
+ }
|
|
|
+ function handleSubmit(values) {
|
|
|
+ try {
|
|
|
+ handleOnSave(values)
|
|
|
+ } finally {
|
|
|
+ createMessage.success('更新成功')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return { register, schemas, handleSubmit }
|
|
|
+ }
|
|
|
+ })
|
|
|
+</script>
|