poppleSet.vue 11 KB

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