companyInfo-detail.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <style scoped>
  2. .user-panel {
  3. margin: 10px auto;
  4. }
  5. </style>
  6. <template>
  7. <el-dialog
  8. :visible.sync="showDialog"
  9. :title="title"
  10. :modal-append-to-body="false"
  11. style="text-align:left;"
  12. @close="closeDialog"
  13. >
  14. <div class="user-panel" v-loading="loading">
  15. <el-form ref="form" :model="formModel" :rules="ruleValidate" :label-width="'100px'">
  16. <el-form-item label="公司名称" prop="name">
  17. <el-input v-model="formModel.name" placeholder="请输入公司名称" style="width:300px"></el-input>
  18. </el-form-item>
  19. <el-form-item label="备注" prop="remark">
  20. <el-input v-model="formModel.remark" placeholder="请输入备注" style="width:300px"></el-input>
  21. </el-form-item>
  22. <el-form-item label="序号" prop="sortNo">
  23. <el-input v-model="formModel.sortNo" placeholder="请输入序号" style="width:300px"></el-input>
  24. </el-form-item>
  25. <el-form-item label="公司logo" prop="logo">
  26. <el-upload
  27. class="avatar-uploader"
  28. action=""
  29. :show-file-list="false"
  30. :on-success="handleAvatarSuccess"
  31. :before-upload="beforeAvatarUpload"
  32. >
  33. <img v-if="imageUrl" :src="imageUrl" class="avatar" />
  34. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  35. </el-upload>
  36. </el-form-item>
  37. </el-form>
  38. </div>
  39. <span slot="footer" class="dialog-footer">
  40. <el-button @click="closeDialog">取 消</el-button>
  41. <el-button type="primary" @click="handleSubmit" :loading="submitting">确 定</el-button>
  42. </span>
  43. </el-dialog>
  44. </template>
  45. <script>
  46. import Constant from "@/constant";
  47. import companyInfoApi from "@/api/base/companyInfo";
  48. export default {
  49. props: ["businessKey", "title"],
  50. data() {
  51. return {
  52. formModel: {},
  53. ruleValidate: {
  54. name: [
  55. { required: true, message: "公司名称不能为空", trigger: "blur" }
  56. ]
  57. },
  58. showDialog: true,
  59. loading: false,
  60. submitting: false,
  61. imageUrl: ""
  62. };
  63. },
  64. methods: {
  65. closeDialog() {
  66. this.$emit("close", false);
  67. },
  68. handleSubmit() {
  69. var self = this;
  70. this.$refs["form"].validate(valid => {
  71. if (valid) {
  72. (function() {
  73. var id = self.formModel.id;
  74. if (id == null || id.length == 0) {
  75. return companyInfoApi.add(self.formModel);
  76. } else {
  77. return companyInfoApi.update(self.formModel);
  78. }
  79. })().then(function(response) {
  80. var jsonData = response.data;
  81. if (jsonData.result) {
  82. self.$message({
  83. message: "保存成功!",
  84. type: "success"
  85. });
  86. self.$emit("close", true);
  87. } else {
  88. self.$message({
  89. message: jsonData.message + "",
  90. type: "warning"
  91. });
  92. self.$emit("close", false);
  93. }
  94. });
  95. }
  96. });
  97. },
  98. handleAvatarSuccess(res, file) {
  99. this.imageUrl = URL.createObjectURL(file.raw);
  100. },
  101. beforeAvatarUpload(file) {
  102. const isJPG = file.type === "image/jpeg";
  103. const isLt2M = file.size / 1024 / 1024 < 2;
  104. if (!isJPG) {
  105. this.$message.error("上传头像图片只能是 JPG 格式!");
  106. }
  107. if (!isLt2M) {
  108. this.$message.error("上传头像图片大小不能超过 2MB!");
  109. }
  110. return isJPG && isLt2M;
  111. }
  112. },
  113. mounted: function() {
  114. var self = this;
  115. (function() {
  116. if (self.businessKey.length == 0) {
  117. return companyInfoApi.create();
  118. } else {
  119. return companyInfoApi.edit(self.businessKey);
  120. }
  121. })()
  122. .then(response => {
  123. var jsonData = response.data;
  124. self.loading = false;
  125. if (jsonData.result) {
  126. self.formModel = jsonData.data;
  127. } else {
  128. self.$message.error(jsonData.message + "");
  129. }
  130. })
  131. .catch(error => {
  132. self.$message.error(error + "");
  133. });
  134. }
  135. };
  136. </script>
  137. <style>
  138. .avatar-uploader .el-upload {
  139. border: 1px dashed #d9d9d9;
  140. border-radius: 6px;
  141. cursor: pointer;
  142. position: relative;
  143. overflow: hidden;
  144. }
  145. .avatar-uploader .el-upload:hover {
  146. border-color: #409EFF;
  147. }
  148. .avatar-uploader-icon {
  149. font-size: 28px;
  150. color: #8c939d;
  151. width: 178px;
  152. height: 178px;
  153. line-height: 178px;
  154. text-align: center;
  155. }
  156. .avatar {
  157. width: 178px;
  158. height: 178px;
  159. display: block;
  160. }
  161. </style>