SpecAdd.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <div>
  3. <el-dialog
  4. v-if="visible"
  5. v-loading="loading"
  6. :visible.sync="visible"
  7. :close-on-press-escape="true"
  8. :close-on-click-modal="false"
  9. :show-close="false"
  10. custom-class="main-edit-dialog"
  11. :title="title"
  12. >
  13. <el-form :ref="formName" :model="formData" :rules="rules" label-width="120px" class="dialog-form">
  14. <el-form-item prop="title" label="标题">
  15. <el-input v-model="formData.title" clearable placeholder="请输入" />
  16. </el-form-item>
  17. <el-form-item prop="scopeIds" label="发布范围">
  18. <el-select v-model="formData.scopeIds" multiple clearable placeholder="请选择" style="width:calc(100% - 110px)">
  19. <el-option
  20. v-for="item in deptOptions"
  21. :key="item.orgCode"
  22. :label="item.shortName"
  23. :value="item.orgCode"
  24. />
  25. </el-select>
  26. <el-button type="primary" style="margin-left: 10px;" @click="showTree">接收单位</el-button>
  27. </el-form-item>
  28. <el-form-item prop="attachmentPath" label="上传文件">
  29. <upload-file :file-type="formData.messageType" :on-success="uploadSuccess" :on-error="uploadError" />
  30. <span v-if="!isNull(formData.attachmentName)" style="margin-left: 10px;">
  31. <i class="upload-success el-icon-circle-check" />{{ formData.attachmentName }}
  32. </span>
  33. </el-form-item>
  34. <el-form-item prop="content" label="信息内容">
  35. <el-input v-model="formData.content" type="textarea" :rows="3" clearable placeholder="请输入" />
  36. </el-form-item>
  37. </el-form>
  38. <div slot="footer">
  39. <el-button @click="close">取消</el-button>
  40. <el-button type="primary" @click="save">确定</el-button>
  41. </div>
  42. </el-dialog>
  43. <dept-tree ref="deptTree" :tree-data="deptData" :checked-keys="formData.scopeIds" @updateValue="setDepts" />
  44. </div>
  45. </template>
  46. <script>
  47. import { isNull } from '@/utils/convert'
  48. import { pushSave } from '@/api/info'
  49. import UploadFile from '@/components/Upload/UploadFile'
  50. import DeptTree from './components/DeptTree'
  51. export default {
  52. components: { UploadFile, DeptTree },
  53. props: {
  54. deptData: {
  55. type: Array,
  56. default() {
  57. return []
  58. }
  59. }
  60. },
  61. data() {
  62. return {
  63. // dialog
  64. visible: false,
  65. isView: true,
  66. viewType: 'ADD',
  67. title: 'Edit',
  68. formName: 'editForm',
  69. formData: {
  70. id: null,
  71. messageType: 1,
  72. title: '',
  73. scopeIds: [],
  74. attachmentPath: '',
  75. attachmentName: '',
  76. content: '',
  77. t: 0
  78. },
  79. rules: {
  80. title: [
  81. { required: true, message: '请输入标题', trigger: 'change' }
  82. ],
  83. scopeIds: [
  84. { required: true, message: '请选择发布范围', trigger: 'blur' }
  85. ],
  86. content: [
  87. { required: true, message: '请输入信息内容', trigger: 'blur' }
  88. ]
  89. },
  90. action: 'add',
  91. // select:
  92. deptOptions: [],
  93. selectTreeProps: {
  94. // 配置项(必选)
  95. nodeKey: 'shortName',
  96. label: 'shortName',
  97. value: 'shortName',
  98. children: 'children'
  99. // disabled:true
  100. },
  101. // others
  102. loading: false
  103. }
  104. },
  105. methods: {
  106. // 取值
  107. setDepts(data) {
  108. this.deptOptions = data
  109. this.formData.scopeIds = data.map(item => item.orgCode)
  110. },
  111. // Upload
  112. uploadSuccess(data) {
  113. // this.$set(this.formData, 'icon', data.url)
  114. this.formData.attachmentPath = data.url
  115. this.formData.attachmentName = data.fileName + '.' + data.extension
  116. },
  117. uploadError(error) {
  118. this.$message({
  119. type: 'error',
  120. duration: 0,
  121. showClose: true,
  122. message: '上传文件出错:' + error.message
  123. })
  124. },
  125. /**
  126. * 加载dialog
  127. */
  128. open(viewType, data) {
  129. this.title = '发布通知通告'
  130. this.isView = false
  131. this.action = 'add'
  132. this.viewType = viewType
  133. this.visible = true
  134. },
  135. close() {
  136. this.visible = false
  137. },
  138. save() {
  139. this.$refs[this.formName].validate((valid) => {
  140. if (valid) {
  141. this.loading = true
  142. this.formData.t = new Date().getTime()
  143. pushSave(this.formData).then(res => {
  144. this.$refs[this.formName].resetFields()
  145. this.formData.attachmentName = ''
  146. this.visible = false
  147. this.loading = false
  148. this.$emit('refreshData')
  149. this.$message({
  150. type: 'success',
  151. message: '保存成功!'
  152. })
  153. }).catch(error => {
  154. console.log(error)
  155. this.loading = false
  156. this.$message({
  157. type: 'error',
  158. duration: 0,
  159. showClose: true,
  160. message: '保存出错:' + error.message
  161. })
  162. })
  163. }
  164. })
  165. },
  166. showTree() {
  167. this.$refs['deptTree'].open()
  168. },
  169. isNull(obj) {
  170. return isNull(obj)
  171. }
  172. }
  173. }
  174. </script>
  175. <style lang="scss" scoped>
  176. </style>