edit.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <el-dialog
  3. :title="classString.title"
  4. :visible.sync="dialogVisible"
  5. width="33%"
  6. :before-close="handleClose"
  7. append-to-body
  8. >
  9. <el-form label-width="100px" :model="form" ref="form" :rules="rules">
  10. <el-form-item label="分类名称:" prop="name">
  11. <el-input placeholder="请输入" v-model="form.name"></el-input>
  12. </el-form-item>
  13. <el-form-item label required>
  14. <template slot="label" class="status">
  15. <span>状&#8195;&emsp;态</span>:
  16. </template>
  17. <el-radio-group v-model="form.status">
  18. <el-radio :label="1">启用</el-radio>
  19. <el-radio :label="0">禁用</el-radio>
  20. </el-radio-group>
  21. </el-form-item>
  22. <el-form-item
  23. style="margin-bottom: 20px"
  24. label
  25. v-for="(item, index) in form.role"
  26. :key="index"
  27. :prop="`role.${index}.value`"
  28. :rules="rules.value"
  29. >
  30. <template v-if="index == 0" slot="label">
  31. <span>访问权限:</span>
  32. </template>
  33. <div class="form_item_content">
  34. <el-input
  35. placeholder="请输入手机号"
  36. v-onlyInt
  37. maxlength="11"
  38. v-model="item.value"
  39. ></el-input>
  40. <i class="el-icon-plus" @click="addjurisdiction"></i>
  41. <i
  42. class="el-icon-minus"
  43. v-if="form.role.length != 1"
  44. @click="deletjurisdiction(index)"
  45. ></i>
  46. </div>
  47. </el-form-item>
  48. </el-form>
  49. <span slot="footer" class="dialog-footer">
  50. <el-button size="small" @click="dialogVisible = false">取 消</el-button>
  51. <el-button
  52. size="small"
  53. style="margin-left: 60px"
  54. type="primary"
  55. @click="submit('form')"
  56. >确 定</el-button
  57. >
  58. </span>
  59. </el-dialog>
  60. </template>
  61. <script>
  62. import * as api from '@/api/api'
  63. export default {
  64. data() {
  65. const validateUser = (rule, value, callback) => {
  66. if (!/^1[3456789]\d{9}$/.test(value)) {
  67. callback(new Error('请输入正确的手机号'))
  68. } else {
  69. callback()
  70. }
  71. }
  72. return {
  73. dialogVisible: false,
  74. classString: {},
  75. form: {
  76. name: '',
  77. status: 0,
  78. role: [{ value: '' }]
  79. },
  80. rules: {
  81. value: [{ required: true, trigger: 'blur', validator: validateUser }],
  82. name: [{ required: true, trigger: 'blur', message: '请输入分类名称' }]
  83. }
  84. }
  85. },
  86. methods: {
  87. handleClose() {
  88. this.dialogVisible = false
  89. this.$parent.search()
  90. this.form = {
  91. name: '',
  92. status: 0,
  93. role: [{ value: '' }]
  94. }
  95. },
  96. openClose(val) {
  97. if (val) {
  98. this.classString = val
  99. if (!val.show) {
  100. this.detailList()
  101. }
  102. }
  103. this.title = val.title
  104. this.dialogVisible = true
  105. },
  106. /**
  107. * @method 分类管理详情
  108. * **/
  109. detailList() {
  110. let code = {
  111. typeId: this.classString.typeId
  112. }
  113. api.POST('/doc/type/detail', code).then(data => {
  114. if (data.code == 0) {
  115. this.form = data.data
  116. let role = []
  117. this.form.role.forEach(item => {
  118. role.push({ value: item })
  119. })
  120. this.form.role = role
  121. }
  122. })
  123. },
  124. /**
  125. * @method 增加访问权限
  126. * **/
  127. addjurisdiction() {
  128. this.form.role.push({ value: '' })
  129. },
  130. /**
  131. * @method 删除访问权限
  132. * **/
  133. deletjurisdiction(val) {
  134. this.form.role.splice(val, 1)
  135. },
  136. /**
  137. * @method 确定提交
  138. **/
  139. submit(formName) {
  140. this.$refs[formName].validate(valid => {
  141. if (valid) {
  142. let role = []
  143. this.form.role.forEach(item => {
  144. role.push(item.value)
  145. })
  146. let code = {
  147. linkUrl: '',
  148. name: this.form.name,
  149. role: role,
  150. status: this.form.status
  151. }
  152. this.classString.show ? this.addclass(code) : this.editclass(code)
  153. }
  154. })
  155. },
  156. /**
  157. * @method 新增
  158. * **/
  159. addclass(val) {
  160. api.POST('/doc/type/add', val).then(data => {
  161. if (data.code == 0) {
  162. this.handleClose()
  163. this.$message.success(data.message)
  164. }
  165. })
  166. },
  167. /**
  168. * @method 编辑
  169. * **/
  170. editclass(val) {
  171. val.typeId = this.form.typeId
  172. api.POST('/doc/type/update', val).then(data => {
  173. if (data.code == 0) {
  174. this.handleClose()
  175. this.$message.success(data.message)
  176. }
  177. })
  178. }
  179. }
  180. }
  181. </script>
  182. <style lang="less" scoped>
  183. .status {
  184. padding: 0 12px 0 0;
  185. }
  186. .status::before {
  187. content: '*';
  188. color: #f56c6c;
  189. margin-right: 4px;
  190. }
  191. .form_item_content {
  192. display: flex;
  193. align-items: center;
  194. margin-bottom: 10px;
  195. }
  196. .el-icon-plus,
  197. .el-icon-minus {
  198. border: 1px solid #f23f3a;
  199. color: #f23f3a;
  200. font-size: 30px;
  201. margin-left: 10px;
  202. border-radius: 4px;
  203. cursor: pointer;
  204. }
  205. .el-icon-minus {
  206. margin-right: 16px;
  207. }
  208. </style>