checkUser.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. <template>
  2. <div id="checkUser">
  3. <el-dialog
  4. :visible.sync="diavos"
  5. width="640px"
  6. :show-close="false"
  7. :close-on-click-modal="false"
  8. >
  9. <div slot="title" class="hearders">
  10. <div class="leftTitle">收件人</div>
  11. <div class="rightBoxs">
  12. <img src="@/assets/images/Close@2x.png" alt="" @click="clears" />
  13. </div>
  14. </div>
  15. <div v-if="diavos">
  16. <div>
  17. <el-radio-group v-model="radio" @change="changeRadio">
  18. <el-radio :label="1">按学员</el-radio>
  19. <el-radio :label="2">按商品</el-radio>
  20. <el-radio :label="3">按班级</el-radio>
  21. </el-radio-group>
  22. <span style="color: #999; float: right; font-size: 14px"
  23. >注:切换选择类型将清空已选收件人</span
  24. >
  25. </div>
  26. <div class="max_height" v-if="radio === 1">
  27. <el-tree
  28. :key="1"
  29. ref="tree1"
  30. default-expand-all
  31. :props="props1"
  32. :load="loadNode1"
  33. lazy
  34. node-key="userId"
  35. show-checkbox
  36. >
  37. </el-tree>
  38. </div>
  39. <div class="max_height" v-if="radio === 2">
  40. <el-select
  41. v-model="educationId"
  42. placeholder="请选择教育类型"
  43. size="small"
  44. @change="changeEducationType"
  45. >
  46. <el-option
  47. v-for="(items, indexs) in educationType"
  48. :key="indexs"
  49. :label="items.educationName"
  50. :value="items.id"
  51. ></el-option>
  52. </el-select>
  53. <el-select
  54. v-if="educationId"
  55. v-model="businessId"
  56. placeholder="请选择业务层次"
  57. size="small"
  58. @change="changeBusinessId"
  59. >
  60. <el-option
  61. v-for="(items, indexs) in newBusinessLevel"
  62. :key="indexs"
  63. :label="items.projectName + '-' + items.businessName"
  64. :value="items.id"
  65. ></el-option>
  66. </el-select>
  67. <el-tree
  68. :key="2"
  69. v-if="businessId && showBox"
  70. ref="tree2"
  71. :props="props2"
  72. :load="loadNode2"
  73. default-expand-all
  74. lazy
  75. node-key="costId"
  76. show-checkbox
  77. @check-change="activeChange"
  78. >
  79. </el-tree>
  80. </div>
  81. <div class="max_height" v-if="radio === 3">
  82. <el-select
  83. v-model="educationId"
  84. placeholder="请选择教育类型"
  85. size="small"
  86. @change="changeEducationType"
  87. >
  88. <el-option
  89. v-for="(items, indexs) in educationType"
  90. :key="indexs"
  91. :label="items.educationName"
  92. :value="items.id"
  93. ></el-option>
  94. </el-select>
  95. <el-select
  96. v-if="educationId"
  97. v-model="businessId"
  98. placeholder="请选择业务层次"
  99. size="small"
  100. @change="changeBusinessId"
  101. >
  102. <el-option
  103. v-for="(items, indexs) in newBusinessLevel"
  104. :key="indexs"
  105. :label="items.projectName + '-' + items.businessName"
  106. :value="items.id"
  107. ></el-option>
  108. </el-select>
  109. <el-tree
  110. :key="3"
  111. v-if="businessId && showBox"
  112. ref="tree3"
  113. :props="props2"
  114. :load="loadNode3"
  115. default-expand-all
  116. lazy
  117. node-key="costId"
  118. show-checkbox
  119. @check-change="activeChangeClass"
  120. >
  121. </el-tree>
  122. </div>
  123. </div>
  124. <span slot="footer" class="dialog-footer">
  125. <el-button @click="clears">取 消</el-button>
  126. <el-button @click="submit">确 定</el-button>
  127. </span>
  128. </el-dialog>
  129. </div>
  130. </template>
  131. <script>
  132. import { mapGetters } from "vuex";
  133. export default {
  134. data() {
  135. return {
  136. diavos: false,
  137. showBox: false,
  138. educationId: "",
  139. businessId: "",
  140. newBusinessLevel: [],
  141. radio: "",
  142. props1: {
  143. label: "realname",
  144. children: "children",
  145. isLeaf: "leaf",
  146. },
  147. props2: {
  148. label: "costomize",
  149. children: "children",
  150. isLeaf: "leaf",
  151. },
  152. setKey: [],
  153. };
  154. },
  155. computed: { ...mapGetters(["educationType"]) },
  156. methods: {
  157. changeEducationType(id) {
  158. this.businessId = "";
  159. this.$api
  160. .inquirebusinessList({ status: 1, educationId: id })
  161. .then((res) => {
  162. this.newBusinessLevel = res.rows;
  163. });
  164. },
  165. changeBusinessId() {
  166. this.showBox = false;
  167. setTimeout(() => {
  168. this.showBox = true;
  169. }, 100);
  170. },
  171. submit() {
  172. if (this.radio == 1) {
  173. let ary = this.$refs.tree1.getCheckedNodes(true);
  174. let arrays = ary.map((item) => {
  175. return item.userId;
  176. });
  177. this.$parent.backUserList(this.radio, arrays);
  178. }
  179. if (this.radio == 2) {
  180. this.$parent.backUserList(this.radio, this.setKey);
  181. }
  182. if (this.radio == 3) {
  183. this.$parent.backUserList(this.radio, this.setKey);
  184. }
  185. this.diavos = false;
  186. },
  187. changeRadio() {
  188. this.setKey = [];
  189. this.educationId = "";
  190. this.businessId = "";
  191. },
  192. /**
  193. * 按学员
  194. */
  195. loadNode1(node, resolve) {
  196. if (node.level === 0) {
  197. return resolve([{ realname: "所有人" }]);
  198. }
  199. if (node.level === 1) {
  200. this.$api.inquiregradestudentlistStudent({ status: 1 }).then((res) => {
  201. res.rows.forEach((item) => {
  202. item.leaf = true;
  203. });
  204. this.$refs.tree1.setCheckedKeys(this.setKey);
  205. resolve(res.rows);
  206. });
  207. }
  208. if (node.level >= 2) {
  209. resolve([]);
  210. }
  211. },
  212. /**
  213. * 按商品
  214. */
  215. loadNode2(node, resolve) {
  216. if (node.level === 0) {
  217. return resolve([
  218. { costomize: "视频商品", type: 1, costId: -1 },
  219. { costomize: "题库商品", type: 2, costId: -2 },
  220. ]);
  221. }
  222. if (node.level === 1) {
  223. if (node.data.type === 1) {
  224. let arrays = [];
  225. this.$api
  226. .inquireGoods({
  227. goodsType: 1,
  228. status: 1,
  229. businessId: this.businessId,
  230. })
  231. .then((res) => {
  232. arrays = res.rows.map((item) => {
  233. item.costomize = item.goodsName;
  234. item.costId = item.goodsId;
  235. return item;
  236. });
  237. })
  238. .finally(() => {
  239. resolve(arrays);
  240. });
  241. }
  242. if (node.data.type === 2) {
  243. let arrays = [];
  244. this.$api
  245. .inquireGoods({
  246. goodsType: 2,
  247. status: 1,
  248. businessId: this.businessId,
  249. })
  250. .then((res) => {
  251. arrays = res.rows.map((item) => {
  252. item.costomize = item.goodsName;
  253. item.costId = item.goodsId;
  254. return item;
  255. });
  256. })
  257. .finally(() => {
  258. resolve(arrays);
  259. });
  260. }
  261. }
  262. if (node.level === 2) {
  263. let arrays = [];
  264. this.$api
  265. .inquireOrderGoodsBuyGoodsUserList({ goodsId: node.data.goodsId })
  266. .then((res) => {
  267. console.log(res.rows);
  268. arrays = res.rows.map((item) => {
  269. console.log(item);
  270. return {
  271. userId: item.userId,
  272. costomize: item.realname,
  273. costId: `${node.data.goodsId}-${item.userId}`,
  274. leaf: true,
  275. getStatus: true,
  276. };
  277. });
  278. })
  279. .finally(() => {
  280. arrays.forEach((item) => {
  281. if (this.setKey.includes(item.userId)) {
  282. this.$nextTick(() => {
  283. this.$refs.tree2.setChecked(item.costId, true);
  284. });
  285. }
  286. });
  287. resolve(arrays);
  288. });
  289. }
  290. if (node.level > 2) {
  291. resolve([]);
  292. }
  293. },
  294. /**
  295. * 按班级
  296. */
  297. loadNode3(node, resolve) {
  298. if (node.level === 0) {
  299. this.$api
  300. .inquireGradegradeList({ status: 1, businessId: this.businessId })
  301. .then((res) => {
  302. let arrays = res.rows.map((item) => {
  303. item.costomize = item.className;
  304. item.costId = item.gradeId;
  305. return item;
  306. });
  307. resolve(arrays);
  308. });
  309. }
  310. if (node.level === 1) {
  311. let arrays = [];
  312. this.$api
  313. .inquireGradegradelistGrade({ gradeId: node.data.gradeId })
  314. .then((res) => {
  315. arrays = res.rows.map((item) => {
  316. return {
  317. userId: item.userId,
  318. costomize: item.realname,
  319. costId: `${node.data.gradeId}-${item.userId}`,
  320. leaf: true,
  321. getStatus: true,
  322. };
  323. });
  324. })
  325. .finally(() => {
  326. arrays.forEach((item) => {
  327. if (this.setKey.includes(item.userId)) {
  328. this.$nextTick(() => {
  329. this.$refs.tree3.setChecked(item.costId, true);
  330. });
  331. }
  332. });
  333. resolve(arrays);
  334. });
  335. }
  336. if (node.level > 1) {
  337. resolve([]);
  338. }
  339. },
  340. /**
  341. * 商品学员发生勾选变化触发
  342. */
  343. activeChange(data, status, bool) {
  344. if (data.getStatus) {
  345. this.changeDataList(data.userId, status);
  346. }
  347. },
  348. changeDataList(userId, status) {
  349. let newArrays = this.$refs.tree2.root.childNodes;
  350. newArrays.forEach((item) => {
  351. item.childNodes.forEach((items) => {
  352. items.childNodes.forEach((it) => {
  353. if (status && it.data.userId === userId) {
  354. this.$refs.tree2.setChecked(it.data.costId, true);
  355. if (!this.setKey.includes(it.data.userId)) {
  356. this.setKey.push(it.data.userId);
  357. }
  358. }
  359. if (!status && it.data.userId === userId) {
  360. this.$refs.tree2.setChecked(it.data.costId, false);
  361. this.setKey = this.setKey.filter((its) => {
  362. return its !== it.data.userId;
  363. });
  364. }
  365. });
  366. });
  367. });
  368. },
  369. /**
  370. * 班级学员发生勾选变化触发
  371. */
  372. activeChangeClass(data, status, bool) {
  373. if (data.getStatus) {
  374. this.changeDataListClass(data.userId, status);
  375. }
  376. },
  377. changeDataListClass(userId, status) {
  378. let newArrays = this.$refs.tree3.root.childNodes;
  379. newArrays.forEach((item) => {
  380. item.childNodes.forEach((it) => {
  381. if (status && it.data.userId === userId) {
  382. this.$refs.tree3.setChecked(it.data.costId, true);
  383. if (!this.setKey.includes(it.data.userId)) {
  384. this.setKey.push(it.data.userId);
  385. }
  386. }
  387. if (!status && it.data.userId === userId) {
  388. this.$refs.tree3.setChecked(it.data.costId, false);
  389. this.setKey = this.setKey.filter((its) => {
  390. return its !== it.data.userId;
  391. });
  392. }
  393. });
  394. });
  395. },
  396. diavosFun(int, item) {
  397. this.radio = int;
  398. this.setKey = JSON.parse(JSON.stringify(item));
  399. this.diavos = true;
  400. },
  401. clears() {
  402. this.diavos = false;
  403. },
  404. },
  405. };
  406. </script>
  407. <style lang="less" scoped>
  408. .max_height {
  409. margin-top: 14px;
  410. min-height: 100px;
  411. max-height: 650px;
  412. overflow: auto;
  413. }
  414. /deep/.el-button {
  415. border-radius: 8px;
  416. }
  417. /deep/.el-dialog {
  418. border-radius: 8px;
  419. .el-dialog__header {
  420. padding: 0;
  421. .hearders {
  422. height: 40px;
  423. display: flex;
  424. align-items: center;
  425. justify-content: space-between;
  426. padding: 0px 18px 0px 20px;
  427. border-bottom: 1px solid #e2e2e2;
  428. .leftTitle {
  429. font-size: 14px;
  430. font-weight: bold;
  431. color: #2f4378;
  432. }
  433. .rightBoxs {
  434. display: flex;
  435. align-items: center;
  436. img {
  437. width: 14px;
  438. height: 14px;
  439. margin-left: 13px;
  440. cursor: pointer;
  441. }
  442. }
  443. }
  444. }
  445. .el-dialog__footer {
  446. padding: 0;
  447. .dialog-footer {
  448. padding: 0px 40px;
  449. height: 70px;
  450. border-top: 1px solid #e2e2e2;
  451. display: flex;
  452. align-items: center;
  453. justify-content: flex-end;
  454. }
  455. }
  456. }
  457. .imgBox {
  458. width: 100%;
  459. // height: 210px;
  460. border: 1px solid #e2e2e2;
  461. border-radius: 8px;
  462. padding: 8px 8px 3px;
  463. display: flex;
  464. flex-direction: column;
  465. align-items: center;
  466. .imgLabel {
  467. flex: 1;
  468. width: 100%;
  469. border: 1px dotted #e2e2e2;
  470. color: #999;
  471. font-size: 14px;
  472. cursor: pointer;
  473. border-radius: 8px;
  474. .msPhoto {
  475. display: flex;
  476. justify-content: center;
  477. align-items: center;
  478. max-width: 100%;
  479. max-height: 270px;
  480. img {
  481. max-width: 100%;
  482. max-height: 270px;
  483. }
  484. }
  485. .imgbbx {
  486. display: flex;
  487. flex-direction: column;
  488. align-items: center;
  489. justify-content: center;
  490. width: 100%;
  491. height: 100%;
  492. i {
  493. font-weight: bold;
  494. margin: 14px 0;
  495. font-size: 24px;
  496. }
  497. }
  498. }
  499. p {
  500. margin: 5px 0px;
  501. }
  502. }
  503. </style>