Keine Beschreibung

editUser.vue 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <el-dialog title="编辑用户" ref="ruleForm" :visible.sync="dialogTableVisible" width="860px" @close='closed'>
  3. <el-form class="form-main" :model="ruleForm2" :rules="rules2" ref="ruleForm2" label-position='top' status-icon>
  4. <el-row>
  5. <el-col :span="12">
  6. <el-form-item label="账号" prop='account'>
  7. <el-input placeholder="请输入账号" v-model="ruleForm2.account" maxlength=11></el-input>
  8. </el-form-item>
  9. </el-col>
  10. <el-col :span="12">
  11. <el-form-item label="用户姓名" prop='name'>
  12. <el-input placeholder="请输入用户姓名" v-model="ruleForm2.name" maxlength=20></el-input>
  13. </el-form-item>
  14. </el-col>
  15. <el-col :span="12">
  16. <el-form-item label="职位" prop='job'>
  17. <el-input placeholder="请输入用户职位" v-model="ruleForm2.job" maxlength=100></el-input>
  18. </el-form-item>
  19. </el-col>
  20. <el-col :span="12">
  21. <el-form-item label="用户所在机构" prop='comp'>
  22. <el-input placeholder="请输入用户所在机构" v-model="ruleForm2.comp" maxlength=200></el-input>
  23. </el-form-item>
  24. </el-col>
  25. <el-col :span="12">
  26. <el-form-item label="用户类型" prop='type'>
  27. <el-select v-model="ruleForm2.type" placeholder="请选择用户类型">
  28. <el-option
  29. v-for="item in options"
  30. :key="item.value"
  31. :label="item.label"
  32. :value="item.value">
  33. </el-option>
  34. </el-select>
  35. </el-form-item>
  36. </el-col>
  37. <el-col :span="12">
  38. <el-form-item label="联系电话" prop='phone'>
  39. <el-input placeholder="请输入手机号码" v-model="ruleForm2.phone" maxlength=11></el-input>
  40. </el-form-item>
  41. </el-col>
  42. <el-col :span="12">
  43. <el-form-item label="联系邮箱" prop='email'>
  44. <el-input placeholder="请输入邮箱地址" v-model="ruleForm2.email" maxlength=100></el-input>
  45. </el-form-item>
  46. </el-col>
  47. <el-col :span="24" >
  48. <el-form-item label="备注" prop='remark'>
  49. <el-input type="textarea" rows=4 v-model="ruleForm2.remark" maxlength=500></el-input>
  50. </el-form-item>
  51. </el-col>
  52. <el-col :span="24" class="el-btn-col">
  53. <div class="el-btn-col-box">
  54. <el-button type="primary" @click="submitForm('ruleForm2')">确认</el-button>
  55. <el-button type="info" @click="resetForm('ruleForm2')">返回</el-button>
  56. </div>
  57. </el-col>
  58. </el-row>
  59. </el-form>
  60. </el-dialog>
  61. </template>
  62. <script>
  63. import { checkRegister, addRegister, updateRegister, queryRegister } from '@/api/userManagemen'
  64. export default {
  65. props: ['dialog', 'id'],
  66. data() {
  67. var account = (rule, value, callback) => {
  68. const regTel = /^1[3|4|5|7|8][0-9]\d{8}$/
  69. if (value === '') {
  70. callback(new Error('请输入账号'))
  71. } else {
  72. if (!regTel.test(value)) {
  73. callback(new Error('账号为手机号格式'))
  74. } else {
  75. if (this.edit) {
  76. checkRegister({ account: value, id: this.edit }).then(response => {
  77. if (!response.data) {
  78. callback(new Error('账户已存在,请重新输入'))
  79. } else {
  80. callback()
  81. }
  82. })
  83. } else {
  84. checkRegister({ account: value }).then(response => {
  85. if (!response.data) {
  86. callback(new Error('账户已存在,请重新输入'))
  87. } else {
  88. callback()
  89. }
  90. })
  91. }
  92. }
  93. }
  94. }
  95. var phone = (rule, value, callback) => {
  96. const regTel = /^1[3|4|5|7|8][0-9]\d{8}$/
  97. if (value === '') {
  98. callback()
  99. } else {
  100. if (!regTel.test(value)) {
  101. callback(new Error('手机号码格式不正确'))
  102. } else {
  103. callback()
  104. }
  105. }
  106. }
  107. var email = (rule, value, callback) => {
  108. const regTel = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
  109. if (value === '') {
  110. callback()
  111. } else {
  112. if (!regTel.test(value)) {
  113. callback(new Error('邮箱格式不正确'))
  114. } else {
  115. callback()
  116. }
  117. }
  118. }
  119. return {
  120. options: [{
  121. value: 0,
  122. label: '普通用户'
  123. }, {
  124. value: 1,
  125. label: '管理员'
  126. }],
  127. dialogTableVisible: false,
  128. ruleForm2: {
  129. edit: '',
  130. account: '',
  131. name: '',
  132. comp: '',
  133. job: '',
  134. phone: '',
  135. email: '',
  136. remark: '',
  137. type: 0
  138. },
  139. rules2: {
  140. account: [
  141. { required: true, validator: account, trigger: 'blur' }
  142. ],
  143. name: [
  144. { required: true, message: '请输入用户姓名', trigger: 'blur' }
  145. ],
  146. comp: [
  147. { required: true, message: '请输入用户所在机构', trigger: 'blur' }
  148. ],
  149. job: [
  150. { required: true, message: '请输入用户职位', trigger: 'blur' }
  151. ],
  152. phone: [
  153. { validator: phone, trigger: 'blur' }
  154. ],
  155. email: [
  156. { validator: email, trigger: 'blur' }
  157. ]
  158. }
  159. }
  160. },
  161. watch: {
  162. dialog() {
  163. this.dialogTableVisible = true
  164. this.edit = this.id
  165. if (this.edit) {
  166. queryRegister({ id: this.edit }).then(response => {
  167. if (response.success) {
  168. const $data = response.data
  169. this.ruleForm2 = {
  170. account: $data.account,
  171. name: $data.name,
  172. comp: $data.comp,
  173. job: $data.job,
  174. phone: $data.phone || '',
  175. email: $data.email || '',
  176. remark: $data.remark || '',
  177. type: $data.type
  178. }
  179. }
  180. })
  181. }
  182. }
  183. },
  184. methods: {
  185. submitForm(formName) {
  186. const that = this
  187. this.$refs[formName].validate((valid) => {
  188. if (valid) {
  189. if (!this.edit) {
  190. addRegister(this.ruleForm2).then(response => {
  191. if (response.success) {
  192. this.$emit('chilF')
  193. setTimeout(function() {
  194. that.pop('已成功添加')
  195. }, 1000)
  196. this.resetForm(this.ruleForm2)
  197. this.dialogTableVisible = false
  198. }
  199. }).catch(error => {
  200. console.log(error)
  201. })
  202. } else {
  203. const par = this.ruleForm2
  204. par.id = this.edit
  205. updateRegister(par).then(response => {
  206. if (response.success) {
  207. setTimeout(function() {
  208. that.pop('已成功更新用户信息')
  209. }, 1000)
  210. this.resetForm('ruleForm2')
  211. this.$emit('chilF')
  212. this.dialogTableVisible = false
  213. this.edit = ''
  214. this.ruleForm2 = {
  215. account: '',
  216. name: '',
  217. comp: '',
  218. job: '',
  219. phone: '',
  220. email: '',
  221. remark: '',
  222. type: 0
  223. }
  224. }
  225. })
  226. }
  227. }
  228. })
  229. },
  230. resetForm(formName) {
  231. this.dialogTableVisible = false
  232. this.$refs[formName].resetFields()
  233. this.edit = ''
  234. this.$emit('chilF', true)
  235. },
  236. closed() {
  237. this.$refs['ruleForm2'].resetFields()
  238. this.edit = ''
  239. this.$emit('chilF', true)
  240. },
  241. pop($par) {
  242. this.$confirm($par, '提示', {
  243. confirmButtonText: '确定',
  244. cancelButtonText: '取消',
  245. type: 'success',
  246. showCancelButton: false,
  247. center: true
  248. }).then(() => {
  249. }).catch(() => {
  250. })
  251. },
  252. resetTemp(row) {
  253. this.ruleForm2 = {
  254. account: row.account,
  255. name: row.name,
  256. comp: row.comp,
  257. job: row.job,
  258. phone: row.phone,
  259. email: row.email,
  260. remark: row.remark,
  261. type: row.type
  262. }
  263. this.edit = row.id
  264. }
  265. }
  266. }
  267. </script>
  268. <style rel="stylesheet/scss" lang="scss" scoped>
  269. .el-form-item{
  270. margin: 0px 10px
  271. }
  272. .el-select{
  273. width: 100%
  274. }
  275. .el-col{
  276. margin-bottom: 15px
  277. }
  278. .el-form--label-top .el-form-item__label {
  279. padding: 0
  280. }
  281. </style>