| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <style scoped>
- .user-panel {
- margin: 10px auto;
- }
- </style>
- <template>
- <el-dialog
- :visible.sync="showDialog"
- :title="title"
- :modal-append-to-body="true"
- append-to-body
- :close-on-click-modal="false"
- style="text-align: left"
- width="80%"
- @close="closeDialog"
- >
- <div class="user-panel" v-loading="loading">
- <el-form
- ref="form"
- :model="formModel"
- :rules="ruleValidate"
- :label-width="'150px'"
- inline
- >
- <el-form-item label="公司名称" prop="companyId">
- <el-select-tree
- size="mini"
- :props="companyProps"
- :options="companyResult"
- v-model="formModel.companyId"
- height="200"
- ></el-select-tree>
- </el-form-item>
- <el-form-item label="结构名称" prop="structureName">
- <el-input
- v-model="formModel.structureName"
- placeholder="请输入结构名称"
- style="width: 300px"
- ></el-input>
- </el-form-item>
- <el-form-item
- label="位置名称"
- prop="positionName"
- >
- <el-input
- v-model="formModel.positionName"
- placeholder="请输入位置名称"
- style="width: 300px"
- ></el-input>
- </el-form-item>
- <el-form-item label="父级" prop="parentId">
- <el-select-tree
- size="mini"
- :props="parentProps"
- :options="parentResult"
- v-model="formModel.parentId"
- height="200"
- ></el-select-tree>
- </el-form-item>
- <el-form-item label="备注信息" prop="remark">
- <el-input
- v-model="formModel.remark"
- placeholder="请输入备注信息"
- style="width: 300px"
- ></el-input>
- </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 Constant from "@/constant";
- import companyStructureInfoApi from "@/api/base/companyStructureInfo";
- import companyInfoApi from "@/api/base/companyInfo";
- import SelectTree from "@/components/SelectTree";
- export default {
- props: ["businessKey", "title"],
- data() {
- return {
- formModel: {},
- ruleValidate: {
- companyId: [
- { required: true, message: "公司id不能为空", trigger: "blur" },
- ],
- structureName: [
- { required: true, message: "结构名称不能为空", trigger: "blur" },
- ],
- positionName: [
- {
- required: true,
- message: "位置名称(如:楼栋、单元、部门、工号)不能为空",
- trigger: "blur",
- },
- ],
- },
- showDialog: true,
- loading: false,
- submitting: false,
- companyResult: [],
- companyProps: {
- value: "id",
- label: "name",
- children: "children"
- },
- parentResult: [],
- parentProps: {
- value: "id",
- label: "structureName"
- },
- };
- },
- methods: {
- closeDialog() {
- this.$emit("close", false);
- },
- handleSubmit() {
- var self = this;
- this.$refs["form"].validate((valid) => {
- if (valid) {
- (function () {
- var id = self.formModel.id;
- if (id == null || id.length == 0) {
- return companyStructureInfoApi.add(self.formModel);
- } else {
- return companyStructureInfoApi.update(self.formModel);
- }
- })().then(function (response) {
- 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);
- }
- });
- }
- });
- },
- },
- created() {
- var self = this;
- companyInfoApi.treeList().then(function(response) {
- var jsonData = response.data;
- if (jsonData.result) {
- self.companyResult = jsonData.data;
- }
- });
- companyStructureInfoApi.query().then(function(response) {
- var jsonData = response.data;
- if (jsonData.result) {
- self.parentResult = jsonData.data;
- }
- });
- // this.changePage(1);
- // this.loadTree();
- },
- mounted: function () {
- var self = this;
- (function () {
- if (self.businessKey.length == 0) {
- return companyStructureInfoApi.create();
- } else {
- return companyStructureInfoApi.edit(self.businessKey);
- }
- })()
- .then((response) => {
- var jsonData = response.data;
- self.loading = false;
- if (jsonData.result) {
- self.formModel = jsonData.data;
- } else {
- self.$message.error(jsonData.message + "");
- }
- })
- .catch((error) => {
- self.$message.error(error + "");
- });
- },
- components: {
- "el-select-tree": SelectTree
- },
- };
- </script>
|