edit.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <el-dialog
  3. :title="title"
  4. :visible.sync="dialogVisible"
  5. width="33%"
  6. :before-close="handleClose"
  7. v-loading.fullscreen.lock="fullscreenLoading"
  8. >
  9. <el-form ref="form" :model="form" label-width="100px" :rules="rules">
  10. <el-form-item prop="account">
  11. <template slot="label" class="status"
  12. ><span>账&#8195;&emsp;号</span>:</template
  13. >
  14. <el-input placeholder="请输入" v-model.trim="form.account"></el-input>
  15. </el-form-item>
  16. <el-form-item prop="name">
  17. <template slot="label" class="status"
  18. ><span>姓&#8195;&emsp;名</span>:</template
  19. >
  20. <el-input placeholder="请输入" v-model.trim="form.name"></el-input>
  21. </el-form-item>
  22. <el-form-item prop="password">
  23. <template slot="label" class="status"
  24. ><span>密&#8195;&emsp;码</span>:</template
  25. >
  26. <el-input placeholder="请输入" v-model.trim="form.password"></el-input>
  27. </el-form-item>
  28. <el-form-item label>
  29. <template slot="label" class="status"
  30. ><span>状&#8195;&emsp;态</span>:</template
  31. >
  32. <el-radio-group v-model="form.status">
  33. <el-radio :label="1">启用</el-radio>
  34. <el-radio :label="0">禁用</el-radio>
  35. </el-radio-group>
  36. </el-form-item>
  37. </el-form>
  38. <span slot="footer" class="dialog-footer">
  39. <el-button size="small" @click="handleClose">取 消</el-button>
  40. <el-button
  41. size="small"
  42. style="margin-left: 60px"
  43. type="primary"
  44. @click="addList('form')"
  45. >确 定</el-button
  46. >
  47. </span>
  48. </el-dialog>
  49. </template>
  50. <script>
  51. import * as api from '@/api/api'
  52. export default {
  53. data() {
  54. const validatePass = (rule, value, callback) => {
  55. if (value.length < 6 || value.length > 18) {
  56. callback(new Error('密码不能小于6位,大于18位'))
  57. } else {
  58. callback()
  59. }
  60. }
  61. return {
  62. fullscreenLoading:false,
  63. dialogVisible: false,
  64. radio: '',
  65. title: '',
  66. form: {
  67. account: '',
  68. name: '',
  69. password: '',
  70. status: 0,
  71. userId: ''
  72. },
  73. userString: {},
  74. rules: {
  75. account: [{ required: true, message: '请输入账号', trigger: 'blur' }],
  76. name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
  77. password: [{ required: true, trigger: 'blur', validator: validatePass }]
  78. }
  79. }
  80. },
  81. methods: {
  82. handleClose() {
  83. this.dialogVisible = false
  84. this.$parent.search()
  85. this.form = {
  86. account: '',
  87. name: '',
  88. password: '',
  89. status: '',
  90. userId: ''
  91. }
  92. this.$refs['form'].resetFields()
  93. },
  94. openClose(val) {
  95. this.title = val.title
  96. if (val) {
  97. this.userString = val
  98. if (val.id) {
  99. this.detail()
  100. }
  101. }
  102. this.dialogVisible = true
  103. },
  104. /**
  105. * @method 用户确定
  106. * **/
  107. addList(formName) {
  108. this.$refs[formName].validate(valid => {
  109. if (valid) {
  110. this.fullscreenLoading = true
  111. let code = {
  112. account: this.form.account,
  113. name: this.form.name,
  114. password: this.form.password,
  115. status: this.form.status
  116. }
  117. this.userString.show
  118. ? this.addListData(code)
  119. : this.editListData(code)
  120. }
  121. })
  122. },
  123. /**
  124. * @method 详情
  125. * **/
  126. detail() {
  127. const code = {
  128. id: this.userString.id
  129. }
  130. api.GET('/user/detail', code).then(data => {
  131. if (data.code == 0) {
  132. this.form = data.data
  133. }
  134. })
  135. },
  136. /**
  137. * @method 新增
  138. * **/
  139. addListData(val) {
  140. api.POST('/user/add', val).then(data => {
  141. if (data.code == 0) {
  142. this.handleClose()
  143. this.$message.success(data.message)
  144. this.fullscreenLoading = false
  145. }
  146. }).catch(()=>{
  147. this.fullscreenLoading = false
  148. })
  149. },
  150. /**
  151. * @method 编辑
  152. * **/
  153. editListData(val) {
  154. val.userId = this.form.userId
  155. api.POST('/user/update', val).then(data => {
  156. if (data.code == 0) {
  157. this.handleClose()
  158. this.$message.success(data.message)
  159. this.fullscreenLoading = false
  160. }
  161. }).catch(()=>{
  162. this.fullscreenLoading = false
  163. })
  164. }
  165. }
  166. }
  167. </script>
  168. <style lang="less" scoped>
  169. .status {
  170. padding: 0 12px 0 0;
  171. }
  172. .status::before {
  173. content: '*';
  174. color: #f56c6c;
  175. margin-right: 4px;
  176. }
  177. </style>