ScheduleEdit.bak.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <div class="c-form">
  3. <div class="c-form__section">
  4. <span class="c-form__label">播放模式:</span>
  5. <el-select
  6. v-model="repeatType"
  7. class="c-form__item"
  8. placeholder="请选择"
  9. >
  10. <el-option
  11. v-for="option in repeatTypeOptions"
  12. :key="option.value"
  13. :label="option.label"
  14. :value="option.value"
  15. />
  16. </el-select>
  17. </div>
  18. <div
  19. v-if="isSingle"
  20. class="c-form__section"
  21. >
  22. <el-date-picker
  23. v-model="range"
  24. type="datetimerange"
  25. start-placeholder="开始时间"
  26. range-separator="至"
  27. end-placeholder="结束时间"
  28. :picker-options="pickerOptions"
  29. :default-time="['00:00:00', '23:59:59']"
  30. @change="onChange"
  31. />
  32. </div>
  33. <template v-if="isWeekly">
  34. <el-checkbox-group
  35. v-model="week"
  36. class="c-form__section wrap"
  37. size="small"
  38. >
  39. <el-checkbox
  40. v-for="option in weekOptions"
  41. :key="option.value"
  42. class="c-form__checkbox"
  43. :label="option.value"
  44. border
  45. >
  46. {{ option.label }}
  47. </el-checkbox>
  48. </el-checkbox-group>
  49. <div class="c-form__section wrap">
  50. <el-date-picker
  51. v-model="startTimeDate"
  52. type="date"
  53. placeholder="开始日期"
  54. :picker-options="pickerOptions"
  55. />
  56. <span class="has-padding">至</span>
  57. <el-date-picker
  58. v-model="endTimeDate"
  59. type="date"
  60. placeholder="结束日期"
  61. :picker-options="pickerOptions"
  62. />
  63. </div>
  64. <div class="c-form__section wrap">
  65. <el-time-picker
  66. v-model="startTime"
  67. placeholder="开始时间"
  68. />
  69. <span class="has-padding">至</span>
  70. <el-time-picker
  71. v-model="endTime"
  72. placeholder="结束时间"
  73. />
  74. </div>
  75. </template>
  76. <div class="c-form__section">
  77. <div
  78. class="o-program-name u-ellipsis u-pointer"
  79. @click="toBind"
  80. >
  81. {{ programName }}
  82. </div>
  83. </div>
  84. <el-dialog
  85. :visible.sync="choosing"
  86. title="选择节目"
  87. custom-class="c-dialog hidden-footer"
  88. append-to-body
  89. >
  90. <ProgramChoose
  91. v-if="choosing"
  92. v-bind="$attrs"
  93. @choose="toChoose"
  94. />
  95. </el-dialog>
  96. </div>
  97. </template>
  98. <script>
  99. import ProgramChoose from '../components/ProgramChoose'
  100. export default {
  101. name: 'ScheduleEdit',
  102. components: {
  103. ProgramChoose
  104. },
  105. props: {
  106. program: {
  107. type: Object,
  108. default () {
  109. return {}
  110. }
  111. }
  112. },
  113. data () {
  114. return {
  115. choosing: false,
  116. repeatTypeOptions: [
  117. { value: 1, label: '单次' }/*,
  118. { value: 2, label: '每周' }*/
  119. ],
  120. repeatType: '',
  121. range: [],
  122. weekOptions: [
  123. { value: 1, label: '周一' },
  124. { value: 2, label: '周二' },
  125. { value: 3, label: '周三' },
  126. { value: 4, label: '周四' },
  127. { value: 5, label: '周五' },
  128. { value: 6, label: '周六' },
  129. { value: 7, label: '周日' }
  130. ],
  131. week: [],
  132. startTimeDate: null,
  133. endTimeDate: null,
  134. startTime: null,
  135. endTime: null,
  136. bindTo: null
  137. }
  138. },
  139. computed: {
  140. isSingle () {
  141. return this.repeatType === 1
  142. },
  143. isWeekly () {
  144. return this.repeatType === 2
  145. },
  146. pickerOptions () {
  147. return {
  148. disabledDate: this.isDisableDate
  149. }
  150. },
  151. programName () {
  152. return this.bindTo ? this.bindTo.itemName : '点击选择节目'
  153. }
  154. },
  155. watch: {
  156. program: {
  157. handler () {
  158. const now = new Date()
  159. this.$min = new Date(now.getFullYear(), now.getMonth(), now.getDate())
  160. this.$max = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 30)
  161. this.init()
  162. },
  163. immediate: true
  164. }
  165. },
  166. methods: {
  167. onChange () {
  168. if (this.range && this.range[0] < Date.now()) {
  169. this.range[0] = new Date()
  170. }
  171. },
  172. transform (date) {
  173. return `${date.year}/${date.month + 1}/${date.day}`
  174. },
  175. init () {
  176. const { repeatType, startTimeDate, endTimeDate, week, startTime, endTime, itemId, itemName } = this.program
  177. this.repeatType = repeatType || 1
  178. if (this.isSingle) {
  179. this.range = startTimeDate ? [new Date(`${this.transform(startTimeDate)} ${startTime}`), new Date(`${this.transform(endTimeDate)} ${endTime}`)] : []
  180. this.week = []
  181. this.startTimeDate = null
  182. this.endTimeDate = null
  183. this.startTime = null
  184. this.endTime = null
  185. } else {
  186. this.range = []
  187. this.week = week || []
  188. this.startTimeDate = startTimeDate ? new Date(this.transform(startTimeDate)) : null
  189. this.endTimeDate = endTimeDate ? new Date(this.transform(endTimeDate)) : null
  190. this.startTime = startTime ? new Date(startTime) : null
  191. this.endTime = endTime ? new Date(endTime) : null
  192. }
  193. this.bindTo = itemId ? { itemId, itemName } : null
  194. },
  195. isDisableDate (date) {
  196. return date < this.$min || date > this.$max
  197. },
  198. toBind () {
  199. this.choosing = true
  200. },
  201. toChoose (program) {
  202. this.choosing = false
  203. this.bindTo = {
  204. itemId: program.id,
  205. itemName: program.name
  206. }
  207. },
  208. getValue () {
  209. return {
  210. repeatType: this.repeatType,
  211. range: this.range,
  212. week: this.week,
  213. startTime: this.startTime,
  214. endTime: this.endTime,
  215. ...this.bindTo
  216. }
  217. }
  218. }
  219. }
  220. </script>
  221. <style lang="scss" scoped>
  222. .o-program-name {
  223. width: 300px;
  224. padding: $spacing;
  225. color: $blue;
  226. font-size: 16px;
  227. line-height: 1;
  228. text-align: center;
  229. border-radius: 4px;
  230. border: 1px solid $gray;
  231. }
  232. </style>