RepairPeo.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <section>
  3. <!-- 添加员工模块 -->
  4. <div class="block">
  5. <el-button round @click="clearValidate()">添加员工</el-button>
  6. </div>
  7. <!-- 添加员工弹窗 -->
  8. <el-dialog title="员工信息" :visible.sync="addPeoVisible" width="30%">
  9. <el-form
  10. status-icon
  11. label-position="left"
  12. :model="registerForm"
  13. :rules="rules"
  14. ref="registerForm"
  15. label-width="100px"
  16. >
  17. <el-form-item label="姓名" prop="name">
  18. <el-input
  19. v-model="registerForm.workName"
  20. placeholder="请输入真实姓名"
  21. ></el-input>
  22. </el-form-item>
  23. <el-form-item label="手机号" prop="tel">
  24. <el-input
  25. v-model="registerForm.workPhone"
  26. placeholder="请输入正确手机号"
  27. ></el-input>
  28. </el-form-item>
  29. <el-form-item label="密码" prop="pwd">
  30. <el-input
  31. v-model="registerForm.workPassword"
  32. placeholder="密码为手机号末尾4位加1位大写字母"
  33. ></el-input>
  34. </el-form-item>
  35. <el-form-item label="校区" prop="region">
  36. <el-select v-model="registerForm.workCampus" placeholder="请选择校区">
  37. <el-option label="墨轩湖校区" value="1"></el-option>
  38. <el-option label="黄家湖校区" value="0"></el-option>
  39. </el-select>
  40. </el-form-item>
  41. </el-form>
  42. <span slot="footer" class="dialog-footer">
  43. <el-button @click="addPeoVisible = false">取 消</el-button>
  44. <el-button type="primary" @click="registerWork()">添 加</el-button>
  45. </span>
  46. </el-dialog>
  47. <!-- 员工列表模块 -->
  48. <el-table :data="tableData" style="width: 100%" height="150">
  49. <el-table-column prop="workName" label="姓名"> </el-table-column>
  50. <el-table-column prop="workPhone" label="手机号"> </el-table-column>
  51. <el-table-column prop="workPassword" label="密码"> </el-table-column>
  52. <el-table-column label="校区">
  53. <template slot-scope="scope">
  54. {{ Campus[scope.row.workCampus] }}</template
  55. >
  56. </el-table-column>
  57. <el-table-column label="操作">
  58. <template slot-scope="scope">
  59. <el-button
  60. @click.native.prevent="
  61. deleteRow(scope.$index, tableData, scope.row.workId)
  62. "
  63. type="text"
  64. size="small"
  65. >
  66. 移除
  67. </el-button>
  68. </template>
  69. </el-table-column>
  70. </el-table>
  71. <!-- 分页器 -->
  72. <el-pagination
  73. :current-page="curpage"
  74. :pager-count="7"
  75. @current-change="handleCurrentChange"
  76. background
  77. layout="prev, pager, next"
  78. :total="100"
  79. >
  80. </el-pagination>
  81. </section>
  82. </template>
  83. <script>
  84. export default {
  85. data() {
  86. //自定义验证方法
  87. var telPass = (rule, value, callback) => {
  88. if (this.registerForm.workPhone == "") {
  89. callback(new Error("手机号不能为空"));
  90. } else {
  91. let phoneCodeVerification = /^[1][3,4,5,7,8][0-9]{9}$/;
  92. let boo = phoneCodeVerification.test(this.registerForm.workPhone);
  93. // console.log(boo);
  94. if (boo) {
  95. callback();
  96. } else {
  97. callback(new Error("请输入正确手机号"));
  98. }
  99. }
  100. };
  101. var pwdPass = (rule, value, callback) => {
  102. if (this.registerForm.workPassword == "") {
  103. callback(new Error("密码不能为空"));
  104. } else {
  105. let phoneCodeVerification = /^\d{4}[A-Z]$/;
  106. let boo = phoneCodeVerification.test(this.registerForm.workPassword);
  107. if (boo) {
  108. callback();
  109. } else {
  110. callback(new Error("请输入正确密码格式"));
  111. }
  112. }
  113. };
  114. var namePass = (rule, value, callback) => {
  115. if (this.registerForm.workName == "") {
  116. callback(new Error("姓名不能为空"));
  117. } else {
  118. callback();
  119. }
  120. };
  121. return {
  122. tableData: [], //员工列表信息
  123. addPeoVisible: false, //添加员工弹窗
  124. dialogVisible: false, //
  125. registerForm: {
  126. workPhone: "", //号码
  127. workCampus: "", //校区
  128. workPassword: "", //密码
  129. workName: "" //姓名
  130. },
  131. rules: {
  132. name: [
  133. {
  134. validator: namePass,
  135. trigger: "blur"
  136. }
  137. ],
  138. tel: [
  139. {
  140. validator: telPass,
  141. trigger: "blur"
  142. }
  143. ],
  144. pwd: [
  145. {
  146. validator: pwdPass,
  147. trigger: "blur"
  148. }
  149. ]
  150. },
  151. curpage: 1, //页码
  152. pageSize: 15, //一页条数
  153. Campus: ["黄家湖校区", "墨轩湖校区"],
  154. token: null
  155. };
  156. },
  157. created() {
  158. this.token = sessionStorage.getItem("token");
  159. if (this.token) {
  160. this.getWorker();
  161. } else {
  162. this.$message({
  163. message: "授权失效,请重新登录",
  164. type: "warning"
  165. });
  166. this.$router.push({ path: "/" });
  167. }
  168. },
  169. methods: {
  170. //当改变当前页数的时候触发的事件
  171. handleCurrentChange(currentPage) {
  172. // console.log(this.sear_data);
  173. this.curpage = currentPage;
  174. this.getWorker();
  175. },
  176. //获取维修人员列表
  177. getWorker() {
  178. const loading = this.$loading({
  179. lock: true,
  180. text: "Loading",
  181. spinner: "el-icon-loading",
  182. background: "rgba(0, 0, 0, 0.7)"
  183. });
  184. this.$axios({
  185. method: "post",
  186. url: `/baoxiu/repairApi/work/queryAllWorkStatus?pageNum=${this.curpage}&pageSize=${this.pageSize}`,
  187. headers: {
  188. token: this.token
  189. }
  190. })
  191. .then(({ data }) => {
  192. if (data.status == 200) {
  193. this.tableData = [];
  194. this.tableData = data.data.list;
  195. } else {
  196. this.$message({
  197. message: data.message,
  198. type: "warning"
  199. });
  200. }
  201. loading.close();
  202. })
  203. .catch(err => {
  204. loading.close();
  205. this.$message({
  206. message: err,
  207. type: "warning"
  208. });
  209. });
  210. },
  211. //清楚表单校验
  212. clearValidate() {
  213. this.addPeoVisible = true;
  214. //清空
  215. this.registerForm.workPhone = "";
  216. this.registerForm.workName = "";
  217. this.registerForm.workCampus = "";
  218. this.registerForm.workPassword = "";
  219. this.$nextTick(() => {
  220. this.$refs["registerForm"].clearValidate();
  221. });
  222. },
  223. //维修人员注册
  224. registerWork() {
  225. this.$axios({
  226. method: "post",
  227. url: `/baoxiu/repairApi/work/insertWork?workPhone=${this.registerForm.workPhone}&workCampus=${this.registerForm.workCampus}&workPassword=${this.registerForm.workPassword}&workName=${this.registerForm.workName}`,
  228. headers: {
  229. token: this.token
  230. }
  231. })
  232. .then(({ data }) => {
  233. // console.log(data);
  234. if (data.status != 200) {
  235. this.$message({
  236. message: data.message,
  237. type: "warning"
  238. });
  239. } else {
  240. this.addPeoVisible = false;
  241. this.$message({
  242. message: data.message,
  243. type: "success"
  244. });
  245. //清空
  246. this.registerForm.workPhone = "";
  247. this.registerForm.workName = "";
  248. this.registerForm.workCampus = "";
  249. this.registerForm.workPassword = "";
  250. }
  251. })
  252. .catch(err => {
  253. this.$message({
  254. message: err,
  255. type: "warning"
  256. });
  257. });
  258. },
  259. //移除人员
  260. deleteRow(index, rows, work_id) {
  261. this.$axios({
  262. method: "post",
  263. url: `/baoxiu/repairApi/work/removeWorkStatus?workId=${work_id}`,
  264. headers: {
  265. token: this.token
  266. }
  267. })
  268. .then(({ data }) => {
  269. if (data.status == 200) {
  270. this.$confirm("此操作将永久移除该员工, 是否继续?", "提示", {
  271. confirmButtonText: "确定",
  272. cancelButtonText: "取消",
  273. type: "warning"
  274. })
  275. .then(() => {
  276. this.$message({
  277. type: "success",
  278. message: "移除成功!"
  279. });
  280. rows.splice(index, 1); // 删除人员
  281. })
  282. .catch(() => {
  283. this.$message({
  284. type: "info",
  285. message: "已取消移除"
  286. });
  287. });
  288. } else {
  289. this.$message({
  290. message: err,
  291. type: "warning"
  292. });
  293. }
  294. })
  295. .catch(err => {
  296. loading.close();
  297. this.$message({
  298. message: err,
  299. type: "warning"
  300. });
  301. });
  302. }
  303. }
  304. };
  305. </script>
  306. <style scoped>
  307. @import url("RepairPeo.css");
  308. </style>