manage.vue 8.04 KB
<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <span style="font-size:24px">后台管理</span>
    </div>
    <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    <el-row type="flex" justify="start" style="text-align :left;border-bottom:1px solid #ebeef5;padding-bottom:18px">
      <el-col :span="6">
        <el-input class="input" v-model="contract_unid" placeholder="合同编号"></el-input>
        <el-button type="primary" @click="contract_unid_add">添加</el-button>
      </el-col>
      <el-col :span="6">
        <el-input class="input" v-model="customer_name" placeholder="客户名称"></el-input>
        <el-button type="primary" @click="customer_name_add">添加</el-button>
      </el-col>
      <el-col :span="6">
        <el-input class="input" v-model="salesperson" placeholder="销售员"></el-input>
        <el-button type="primary" @click="salesperson_add('employee')">添加</el-button>
      </el-col>
      <el-col :span="6">
        <el-input class="input" v-model="project_name" placeholder="项目名称"></el-input>
        <el-button type="primary" @click="project_name_add">添加</el-button>
      </el-col>
    </el-row>
    <el-row>
      <el-button class="add_button" type="text" @click="login_user_dialog_show = true">添加登录用户</el-button>
    </el-row>

    <el-dialog id="login_user_dialog" title="添加登录户" :visible.sync="login_user_dialog_show" width="30%" :show-close="false">
      <el-form :model="login_user_form" label-width="100px" label-position="left" :rules="login_user_form_rules" ref="login_user_form">
        <el-form-item label="用户类型" prop="role_unid">
          <el-select v-model="login_user_form.role_unid" clearable placeholder="用户类型" style="width:100%">
            <el-option v-for="item in roles" :key="item.role_unid" :label="item.name" :value="item.role_unid">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用户名" prop="username">
          <el-input v-model="login_user_form.username" placeholder="用户名" style="width:100%"></el-input>
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="login_user_form.name" placeholder="姓名" style="width:100%"></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="login_user_dialog_cancel()">取 消</el-button>
        <el-button type="primary" @click="login_user_dialog_confirm()">确 定</el-button>
      </div>
    </el-dialog>
  </el-card>

</template>

<script>
export default {
  name: "manage",
  data() {
    return {
      login_user_dialog_show: false,
      code_base_url: disparch_data.code_base_url,
      contract_base_url: disparch_data.contract_base_url,
      auth_base_url: disparch_data.auth_base_url,
      contract_unid: null,
      customer_name: null,
      salesperson: null,
      project_name: null,

      roles: [],
      login_user_form: {
        role_unid: "",
        username: "",
        name: "",
        password: "0000",
        norm_type: "login"
      },

      login_user_form_rules: {
        username: {
          required: true,
          pattern: /^[a-z]{2,8}$/,
          message: "请输入2至8位英文",
          trigger: "blur"
        },
        name: {
          required: true,
          message: "请输入用户姓名",
          trigger: "blur"
        },
        role_unid: {
          required: true,
          message: "请选择用户类型",
          trigger: "blur"
        }
      }
    };
  },
  methods: {
    contract_unid_add() {
      if (this.contract_unid) {
        this.$Axios({
          method: "post",
          data: { contract_unid: this.contract_unid },
          url: this.contract_base_url,
          headers: { "Content-Type": "application/json" }
        }).then(response => {
          this.contract_unid = null;
          if (response.data.ecode == "200") {
            this.show_message("添加成功", "success");
          } else {
            this.show_message("添加失败", "error");
          }
        });
      } else {
        this.show_message("请填写信息", "info");
      }
    },
    customer_name_add() {
      if (this.customer_name) {
        this.$Axios({
          method: "post",
          url: this.contract_base_url + "customers",
          data: { customer_name: this.customer_name },
          headers: { "Content-Type": "application/json" }
        }).then(response => {
          this.customer_name = null;
          if (response.data.ecode == "200") {
            this.show_message("添加成功", "success");
          } else {
            this.show_message("添加失败", "error");
          }
        });
      } else {
        this.show_message("请填写信息", "info");
      }
    },
    salesperson_add(type) {
      if (this.salesperson) {
        this.$Axios({
          method: "post",
          url: this.auth_base_url + "users",
          data: {
            norm_type: type,
            username: this.salesperson,
            name: this.salesperson,
            password: "0000"
          },
          headers: { "Content-Type": "application/json" }
        }).then(response => {
          this.salesperson = null;
          this.show_message("添加成功", "success");
        });
      } else {
        this.show_message("请填写信息", "info");
      }
    },
    project_name_add() {
      if (this.project_name) {
        this.$Axios({
          method: "post",
          url: this.contract_base_url + "projects",
          data: { project_name: this.project_name },
          headers: { "Content-Type": "application/json" }
        }).then(response => {
          this.project_name = null;
          if (response.data.ecode == "200") {
            this.show_message("添加成功", "success");
          } else {
            this.show_message("添加失败", "error");
          }
        });
      } else {
        this.show_message("请填写信息", "info");
      }
    },
    show_message(message, type) {
      this.$message({
        message: message,
        type: type,
        center: true,
        showClose: true,
        duration: 1500
      });
    },
    get_roles() {
      this.$Axios({
        method: "get",
        url: this.auth_base_url + "roles"
      })
        .then(response => {
          if (response.data.list_data) {
            this.roles = response.data.list_data;
          }
        })
        .catch(err => {
          console.log(err.message);
        });
    },
    login_user_dialog_cancel() {
      this.$refs["login_user_form"].resetFields();
      this.login_user_dialog_show = false;
    },
    login_user_dialog_confirm() {
      this.$refs["login_user_form"].validate(valid => {
        if (valid) {
          this.$Axios({
            method: "post",
            url: this.auth_base_url + "users",
            headers: { "Content-Type": "application/json" },
            data: this.login_user_form
          }).then(res => {
            if (res.data.user_unid) {
              this.$Axios({
                method: "post",
                url:
                  this.auth_base_url + "users/" + res.data.user_unid + "/roles",
                headers: { "Content-Type": "application/json" },
                data: {
                  role_unid: this.login_user_form.role_unid
                }
              })
                .then(res => {
                  this.show_message("添加成功", "success");
                  this.$refs["login_user_form"].resetFields();
                  this.login_user_dialog_show = false;
                  console.log(res.data);
                })
                .catch(err => {
                  this.show_message("添加失败", "error");
                });
            } else {
              this.show_message("添加失败", "error");
            }
          });
        }
      });
    }
  },
  created() {
    this.get_roles();
  }
};
</script>

<style scoped>
.input {
  width: 200px;
}
.add_button {
  font-size: 20px;
  padding-top: 18px;
  color: #409eff;
}
</style>