StaffRegister.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <template>
  2. <div>
  3. <el-dialog
  4. :title="isView ? '用户新增' : '用户编辑'"
  5. :visible.sync="dialogVisible"
  6. :before-close="cancle"
  7. width="60%"
  8. >
  9. <el-form
  10. :inline="true"
  11. :model="ruleForm"
  12. :rules="rules"
  13. ref="ruleForm"
  14. label-width="120px"
  15. class="demo-ruleForm"
  16. >
  17. <el-row>
  18. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  19. <el-form-item label="头像" prop="avatar">
  20. <el-upload
  21. accept=".png, .jpg, .jpeg"
  22. class="avatar-uploader"
  23. name="file"
  24. :action="action"
  25. :show-file-list="false"
  26. :on-success="handleAvatarSuccess"
  27. :before-upload="beforeAvatarUpload"
  28. >
  29. <img v-if="ruleForm.avatar" :src="ruleForm.avatar" class="avatar" />
  30. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  31. <div class="el-upload__tip" slot="tip">
  32. 建议上传jpg/png/jpeg文件,且不超过500kb
  33. </div>
  34. </el-upload>
  35. </el-form-item>
  36. </el-col>
  37. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  38. <el-form-item label="姓名" prop="name">
  39. <el-input
  40. v-model="ruleForm.name"
  41. class="inputCom"
  42. placeholder="请输入姓名"
  43. ></el-input>
  44. </el-form-item>
  45. </el-col>
  46. </el-row>
  47. <el-row>
  48. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  49. <el-form-item label="个人描述" prop="description">
  50. <el-input
  51. v-model="ruleForm.description"
  52. class="inputCom"
  53. placeholder="请输入描述"
  54. ></el-input>
  55. </el-form-item>
  56. </el-col>
  57. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  58. <el-form-item label="岗位" prop="job">
  59. <el-input
  60. v-model="ruleForm.job"
  61. class="inputCom"
  62. placeholder="请输入岗位"
  63. ></el-input>
  64. </el-form-item>
  65. </el-col>
  66. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  67. <el-form-item label="邮箱" prop="mail">
  68. <el-input
  69. v-model="ruleForm.mail"
  70. class="inputCom"
  71. placeholder="请输入邮箱"
  72. ></el-input>
  73. </el-form-item>
  74. </el-col>
  75. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  76. <el-form-item label="手机号" prop="phone">
  77. <el-input
  78. v-model="ruleForm.phone"
  79. class="inputCom"
  80. placeholder="请输入手机号"
  81. ></el-input>
  82. </el-form-item>
  83. </el-col>
  84. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  85. <el-form-item label="状态" prop="state">
  86. <el-select v-model="ruleForm.state" placeholder="请选择状态">
  87. <el-option
  88. :label="item.name"
  89. :value="item.state"
  90. v-for="item in stateList"
  91. :key="item.state"
  92. ></el-option>
  93. </el-select>
  94. </el-form-item>
  95. </el-col>
  96. </el-row>
  97. </el-form>
  98. <span slot="footer" class="dialog-footer">
  99. <el-button @click="cancle" round>取 消</el-button>
  100. <el-button
  101. v-show="isView"
  102. type="primary"
  103. round
  104. :disabled="disableFlag"
  105. @click="submitCom"
  106. >确 定</el-button
  107. >
  108. <el-button
  109. v-show="!isView"
  110. type="primary"
  111. round
  112. :disabled="disableFlag"
  113. @click="submitCom"
  114. >修 改</el-button
  115. >
  116. </span>
  117. </el-dialog>
  118. </div>
  119. </template>
  120. <script>
  121. // import { oSessionStorage } from "../../utils/utils";
  122. import { oSessionStorage } from "../utils/utils";
  123. import { basePath } from "../utils/http";
  124. import md5 from "md5";
  125. export default {
  126. data() {
  127. var validatePass = (rule, value, callback) => {
  128. if (value === "") {
  129. callback(new Error("请输入密码"));
  130. } else if (value.length < 6) {
  131. callback(new Error("密码至少6位"));
  132. } else {
  133. callback();
  134. }
  135. };
  136. var validatePhone = (rule, value, callback) => {
  137. let myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
  138. if (value === "") {
  139. callback(new Error("请输入手机号"));
  140. } else if (!myreg.test(value)) {
  141. callback(new Error("请输入正确格式"));
  142. } else {
  143. callback();
  144. }
  145. };
  146. return {
  147. action:'',
  148. disableFlag: false,
  149. phoneFlag: false,
  150. flag: 3,
  151. dialogVisible: false,
  152. //渠道列表
  153. stateList: [
  154. { name: "签约", state: "1" },
  155. { name: "解约", state: "0" },
  156. ],
  157. ruleForm: {
  158. id: "",
  159. channelId: "",
  160. //头像
  161. avatar: "",
  162. //员工姓名
  163. name: "",
  164. //描述
  165. description: "",
  166. //岗位
  167. job: "",
  168. //邮箱
  169. mail: "",
  170. //手机号
  171. phone: "",
  172. //状态
  173. state: "",
  174. // //删除状态
  175. isDelete: "0",
  176. },
  177. isView: true,
  178. rules: {
  179. name: [{ required: true, message: "请输入姓名", trigger: "blur" }],
  180. phone: [
  181. { required: true, message: "请输入手机号", trigger: "blur" },
  182. { pattern: /^1[3456789]\d{9}$/, message: "请输入正确的手机号", trigger: ["blur", "change"] },
  183. ],
  184. state: [{ required: true, message: "请输选择状态", trigger: "change" }],
  185. mail: [
  186. { required: true, message: "请输选择邮箱", trigger: "blur" },
  187. { type: "email", message: "请输入正确的邮箱地址", trigger: ["blur", "change"] },
  188. ],
  189. },
  190. };
  191. },
  192. mounted() {
  193. let userInfo = JSON.parse(oSessionStorage.getItem("userInfo"));
  194. this.ruleForm.parentCode = userInfo.invitationCode;
  195. this.action = basePath+ "/file/customUpload";
  196. //获取到router 传输过来的信息
  197. this.ruleForm.channelId = this.$route.query.channelId;
  198. //获取渠道信息
  199. // this.ruleForm.type = "3";
  200. },
  201. methods: {
  202. beforeAvatarUpload(file) {
  203. const fileName = file.name;
  204. const fileType = fileName.substring(fileName.lastIndexOf("."));
  205. if (fileType !== ".jpg" && fileType !== ".jpeg" && fileType !== ".png") {
  206. // alert("请上传jpg、jpge或png的图片!");
  207. this.$message.error('请上传jpg、jpge或png的图片!')
  208. return false;
  209. }
  210. return true;
  211. },
  212. //handleAvatarSuccess
  213. //上传成功后的回调
  214. handleAvatarSuccess(data) {
  215. if (data.code == 200) {
  216. this.ruleForm.avatar = basePath + "/file/show?filePath=" + data.data;
  217. console.log(basePath + "/file/show?filePath=" + data.data);
  218. } else {
  219. //失败
  220. }
  221. },
  222. phoneCheck() {
  223. //判断是否重复
  224. this.$http.get(`v1/system/checkPhone/${this.ruleForm.phone}`, {}, (res) => {
  225. // this.$toast.success({message:'成功'});
  226. if (res && res.code == 200) {
  227. if (res.data) {
  228. this.phoneFlag = true;
  229. } else {
  230. this.phoneFlag = false;
  231. // this.$toast.success({ message: "手机号重复" });
  232. this.$message.warning("手机号重复");
  233. }
  234. } else {
  235. // this.$toast.fail({ message: res.msg });
  236. this.$message.error(res.msg);
  237. }
  238. });
  239. },
  240. timeChange(val) {
  241. if (val !== null) {
  242. //根据时间得到格式化的数据
  243. this.ruleForm.birthDate = this.formatterTime(val);
  244. }
  245. },
  246. formatterTime(val) {
  247. let date = new Date(val);
  248. let year = date.getFullYear();
  249. let month = date.getMonth() + 1;
  250. month = this.formatterMon(month);
  251. let day = date.getDate();
  252. day = this.formatterMon(day);
  253. return year + "-" + month + "-" + day;
  254. },
  255. formatterMon(val) {
  256. if (val < 10) {
  257. return "0" + val;
  258. } else {
  259. return val;
  260. }
  261. },
  262. open(val) {
  263. this.dialogVisible = true;
  264. this.isView = val;
  265. this.$nextTick(() => {
  266. this.$refs["ruleForm"].clearValidate();
  267. });
  268. },
  269. edit(val) {
  270. this.dialogVisible = true;
  271. this.isView = false;
  272. this.ruleForm.id = val.id;
  273. this.ruleForm.channelId = val.channelId;
  274. this.ruleForm.avatar = val.avatar;
  275. this.ruleForm.name = val.name;
  276. this.ruleForm.description = val.description;
  277. this.ruleForm.phone = val.phone;
  278. this.ruleForm.mail = val.mail;
  279. this.ruleForm.job = val.job;
  280. this.ruleForm.state = val.state;
  281. this.ruleForm.isDelete = val.isDelete;
  282. },
  283. cancle() {
  284. //清空表单
  285. // id: "",
  286. // channelId:'',
  287. // //头像
  288. // avatar: "",
  289. // //员工姓名
  290. // name: "",
  291. // //描述
  292. // description: "",
  293. // //岗位
  294. // job: "",
  295. // //邮箱
  296. // mail: "",
  297. // //手机号
  298. // phone: "",
  299. // //状态
  300. // state: "",
  301. this.ruleForm.id = "";
  302. // this.ruleForm.channelId='';
  303. this.ruleForm.avatar = "";
  304. this.ruleForm.name = "";
  305. this.ruleForm.description = "";
  306. this.ruleForm.job = "";
  307. this.ruleForm.mail = "";
  308. this.ruleForm.phone = "";
  309. this.ruleForm.state = "";
  310. this.ruleForm.isDelete = "";
  311. this.$refs["ruleForm"].clearValidate();
  312. this.dialogVisible = false;
  313. },
  314. submitCom() {
  315. this.$refs["ruleForm"].validate((valid) => {
  316. if (valid) {
  317. //判断是编辑还是新增
  318. if (this.isView) {
  319. this.register();
  320. } else {
  321. this.editUserFun();
  322. }
  323. //都校验通过后可以触发注册接口了
  324. //调用方法进行入参
  325. }
  326. });
  327. },
  328. register() {
  329. let that = this;
  330. this.$http.post(
  331. `/staff/save`,
  332. {
  333. avatar: this.ruleForm.avatar,
  334. name: this.ruleForm.name,
  335. description: this.ruleForm.description,
  336. job: this.ruleForm.job,
  337. mail: this.ruleForm.mail,
  338. phone: this.ruleForm.phone,
  339. state: this.ruleForm.state,
  340. channelId: this.ruleForm.channelId,
  341. isDelete: this.ruleForm.isDelete,
  342. // ...this.ruleForm, //解构对象
  343. },
  344. (res) => {
  345. this.disableFlag = false;
  346. if (res && res.code == 200) {
  347. this.dialogVisible = false;
  348. this.$message.success(res.msg);
  349. // this.$toast.success({ message: "成功" });
  350. //调用父组件的查询方法
  351. that.$emit("search");
  352. } else {
  353. // this.$toast.fail({ message: res.msg });
  354. this.$message.error(res.msg);
  355. }
  356. //清空缓存
  357. this.cancle();
  358. }
  359. );
  360. },
  361. editUserFun() {
  362. let that = this;
  363. this.$http.post(
  364. `/staff/save`,
  365. {
  366. ...this.ruleForm,
  367. // ...this.ruleForm, //解构对象
  368. },
  369. (res) => {
  370. this.disableFlag = false;
  371. if (res && res.code == 200) {
  372. this.dialogVisible = false;
  373. // this.$toast.success({ message: "成功" });
  374. //调用父组件的查询方法
  375. that.$emit("search");
  376. this.$message.success("修改成功");
  377. } else {
  378. // this.$toast.fail({ message: res.msg });
  379. this.$message.error(res.msg);
  380. }
  381. //清空缓存
  382. this.cancle();
  383. }
  384. );
  385. },
  386. },
  387. };
  388. </script>
  389. <style scoped>
  390. .inputCom {
  391. width: 200px;
  392. }
  393. .avatar-uploader .el-upload {
  394. border: 1px dashed #d9d9d9;
  395. border-radius: 6px;
  396. cursor: pointer;
  397. position: relative;
  398. overflow: hidden;
  399. }
  400. .avatar-uploader .el-upload:hover {
  401. border-color: #409eff;
  402. }
  403. .avatar-uploader-icon {
  404. font-size: 28px;
  405. color: #8c939d;
  406. width: 178px;
  407. height: 178px;
  408. line-height: 178px;
  409. text-align: center;
  410. border: 1px solid;
  411. }
  412. .avatar {
  413. width: 178px;
  414. height: 178px;
  415. display: block;
  416. }
  417. </style>