addDialog.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <template>
  2. <div>
  3. <a-modal
  4. v-model:visible="modalVisible"
  5. :title="modeTag == 'add'?'添加课时':'修改课时'"
  6. :footer="null"
  7. width="900px"
  8. class="add-class-hours-modal"
  9. >
  10. <a-tabs v-model:activeKey="activeKey" type="card" @change="handleChange">
  11. <a-tab-pane key="1" tab="课时">
  12. <addClassHours ref="addClassHoursRef" @handlerSelect="handlerSelect"
  13. @handlerUpSelect="handlerUpSelect" @handlerEx="handlerEx"
  14. @handlerExs="handlerExs"></addClassHours>
  15. </a-tab-pane>
  16. <a-tab-pane key="2" tab="作业">
  17. <exList v-if="activeKey == '2'" ref="exListRef" @handlerEx="handlerEx"></exList>
  18. </a-tab-pane>
  19. <a-tab-pane key="3" tab="考试">
  20. <exLists v-if="activeKey == '3'" ref="exListsRef" @handlerExs="handlerExs"></exLists>
  21. </a-tab-pane>
  22. </a-tabs>
  23. <div class="footer-btns">
  24. <a-button @click="handleCancel">取消</a-button>
  25. <a-button type="primary" @click="handleOk">确定</a-button>
  26. </div>
  27. </a-modal>
  28. <resListDialog ref="resListDialogRef" @handleSelectFile="handleSelectFile"></resListDialog>
  29. <resourceUpload ref="resourceUploadRef" @onSub="onSub"></resourceUpload>
  30. </div>
  31. </template>
  32. <script setup>
  33. import {ref, reactive, watch, defineProps, defineEmits} from 'vue'
  34. import {message} from 'ant-design-vue'
  35. import addClassHours from './addClassHours.vue'
  36. import resListDialog from './resListDialog.vue'
  37. import resourceUpload from './resourceUpload.vue'
  38. import exList from './exList.vue'
  39. import exLists from './exLists.vue'
  40. import {add, edit as editApi} from '@/api/hour/index'
  41. const addClassHoursRef = ref(null)
  42. const resListDialogRef = ref(null)
  43. const resourceUploadRef = ref(null)
  44. const exListRef = ref(null)
  45. const exListsRef = ref(null)
  46. const exListRefData = ref(null)
  47. const exListsRefData = ref(null)
  48. const exListRefCount = ref(0)
  49. const exListsRefCount = ref(0)
  50. const activeKey = ref('1')
  51. const modeTag = ref('add')
  52. const emit = defineEmits(['update:visible', 'ok', 'onAddChapter'])
  53. const props = defineProps({
  54. //课程id
  55. courseInfoId: {
  56. type: Number,
  57. required: true,
  58. default: null
  59. },
  60. // visible: Boolean
  61. })
  62. const form = ref({
  63. id: '',
  64. courseId: ''
  65. })
  66. const modalVisible = ref(false)
  67. // watch(
  68. // () => props.visible,
  69. // (v) => {
  70. // modalVisible.value = v
  71. // }
  72. // )
  73. // watch(modalVisible, (v) => {
  74. // emit('update:visible', v)
  75. // })
  76. const open = () => {
  77. exListRefCount.value = 0
  78. exListsRefCount.value = 0
  79. modalVisible.value = true
  80. activeKey.value = '1'
  81. modeTag.value = 'add'
  82. nextTick(() => {
  83. addClassHoursRef.value.reset()
  84. addClassHoursRef.value.open()
  85. })
  86. }
  87. const handleChange = (activeKey) => {
  88. nextTick(() => {
  89. if (activeKey == '1' && addClassHoursRef.value) {
  90. if (modeTag.value == 'add') {
  91. addClassHoursRef.value.reset()
  92. addClassHoursRef.value.open()
  93. }
  94. if (modeTag.value == 'edit') {
  95. addClassHoursRef.value.edit()
  96. }
  97. }
  98. if (activeKey == '2' && exListRef.value) {
  99. if (modeTag.value == 'add') {
  100. exListRef.value.open()
  101. }
  102. if (modeTag.value == 'edit') {
  103. console.log('走没走1', exListRefData.value)
  104. if(exListRefData.value && exListRefData.value[0]&& exListRefData.value[0].relateId){
  105. exListRef.value.edit(exListRefData.value[0].relateId)
  106. }else if(exListRefData.value && exListRefData.value[0]&& exListRefData.value[0].id){
  107. exListRef.value.edit(exListRefData.value[0].id)
  108. }
  109. console.log('走没走2', exListRefData.value)
  110. if(exListRefData.value == null){
  111. exListRef.value.open()
  112. }
  113. }
  114. }
  115. if (activeKey == '3' && exListsRef.value) {
  116. if (modeTag.value == 'add') {
  117. exListsRef.value.open()
  118. }
  119. if (modeTag.value == 'edit') {
  120. console.log('走没走3', exListsRefData.value)
  121. if(exListsRefData.value && exListsRefData.value[0]&& exListsRefData.value[0].relateId){
  122. exListsRef.value.edit(exListsRefData.value[0].relateId)
  123. }else if(exListRefData.value && exListRefData.value[0]&& exListRefData.value[0].id){
  124. exListRef.value.edit(exListRefData.value[0].id)
  125. }
  126. console.log('走没走4', exListsRefData.value)
  127. if(exListsRefData.value == null){
  128. exListsRef.value.open()
  129. }
  130. }
  131. }
  132. })
  133. }
  134. const setData = (data) => {
  135. console.log('进来的章节信息添加的时候', data)
  136. form.value.id = data.id
  137. }
  138. const edit = (item) => {
  139. exListRefCount.value = 0
  140. exListsRefCount.value = 0
  141. activeKey.value = '1'
  142. modalVisible.value = true
  143. console.log('修改进来的', item)
  144. form.value.id = item.id
  145. form.value.chapterId = item.courseId
  146. modeTag.value = 'edit'
  147. console.log('有没有', addClassHoursRef.value)
  148. nextTick(() => {
  149. addClassHoursRef.value.edit(item)
  150. })
  151. }
  152. const handlerEx = (item) => {
  153. console.log('有没有1 ', item)
  154. exListRefData.value = item
  155. // exListRef.value.setData(item)
  156. }
  157. const handlerExs = (item) => {
  158. exListsRefData.value = item
  159. // exListsRef.value.setData(item)
  160. }
  161. const handlerSelect = () => {
  162. resListDialogRef.value.open()
  163. }
  164. const handlerUpSelect = () => {
  165. resourceUploadRef.value.open()
  166. }
  167. const handleSelectFile = (item) => {
  168. resListDialogRef.value.close()
  169. addClassHoursRef.value.setFile(item)
  170. }
  171. const onSub = (list) => {
  172. console.log('上传的id', list)
  173. // resListDialogRef.value.close()
  174. addClassHoursRef.value.setFile(list)
  175. // addClassHoursRef.value.close()
  176. }
  177. const handleOk = () => {
  178. addClassHoursRef.value.getData((data) => {
  179. let exlist = exListRefData.value
  180. if (exlist && exlist.length == 1) {
  181. if(exlist[0].id){
  182. data.courseRelates.push({funcType: 4, relateId: exlist[0].id})
  183. }else if(exlist[0].relateId){
  184. data.courseRelates.push({funcType: 4, relateId: exlist[0].relateId})
  185. }
  186. }
  187. let exlists = exListsRefData.value
  188. if (exlists &&exlists.length == 1) {
  189. if(exlists[0].id){
  190. data.courseRelates.push({funcType: 5, relateId: exlists[0].id})
  191. }else if(exlist[0].relateId){
  192. data.courseRelates.push({funcType: 5, relateId: exlists[0].relateId})
  193. }
  194. }
  195. //设置章节id
  196. data.chapterId = form.value.id
  197. // props.courseInfoId
  198. console.log('提交的参数', data)
  199. if (modeTag.value == 'add') {
  200. add(data).then((res) => {
  201. modalVisible.value = false
  202. emit('onAddChapter')
  203. resourceUploadRef.value.close()
  204. }).catch((err) => {
  205. })
  206. }
  207. if (modeTag.value == 'edit') {
  208. data.id = form.value.id
  209. data.chapterId = form.value.chapterId
  210. editApi(data).then((res) => {
  211. modalVisible.value = false
  212. emit('onAddChapter')
  213. }).catch((err) => {
  214. })
  215. }
  216. })
  217. // formRef.value.validate().then(() => {
  218. // emit('ok', { ...form })
  219. // modalVisible.value = false
  220. // })
  221. }
  222. function handleCancel() {
  223. modalVisible.value = false
  224. }
  225. defineExpose({open, setData, edit})
  226. </script>
  227. <style lang="less" scoped>
  228. .add-class-hours-modal {
  229. .ant-modal-content {
  230. border-radius: 10px;
  231. }
  232. .ant-modal-header {
  233. border-radius: 10px 10px 0 0;
  234. }
  235. .ant-form-item {
  236. margin-bottom: 24px;
  237. }
  238. .video-select-row {
  239. display: flex;
  240. align-items: center;
  241. }
  242. .cover-upload-row {
  243. display: flex;
  244. align-items: center;
  245. .cover-upload-box {
  246. width: 120px;
  247. height: 120px;
  248. background: #f7f8fa;
  249. border-radius: 8px;
  250. display: flex;
  251. align-items: center;
  252. justify-content: center;
  253. margin-right: 24px;
  254. border: 1px dashed #d9d9d9;
  255. cursor: pointer;
  256. .cover-img {
  257. width: 100%;
  258. height: 100%;
  259. object-fit: cover;
  260. border-radius: 8px;
  261. }
  262. .cover-placeholder {
  263. display: flex;
  264. align-items: center;
  265. justify-content: center;
  266. width: 100%;
  267. height: 100%;
  268. color: #bbb;
  269. font-size: 32px;
  270. }
  271. }
  272. .cover-tip {
  273. color: #888;
  274. font-size: 13px;
  275. }
  276. }
  277. .upload-tip {
  278. color: #888;
  279. font-size: 13px;
  280. margin-left: 12px;
  281. }
  282. .footer-btns {
  283. display: flex;
  284. justify-content: flex-end;
  285. gap: 16px;
  286. margin-top: 24px;
  287. }
  288. }
  289. </style>