edit.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. <template>
  2. <van-popup
  3. v-model="dialogVisible"
  4. class="ibps-fullscreen-popup"
  5. position="bottom"
  6. @opened="loadFormData"
  7. >
  8. <div v-if="dialogLoading">
  9. <van-sticky>
  10. <van-nav-bar title="公告" left-arrow @click-left="onClose">
  11. <template #left>
  12. <van-icon name="cross" class="ibps-nav-bar__close-icon" />
  13. </template>
  14. </van-nav-bar>
  15. </van-sticky>
  16. <div v-if="!readonly" class="ibps-fixed-toolbar">
  17. <van-form ref="form">
  18. <van-field
  19. v-model="form.title"
  20. label="标题"
  21. placeholder="请输入"
  22. clearable
  23. required
  24. input-align="right"
  25. name="title"
  26. autocomplete="off"
  27. :rules="[{ required: true, message: '必填' }]"
  28. />
  29. <!-- <ibps-radio
  30. v-model="form.publicItem"
  31. :options="publishOptions"
  32. :clearable="false"
  33. label="发布类型"
  34. placeholder="请选择"
  35. />
  36. <ibps-type-selector
  37. v-model="form.typeId"
  38. category-key="NOTICE_TYPE"
  39. label="类型"
  40. clearable
  41. /> -->
  42. <!-- <ibps-user-selector
  43. v-model="userSelect"
  44. label="发布人"
  45. type="user"
  46. store="array"
  47. clearable
  48. />
  49. <van-field label="是否公共" input-align="right">
  50. <template #input>
  51. <van-switch
  52. v-model="form.public0"
  53. size="20"
  54. active-value="Y"
  55. inactive-value="N"
  56. />
  57. </template>
  58. </van-field> -->
  59. <!-- <ibps-user-selector
  60. v-show="form.public0 === 'N'"
  61. v-model="orgSelect"
  62. label="发布范围"
  63. type="org"
  64. store="array"
  65. clearable
  66. /> -->
  67. <!-- <van-field
  68. v-model="form.author"
  69. label="作者"
  70. placeholder="请输入"
  71. input-align="right"
  72. clearable
  73. autocomplete="off"
  74. name="text"
  75. /> -->
  76. <!-- <van-field
  77. v-model="form.key"
  78. label="关键字"
  79. placeholder="请输入"
  80. input-align="right"
  81. clearable
  82. name="text"
  83. autocomplete="off"
  84. /> -->
  85. <ibps-date-picker
  86. v-model="form.publicDate"
  87. label="发布时间"
  88. placeholder="请选择"
  89. format="yyyy-MM-dd"
  90. clearable
  91. />
  92. <ibps-date-picker
  93. v-model="form.loseDate"
  94. label="过期时间"
  95. placeholder="请选择"
  96. format="yyyy-MM-dd"
  97. clearable
  98. />
  99. <ibps-uploader
  100. v-model="form.fileAttach"
  101. multiple
  102. label="附件"
  103. placeholder="请上传附件"
  104. clearable
  105. />
  106. <ibps-editor v-model="form.content" label="内容" />
  107. <ibps-toolbar :actions="actions" />
  108. </van-form>
  109. </div>
  110. <!--明细-->
  111. <div v-else class="ibps-notice-detail">
  112. <van-row>
  113. <van-col span="24" class="notice-title ibps-size-l_xx">{{
  114. form.title
  115. }}</van-col>
  116. <van-col span="24" class="notice-detailed">
  117. <van-row gutter="5" type="flex" align="center" style="align-items: baseline;">
  118. <!-- <van-col class="notice-time-horizon">{{ form.publicDate|dateFormat('yyyy-MM-dd') }} <span v-if="$utils.isNotEmpty(form.loseDate)"> ~ </span>{{ form.loseDate|dateFormat('yyyy-MM-dd') }}</van-col>
  119. <van-col class="notice-userName ibps-is-link">{{ form.userName }}</van-col> -->
  120. <van-col span="15">
  121. <div class="notice-userName ibps-is-link ibps-wingblank" style="margin-left: 0;line-height: 21px;">
  122. {{ form.userName }}
  123. </div>
  124. <span class="notice-time-horizon">
  125. {{ form.publicDate | dateFormat('yyyy-MM-dd') }}
  126. <span v-if="$utils.isNotEmpty(form.loseDate)"> ~ </span
  127. >{{ form.loseDate | dateFormat('yyyy-MM-dd') }}
  128. </span>
  129. </van-col>
  130. <!-- <van-col
  131. span="9"
  132. class="notice-publicItem"
  133. :style="{'color':form.publicItem==='important'?'#f56c6c':'#67c23a'}"
  134. > {{ form.publicItem| optionsFilter(publishOptions) }}</van-col> -->
  135. <van-col span="9" class="notice-publicItem">
  136. <van-tag
  137. size="medium"
  138. :color="
  139. form.publicItem | optionsFilter(publishOptions, 'color')
  140. "
  141. :text-color="
  142. form.publicItem | optionsFilter(publishOptions, 'textColor')
  143. "
  144. >
  145. {{ form.publicItem | optionsFilter(publishOptions) }}
  146. </van-tag>
  147. </van-col>
  148. </van-row>
  149. </van-col>
  150. <van-col span="24" class="notice-content">
  151. <ibps-editor
  152. v-model="form.content"
  153. label="内容"
  154. :have-padding="false"
  155. readonly
  156. class="scrollRestrict"
  157. />
  158. </van-col>
  159. <van-col span="24" class="notice-fileAttach">
  160. <div class="ibps-blank-bar" />
  161. <ibps-uploader
  162. v-model="form.fileAttach"
  163. label="附件"
  164. download
  165. :have-padding="false"
  166. multiple
  167. clearable
  168. readonly
  169. />
  170. </van-col>
  171. </van-row>
  172. </div>
  173. </div>
  174. </van-popup>
  175. </template>
  176. <script>
  177. import { save, get } from '@/api/platform/system/news'
  178. import navbar from '@/mixins/navbar'
  179. import fecha from '@/utils/fecha'
  180. import { publishOptions } from './constants'
  181. import IbpsRadio from '@/components/ibps-radio'
  182. import IbpsUserSelector from '@/business/platform/org/selector'
  183. import IbpsDatePicker from '@/components/ibps-date-picker'
  184. import IbpsUploader from '@/business/platform/file/uploader'
  185. import IbpsEditor from '@/components/ibps-editor'
  186. import IbpsTypeSelector from '@/business/platform/cat/type/selector'
  187. import IbpsToolbar from '@/components/ibps-toolbar'
  188. export default {
  189. components: {
  190. IbpsRadio,
  191. IbpsDatePicker,
  192. IbpsUserSelector,
  193. IbpsUploader,
  194. IbpsEditor,
  195. IbpsTypeSelector,
  196. IbpsToolbar
  197. },
  198. mixins: [navbar],
  199. props: {
  200. visible: Boolean,
  201. id: String,
  202. readonly: Boolean
  203. },
  204. data() {
  205. const { first = '', second = '' } = this.$store.getters.level || {}
  206. const { positions = [] } = this.$store.getters.userInfo || {}
  207. const position = positions.length ? positions[0] : {}
  208. return {
  209. dialogVisible: false,
  210. dialogLoading: false,
  211. defaultForm: {
  212. author: '',
  213. content: '',
  214. createBy: '',
  215. createOrgId: '',
  216. createTime: '',
  217. dataStatus: '',
  218. dbtype: '',
  219. depId: position.id,
  220. depName: position.name,
  221. fileAttach: '',
  222. id: '',
  223. ip: '',
  224. public0: 'Y',
  225. includeChild: 'N',
  226. key: '',
  227. loseDate: '',
  228. name: '',
  229. picture: '',
  230. pk: '',
  231. publicDate: this.$common.getDateNow(19),
  232. publicItem: 'notices',
  233. status: '',
  234. tenantId: '',
  235. title: '',
  236. // 改字段暂时无用,改存当前层级第一级ID
  237. type: second || first,
  238. typeId: '',
  239. updateBy: '',
  240. updateTime: '',
  241. userId: this.$store.getters.userId,
  242. userName: this.$store.getters.name
  243. // id: '',
  244. // picture: '',
  245. // status: '',
  246. // publicItem: 'notices',
  247. // typeId: '',
  248. // type: '',
  249. // title: '',
  250. // userId: '',
  251. // userName: '',
  252. // public0: 'Y',
  253. // depId: '',
  254. // depName: '',
  255. // author: '',
  256. // key: '',
  257. // publicDate: '',
  258. // loseDate: '',
  259. // fileAttach: '',
  260. // content: '',
  261. // editorValue: ''
  262. },
  263. form: {},
  264. userSelect: [],
  265. orgSelect: [],
  266. publishOptions: publishOptions,
  267. actions: [
  268. {
  269. name: this.$t('common.button.ts'),
  270. type: 'default',
  271. callback: this.saveDraft
  272. },
  273. {
  274. name: this.$t('common.button.save'),
  275. type: 'primary',
  276. callback: this.saveData
  277. }
  278. ]
  279. }
  280. },
  281. watch: {
  282. visible: {
  283. handler: function(val, oldVal) {
  284. this.dialogVisible = this.visible
  285. if (!val) {
  286. this.dialogLoading = false
  287. }
  288. },
  289. immediate: true
  290. },
  291. userSelect() {
  292. if (this.userSelect[0]) {
  293. this.form.userId = this.userSelect[0].id
  294. this.form.userName = this.userSelect[0].name
  295. }
  296. },
  297. orgSelect() {
  298. if (this.orgSelect[0]) {
  299. this.form.depId = this.orgSelect[0].id
  300. this.form.depName = this.orgSelect[0].name
  301. }
  302. }
  303. },
  304. created() {
  305. this.form = JSON.parse(JSON.stringify(this.defaultForm))
  306. this.form.userId = this.$store.getters.userId
  307. this.form.userName = this.$store.getters.name
  308. },
  309. methods: {
  310. loadFormData() {
  311. this.userSelect = []
  312. this.orgSelect = []
  313. this.form = JSON.parse(JSON.stringify(this.defaultForm))
  314. this.dialogLoading = true
  315. if (this.$utils.isEmpty(this.id)) {
  316. this.form.publicItem = 'notices'
  317. this.form.publicDate = fecha.format(new Date(), 'yyyy-MM-dd')
  318. this.userSelect = [
  319. { id: this.$store.getters.userId, name: this.$store.getters.userName }
  320. ]
  321. return
  322. }
  323. get({
  324. newsId: this.id
  325. })
  326. .then(response => {
  327. const data = response.data
  328. if (this.$utils.isNotEmpty(data.publicDate)) {
  329. data.publicDate = fecha.format(
  330. fecha.parse(data.publicDate, 'yyyy-MM-dd'),
  331. 'yyyy-MM-dd'
  332. )
  333. }
  334. if (this.$utils.isNotEmpty(data.loseDate)) {
  335. data.loseDate = fecha.format(
  336. fecha.parse(data.loseDate, 'yyyy-MM-dd'),
  337. 'yyyy-MM-dd'
  338. )
  339. }
  340. this.form = data
  341. if (
  342. this.$utils.isNotEmpty(this.form.userId) &&
  343. this.$utils.isNotEmpty(this.form.userName)
  344. ) {
  345. this.userSelect = [
  346. { id: this.form.userId, name: this.form.userName }
  347. ]
  348. }
  349. if (
  350. this.$utils.isNotEmpty(this.form.depId) &&
  351. this.$utils.isNotEmpty(this.form.depName)
  352. ) {
  353. this.orgSelect = [{ id: this.form.depId, name: this.form.depName }]
  354. }
  355. })
  356. .catch(error => {
  357. console.error(error)
  358. })
  359. },
  360. onBack() {
  361. this.$router.push({ name: 'notice' })
  362. },
  363. onClose() {
  364. this.$emit('close', false)
  365. },
  366. onSave() {
  367. const data = JSON.parse(JSON.stringify(this.form))
  368. const publicDate = new Date(this.form.publicDate).getTime() || ''
  369. const loseDate = new Date(this.form.loseDate).getTime() || ''
  370. // 检测失效日期是否发布日期在之前。
  371. if (publicDate > loseDate && loseDate !== '') {
  372. this.$notify({
  373. type: 'warning',
  374. message: '发布时间与失效时间范围不合法!'
  375. })
  376. return
  377. }
  378. if (this.$utils.isNotEmpty(data.publicDate)) {
  379. data.publicDate += ' 00:00:00'
  380. }
  381. if (this.$utils.isNotEmpty(data.loseDate)) {
  382. data.loseDate += ' 00:00:00'
  383. }
  384. save(data)
  385. .then(response => {
  386. const message =
  387. this.form.status === 'drafts' ? `暂存公告成功!` : `保存公告成功!`
  388. this.$notify({
  389. type: 'success',
  390. message: message
  391. })
  392. this.onClose()
  393. this.$emit('callback', true)
  394. // this.$router.push({ name: 'notice' })
  395. })
  396. .catch(error => {
  397. console.error(error)
  398. })
  399. },
  400. saveDraft() {
  401. this.form.status = 'drafts'
  402. this.onSave()
  403. },
  404. saveData() {
  405. this.$refs.form
  406. .validate()
  407. .then(() => {
  408. this.form.status = 'publish'
  409. this.onSave()
  410. })
  411. .catch(() => {
  412. this.$notify({
  413. type: 'warning',
  414. message: this.$t('common.formError')
  415. })
  416. this.$refs.form.scrollToField('title')
  417. })
  418. }
  419. }
  420. }
  421. </script>
  422. <style lang="scss" scoped>
  423. .ibps-notice-detail {
  424. .ibps-field__control--left {
  425. text-align: right;
  426. }
  427. .notice-title {
  428. flex: 1;
  429. -webkit-box-flex: 1;
  430. display: flex;
  431. box-sizing: border-box;
  432. width: 100%;
  433. padding: 10px 16px;
  434. overflow: hidden;
  435. color: #323233;
  436. font-size: 14px;
  437. line-height: 24px;
  438. background-color: #fff;
  439. }
  440. .notice-detailed {
  441. padding: 0px 16px;
  442. color: #969799;
  443. font-size: 12px !important;
  444. line-height: 18px;
  445. }
  446. .notice-publicItem {
  447. text-align: right;
  448. }
  449. .ibps-cell-wrapper {
  450. padding: 0;
  451. }
  452. }
  453. ::v-deep
  454. .scrollRestrict
  455. .ibps-editor.van-cell.van-cell--borderless.van-field
  456. .van-cell__value.van-field__value
  457. .van-field__body
  458. .van-field__control.van-field__control--left.van-field__control--custom
  459. div {
  460. overflow-x: scroll;
  461. }
  462. </style>