add.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <!-- 引入样式 -->
  9. <link rel="stylesheet" href="../../plugins/element-ui/index.css" />
  10. <link rel="stylesheet" href="../../styles/common.css" />
  11. <link rel="stylesheet" href="../../styles/page.css" />
  12. </head>
  13. <body>
  14. <div class="addBrand-container" id="member-add-app">
  15. <div class="container">
  16. <el-form
  17. ref="ruleForm"
  18. :model="ruleForm"
  19. :rules="rules"
  20. :inline="false"
  21. label-width="180px"
  22. class="demo-ruleForm"
  23. >
  24. <el-form-item label="账号:" prop="username">
  25. <el-input v-model="ruleForm.username" placeholder="请输入账号" maxlength="20"/>
  26. </el-form-item>
  27. <el-form-item
  28. label="员工姓名:"
  29. prop="name"
  30. >
  31. <el-input
  32. v-model="ruleForm.name"
  33. placeholder="请输入员工姓名"
  34. maxlength="20"
  35. />
  36. </el-form-item>
  37. <el-form-item
  38. label="手机号:"
  39. prop="phone"
  40. >
  41. <el-input
  42. v-model="ruleForm.phone"
  43. placeholder="请输入手机号"
  44. maxlength="20"
  45. />
  46. </el-form-item>
  47. <el-form-item
  48. label="性别:"
  49. prop="sex"
  50. >
  51. <el-radio-group v-model="ruleForm.sex">
  52. <el-radio label="男"></el-radio>
  53. <el-radio label="女"></el-radio>
  54. </el-radio-group>
  55. </el-form-item>
  56. <el-form-item
  57. label="身份证号:"
  58. prop="idNumber"
  59. >
  60. <el-input
  61. v-model="ruleForm.idNumber"
  62. placeholder="请输入身份证号"
  63. maxlength="20"
  64. />
  65. </el-form-item>
  66. <div class="subBox address">
  67. <el-form-item>
  68. <el-button @click="goBack()">
  69. 取消
  70. </el-button>
  71. <el-button
  72. type="primary"
  73. @click="submitForm('ruleForm', false)"
  74. >
  75. 保存
  76. </el-button>
  77. <el-button
  78. v-if="actionType == 'add'"
  79. type="primary"
  80. class="continue"
  81. @click="submitForm('ruleForm', true)"
  82. >
  83. 保存并继续添加
  84. </el-button>
  85. </el-form-item>
  86. </div>
  87. </el-form>
  88. </div>
  89. </div>
  90. <!-- 开发环境版本,包含了有帮助的命令行警告 -->
  91. <script src="../../plugins/vue/vue.js"></script>
  92. <!-- 引入组件库 -->
  93. <script src="../../plugins/element-ui/index.js"></script>
  94. <!-- 引入axios -->
  95. <script src="../../plugins/axios/axios.min.js"></script>
  96. <script src="../../js/request.js"></script>
  97. <script src="../../api/member.js"></script>
  98. <script src="../../js/validate.js"></script>
  99. <script src="../../js/index.js"></script>
  100. <script>
  101. new Vue({
  102. el: '#member-add-app',
  103. data() {
  104. return {
  105. id: '',
  106. actionType : '',
  107. ruleForm : {
  108. 'name': '',
  109. 'phone': '',
  110. 'sex': '男',
  111. 'idNumber': '',
  112. username: ''
  113. }
  114. }
  115. },
  116. computed: {
  117. rules () {
  118. return {
  119. //账号
  120. username: [
  121. {
  122. required: true, 'validator': checkUserName, trigger: 'blur'
  123. }
  124. ],
  125. //姓名
  126. name: [{ required: true, 'validator': checkName, 'trigger': 'blur' }],
  127. 'phone': [{ 'required': true, 'validator': checkPhone, 'trigger': 'blur' }],
  128. 'idNumber': [{ 'required': true, 'validator': validID, 'trigger': 'blur' }]
  129. }
  130. }
  131. },
  132. created() {
  133. this.id = requestUrlParam('id')
  134. this.actionType = this.id ? 'edit' : 'add'
  135. if (this.id) {
  136. this.init()
  137. }
  138. },
  139. mounted() {
  140. },
  141. methods: {
  142. async init () {
  143. queryEmployeeById(this.id).then(res => {
  144. console.log(res)
  145. if (String(res.code) === '1') {
  146. console.log(res.data)
  147. this.ruleForm = res.data
  148. this.ruleForm.sex = res.data.sex === '0' ? '女' : '男'
  149. // this.ruleForm.password = ''
  150. } else {
  151. this.$message.error(res.msg || '操作失败')
  152. }
  153. })
  154. },
  155. submitForm (formName, st) {
  156. this.$refs[formName].validate((valid) => {
  157. if (valid) {
  158. if (this.actionType === 'add') {
  159. const params = {
  160. ...this.ruleForm,
  161. sex: this.ruleForm.sex === '女' ? '0' : '1'
  162. }
  163. addEmployee(params).then(res => {
  164. if (res.code === 1) {
  165. this.$message.success('员工添加成功!')
  166. if (!st) {
  167. this.goBack()
  168. } else {
  169. this.ruleForm = {
  170. username: '',
  171. 'name': '',
  172. 'phone': '',
  173. // 'password': '',
  174. // 'rePassword': '',/
  175. 'sex': '男',
  176. 'idNumber': ''
  177. }
  178. }
  179. } else {
  180. this.$message.error(res.msg || '操作失败')
  181. }
  182. }).catch(err => {
  183. this.$message.error('请求出错了:' + err)
  184. })
  185. } else {
  186. const params = {
  187. ...this.ruleForm,
  188. sex: this.ruleForm.sex === '女' ? '0' : '1'
  189. }
  190. editEmployee(params).then(res => {
  191. if (res.code === 1) {
  192. this.$message.success('员工信息修改成功!')
  193. this.goBack()
  194. } else {
  195. this.$message.error(res.msg || '操作失败')
  196. }
  197. }).catch(err => {
  198. this.$message.error('请求出错了:' + err)
  199. })
  200. }
  201. } else {
  202. console.log('error submit!!')
  203. return false
  204. }
  205. })
  206. },
  207. goBack(){
  208. window.parent.menuHandle({
  209. id: '2',
  210. url: '/backend/page/member/list.html',
  211. name: '员工管理'
  212. },false)
  213. }
  214. }
  215. })
  216. </script>
  217. </body>
  218. </html>