ScheduleDesigner.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <wrapper
  3. fill
  4. margin
  5. padding
  6. background
  7. >
  8. <el-tabs
  9. :value="active"
  10. class="c-tabs has-bottom-padding"
  11. @tab-click="onTabClick"
  12. >
  13. <el-tab-pane name="0">
  14. <template #label>
  15. <div class="o-tab">
  16. <i
  17. class="o-tab__icon el-icon-circle-plus-outline"
  18. @click.stop="onAdd"
  19. />
  20. 待提交
  21. </div>
  22. </template>
  23. </el-tab-pane>
  24. <el-tab-pane
  25. label="已审核"
  26. name="2"
  27. />
  28. <el-tab-pane
  29. label="待审核"
  30. name="1"
  31. />
  32. <el-tab-pane
  33. label="驳回"
  34. name="3"
  35. />
  36. </el-tabs>
  37. <schema-table
  38. ref="table"
  39. :schema="schema"
  40. />
  41. <confirm-dialog
  42. ref="addDialog"
  43. :title="dialogTitle"
  44. @confirm="onConfirmAdd"
  45. >
  46. <div class="c-grid-form u-align-self--center">
  47. <span class="c-grid-form__label required">名称:</span>
  48. <el-input
  49. v-model.trim="schedule.name"
  50. placeholder="最多50个字符"
  51. maxlength="50"
  52. clearable
  53. />
  54. <span class="c-grid-form__label required">分辨率:</span>
  55. <schema-select
  56. v-model="schedule.resolutionRatio"
  57. placeholder="请选择分辨率"
  58. :schema="resolutionRatioSelectSchema"
  59. />
  60. </div>
  61. </confirm-dialog>
  62. <confirm-dialog
  63. ref="copyDialog"
  64. title="复制"
  65. @confirm="onConfirmCopy"
  66. >
  67. <div class="c-grid-form u-align-self--center">
  68. <span class="c-grid-form__label required">名称:</span>
  69. <el-input
  70. v-model.trim="copySchedule.name"
  71. placeholder="最多500个字符"
  72. maxlength="50"
  73. clearable
  74. />
  75. </div>
  76. </confirm-dialog>
  77. <schedule-dialog ref="scheduleDialog" />
  78. </wrapper>
  79. </template>
  80. <script>
  81. import { getRatiosWithUser } from '@/api/device'
  82. import {
  83. addSchedule,
  84. submitSchedule,
  85. copySchedule
  86. } from '@/api/calendar'
  87. import { State } from '@/constant'
  88. import mixin from './mixin'
  89. export default {
  90. name: 'ScheduleDesigner',
  91. mixins: [mixin],
  92. props: {
  93. redirect: {
  94. type: String,
  95. default: ''
  96. }
  97. },
  98. data () {
  99. return {
  100. invokes: [
  101. { label: '编辑', render ({ status }) { return status !== State.SUBMITTED && status !== State.RESOLVED }, on: this.onDesign },
  102. { label: '提交', render ({ status }) { return status !== State.SUBMITTED && status !== State.RESOLVED }, on: this.onSubmit },
  103. { label: '查看', render ({ status }) { return status === State.SUBMITTED || status === State.RESOLVED }, on: this.onView },
  104. { label: '复制', render ({ status }) { return status === State.SUBMITTED || status === State.RESOLVED }, on: this.onCopy },
  105. { label: '删除', render ({ del }) { return del }, on: this.onDel }
  106. ],
  107. active: `${this.status}`,
  108. resolutionRatioSelectSchema: { remote: getRatiosWithUser },
  109. schedule: {},
  110. copySchedule: {
  111. id: null,
  112. name: ''
  113. }
  114. }
  115. },
  116. computed: {
  117. dialogTitle () {
  118. return `新增${[null, '日程', '轮播', '排期'][this.type]}`
  119. }
  120. },
  121. activated () {
  122. this.$refs.table.pageTo(1)
  123. },
  124. methods: {
  125. onTabClick ({ name: active }) {
  126. if (this.active !== active) {
  127. this.active = active
  128. this.$refs.table.mergeCondition({ status: Number(active) })
  129. }
  130. },
  131. onAdd () {
  132. this.schedule = {
  133. type: this.type,
  134. name: '',
  135. resolutionRatio: ''
  136. }
  137. this.$refs.addDialog.show()
  138. },
  139. onConfirmAdd (done) {
  140. if (!this.schedule.name) {
  141. this.$message({
  142. type: 'warning',
  143. message: '名称不能为空'
  144. })
  145. return
  146. }
  147. if (!this.schedule.resolutionRatio) {
  148. this.$message({
  149. type: 'warning',
  150. message: '请选择分辨率'
  151. })
  152. return
  153. }
  154. addSchedule(this.schedule).then(({ data: id }) => {
  155. done()
  156. this.active = `${State.READY}`
  157. this.$refs.table.resetCondition({ status: State.READY, name: this.schedule.name })
  158. this.onDesign({ id })
  159. })
  160. },
  161. onDesign ({ id }) {
  162. if (this.redirect) {
  163. this.$router.push({
  164. name: this.redirect,
  165. params: { id: `${id}` }
  166. })
  167. }
  168. },
  169. onSubmit (item) {
  170. submitSchedule(item).then(() => {
  171. this.$refs.table.decrease(1)
  172. })
  173. },
  174. onCopy ({ id, name }) {
  175. this.copySchedule = { id, name }
  176. this.$refs.copyDialog.show()
  177. },
  178. onConfirmCopy (done) {
  179. const { id, name } = this.copySchedule
  180. copySchedule({ id }, name).then(() => {
  181. done()
  182. this.active = `${State.READY}`
  183. this.$refs.table.resetCondition({ status: State.READY, name })
  184. })
  185. }
  186. }
  187. }
  188. </script>