Browse Source

创建项目

ZaiZai 10 months ago
parent
commit
7aa7f438b2
2 changed files with 95 additions and 147 deletions
  1. 47 0
      src/views/project/info/style/template.scss
  2. 48 147
      src/views/project/info/template.vue

+ 47 - 0
src/views/project/info/style/template.scss

@@ -0,0 +1,47 @@
+.hc-project-wbs-template {
+    padding: 0 12px;
+    .wbs-template-segmented .el-segmented {
+        --el-border-radius-base: 50px;
+        .el-segmented__item {
+            padding: 0 18px;
+        }
+    }
+    .wbs-template-body {
+        position: relative;
+        height: calc(100% - 120px);
+        display: flex;
+        .hc-card-item-box {
+            background: white !important;
+            border: 1px solid #eee;
+            border-radius: 5px;
+            padding: 0;
+            .hc-card-item-header {
+                height: 40px;
+                padding: 0 12px;
+                margin-bottom: 0;
+                background: #f9f9f9;
+                border-radius: 4px 4px 0 0;
+                border-bottom: 1px solid #eee;
+            }
+            .hc-card-item-body {
+                padding: 12px;
+                height: calc(100% - 40px) !important;
+            }
+        }
+        .left {
+            position: relative;
+            flex: 1;
+        }
+        .action {
+            position: relative;
+            display: flex;
+            align-items: center;
+            justify-content: center;
+            padding: 0 14px;
+        }
+        .right {
+            position: relative;
+            flex: 1;
+        }
+    }
+}

+ 48 - 147
src/views/project/info/template.vue

@@ -77,15 +77,18 @@ onMounted(() => {
 
 //顶部类型
 const templateType = ref(1)
-const templateTypeData = [{ value: 1, label: '质检' }, { value: 2, label: '试验' }, { value: 3, label: '计量' }, { value: 5, label: '征拆' }]
+const templateTypeData = [
+    { value: 1, label: '质检' }, { value: 2, label: '试验' },
+    { value: 3, label: '计量' }, { value: 5, label: '征拆' },
+]
 
 //获取WBS树列表
 const wbsId = ref('')
 const wbsTreeList = ref([])
 const isLoading = ref(false)
 const getWbsTreeList = async () => {
-    const type = templateType.value
     isLoading.value = true
+    const type = templateType.value
     const { data } = await mainApi.findWbsTreeList(type)
     // 格式化数据
     const res = getObjValue(data)
@@ -114,32 +117,26 @@ const getWbsTreeList = async () => {
     await wbsChange(wbsId.value)
 }
 
+//左边树
+const leftLoading = ref(false)
+const leftTreeData = ref([])
+
 //切换wbs树
 const isDisabled = ref(false)
+const referenceWbsId = ref('')
+const referenceWbsType = ref('')
 const wbsChange = async (val) => {
     isDisabled.value = false
-    const type = templateType.value
-    if (type === 1) {
-        formModel.value.referenceWbsTemplateId = val
-    } else if (type === 3) {
-        formModel.value.referenceWbsTemplateIdMeter = val
-    } else if (type === 5) {
-        formModel.value.referenceWbsTemplateIdLar = val
-    } else {
-        formModel.value.referenceWbsTemplateIdTrial = val
-    }
     leftLoading.value = true
-    if (!isNullES(val) && val.toString().indexOf(',') >= 0) {
-        //私有库
-        if (type === 1) {
-            formModel.value.referenceWbsTemplateType = 'private'
-        } else if (type === 2) {
-            formModel.value.referenceWbsTemplateTypeMeter = 'private'
-        } else if (type === 5) {
-            formModel.value.referenceWbsTemplateTypeLar = 'private'
-        } else {
-            formModel.value.referenceWbsTemplateTypeTrial = 'private'
-        }
+    referenceWbsId.value = val
+    //无值
+    if (isNullES(val)) {
+        await getRightTreeApi()
+        return
+    }
+    //私有库
+    if (val.toString().indexOf(',') >= 0) {
+        referenceWbsType.value = 'private'
         let ids = val.toString().split(',')
         const { data } = await mainApi.findProjectTree({
             projectId: ids[1],
@@ -147,19 +144,12 @@ const wbsChange = async (val) => {
         })
         leftTreeData.value = getArrValue(data)
         leftLoading.value = false
-    } else {
-        //公有库
-        if (!isNullES(val) && val.length > 0) {
-            if (type === 1) {
-                formModel.value.referenceWbsTemplateType = 'public'
-            } else if (type === 2) {
-                formModel.value.referenceWbsTemplateTypeMeter = 'public'
-            } else if (type === 5) {
-                formModel.value.referenceWbsTemplateTypeLar = 'public'
-            } else {
-                formModel.value.referenceWbsTemplateTypeTrial = 'public'
-            }
-        }
+        await getRightTreeApi()
+        return
+    }
+    //公有库
+    if (val.length > 0) {
+        referenceWbsType.value = 'public'
         const { tenant_id } = getObjValue(userInfo.value)
         const { data } = await treeApi.getAlltree({
             tenantId: tenant_id,
@@ -168,49 +158,39 @@ const wbsChange = async (val) => {
         })
         leftTreeData.value = getArrValue(data)
         leftLoading.value = false
+        await getRightTreeApi()
     }
-    await getRightTreeApi()
 }
 
-//左边树
-const leftLoading = ref(false)
-const leftTreeData = ref([])
-const nowref = ref({})
-const finalWbsid = ref('')
-
-//右边树
+//获取右边数据
 const rightLoading = ref(false)
 const rightTreeData = ref([])
-const rightObj1 = ref({})
-const rightObj2 = ref({})
-const rightObj3 = ref({})
-const rightObj4 = ref({})
-
-//获取右边数据
 const getRightTreeApi = async () => {
     rightLoading.value = true
-    isDisabled.value = true
-    const type = templateType.value, form = getObjValue(formModel.value)
-    let refId = type === 1 ? form.referenceWbsTemplateId : form.referenceWbsTemplateIdTrial
-    if (type === 3) refId = form.referenceWbsTemplateIdMeter
-    if (type === 5) refId = form.referenceWbsTemplateIdLar
+    //isDisabled.value = true
+    let refId = referenceWbsId.value
     if (isNullES(refId)) {
         isDisabled.value = false
         rightLoading.value = false
         return
     }
-    let newWbsId = ''
-    if (refId.toString().length > 0 && ifPrivateType()) {
-        refId = setRefId(refId)
+    //私有
+    if (refId.toString().length > 0 && referenceWbsType.value === 'private') {
+        let ids = refId.toString().split(',')
+        if (ids.length > 1) {
+            refId = ids[0]
+            let list = wbsTreeList.value[1].data
+            refId = list.filter(({ projectId }) => projectId === ids[1])[0].pkeyId
+        }
     }
     //引用被删会出现 wbsType -1
     if (refId && refId > 0) {
         let priv = {}
-        if (ifPrivateType()) {
-            //私有
+        //私有
+        if (referenceWbsType.value === 'private') {
             let list = wbsTreeList.value[1].data
             for (let i = 0; i < list.length; i++) {
-                if (list[i].pkeyId == refId) {
+                if (list[i].pkeyId === refId) {
                     refId = list[i].wbsId + ',' + list[i].projectId
                     priv.wbsId = list[i].wbsId
                     priv.projectId = list[i].projectId
@@ -221,102 +201,23 @@ const getRightTreeApi = async () => {
             }
         } else {
             //公有
-            newWbsId = refId
-        }
-        const now = getObjValue(nowref.value)
-        if (now.key === refId) {
-            newWbsId = now.id
-        } else {
-            if (refId.toString().length > 0 && ifPrivateType()) {
-                newWbsId = priv.pkeyId
-            } else {
-                newWbsId = type === 1 ? form.referenceWbsTemplateId : form.referenceWbsTemplateIdTrial
-                if (type === 5) {
-                    newWbsId = form.referenceWbsTemplateIdLar
-                }
-                if (type === 3) {
-                    newWbsId = form.referenceWbsTemplateIdMeter
-                }
-            }
+            refId = referenceWbsId.value
         }
     }
-    finalWbsid.value = newWbsId
+    const form = getObjValue(formModel.value)
     const { data } = await mainApi.findProjectTree({
         projectId: form.id,
-        wbsId: newWbsId,
+        wbsId: refId,
     })
-    console.log(data)
+    const projectTree = getArrValue(data)
+    isDisabled.value = projectTree.length > 0
+    rightTreeData.value = projectTree
     rightLoading.value = false
 }
 
-//判断是否为私有
-const ifPrivateType = () => {
-    const type = templateType.value, form = getObjValue(formModel.value)
-    return form.referenceWbsTemplateType === 'private' && type === 1
-        || form.referenceWbsTemplateTypeTrial === 'private' && type === 2
-        || form.referenceWbsTemplateTypeMeter === 'private' && type === 3
-        || form.referenceWbsTemplateTypeLar === 'private' && type === 5
-}
-
-const setRefId = (refId) => {
-    let ids = refId.toString().split(',')
-    if (ids.length > 1) {
-        refId = ids[0]
-        let list = wbsTreeList.value[1].data
-        refId = list.filter(e => e.projectId == ids[1])[0].pkeyId
-    }
-    return refId
-}
-
 const allChecked = ref(false)
 </script>
 
 <style lang="scss">
-.hc-project-wbs-template {
-    padding: 0 12px;
-    .wbs-template-segmented .el-segmented {
-        --el-border-radius-base: 50px;
-        .el-segmented__item {
-            padding: 0 18px;
-        }
-    }
-    .wbs-template-body {
-        position: relative;
-        height: calc(100% - 120px);
-        display: flex;
-        .hc-card-item-box {
-            background: white !important;
-            border: 1px solid #eee;
-            border-radius: 5px;
-            padding: 0;
-            .hc-card-item-header {
-                height: 40px;
-                padding: 0 12px;
-                margin-bottom: 0;
-                background: #f9f9f9;
-                border-radius: 4px 4px 0 0;
-                border-bottom: 1px solid #eee;
-            }
-            .hc-card-item-body {
-                padding: 12px;
-                height: calc(100% - 40px) !important;
-            }
-        }
-        .left {
-            position: relative;
-            flex: 1;
-        }
-        .action {
-            position: relative;
-            display: flex;
-            align-items: center;
-            justify-content: center;
-            padding: 0 14px;
-        }
-        .right {
-            position: relative;
-            flex: 1;
-        }
-    }
-}
+@import './style/template';
 </style>