enterpriseInfo-detail.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <el-dialog
  3. :visible.sync="showDialog"
  4. :title="title"
  5. :modal-append-to-body="false"
  6. style="text-align: left;"
  7. @close="closeDialog"
  8. :close-on-click-modal="false"
  9. width="600px"
  10. >
  11. <div class="user-panel" v-loading="loading">
  12. <el-form
  13. ref="form"
  14. :model="formModel"
  15. :rules="ruleValidate"
  16. :label-width="'100px'"
  17. >
  18. <el-form-item label="企业名称" prop="name">
  19. <el-input v-model="formModel.name" placeholder="请输入企业名称" style="width: 300px"></el-input>
  20. </el-form-item>
  21. <el-form-item label="企业地址" prop="address">
  22. <el-input v-model="formModel.address" placeholder="请输入企业地址" style="width: 300px"></el-input>
  23. </el-form-item>
  24. <el-form-item label="企业联系人" prop="contactsPersonId">
  25. <el-input v-model="formModel.contactsPersonId" placeholder="请输入企业联系人" style="width: 300px"></el-input>
  26. </el-form-item>
  27. <el-form-item label="联系电话" prop="contactsPhone">
  28. <el-input v-model="formModel.contactsPhone" placeholder="请输入联系电话" style="width: 300px"></el-input>
  29. </el-form-item>
  30. <el-form-item label="营业执照" prop="licenseImage">
  31. <el-upload
  32. style="width:300px"
  33. class="avatar-uploader"
  34. name="photoFile"
  35. :action="uploadUrl"
  36. :headers="headers"
  37. :data="uploadData"
  38. :show-file-list="false"
  39. :on-success="handleAvatarSuccess"
  40. :before-upload="beforeAvatarUpload">
  41. <img v-if="fileUrl" :src="fileUrl" class="avatar">
  42. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  43. </el-upload>
  44. </el-form-item>
  45. </el-form>
  46. </div>
  47. <span slot="footer" class="dialog-footer">
  48. <el-button @click="closeDialog">取 消</el-button>
  49. <el-button type="primary" @click="handleSubmit" :loading="submitting"
  50. >确 定</el-button
  51. >
  52. </span>
  53. </el-dialog>
  54. </template>
  55. <script>
  56. import Constant from "@/constant";
  57. import { getToken } from "@/utils/auth"; // get token from cookie
  58. import enterpriseInfoApi from "@/api/base/enterpriseInfo";
  59. export default {
  60. props: ["businessKey", "title"],
  61. data() {
  62. const validateIsReName=(rule,value,callBack)=>{
  63. var formData = new FormData();
  64. formData.append("id", this.businessKey);
  65. formData.append("name", value);
  66. enterpriseInfoApi.nameIsRepeatCheck(formData).then(function (response) {
  67. self.loading = false;
  68. var jsonData = response.data;
  69. if(jsonData.result){
  70. if(!jsonData.data){
  71. callBack(new Error("检测到重复的企业名称,不能重复添加!"));
  72. }
  73. else{
  74. callBack();
  75. }
  76. }
  77. })
  78. }
  79. return {
  80. showPwd: true,
  81. ruleValidate: {
  82. name: [
  83. { required: true, message: "企业名称不能为空", trigger: "blur" },
  84. { validator: validateIsReName, trigger: "blur" }
  85. ],
  86. },
  87. roleList: [],
  88. formModel: {},
  89. showDialog: true,
  90. loading: false,
  91. submitting: false,
  92. companyProps: {
  93. value: "id",
  94. label: "name",
  95. },
  96. //上传地址
  97. uploadUrl: Constant.serverUrl + "/uploadPicture",
  98. uploadData: {
  99. subFolder: "temporary-workers",
  100. },
  101. fileUrl: "",
  102. headers: {
  103. Authorization: getToken(),
  104. },
  105. };
  106. },
  107. methods: {
  108. closeDialog() {
  109. this.$emit("close", false);
  110. },
  111. handleSubmit() {
  112. var self = this;
  113. this.$refs["form"].validate((valid) => {
  114. if (valid) {
  115. (function () {
  116. var id = self.formModel.id;
  117. if (id == null || id.length == 0) {
  118. return enterpriseInfoApi.add(self.formModel);
  119. } else {
  120. return enterpriseInfoApi.update(self.formModel);
  121. }
  122. })().then(function (response) {
  123. var jsonData = response.data;
  124. if (jsonData.result) {
  125. self.$message({
  126. message: "保存成功!",
  127. type: "success",
  128. });
  129. self.$emit("close", true);
  130. } else {
  131. self.$message({
  132. message: jsonData.message + "",
  133. type: "warning",
  134. });
  135. self.$emit("close", false);
  136. }
  137. });
  138. }
  139. });
  140. },
  141. handleAvatarSuccess(res, file) {
  142. var self = this;
  143. self.formModel.licenseImage = res.data;
  144. self.fileUrl =
  145. res.data + "?x-oss-process=image/resize,m_lfit,h_300,w_300";
  146. },
  147. beforeAvatarUpload(file) {
  148. const isJPG = file.type === 'image/jpeg';
  149. const isLt2M = file.size / 1024 / 1024 < 2;
  150. // if (!isJPG) {
  151. // this.$message.error('上传头像图片只能是 JPG 格式!');
  152. // }
  153. if (!isLt2M) {
  154. this.$message.error('上传头像图片大小不能超过 2MB!');
  155. }
  156. return isLt2M;
  157. }
  158. },
  159. async mounted() {
  160. var self = this;
  161. self.loading = true;
  162. (function () {
  163. if (self.businessKey != null && self.businessKey.length > 0) {
  164. return enterpriseInfoApi.edit(self.businessKey);
  165. } else {
  166. return enterpriseInfoApi.create();
  167. }
  168. })()
  169. .then((response) => {
  170. var jsonData = response.data;
  171. if (jsonData.result) {
  172. self.formModel = jsonData.data;
  173. let licenseImage = self.formModel.licenseImage;
  174. if (licenseImage != null) {
  175. self.fileUrl = licenseImage
  176. }
  177. self.showModal = true;
  178. } else {
  179. self.$message.error(jsonData.message + "");
  180. }
  181. self.loading = false;
  182. })
  183. .catch((error) => {
  184. self.$message.error(error + "");
  185. self.loading = false;
  186. });
  187. },
  188. components: {
  189. },
  190. };
  191. </script>
  192. <style scoped>
  193. .user-panel {
  194. margin: 10px auto;
  195. }
  196. .avatar-uploader .el-upload {
  197. border: 1px dashed #d9d9d9;
  198. border-radius: 6px;
  199. cursor: pointer;
  200. position: relative;
  201. overflow: hidden;
  202. }
  203. .avatar-uploader .el-upload:hover {
  204. border-color: #409EFF;
  205. }
  206. .avatar-uploader-icon {
  207. font-size: 28px;
  208. color: #8c939d;
  209. width: 178px;
  210. height: 178px;
  211. line-height: 178px;
  212. text-align: center;
  213. }
  214. .avatar {
  215. width: 178px;
  216. height: 178px;
  217. display: block;
  218. }
  219. </style>