Browse Source

删除冗余代码与接口调整(根据分类和项目调用子类接口)

XuZinan 3 years ago
parent
commit
186640048c

+ 0 - 129
pages/WorkingHours/AddModal.vue

@@ -1,129 +0,0 @@
-<template>
-  <uni-popup ref="popup" background-color="#fff">
-    <view class="popup-content">
-      <uni-forms ref="baseForm" :modelValue="formData">
-        <uni-forms-item label="分类">
-          <ld-select
-            :list="typeList"
-            placeholder="请选择分类"
-            class="select"
-            v-model="formData.typeId"
-            labelKey="name"
-            valueKey="id"
-            @change="onChangeType"
-          />
-        </uni-forms-item>
-        <uni-forms-item
-          v-show="currentType.type === 0 || currentSubType.type === 0"
-          label="项目"
-        >
-          <ld-select
-            :list="projectList"
-            placeholder="请选择项目"
-            class="select"
-            v-model="formData.projectId"
-            labelKey="Name"
-            valueKey="ID"
-            @change="onChangeProject"
-          />
-        </uni-forms-item>
-        <uni-forms-item label="子类">
-          <ld-select
-            :list="currentType.children"
-            placeholder="请选择子类"
-            class="select"
-            v-model="formData.subTypeId"
-            labelKey="name"
-            valueKey="id"
-            @change="onChangeSubType"
-          />
-        </uni-forms-item>
-      </uni-forms>
-    </view>
-    <view class="group">
-      <button @click="close" class="button">取消</button>
-      <button @click="submit" type="primary">保存</button>
-    </view>
-  </uni-popup>
-</template>
-<script>
-export default {
-  props: ["projectList", "typeList"],
-  data() {
-    return {
-      formData: {},
-      currentType: {},
-      currentSubType: {},
-    };
-  },
-  methods: {
-    open() {
-      this.$refs.popup.open("center");
-    },
-    close() {
-      this.formData = {};
-      this.currentType = {};
-      this.currentSubType = {};
-      this.$refs.popup.close();
-    },
-    submit() {
-      let type = this.currentType;
-      let subType = this.currentSubType;
-      let formData = this.formData;
-      if (type.type == 0 || subType.type == 0) {
-        if (!formData.projectId) {
-          uni.showToast({
-            title: "请选择项目",
-            icon: "none",
-          });
-          return;
-        }
-      } else {
-        formData.projectId = "0";
-      }
-      this.$emit("submit", this.formData);
-      this.close();
-    },
-    onChangeType(value) {
-      this.formData = {
-        typeId: value,
-        projectId: null,
-        subTypeId: null,
-      };
-      this.currentType = this.typeList.find((item) => item.id == value) || {};
-      this.currentSubType = {};
-    },
-    onChangeProject(value) {
-      this.formData.projectId = value;
-    },
-    onChangeSubType(value) {
-      this.formData.subTypeId = value;
-      this.currentSubType =
-        this.currentType.children.find((item) => item.id == value) || {};
-    },
-  },
-};
-</script>
-<style lang="less" scoped>
-.popup-content {
-  padding: 40rpx;
-}
-.group {
-  display: flex;
-  button {
-    width: 50%;
-    border-radius: 0;
-  }
-}
-.select {
-  width: 100%;
-  margin-bottom: 25rpx;
-  background: #fff;
-  height: 70rpx;
-  color: #777777;
-  padding-left: 20rpx;
-  font-size: 24rpx;
-  border-radius: 0px;
-  border-bottom: 1px solid #333;
-}
-</style>

+ 33 - 26
pages/WorkingHours/add.vue

@@ -35,13 +35,13 @@
         </uni-forms-item>
         </uni-forms-item>
         <uni-forms-item label="子类">
         <uni-forms-item label="子类">
           <ld-select
           <ld-select
-            :list="currentType.children"
+            :list="subTypeList"
             placeholder="请选择子类"
             placeholder="请选择子类"
             class="select"
             class="select"
             v-model="formData.subTypeId"
             v-model="formData.subTypeId"
             labelKey="name"
             labelKey="name"
             valueKey="id"
             valueKey="id"
-            :disabled="currentType.id == 2 || currentType.id == 35"
+            :disabled="currentType.id == 2"
             @change="onChangeSubType"
             @change="onChangeSubType"
           />
           />
         </uni-forms-item>
         </uni-forms-item>
@@ -58,7 +58,7 @@
 </template>
 </template>
 <script>
 <script>
 import comboxSearch from "@/components/cuihai-combox/cuihai-combox";
 import comboxSearch from "@/components/cuihai-combox/cuihai-combox";
-import { addWorkHours, queryProject } from "@/services/workload";
+import { addWorkHours, queryProject, queryWorkType } from "@/services/workload";
 import { mapState } from "vuex";
 import { mapState } from "vuex";
 export default {
 export default {
   components: { comboxSearch },
   components: { comboxSearch },
@@ -84,6 +84,7 @@ export default {
       currentType: {},
       currentType: {},
       currentSubType: {},
       currentSubType: {},
       project: [],
       project: [],
+      subTypeList: [],
       day: "",
       day: "",
     };
     };
   },
   },
@@ -96,6 +97,11 @@ export default {
       data = await queryProject({ stage: value });
       data = await queryProject({ stage: value });
       this.project = data;
       this.project = data;
     },
     },
+    async getSubType(params) {
+      let res = {};
+      res = await queryWorkType(params);
+      this.subTypeList = res.data;
+    },
     async submit() {
     async submit() {
       let type = this.currentType;
       let type = this.currentType;
       let subType = this.currentSubType;
       let subType = this.currentSubType;
@@ -131,47 +137,48 @@ export default {
     close() {
     close() {
       uni.navigateBack();
       uni.navigateBack();
     },
     },
-    onChangeType(value) {
+    async onChangeType(value) {
       let item = this.typeList.find((t) => t.id == value);
       let item = this.typeList.find((t) => t.id == value);
+      this.formData = {
+        typeId: value,
+        projectId: null,
+        subTypeId: null,
+      };
+      this.currentType = item;
+      this.currentSubType = {};
+      this.projectName = "";
       if (!item.type) {
       if (!item.type) {
         this.getProject(value);
         this.getProject(value);
-      }
-      this.projectName = "";
-      if (value == 33 || value == 35) {
-        this.formData = {
-          typeId: value,
-          projectId: null,
-          subTypeId: item.children[0].id,
-        };
-        this.currentType = item;
-        this.onChangeSubType(item.children[0].id);
       } else {
       } else {
-        this.formData = {
-          typeId: value,
-          projectId: null,
-          subTypeId: null,
-        };
-        this.currentType = item;
-        this.currentSubType = {};
+        await this.getSubType({ parent_id: item.id });
+        if (value == 33) {
+          this.onChangeSubType(this.subTypeList[0].id);
+        }
       }
       }
     },
     },
-    onChangeProject(index) {
+    async onChangeProject(index) {
       let project = this.projectList[index];
       let project = this.projectList[index];
       this.formData.projectId = project.ID;
       this.formData.projectId = project.ID;
       this.projectName = project.fullName;
       this.projectName = project.fullName;
+      await this.getSubType({
+        parent_id: this.currentType.id,
+        project_id: project.ID,
+      });
+      if (this.currentType.id == 35) {
+        this.onChangeSubType(this.subTypeList[0].id);
+      }
       if (this.currentType.id == 2) {
       if (this.currentType.id == 2) {
-        let subList = this.currentType.children;
         if (index == 0) {
         if (index == 0) {
-          this.onChangeSubType(subList[0].id);
+          this.onChangeSubType(this.subTypeList[0].id);
         } else {
         } else {
-          this.onChangeSubType(subList[1].id);
+          this.onChangeSubType(this.subTypeList[1].id);
         }
         }
       }
       }
     },
     },
     onChangeSubType(value) {
     onChangeSubType(value) {
       this.formData.subTypeId = value;
       this.formData.subTypeId = value;
       this.currentSubType =
       this.currentSubType =
-        this.currentType.children.find((item) => item.id == value) || {};
+        this.subTypeList.find((item) => item.id == value) || {};
     },
     },
   },
   },
 };
 };

+ 1 - 1
pages/WorkingHours/audit.vue

@@ -124,7 +124,7 @@ export default {
     this.init();
     this.init();
   },
   },
   computed: {
   computed: {
-    ...mapState(["allType", "typeList"]),
+    ...mapState(["allType"]),
     collapseList() {
     collapseList() {
       const projectList = this.projectList;
       const projectList = this.projectList;
       let data = {};
       let data = {};

+ 1 - 9
pages/WorkingHours/index.vue

@@ -87,12 +87,6 @@
         @confirm="auditConfirm"
         @confirm="auditConfirm"
       ></uni-popup-dialog>
       ></uni-popup-dialog>
     </uni-popup>
     </uni-popup>
-    <!-- <AddModal
-      ref="addModal"
-      @submit="onSubmit"
-      :projectList="projectList"
-      :typeList="typeList"
-    /> -->
     <view class="group">
     <view class="group">
       <button
       <button
         class="approval"
         class="approval"
@@ -129,12 +123,10 @@ import {
   addAuthWorkHours,
   addAuthWorkHours,
   queryProject,
   queryProject,
 } from "@/services/workload";
 } from "@/services/workload";
-import AddModal from "./AddModal.vue";
 import moment from "moment";
 import moment from "moment";
 import { mapState } from "vuex";
 import { mapState } from "vuex";
 
 
 export default {
 export default {
-  components: { AddModal },
   data() {
   data() {
     return {
     return {
       info: {
       info: {
@@ -170,7 +162,7 @@ export default {
     this.queryWorkHours();
     this.queryWorkHours();
   },
   },
   computed: {
   computed: {
-    ...mapState(["allType", "typeList"]),
+    ...mapState(["allType"]),
     collapseList() {
     collapseList() {
       const allType = this.allType;
       const allType = this.allType;
       let data = {};
       let data = {};

+ 4 - 7
services/workload.js

@@ -1,24 +1,21 @@
 import request from "./request";
 import request from "./request";
 import moment from "moment";
 import moment from "moment";
 
 
-function queryWorkType(params) {
+export async function queryWorkType(params) {
   return request(`v2/workload/type/info`, "GET", params, true);
   return request(`v2/workload/type/info`, "GET", params, true);
 }
 }
 
 
 export async function queryAllWorkType() {
 export async function queryAllWorkType() {
   uni.showLoading();
   uni.showLoading();
   try {
   try {
-    const { data } = await queryWorkType();
+    const { data } = await queryWorkType({ parent_id: -1 });
     let typeList = [];
     let typeList = [];
     let allType = {};
     let allType = {};
     for (let i = 0; i < data.length; i++) {
     for (let i = 0; i < data.length; i++) {
       let item = data[i];
       let item = data[i];
       allType[item.id] = item;
       allType[item.id] = item;
       if (item.parent_id == 0) {
       if (item.parent_id == 0) {
-        item.children = [];
         typeList.push(item);
         typeList.push(item);
-      } else {
-        typeList.find(t => t.id == item.parent_id).children.push(item);
       }
       }
     }
     }
     return { typeList, allType };
     return { typeList, allType };
@@ -72,9 +69,9 @@ export async function queryAuthWorkHours(params = {}) {
 
 
 export async function queryProject(data) {
 export async function queryProject(data) {
   const res = await request(`v2/workload/project`, "GET", data);
   const res = await request(`v2/workload/project`, "GET", data);
-  return res.data.list.map(item => ({
+  return res.data.list.map((item) => ({
     ...item,
     ...item,
-    fullName: `${item.Name}(${item.Code})`
+    fullName: `${item.Name}(${item.Code})`,
   }));
   }));
 }
 }
 /** id,status,desc */
 /** id,status,desc */