| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <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;"
- @close="closeDialog"
- >
- <div class="user-panel" v-loading="loading">
- <el-form ref="form" :model="formModel" :rules="ruleValidate" :label-width="'100px'">
- <el-form-item label="公司名称" prop="name">
- <el-input v-model="formModel.name" placeholder="请输入公司名称" style="width:300px"></el-input>
- </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-item label="序号" prop="sortNo">
- <el-input v-model="formModel.sortNo" placeholder="请输入序号" style="width:300px"></el-input>
- </el-form-item>
- <el-form-item label="公司logo" prop="logo">
- <el-upload
- class="avatar-uploader"
- action=""
- :show-file-list="false"
- :on-success="handleAvatarSuccess"
- :before-upload="beforeAvatarUpload"
- >
- <img v-if="imageUrl" :src="imageUrl" class="avatar" />
- <i v-else class="el-icon-plus avatar-uploader-icon"></i>
- </el-upload>
- </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 companyInfoApi from "@/api/base/companyInfo";
- export default {
- props: ["businessKey", "title"],
- data() {
- return {
- formModel: {},
- ruleValidate: {
- name: [
- { required: true, message: "公司名称不能为空", trigger: "blur" }
- ]
- },
- showDialog: true,
- loading: false,
- submitting: false,
- imageUrl: ""
- };
- },
- 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 companyInfoApi.add(self.formModel);
- } else {
- return companyInfoApi.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);
- }
- });
- }
- });
- },
- handleAvatarSuccess(res, file) {
- this.imageUrl = URL.createObjectURL(file.raw);
- },
- beforeAvatarUpload(file) {
- const isJPG = file.type === "image/jpeg";
- const isLt2M = file.size / 1024 / 1024 < 2;
- if (!isJPG) {
- this.$message.error("上传头像图片只能是 JPG 格式!");
- }
- if (!isLt2M) {
- this.$message.error("上传头像图片大小不能超过 2MB!");
- }
- return isJPG && isLt2M;
- }
- },
- mounted: function() {
- var self = this;
- (function() {
- if (self.businessKey.length == 0) {
- return companyInfoApi.create();
- } else {
- return companyInfoApi.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 + "");
- });
- }
- };
- </script>
- <style>
- .avatar-uploader .el-upload {
- border: 1px dashed #d9d9d9;
- border-radius: 6px;
- cursor: pointer;
- position: relative;
- overflow: hidden;
- }
- .avatar-uploader .el-upload:hover {
- border-color: #409EFF;
- }
- .avatar-uploader-icon {
- font-size: 28px;
- color: #8c939d;
- width: 178px;
- height: 178px;
- line-height: 178px;
- text-align: center;
- }
- .avatar {
- width: 178px;
- height: 178px;
- display: block;
- }
- </style>
|