Browse Source

节假日关联部门

yanliming 4 years ago
parent
commit
7dd73adac3

+ 46 - 0
src/api/base/holidayCompany.js

@@ -0,0 +1,46 @@
+import request from '@/utils/request'
+import constant from '@/constant'
+
+function pageList(formData){
+  return request.post(constant.serverUrl + "/base/holidayCompany/pageList", formData);
+}
+
+function create(){
+  return request.get(constant.serverUrl + "/base/holidayCompany/create");
+}
+
+function edit(id){
+  return request.get(constant.serverUrl + "/base/holidayCompany/edit/" + id);
+}
+
+function add(formModel){
+  return request.post(constant.serverUrl + "/base/holidayCompany/add", formModel,{
+    headers: {
+      "Content-Type": "application/json"
+    }
+  });
+}
+
+function update(formModel){  
+  return request.post(constant.serverUrl + "/base/holidayCompany/update", formModel,{
+    headers: {
+      "Content-Type": "application/json"
+    }
+  });
+}
+
+function remove(id){
+  return request.post(constant.serverUrl + "/base/holidayCompany/delete/" + id);
+}
+
+function batchRemove(idList){
+  return request.post(constant.serverUrl + "/base/holidayCompany/batchDelete",idList,{
+    headers: {
+      "Content-Type": "application/json"
+    }
+  });
+}
+
+export default {
+  pageList,create,edit,add,update,remove,batchRemove
+}

+ 214 - 0
src/views/base/holidayCompany-list.vue

@@ -0,0 +1,214 @@
+<style scoped>
+.user-panel {
+  margin: 10px auto;
+}
+</style>
+<template>
+  <el-dialog
+    :visible.sync="showDialog"
+    :title="title"
+    :modal-append-to-body="false"
+    style="text-align:left;"
+    width="800px;"
+    @close="closeDialog"
+    :close-on-click-modal="false"
+  >
+    <div class="user-panel" v-loading="loading">
+      <el-form ref="form" :model="formModel" :label-width="'150px'">
+        <el-form-item label="关联部门" prop="companyId">
+            <el-select-tree
+            :props="props"
+            :options="companyResult"
+            v-model="formModel.companyId"
+            height="200"
+            style="width:510px"
+            ></el-select-tree>
+        </el-form-item>
+        <el-form-item label="已关联部门" >
+            <el-table
+            ref="formTable"
+            :data="tableData"
+            v-loading="loading"
+            stripe
+            border
+            style="width:84%"
+            >
+            <el-table-column prop="name" label="部门名称" ></el-table-column>
+            <el-table-column prop="subordinate" label="是否关联下级" >
+                <template  slot-scope="{row}">
+                    <el-switch
+                        v-model="row.subordinate"
+                        active-color="#13ce66"
+                        inactive-color="#ff4949">
+                    </el-switch>
+                </template>
+            </el-table-column>
+            <el-table-column label="操作" >
+                <template slot-scope="{row}">
+                <el-button size="mini" type="danger" @click="handleDelete(row)">删除</el-button>
+                </template>
+            </el-table-column>
+            </el-table>
+        </el-form-item>
+        
+      </el-form>
+    </div>
+    <span slot="footer" class="dialog-footer">
+      <el-button @click="closeDialog">取 消</el-button>
+      <el-button type="primary" @click="handleSubmit" :loading="submitting">确 定</el-button>
+    </span>
+  </el-dialog>
+</template>
+<script>
+import SelectTree from "@/components/SelectTree";
+import companyInfoApi from "@/api/base/companyInfo";
+import holidayCompanyApi from "@/api/base/holidayCompany";
+
+export default {
+  props: ["businessKey", "title"],
+  data() {
+      return{
+        companyResult: [],
+        showDialog: true,
+        loading: false,
+        submitting: false,
+        formModel: {
+            holidayId:"",
+            tableJson:[],
+        },
+        tableData:[],
+        props: {
+        // 配置项(必选)
+        value: "id",
+        label: "name",
+        children: "children"
+        }
+      }
+  },
+  created() {
+    var self = this;
+
+    companyInfoApi.list().then(function (response) {
+      var jsonData = response.data;
+      if (jsonData.result) {
+        if (jsonData.data != null && jsonData.data != "") {
+          self.companyResult = jsonData.data;
+        }
+      }
+    });
+  },
+   watch: {
+    "formModel.companyId": function (newVal, oldVal) {
+      var self = this;
+      if(newVal!=oldVal){
+
+        var formData = new FormData();
+
+        formData.append("id", newVal);
+
+        companyInfoApi.getCompanyName(formData).then(function (response) {
+            var jsonData = response.data;
+            if (jsonData.result) {
+                if (jsonData.data != null && jsonData.data != "") {
+                    var name = jsonData.data;
+                    var row={"id":newVal,"name":name,"subordinate":false}
+                    self.tableData.push(row);
+                }
+            }
+        });
+        
+      }
+    },
+  },
+  methods:{
+    closeDialog() {
+      this.$emit("close", false);
+    },
+    handleSubmit() {
+      var self = this;
+      var valid = false;
+
+      if(self.tableData.length>0){
+        valid = true;
+      }
+
+      if (valid) {
+        (function() {
+          var id = self.formModel.id;
+
+          self.loading = true;
+
+          self.formModel.holidayId = self.businessKey;
+
+          self.formModel.tableJson = self.tableData;
+
+          return holidayCompanyApi.update(self.formModel);
+          
+        })().then(function(response) {
+          self.loading = false;
+
+          var jsonData = response.data;
+
+          if (jsonData.result) {
+            self.$message({
+              message: "保存成功!",
+              type: "success"
+            });
+
+            self.$emit("close", true);
+          } else {
+            self.$message({
+              message: jsonData.message + "",
+              type: "warning"
+            });
+
+            self.$emit("close", false);
+          }
+        });
+      }
+      else{
+        self.$message({
+          message: "至少需选择一个部门关联!",
+          type: "warning"
+        });
+      }
+
+    },
+    handleDelete(row){
+        alert(row.id);
+        this.tableData.forEach((item, index) => {
+            if(item.id == row.id){
+                this.tableData.splice(item);
+            }
+        })
+    }
+  },
+mounted: function() {
+    var self = this;
+    (function() {
+      if (self.businessKey.length == 0) {
+        return holidayCompanyApi.create();
+      } else {
+        return holidayCompanyApi.edit(self.businessKey);
+      }
+    })()
+      .then(response => {
+        var jsonData = response.data;
+        self.loading = false;
+
+        if (jsonData.result) {
+          self.tableData = jsonData.data
+
+        } else {
+          self.$message.error(jsonData.message + "");
+        }
+      })
+      .catch(error => {
+        self.$message.error(error + "");
+      });
+  },
+  components: {
+    "el-select-tree": SelectTree,
+  },
+}
+</script>

+ 26 - 3
src/views/base/holidayInfo-list.vue

@@ -42,10 +42,11 @@
           <span v-html="row.working ? '是': '否'"></span>
           <span v-html="row.working ? '是': '否'"></span>
         </template>
         </template>
       </el-table-column>
       </el-table-column>
-      <el-table-column prop="refWeekday" label="参考上班日" width="120"></el-table-column>
-      <el-table-column label="操作" width="200" fixed="right">
+      <el-table-column prop="refWeekday" label="参考上班日" ></el-table-column>
+      <el-table-column label="操作" width="300" fixed="right">
         <template slot-scope="{row}">
         <template slot-scope="{row}">
           <el-button size="mini" type="warning" @click="handleEdit(row)">修改</el-button>
           <el-button size="mini" type="warning" @click="handleEdit(row)">修改</el-button>
+          <el-button size="mini" type="primary" @click="bindCompany(row)">关联部门</el-button>
           <el-button size="mini" type="danger" @click="handleDelete(row)">删除</el-button>
           <el-button size="mini" type="danger" @click="handleDelete(row)">删除</el-button>
         </template>
         </template>
       </el-table-column>
       </el-table-column>
@@ -65,11 +66,18 @@
       :companyResult="companyResult"
       :companyResult="companyResult"
       @close="onDetailModalClose"
       @close="onDetailModalClose"
     ></holidayInfo-detail>
     ></holidayInfo-detail>
+    <holidayCompany-list
+      v-if="showModal2"
+      :businessKey="businessKey"
+      :title="modalTitle2"
+      @close="onDetailModalClose2"
+    ></holidayCompany-list>
   </div>
   </div>
 </template>
 </template>
 <script>
 <script>
 import Constant from "@/constant";
 import Constant from "@/constant";
 import holidayInfoDetail from "./holidayInfo-detail";
 import holidayInfoDetail from "./holidayInfo-detail";
+import holidayCompanyList from "./holidayCompany-list";
 import holidayInfoApi from "@/api/base/holidayInfo";
 import holidayInfoApi from "@/api/base/holidayInfo";
 import companyInfoApi from "@/api/base/companyInfo";
 import companyInfoApi from "@/api/base/companyInfo";
 
 
@@ -93,7 +101,9 @@ export default {
       pageSizeList: [10, 20, 30],
       pageSizeList: [10, 20, 30],
       multipleSelection: [],
       multipleSelection: [],
       showModal: false,
       showModal: false,
+      showModal2: false,
       modalTitle: "",
       modalTitle: "",
+      modalTitle2: "",
       businessKey: ""
       businessKey: ""
     };
     };
   },
   },
@@ -161,6 +171,11 @@ export default {
       this.businessKey = record.id;
       this.businessKey = record.id;
       this.showModal = true;
       this.showModal = true;
     },
     },
+    bindCompany(record) {
+      this.modalTitle2 = "关联部门";
+      this.businessKey = record.id;
+      this.showModal2 = true;
+    },
     handleDelete(record) {
     handleDelete(record) {
       var self = this;
       var self = this;
 
 
@@ -219,6 +234,13 @@ export default {
       if (refreshed) {
       if (refreshed) {
         this.changePage(this.pageIndex);
         this.changePage(this.pageIndex);
       }
       }
+    },
+    onDetailModalClose2(refreshed) {
+      //保存成功后回调
+      this.showModal2 = false;
+      if (refreshed) {
+        this.changePage(this.pageIndex);
+      }
     }
     }
   },
   },
   mounted: function() {
   mounted: function() {
@@ -233,7 +255,8 @@ export default {
     });
     });
   },
   },
   components: {
   components: {
-    "holidayInfo-detail": holidayInfoDetail
+    "holidayInfo-detail": holidayInfoDetail,
+    "holidayCompany-list":holidayCompanyList
   }
   }
 };
 };
 </script>
 </script>