editModal.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <a-modal
  3. centered
  4. class="noticeEdit-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. :title="modalTit"
  8. v-model="isShow"
  9. @cancle="isShow=false"
  10. :width="960">
  11. <!-- 表单 -->
  12. <div>
  13. <a-spin :spinning="spinning" tip="Loading...">
  14. <a-form-model
  15. id="noticeEdit-form"
  16. ref="ruleForm"
  17. :model="form"
  18. :rules="rules"
  19. :label-col="formItemLayout.labelCol"
  20. :wrapper-col="formItemLayout.wrapperCol"
  21. >
  22. <a-form-model-item label="类别" prop="type">
  23. <v-select code="NOTITY_BIZ_TYPE" id="noticeEdit-type" v-model="form.type" allowClear placeholder="请选择类别"></v-select>
  24. </a-form-model-item>
  25. <a-form-model-item label="可见性" prop="toAppName">
  26. <v-select code="NOTITY_APP_TYPE" id="noticeEdit-toAppName" v-model="form.toAppName" allowClear placeholder="请选择可见性"></v-select>
  27. </a-form-model-item>
  28. <a-form-model-item label="公告标题" prop="title">
  29. <a-input
  30. id="noticeEdit-title"
  31. :maxLength="30"
  32. v-model.trim="form.title"
  33. placeholder="请输入公告标题(最多30个字符)"
  34. allowClear />
  35. </a-form-model-item>
  36. <a-form-model-item label="发布时间" prop="releaseDate">
  37. <a-date-picker
  38. show-time
  39. id="noticeEdit-releaseDate"
  40. format="YYYY-MM-DD HH:mm:ss"
  41. placeholder="年/月/日 时/分/秒"
  42. :disabled-date="disabledDate"
  43. :disabledTime="disabledDateTime"
  44. v-model="form.releaseDate"/>
  45. </a-form-model-item>
  46. <a-form-model-item label="图片上传" prop="imgPaths">
  47. <Upload
  48. class="upload"
  49. id="noticeEdit-imgPaths"
  50. v-model="form.imgPaths"
  51. ref="imgPaths"
  52. :fileSize="10"
  53. :maxNums="5"
  54. @change="changeImage"
  55. listType="picture-card"></Upload>
  56. <span class="upload-desc">说明:单张大小小于10Mb,最多5张。</span>
  57. </a-form-model-item>
  58. <a-form-model-item label="附件上传" prop="attachList">
  59. <Upload
  60. id="noticeEdit-attachList"
  61. v-model="form.attachList"
  62. ref="attachList"
  63. :fileSize="10"
  64. :maxNums="3"
  65. fileType="*"
  66. uploadType="attach"
  67. :action="attachAction"
  68. @change="changeAttach"></Upload>
  69. <span class="upload-desc">说明:单个文件小于10Mb,最多3个附件。</span>
  70. </a-form-model-item>
  71. <a-form-model-item label="公告内容" prop="content">
  72. <editor id="noticeEdit-editor" ref="editor" class="noticeEdit-editor" @on-change="editorChange" :cache="false"></editor>
  73. </a-form-model-item>
  74. </a-form-model>
  75. <div class="btn-cont">
  76. <a-button type="primary" id="product-brand-edit-modal-save" @click="handleSave">保存</a-button>
  77. <a-button id="product-brand-edit-modal-back" @click="isShow = false" style="margin-left: 15px;">返回列表</a-button>
  78. </div>
  79. </a-spin>
  80. </div>
  81. </a-modal>
  82. </template>
  83. <script>
  84. import moment from 'moment'
  85. import { VSelect, Upload } from '@/components'
  86. import Editor from '@/components/WEeditor'
  87. import { noticeSave, noticeDetail } from '@/api/notice'
  88. export default {
  89. name: 'ProductBrandEditModal',
  90. components: { VSelect, Upload, Editor },
  91. props: {
  92. openModal: { // 弹框显示状态
  93. type: Boolean,
  94. default: false
  95. },
  96. itemId: {
  97. type: [Number, String],
  98. default: ''
  99. },
  100. nowData: {
  101. type: Object,
  102. default: null
  103. }
  104. },
  105. computed: {
  106. modalTit () {
  107. return (this.itemId ? '编辑' : '新增') + '公告'
  108. }
  109. },
  110. data () {
  111. return {
  112. isShow: this.openModal, // 是否打开弹框
  113. spinning: false,
  114. formItemLayout: {
  115. labelCol: { span: 4 },
  116. wrapperCol: { span: 20 }
  117. },
  118. form: {
  119. type: undefined,
  120. toAppName: undefined,
  121. title: '',
  122. releaseDate: null,
  123. imgPaths: '',
  124. attachList: '',
  125. content: ''
  126. },
  127. attachList: [],
  128. rules: {
  129. type: [
  130. { required: true, message: '请选择类别', trigger: 'change' }
  131. ],
  132. toAppName: [
  133. { required: true, message: '请选择可见性', trigger: 'change' }
  134. ],
  135. title: [
  136. { required: true, message: '请输入公告标题', trigger: 'blur' }
  137. ],
  138. releaseDate: [
  139. { required: true, message: '请选择发布时间', trigger: 'change' }
  140. ]
  141. },
  142. attachAction: process.env.VUE_APP_API_BASE_URL + '/uploadGetFileInfo'
  143. }
  144. },
  145. methods: {
  146. disabledDate (current) {
  147. return current && current < moment().startOf('day')
  148. },
  149. disabledDateTime (date) {
  150. if (!date) {
  151. date = moment()
  152. }
  153. return {
  154. disabledHours: () => this.getDisabledHours(date.format('YYYY-MM-DD HH:mm:ss')),
  155. disabledMinutes: () => this.getDisabledMinutes(date.format('YYYY-MM-DD HH:mm:ss')),
  156. disabledSeconds: () => this.getDisabledSeconds(date.format('YYYY-MM-DD HH:mm:ss'))
  157. }
  158. },
  159. // 禁用时间范围 时
  160. getDisabledHours (nowTime) {
  161. const todayDate = moment().format('YYYY-MM-DD HH:mm:ss')
  162. const time = nowTime.split(' ')
  163. const times = todayDate.split(' ')
  164. const timeArrs = times[1].split(':')
  165. const hours = []
  166. if (todayDate.split(' ')[0] == time[0]) {
  167. for (var i = 0; i < parseInt(timeArrs[0]); i++) {
  168. hours.push(i)
  169. }
  170. }
  171. return hours
  172. },
  173. // 禁用时间范围 分
  174. getDisabledMinutes (nowTime) {
  175. const todayDate = moment().format('YYYY-MM-DD HH:mm:ss')
  176. const time = nowTime.split(' ')
  177. const times = todayDate.split(' ')
  178. const timeArr = time[1].split(':')
  179. const timeArrs = times[1].split(':')
  180. const minutes = []
  181. if (todayDate.split(' ')[0] == time[0] && timeArrs[0] == timeArr[0]) {
  182. for (var i = 0; i < parseInt(timeArrs[1]); i++) {
  183. minutes.push(i)
  184. }
  185. }
  186. return minutes
  187. },
  188. // 禁用时间范围 秒
  189. getDisabledSeconds (nowTime) {
  190. const todayDate = moment().format('YYYY-MM-DD HH:mm:ss')
  191. const time = nowTime.split(' ')
  192. const times = todayDate.split(' ')
  193. const timeArr = time[1].split(':')
  194. const timeArrs = times[1].split(':')
  195. const second = []
  196. if (todayDate.split(' ')[0] == time[0] && timeArrs[0] == timeArr[0] && timeArrs[1] == timeArr[1]) {
  197. for (var i = 0; i <= parseInt(timeArrs[2]); i++) {
  198. second.push(i)
  199. }
  200. }
  201. return second
  202. },
  203. // 详情
  204. getDetail () {
  205. noticeDetail({ id: this.itemId }).then(res => {
  206. if (res.status == 200) {
  207. this.form = Object.assign(this.form, res.data)
  208. this.form.attachList = ''
  209. this.attachList = res.data.attachList
  210. this.form.releaseDate = moment(res.data.releaseDate, 'YYYY-MM-DD HH:mm:ss')
  211. this.$refs.imgPaths.setFileList(res.data.imgPaths)
  212. this.$refs.attachList.setFileList(res.data.attachList)
  213. this.$refs.editor.setHtml(res.data.content)
  214. }
  215. })
  216. },
  217. // 保存
  218. handleSave () {
  219. const _this = this
  220. _this.$refs.ruleForm.validate(valid => {
  221. if (valid) {
  222. const formData = JSON.parse(JSON.stringify(_this.form))
  223. formData.releaseDate = moment(formData.releaseDate).format('YYYY-MM-DD HH:mm:ss')
  224. formData.id = _this.itemId ? _this.itemId : undefined
  225. formData.attachList = this.attachList
  226. _this.spinning = true
  227. noticeSave(formData).then(res => {
  228. if (res.status == 200) {
  229. _this.$message.success(res.message)
  230. _this.$emit('ok')
  231. _this.isShow = false
  232. _this.spinning = false
  233. }else{
  234. _this.spinning = false
  235. }
  236. })
  237. } else {
  238. return false
  239. }
  240. })
  241. },
  242. // 图片上传
  243. changeImage (file) {
  244. this.form.imgPaths = file
  245. },
  246. // 附件上传
  247. changeAttach (file) {
  248. this.attachList = JSON.parse(file)
  249. },
  250. // 文本编辑器
  251. editorChange (html, text) {
  252. this.form.content = html
  253. }
  254. },
  255. watch: {
  256. // 父页面传过来的弹框状态
  257. openModal (newValue, oldValue) {
  258. this.isShow = newValue
  259. },
  260. // 重定义的弹框状态
  261. isShow (newValue, oldValue) {
  262. if (!newValue) {
  263. this.$emit('close')
  264. this.attachList = []
  265. this.$refs.imgPaths.setFileList('')
  266. this.$refs.attachList.setFileList([])
  267. this.$refs.editor.setHtml('')
  268. this.$refs.ruleForm.resetFields()
  269. }
  270. },
  271. itemId (newValue, oldValue) {
  272. if (this.isShow && newValue) {
  273. this.getDetail()
  274. }
  275. }
  276. }
  277. }
  278. </script>
  279. <style lang="less">
  280. .noticeEdit-modal{
  281. .ant-modal-body {
  282. padding: 40px 40px 24px;
  283. }
  284. .upload{
  285. width: 100%!important;
  286. }
  287. // 商品图片描述
  288. .upload-desc{
  289. font-size: 12px;
  290. color: #808695;
  291. }
  292. // 文本编辑器 工具栏样式换行
  293. .noticeEdit-editor{
  294. .w-e-toolbar{
  295. flex-wrap: wrap;
  296. }
  297. }
  298. .btn-cont {
  299. text-align: center;
  300. margin: 35px 0 10px;
  301. }
  302. #noticeEdit-attachList{
  303. height: auto;
  304. }
  305. a{
  306. color: inherit;
  307. }
  308. }
  309. </style>