addDialog.vue 8.1 KB

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