busIns.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <template>
  2. <div id="busIns">
  3. <el-form label-position="right" label-width="110px" :model="listData">
  4. <el-form-item
  5. v-for="(items, indexs) in listitem"
  6. :key="indexs"
  7. :label="items.label"
  8. :prop="items.prop"
  9. :required="true"
  10. >
  11. <div v-if="items.scope === 'buss'">
  12. <el-select
  13. v-model="eduType"
  14. placeholder="请选择教育类型"
  15. @change="changeEduType"
  16. >
  17. <el-option
  18. v-for="(item, index) in eduTypeOptions"
  19. :key="index"
  20. :label="item.educationName"
  21. :value="item.id"
  22. >
  23. </el-option>
  24. </el-select>
  25. <el-select
  26. v-model="courType"
  27. placeholder="请选择业务层次"
  28. @change="changecourseType"
  29. >
  30. <el-option
  31. v-for="(item, index) in newCourTypeOptions"
  32. :key="index"
  33. :label="item.projectName + '-' + item.businessName"
  34. :value="item.id"
  35. >
  36. </el-option>
  37. </el-select>
  38. <el-popover
  39. ref="popovers"
  40. placement="bottom"
  41. trigger="click"
  42. @show="showHandle"
  43. @hide="hideHandle"
  44. :disabled="courType ? false : true"
  45. >
  46. <el-checkbox
  47. v-model="checkAll"
  48. @change="handleCheckAllChange"
  49. :indeterminate="isIndeterminate"
  50. >全选</el-checkbox
  51. >
  52. <el-checkbox-group
  53. v-model="sujectArray"
  54. class="checkboxSty"
  55. @change="handleCheckedCitiesChange"
  56. >
  57. <el-checkbox
  58. v-for="(item, index) in newSujectOption"
  59. :label="item.newId"
  60. :key="index"
  61. >{{ item.subjectName }}</el-checkbox
  62. >
  63. </el-checkbox-group>
  64. <div style="display: block; text-align: center; margin-top: 10px">
  65. <el-button size="mini" type="primary" @click="submitSujectArray"
  66. >确定</el-button
  67. >
  68. </div>
  69. <el-button
  70. slot="reference"
  71. style="margin-left: 12px"
  72. @click="getMessage"
  73. >请选择科目</el-button
  74. >
  75. </el-popover>
  76. </div>
  77. <div v-else>
  78. <div :class="changeHeight ? 'ach' : 'clh'">
  79. <div
  80. v-for="(item, index) in newSujectApis"
  81. :key="index"
  82. class="listBoxStys"
  83. >
  84. {{
  85. item.educationName +
  86. " - " +
  87. item.projectName +
  88. " - " +
  89. item.businessName +
  90. " - " +
  91. item.subjectName
  92. }}
  93. <i class="el-icon-error closeIcons" @click="closeType(index)"></i>
  94. </div>
  95. </div>
  96. <el-popover
  97. placement="bottom-start"
  98. trigger="hover"
  99. :close-delay="50"
  100. >
  101. <ul style="margin: 0; max-width: 600px">
  102. <li
  103. class="copyDataLi"
  104. :class="changeSty(itemT)"
  105. v-for="(itemT, indexT) in localData"
  106. :key="indexT"
  107. @click="unTime(itemT)"
  108. >
  109. {{
  110. `${itemT.educationName}-${itemT.projectName}-${itemT.businessName}-${itemT.subjectName}`
  111. }}
  112. </li>
  113. </ul>
  114. <el-button
  115. v-show="localData.length"
  116. type="danger"
  117. slot="reference"
  118. size="mini"
  119. style="margin-right: 10px"
  120. >最近选择</el-button
  121. >
  122. </el-popover>
  123. <el-button
  124. size="mini"
  125. v-if="newSujectApis.length > 1"
  126. @click="changeType"
  127. >{{ changeHeight ? "展开" : "关闭" }}</el-button
  128. ><el-button
  129. size="mini"
  130. v-if="newSujectApis.length > 0"
  131. @click="sujectApis = []"
  132. >清空</el-button
  133. >
  134. <!-- <span v-if="newSujectApis.length === 0">未选项目类型</span> -->
  135. </div>
  136. </el-form-item>
  137. </el-form>
  138. </div>
  139. </template>
  140. <script>
  141. export default {
  142. props: ["typeBus", "sujectApisTable", "newSujectApisTable"],
  143. data() {
  144. return {
  145. isIndeterminate: false,
  146. checkAll: false,
  147. changeHeight: false,
  148. eduTypeOptions: [], //教育类型数据
  149. projectTypeOptions: [], //项目类型数据
  150. courTypeOptions: [], //业务层次数据
  151. newCourTypeOptions: [], //当前业务层次数据
  152. sujectOption: [], //科目数据
  153. newSujectOption: [], //当前科目数据数据
  154. eduType: "", //当前选中教育类型
  155. courType: "", //当前选中业务层次
  156. sujectApis: [], //当前存在的科目
  157. newSujectApis: [],
  158. sujectArray: [], //选中的科目
  159. listData: {},
  160. listitem: [
  161. {
  162. label: "适用业务层级",
  163. scope: "buss",
  164. },
  165. {
  166. label: "",
  167. scope: "activeBox",
  168. },
  169. ],
  170. };
  171. },
  172. watch: {
  173. sujectApis: {
  174. immediate: true,
  175. handler(newName, oldName) {
  176. this.changeTypes();
  177. },
  178. },
  179. sujectApisTable: {
  180. handler(newVal, oldVal) {
  181. this.sujectApis = newVal;
  182. },
  183. // 立即处理 进入页面就触发
  184. immediate: true,
  185. },
  186. newSujectApisTable: {
  187. handler(newVal, oldVal) {
  188. console.log(newVal, 2);
  189. this.newSujectApis = newVal;
  190. },
  191. // 立即处理 进入页面就触发
  192. immediate: true,
  193. },
  194. },
  195. created() {
  196. this.localData = this.$methodsTools.getBusinessList();
  197. },
  198. mounted() {
  199. this.getDict();
  200. },
  201. methods: {
  202. UPDates() {
  203. this.localData = this.$methodsTools.getBusinessList();
  204. },
  205. unTime(val) {
  206. let a = `${val.businessId}-${val.subjectId}`;
  207. if (this.sujectApis.includes(a)) {
  208. this.sujectApis.splice(this.sujectApis.indexOf(a), 1);
  209. } else {
  210. this.sujectApis.push(a);
  211. }
  212. },
  213. changeSty(val) {
  214. var arr = "";
  215. this.sujectApis.forEach((item) => {
  216. let arr1 = item.split("-").map(Number);
  217. if (val.businessId == arr1[0] && val.subjectId == arr1[1]) {
  218. arr = "activeStyIcons";
  219. }
  220. });
  221. return arr;
  222. },
  223. handleCheckedCitiesChange() {
  224. let nid = this.newSujectOption.map((item) => {
  225. return item.newId;
  226. });
  227. this.checkAll = this.sujectArray.length === nid.length;
  228. this.isIndeterminate =
  229. this.sujectArray.length > 0 && this.sujectArray.length < nid.length;
  230. },
  231. setFunc(arr) {
  232. var arrays = [];
  233. for (let i = 0; i < arr.length; i++) {
  234. if (!arrays.includes(arr[i])) {
  235. arrays.push(arr[i]);
  236. }
  237. }
  238. return arrays;
  239. },
  240. handleCheckAllChange(val) {
  241. if (val) {
  242. let nid = this.newSujectOption.map((item) => {
  243. return item.newId;
  244. });
  245. let arrays = this.sujectArray.concat(nid);
  246. this.sujectArray = this.setFunc(arrays);
  247. this.isIndeterminate = false;
  248. } else {
  249. let nid = this.newSujectOption.map((item) => {
  250. return item.newId;
  251. });
  252. let newArr = [];
  253. this.sujectArray.forEach((item) => {
  254. if (!nid.includes(item)) {
  255. newArr.push(item);
  256. }
  257. });
  258. this.sujectArray = newArr;
  259. this.isIndeterminate = false;
  260. }
  261. },
  262. getMessage() {
  263. if (!this.courType) {
  264. this.$message.warning("请先选择业务层级");
  265. }
  266. },
  267. changeTypes() {
  268. var self = this;
  269. var arrays = [];
  270. this.sujectApis.map((item, index) => {
  271. this.courTypeOptions.map((items) => {
  272. if (items.id === item.split("-").map(Number)[0]) {
  273. var obj = {
  274. type: self.typeBus,
  275. educationTypeId: items.educationId,
  276. educationName: items.educationName,
  277. projectId: items.projectId,
  278. projectName: items.projectName,
  279. businessId: items.id,
  280. businessName: items.businessName,
  281. };
  282. self.sujectOption.map((i) => {
  283. if (
  284. i.id === item.split("-").map(Number)[1] &&
  285. i.courseArrays.indexOf(items.projectId) !== -1
  286. ) {
  287. obj.subjectName = i.subjectName;
  288. obj.subjectId = i.id;
  289. }
  290. });
  291. arrays.push(obj);
  292. }
  293. });
  294. });
  295. this.newSujectApis = arrays;
  296. },
  297. getDict() {
  298. this.$api.inquireCourseEducationType({ status: 1 }).then((res) => {
  299. this.eduTypeOptions = res.rows;
  300. });
  301. this.$api.inquireCourseProjectType({ status: 1 }).then((res) => {
  302. this.projectTypeOptions = res.rows;
  303. });
  304. this.$api.inquirebusinessList({ status: 1 }).then((res) => {
  305. this.courTypeOptions = res.rows;
  306. this.newCourTypeOptions = res.rows;
  307. });
  308. this.$api.inquireCourseSubject({ status: 1 }).then((res) => {
  309. res.rows.map((item, index) => {
  310. var array = [];
  311. item.courseProjectTypes.map((items, indexs) => {
  312. array.push(items.id);
  313. });
  314. item.courseArrays = array;
  315. });
  316. this.sujectOption = res.rows;
  317. });
  318. },
  319. changeType() {
  320. this.changeHeight = !this.changeHeight;
  321. },
  322. changeEduType() {
  323. if (!(this.courType === undefined || this.courType === "")) {
  324. this.courType = "";
  325. }
  326. var arrays = [];
  327. this.courTypeOptions.map((item) => {
  328. if (item.educationId === this.eduType) {
  329. arrays.push(item);
  330. }
  331. });
  332. this.newCourTypeOptions = arrays;
  333. },
  334. changecourseType() {
  335. this.newCourTypeOptions.map((item, index) => {
  336. if (item.id === this.courType) {
  337. this.eduType = item.educationId;
  338. var array = [];
  339. this.sujectOption.map((items, indexs) => {
  340. if (items.courseArrays.indexOf(item.projectId) !== -1) {
  341. array.push(items);
  342. }
  343. });
  344. this.newSujectOption = array;
  345. }
  346. });
  347. var arrays = [];
  348. this.courTypeOptions.map((item) => {
  349. if (item.educationId === this.eduType) {
  350. arrays.push(item);
  351. }
  352. });
  353. this.newCourTypeOptions = arrays;
  354. this.$refs.popovers[0].doClose();
  355. this.$emit("amdis", this.courType);
  356. },
  357. submitSujectArray() {
  358. var self = this;
  359. this.sujectApis = this.sujectApis.filter((item, index) => {
  360. return item.split("-").map(Number)[0] !== Number(self.courType);
  361. });
  362. for (let i = 0; i < this.sujectArray.length; i++) {
  363. this.sujectApis.push(this.sujectArray[i]);
  364. }
  365. this.$refs.popovers[0].doClose();
  366. },
  367. hideHandle() {},
  368. showHandle() {
  369. var array = [];
  370. for (let i = 0; i < this.sujectApis.length; i++) {
  371. if (
  372. this.sujectApis[i].split("-").map(Number)[0] === Number(this.courType)
  373. ) {
  374. array.push(this.sujectApis[i]);
  375. }
  376. }
  377. this.sujectArray = array;
  378. if (!this.newSujectOption.length) {
  379. this.$message.warning("该业务层次暂无关联科目");
  380. this.$refs.popovers[0].doClose();
  381. return;
  382. }
  383. this.newSujectOption.map((item) => {
  384. item.newId = this.courType + "-" + item.id;
  385. });
  386. this.handleCheckedCitiesChange();
  387. },
  388. closeType(index) {
  389. this.sujectApis.splice(index, 1);
  390. },
  391. },
  392. };
  393. </script>
  394. <style lang="less" scoped>
  395. .checkboxSty {
  396. display: flex;
  397. flex-direction: column;
  398. }
  399. .listBoxStys {
  400. flex-shrink: 0;
  401. padding: 0px 10px;
  402. border-radius: 8px;
  403. border: 1px solid #eee;
  404. margin-right: 10px;
  405. margin-bottom: 6px;
  406. }
  407. .closeIcons {
  408. color: red;
  409. cursor: pointer;
  410. margin-left: 6px;
  411. }
  412. .ach {
  413. display: flex;
  414. align-items: center;
  415. overflow: hidden;
  416. }
  417. .clh {
  418. display: flex;
  419. align-items: center;
  420. flex-wrap: wrap;
  421. }
  422. </style>