poppleSet.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <template>
  2. <div id="poppleSet">
  3. <el-dialog
  4. :visible.sync="dialogVisible"
  5. width="60%"
  6. @open="openExpand"
  7. :show-close="false"
  8. :close-on-click-modal="false"
  9. destroy-on-close
  10. >
  11. <div slot="title" class="hearders">
  12. <div class="leftTitle">试听设置</div>
  13. <div class="rightBoxs">
  14. <img
  15. src="@/assets/images/Close@2x.png"
  16. alt=""
  17. @click="dialogVisible = false"
  18. />
  19. </div>
  20. </div>
  21. <div style="text-align: end">
  22. <el-button type="text" @click="inits">重置</el-button>
  23. </div>
  24. <el-tree
  25. v-if="showPop"
  26. ref="trees"
  27. :data="datas"
  28. :props="layoutTreeProps"
  29. :load="loadNode"
  30. lazy
  31. :default-checked-keys="audition"
  32. :show-checkbox="true"
  33. :check-strictly="true"
  34. @check-change="getCheckedKeys"
  35. node-key="onlyId"
  36. >
  37. <span class="custom-tree-node" slot-scope="{ node }">
  38. <span>{{ node.label }}</span>
  39. <span v-if="node.checked && node.data.sectionType !== 2"
  40. >试听前
  41. <el-time-picker
  42. style="width: 140px"
  43. size="mini"
  44. value-format="HH:mm:ss"
  45. range-separator="-"
  46. v-model="node.data.auditionMinute"
  47. :picker-options="{
  48. selectableRange: compTimes(node.data.durationTime),
  49. }"
  50. placeholder="请选择试听时长"
  51. @blur="changeNum(node)"
  52. >
  53. </el-time-picker>
  54. </span>
  55. </span>
  56. </el-tree>
  57. <span slot="footer" class="dialog-footer">
  58. <el-button @click="dialogVisible = false">取 消</el-button>
  59. <el-button type="primary" @click="submitTable">确 定</el-button>
  60. </span>
  61. </el-dialog>
  62. </div>
  63. </template>
  64. <script>
  65. export default {
  66. props: ["tableData", "auditionList"],
  67. data() {
  68. return {
  69. copyData: [],
  70. showPop: false,
  71. datas: [],
  72. audition: [],
  73. auditionListCope: [],
  74. dialogVisible: false,
  75. layoutTreeProps: {
  76. label(data, node) {
  77. return (
  78. data.courseName || data.categoryName || data.name || data.menuName
  79. );
  80. },
  81. isLeaf(data, node) {
  82. return !data.hasChildren;
  83. },
  84. },
  85. getAllSeNum: [], //当前tree所有节ID
  86. };
  87. },
  88. computed: {
  89. compTimes: function () {
  90. return function (aTime) {
  91. let chasTime = this.$methodsTools.secondToDate(aTime, false);
  92. return `00:00:00 - ${chasTime}`;
  93. };
  94. },
  95. },
  96. methods: {
  97. /**
  98. * 相同节-时长同步修改
  99. */
  100. changeNum(v) {
  101. if (v.data.auditionMinute == "00:00:00") {
  102. this.$message.warning("试听时长禁止为0,请重新设置");
  103. } else {
  104. var arrays = this.$refs.trees;
  105. //修改指定项的 auditionMinute
  106. arrays.root.childNodes.forEach((item, index) => {
  107. if (item.data.type && item.data.type === 3) {
  108. if (
  109. item.data.TypeId === v.data.TypeId &&
  110. item.data.courseId === v.data.courseId
  111. ) {
  112. item.data.auditionMinute = v.data.auditionMinute;
  113. }
  114. } else {
  115. item.childNodes.forEach((items, indexs) => {
  116. if (
  117. items.data.TypeId === v.data.TypeId &&
  118. items.data.courseId === v.data.courseId
  119. ) {
  120. items.data.auditionMinute = v.data.auditionMinute;
  121. }
  122. if (items.childNodes.length) {
  123. items.childNodes.forEach((ik) => {
  124. if (
  125. ik.data.TypeId === v.data.TypeId &&
  126. ik.data.courseId === v.data.courseId
  127. ) {
  128. ik.data.auditionMinute = v.data.auditionMinute;
  129. }
  130. if (ik.childNodes.length) {
  131. ik.childNodes.forEach((iks) => {
  132. if (
  133. iks.data.TypeId === v.data.TypeId &&
  134. iks.data.courseId === v.data.courseId
  135. ) {
  136. iks.data.auditionMinute = v.data.auditionMinute;
  137. }
  138. });
  139. }
  140. });
  141. }
  142. });
  143. }
  144. });
  145. this.auditionListCope.forEach((items) => {
  146. if (
  147. items.TypeId === v.data.TypeId &&
  148. v.data.courseId === items.courseId
  149. ) {
  150. items.auditionMinute = v.data.auditionMinute;
  151. }
  152. });
  153. }
  154. },
  155. /**
  156. * 重置按钮
  157. */
  158. inits() {
  159. this.showPop = false;
  160. if (this.auditionList) {
  161. this.auditionListCope = JSON.parse(JSON.stringify(this.auditionList));
  162. }
  163. this.datas = JSON.parse(JSON.stringify(this.copyData));
  164. setTimeout(() => {
  165. this.showPop = true;
  166. }, 50);
  167. },
  168. /**
  169. * 弹窗打开触发
  170. */
  171. openExpand() {
  172. this.showPop = true;
  173. if (this.auditionList) {
  174. this.auditionListCope = JSON.parse(JSON.stringify(this.auditionList));
  175. }
  176. },
  177. /**
  178. * @param {Objact,Bool} 当前点击数据 当前是否勾选
  179. * 复选框变化触发
  180. */
  181. getCheckedKeys(item, node) {
  182. var self = this;
  183. if (item.TypeId.split("-")[0] != "3") {
  184. return;
  185. }
  186. if (node) {
  187. var ast = self.getAllSeNum.filter((items, indexs) => {
  188. if (
  189. items.split("-")[0] == item.courseId &&
  190. items.split("-")[3] == item.menuId
  191. ) {
  192. return items;
  193. }
  194. });
  195. var st = ast.concat(self.audition);
  196. self.audition = [...new Set(st)];
  197. var pds = self.auditionListCope.some((items, indexs) => {
  198. return (
  199. items.courseId === item.courseId && items.menuId === item.menuId
  200. );
  201. });
  202. if (!pds) {
  203. var data = {
  204. TypeId: item.TypeId,
  205. // typeId: item.onlyId,
  206. auditionMinute: item.auditionMinute,
  207. courseId: item.courseId,
  208. menuId: item.menuId,
  209. };
  210. self.auditionListCope.push(data);
  211. }
  212. } else {
  213. self.audition = self.audition.filter((items, indexs) => {
  214. if (items.split("-")[0] != item.courseId) {
  215. return items;
  216. } else {
  217. if (items.split("-")[3] != item.menuId) {
  218. return items;
  219. } else {
  220. self.$refs.trees.setChecked(items, node);
  221. }
  222. }
  223. });
  224. var pdst = self.auditionListCope.filter((itx, indx) => {
  225. if (itx.courseId != item.courseId) {
  226. return itx;
  227. } else {
  228. if (itx.menuId != item.menuId) {
  229. return itx;
  230. }
  231. }
  232. });
  233. self.auditionListCope = pdst;
  234. }
  235. },
  236. submitTable() {
  237. if (!this.auditionListCope.length) {
  238. this.$message.warning("请勾选至少一节的试听时间");
  239. return;
  240. }
  241. this.auditionListCope.forEach((item) => {
  242. if (!item.auditionMinute || item.auditionMinute === "00:00:00") {
  243. this.$message.warning("不允许填写时长为0的节,请重新输入");
  244. return;
  245. }
  246. });
  247. this.$emit("uploadArrays", this.auditionListCope);
  248. this.dialogVisible = false;
  249. },
  250. loadNode(node, resolve) {
  251. var self = this;
  252. if (node.level === 0) {
  253. if (this.tableData[0].type > 0) {
  254. this.tableData.forEach((item) => {
  255. item.TypeId = `${item.type}-${item.menuId}`;
  256. if (item.type === 3) {
  257. console.log(item,'item')
  258. item.hasChildren = false;
  259. item.disabled = false;
  260. item.onlyId = `${item.courseId || 0}-0-0-${item.menuId}`;
  261. if (self.getAllSeNum.indexOf(item.onlyId) === -1) {
  262. self.getAllSeNum.push(item.onlyId);
  263. }
  264. if (self.auditionListCope) {
  265. self.auditionListCope.map((items) => {
  266. if (items.TypeId === item.TypeId) {
  267. if (self.audition.indexOf(item.onlyId) === -1) {
  268. self.audition.push(item.onlyId);
  269. }
  270. item.auditionMinute = items.auditionMinute;
  271. }
  272. });
  273. }
  274. } else {
  275. item.hasChildren = true;
  276. item.disabled = true;
  277. }
  278. });
  279. this.copyData = JSON.parse(JSON.stringify(this.tableData));
  280. return resolve(this.tableData);
  281. } else {
  282. this.tableData.forEach((item) => {
  283. item.TypeId = "0-" + item.courseId;
  284. item.disabled = true;
  285. item.hasChildren = true;
  286. });
  287. this.copyData = JSON.parse(JSON.stringify(this.tableData));
  288. return resolve(this.tableData);
  289. }
  290. } else {
  291. if (node.data.type === 1) {
  292. this.$api
  293. .inquireCourseListmodulechapter(node.data.menuId)
  294. .then((res) => {
  295. res.data.map((item) => {
  296. item.onlyId = `${node.data.courseId || 0}-${node.data.menuId}-${
  297. item.chapterId
  298. }-0`;
  299. item.courseId = node.data.courseId || 0;
  300. item.TypeId = "2" + "-" + item.chapterId;
  301. item.hasChildren = true;
  302. item.disabled = true;
  303. item.menuId = item.chapterId;
  304. item.type = 2;
  305. });
  306. return resolve(res.data);
  307. });
  308. } else if (node.data.type === 2) {
  309. this.$api
  310. .inquireCoursechaptersectionlist(node.data.menuId)
  311. .then((res) => {
  312. res.data.map((item) => {
  313. item.onlyId = `${node.data.courseId || 0}-${
  314. node.data.moduleId ? node.data.moduleId : 0
  315. }-${item.chapterId}-${item.sectionId}`;
  316. if (this.getAllSeNum.indexOf(item.onlyId) === -1) {
  317. this.getAllSeNum.push(item.onlyId);
  318. }
  319. item.type = 3;
  320. item.TypeId = "3" + "-" + item.sectionId;
  321. item.menuId = item.sectionId;
  322. item.auditionMinute = self.$methodsTools.secondToDate(
  323. item.durationTime,
  324. false
  325. );
  326. item.courseId = node.data.courseId || 0;
  327. if (self.auditionListCope) {
  328. self.auditionListCope.map((items) => {
  329. if (
  330. items.TypeId === item.TypeId &&
  331. items.courseId === node.data.courseId
  332. ) {
  333. if (self.audition.indexOf(item.onlyId) === -1) {
  334. self.audition.push(item.onlyId);
  335. }
  336. item.auditionMinute = items.auditionMinute;
  337. }
  338. });
  339. }
  340. item.hasChildren = false;
  341. });
  342. return resolve(res.data);
  343. });
  344. } else if (node.data.type === 3) {
  345. return resolve([]);
  346. } else {
  347. this.$api
  348. .inquireCoursemenuListS({ courseId: node.data.courseId })
  349. .then((res) => {
  350. res.rows.map((item) => {
  351. if (item.type === 1) {
  352. item.onlyId = `${node.data.courseId}-${item.menuId}-0-0`;
  353. item.TypeId = item.type + "-" + item.menuId;
  354. }
  355. if (item.type === 2) {
  356. item.onlyId = `${node.data.courseId}-0-${item.menuId}-0`;
  357. item.TypeId = item.type + "-" + item.menuId;
  358. }
  359. if (item.type === 3) {
  360. item.onlyId = `${node.data.courseId}-0-0-${item.menuId}`;
  361. if (this.getAllSeNum.indexOf(item.onlyId) === -1) {
  362. this.getAllSeNum.push(item.onlyId);
  363. }
  364. item.TypeId = item.type + "-" + item.menuId;
  365. item.auditionMinute = self.$methodsTools.secondToDate(
  366. item.durationTime,
  367. false
  368. );
  369. if (self.auditionListCope) {
  370. self.auditionListCope.map((items) => {
  371. if (
  372. items.TypeId === item.TypeId &&
  373. items.courseId === node.data.courseId
  374. ) {
  375. if (self.audition.indexOf(item.onlyId) === -1) {
  376. self.audition.push(item.onlyId);
  377. }
  378. item.auditionMinute = items.auditionMinute;
  379. }
  380. });
  381. }
  382. item.disabled = false;
  383. item.hasChildren = false;
  384. } else {
  385. item.disabled = true;
  386. item.hasChildren = true;
  387. }
  388. });
  389. return resolve(res.rows);
  390. });
  391. }
  392. }
  393. },
  394. },
  395. };
  396. </script>
  397. <style lang="less" scoped>
  398. /deep/.el-tree-node__content {
  399. height: 35px;
  400. }
  401. .custom-tree-node {
  402. flex: 1;
  403. display: flex;
  404. align-items: center;
  405. justify-content: space-between;
  406. font-size: 14px;
  407. padding-right: 8px;
  408. }
  409. </style>