NoticeAdd.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <div>
  3. <el-dialog
  4. v-loading="loading"
  5. :visible.sync="visible"
  6. :close-on-press-escape="true"
  7. :close-on-click-modal="false"
  8. :show-close="false"
  9. custom-class="main-edit-dialog"
  10. :title="title"
  11. >
  12. <el-form :ref="formName" :model="formData" :rules="rules" label-width="120px" class="dialog-form">
  13. <el-form-item prop="title" label="Title">
  14. <el-input v-model="formData.systemName" placeholder="Please Input" clearable />
  15. </el-form-item>
  16. <el-form-item prop="scopeIds" label="Range">
  17. <el-input v-model="formData.scopeIds" clearable />
  18. </el-form-item>
  19. <el-form-item prop="attachmentPath" label="File">
  20. <upload-file :file-type="formData.messageType" :on-success="uploadSuccess" :on-error="uploadError" />
  21. <span style="display:none">{{ formData.attachmentPath }} </span>
  22. <div v-if="!isNull(formData.attachmentName)">
  23. <i class="upload-success el-icon-circle-check" />{{ formData.attachmentName }}
  24. </div>
  25. </el-form-item>
  26. <el-form-item prop="content" label="Content">
  27. <el-input v-model="formData.content" type="textarea" :rows="3" />
  28. </el-form-item>
  29. </el-form>
  30. <div slot="footer">
  31. <el-button @click="close">Cancel</el-button>
  32. <el-button type="primary" @click="save">Confirm</el-button>
  33. </div>
  34. </el-dialog>
  35. </div>
  36. </template>
  37. <script>
  38. import { isNull, formatDictData } from '@/utils/convert'
  39. import { pushSaveSystem } from '@/api/system'
  40. import { getDeptRootData, getDeptChildren, getDeptTreeData } from '@/api/dept'
  41. import UploadFile from '@/components/Upload/UploadFile'
  42. export default {
  43. components: { UploadFile },
  44. props: {
  45. typeData: {
  46. type: Array,
  47. default() {
  48. return []
  49. }
  50. }
  51. },
  52. data() {
  53. return {
  54. // dialog
  55. visible: false,
  56. isView: true,
  57. viewType: 'ADD',
  58. title: 'Edit',
  59. formName: 'editForm',
  60. formData: {
  61. id: null,
  62. messageType: 1,
  63. title: '',
  64. scopeIds: [],
  65. attachmentPath: '',
  66. attachmentName: '',
  67. content: ''
  68. },
  69. rules: {
  70. title: [
  71. { required: true, message: '请输入标题', trigger: 'change' }
  72. ],
  73. scopeIds: [
  74. { required: true, message: '请选择发布范围', trigger: 'blur' }
  75. ],
  76. content: [
  77. { required: true, message: '请输入信息内容', trigger: 'blur' }
  78. ]
  79. },
  80. action: 'add',
  81. // select:
  82. selectTreeProps: {
  83. // 配置项(必选)
  84. nodeKey: 'shortName',
  85. label: 'shortName',
  86. value: 'shortName',
  87. children: 'children'
  88. // disabled:true
  89. },
  90. defaultTreeId: '',
  91. deptData: [],
  92. policeCategoryData: [],
  93. activeFlagData: [{ id: 1, label: '在用' }, { id: 0, label: '停用' }],
  94. // others
  95. loading: false
  96. }
  97. },
  98. created() {
  99. console.log('created')
  100. },
  101. mounted() {
  102. console.log('mounted')
  103. },
  104. methods: {
  105. // 取值
  106. getSelectValue(value) {
  107. this.formData.deptName = value
  108. },
  109. // Upload
  110. uploadSuccess(data) {
  111. this.$set(this.formData, 'icon', data.url)
  112. this.fileName = data.fileName + '.' + data.extension
  113. },
  114. uploadError(error) {
  115. this.$message.error({
  116. type: 'error',
  117. duration: 0,
  118. showClose: true,
  119. message: error.message
  120. })
  121. },
  122. /**
  123. * 加载dialog
  124. */
  125. open(viewType, data) {
  126. this.title = 'Publish Notice'
  127. this.isView = false
  128. this.action = 'add'
  129. this.viewType = viewType
  130. this.visible = true
  131. },
  132. close() {
  133. this.visible = false
  134. },
  135. save() {
  136. this.$refs[this.formName].validate((valid) => {
  137. if (valid) {
  138. this.loading = true
  139. pushSaveSystem(this.action, this.formData).then(res => {
  140. this.$refs[this.formName].resetFields()
  141. this.visible = false
  142. this.loading = false
  143. this.$emit('refreshData')
  144. this.$message({
  145. type: 'success',
  146. message: '保存成功!'
  147. })
  148. }).catch(error => {
  149. console.log(error)
  150. this.loading = false
  151. this.$message.error({
  152. type: 'error',
  153. duration: 0,
  154. showClose: true,
  155. message: '保存失败:' + error.message
  156. })
  157. })
  158. }
  159. })
  160. },
  161. getDeptData() {
  162. getDeptTreeData().then(res => {
  163. if (!isNull(res.data)) {
  164. this.deptData = res.data
  165. } else {
  166. this.deptData = []
  167. }
  168. }).catch(error => {
  169. console.log(error)
  170. this.$message.error({
  171. type: 'error',
  172. duration: 0,
  173. showClose: true,
  174. message: '获取机构出错: ' + error.message
  175. })
  176. })
  177. },
  178. loadNode(node, resolve) {
  179. if (node.level === 0) {
  180. getDeptRootData().then(res => {
  181. if (!isNull(res.data)) {
  182. resolve(res.data)
  183. this.defaultTreeId = res.data[0].orgCode
  184. } else {
  185. resolve([])
  186. }
  187. }).catch(error => {
  188. console.log(error)
  189. this.$message.error({
  190. type: 'error',
  191. duration: 0,
  192. showClose: true,
  193. message: '获取机构出错: ' + error.message
  194. })
  195. })
  196. } else {
  197. getDeptChildren(node.data.orgCode).then(res => {
  198. if (!isNull(res.data)) {
  199. resolve(res.data)
  200. } else {
  201. resolve([])
  202. }
  203. }).catch(error => {
  204. console.log(error)
  205. this.$message.error({
  206. type: 'error',
  207. duration: 0,
  208. showClose: true,
  209. message: '获取机构出错: ' + error.message
  210. })
  211. })
  212. }
  213. },
  214. formatDictData(dictType, type) {
  215. if (dictType === 'system_type') {
  216. return formatDictData(this.typeData, type)
  217. }
  218. if (dictType === 'active_type') {
  219. return formatDictData(this.activeFlagData, type)
  220. }
  221. return ''
  222. },
  223. isNull(obj) {
  224. return isNull(obj)
  225. }
  226. }
  227. }
  228. </script>
  229. <style lang="scss" scoped>
  230. .main-edit-dialog {
  231. .dialog-form {
  232. ::v-deep {
  233. .el-input__inner {
  234. width: 250px !important;
  235. }
  236. }
  237. }
  238. .upload-success {
  239. color: #13ce66;
  240. margin-right: 5px;
  241. }
  242. }
  243. </style>