busIns.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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. this.newSujectApis = newVal;
  189. },
  190. // 立即处理 进入页面就触发
  191. immediate: true,
  192. },
  193. newSujectApis: {
  194. handler(newVal, oldVal) {
  195. if (newVal && newVal.length > 0) {
  196. const finds = newVal.findIndex((item) => {
  197. return item.businessName === "安管三类";
  198. });
  199. this.$emit("disableType", finds);
  200. }else{
  201. this.$emit("disableType", -1);
  202. }
  203. },
  204. immediate: true,
  205. },
  206. },
  207. created() {
  208. this.localData = this.$methodsTools.getBusinessList();
  209. },
  210. mounted() {
  211. this.getDict();
  212. },
  213. methods: {
  214. UPDates() {
  215. this.localData = this.$methodsTools.getBusinessList();
  216. },
  217. unTime(val) {
  218. let a = `${val.businessId}-${val.subjectId}`;
  219. if (this.sujectApis.includes(a)) {
  220. this.sujectApis.splice(this.sujectApis.indexOf(a), 1);
  221. } else {
  222. this.sujectApis.push(a);
  223. }
  224. },
  225. changeSty(val) {
  226. var arr = "";
  227. this.sujectApis.forEach((item) => {
  228. let arr1 = item.split("-").map(Number);
  229. if (val.businessId == arr1[0] && val.subjectId == arr1[1]) {
  230. arr = "activeStyIcons";
  231. }
  232. });
  233. return arr;
  234. },
  235. handleCheckedCitiesChange() {
  236. let nid = this.newSujectOption.map((item) => {
  237. return item.newId;
  238. });
  239. this.checkAll = this.sujectArray.length === nid.length;
  240. this.isIndeterminate =
  241. this.sujectArray.length > 0 && this.sujectArray.length < nid.length;
  242. },
  243. setFunc(arr) {
  244. var arrays = [];
  245. for (let i = 0; i < arr.length; i++) {
  246. if (!arrays.includes(arr[i])) {
  247. arrays.push(arr[i]);
  248. }
  249. }
  250. return arrays;
  251. },
  252. handleCheckAllChange(val) {
  253. if (val) {
  254. let nid = this.newSujectOption.map((item) => {
  255. return item.newId;
  256. });
  257. let arrays = this.sujectArray.concat(nid);
  258. this.sujectArray = this.setFunc(arrays);
  259. this.isIndeterminate = false;
  260. } else {
  261. let nid = this.newSujectOption.map((item) => {
  262. return item.newId;
  263. });
  264. let newArr = [];
  265. this.sujectArray.forEach((item) => {
  266. if (!nid.includes(item)) {
  267. newArr.push(item);
  268. }
  269. });
  270. this.sujectArray = newArr;
  271. this.isIndeterminate = false;
  272. }
  273. },
  274. getMessage() {
  275. if (!this.courType) {
  276. this.$message.warning("请先选择业务层级");
  277. }
  278. },
  279. changeTypes() {
  280. var self = this;
  281. var arrays = [];
  282. this.sujectApis.map((item, index) => {
  283. this.courTypeOptions.map((items) => {
  284. if (items.id === item.split("-").map(Number)[0]) {
  285. var obj = {
  286. type: self.typeBus,
  287. educationTypeId: items.educationId,
  288. educationName: items.educationName,
  289. projectId: items.projectId,
  290. projectName: items.projectName,
  291. businessId: items.id,
  292. businessName: items.businessName,
  293. };
  294. self.sujectOption.map((i) => {
  295. if (
  296. i.id === item.split("-").map(Number)[1] &&
  297. i.courseArrays.indexOf(items.projectId) !== -1
  298. ) {
  299. obj.subjectName = i.subjectName;
  300. obj.subjectId = i.id;
  301. }
  302. });
  303. arrays.push(obj);
  304. }
  305. });
  306. });
  307. this.newSujectApis = arrays;
  308. },
  309. getDict() {
  310. this.$api.inquireCourseEducationType({ status: 1 }).then((res) => {
  311. this.eduTypeOptions = res.rows;
  312. });
  313. this.$api.inquireCourseProjectType({ status: 1 }).then((res) => {
  314. this.projectTypeOptions = res.rows;
  315. });
  316. this.$api.inquirebusinessList({ status: 1 }).then((res) => {
  317. this.courTypeOptions = res.rows;
  318. this.newCourTypeOptions = res.rows;
  319. });
  320. this.$api.inquireCourseSubject({ status: 1 }).then((res) => {
  321. res.rows.map((item, index) => {
  322. var array = [];
  323. item.courseProjectTypes.map((items, indexs) => {
  324. array.push(items.id);
  325. });
  326. item.courseArrays = array;
  327. });
  328. this.sujectOption = res.rows;
  329. });
  330. },
  331. changeType() {
  332. this.changeHeight = !this.changeHeight;
  333. },
  334. changeEduType() {
  335. if (!(this.courType === undefined || this.courType === "")) {
  336. this.courType = "";
  337. }
  338. var arrays = [];
  339. this.courTypeOptions.map((item) => {
  340. if (item.educationId === this.eduType) {
  341. arrays.push(item);
  342. }
  343. });
  344. this.newCourTypeOptions = arrays;
  345. },
  346. changecourseType() {
  347. this.newCourTypeOptions.map((item, index) => {
  348. if (item.id === this.courType) {
  349. this.eduType = item.educationId;
  350. var array = [];
  351. this.sujectOption.map((items, indexs) => {
  352. if (items.courseArrays.indexOf(item.projectId) !== -1) {
  353. array.push(items);
  354. }
  355. });
  356. this.newSujectOption = array;
  357. }
  358. });
  359. var arrays = [];
  360. this.courTypeOptions.map((item) => {
  361. if (item.educationId === this.eduType) {
  362. arrays.push(item);
  363. }
  364. });
  365. this.newCourTypeOptions = arrays;
  366. this.$refs.popovers[0].doClose();
  367. this.$emit("amdis", this.courType);
  368. },
  369. submitSujectArray() {
  370. var self = this;
  371. this.sujectApis = this.sujectApis.filter((item, index) => {
  372. return item.split("-").map(Number)[0] !== Number(self.courType);
  373. });
  374. for (let i = 0; i < this.sujectArray.length; i++) {
  375. this.sujectApis.push(this.sujectArray[i]);
  376. }
  377. this.$refs.popovers[0].doClose();
  378. },
  379. hideHandle() {},
  380. showHandle() {
  381. var array = [];
  382. for (let i = 0; i < this.sujectApis.length; i++) {
  383. if (
  384. this.sujectApis[i].split("-").map(Number)[0] === Number(this.courType)
  385. ) {
  386. array.push(this.sujectApis[i]);
  387. }
  388. }
  389. this.sujectArray = array;
  390. if (!this.newSujectOption.length) {
  391. this.$message.warning("该业务层次暂无关联科目");
  392. this.$refs.popovers[0].doClose();
  393. return;
  394. }
  395. this.newSujectOption.map((item) => {
  396. item.newId = this.courType + "-" + item.id;
  397. });
  398. this.handleCheckedCitiesChange();
  399. },
  400. closeType(index) {
  401. this.sujectApis.splice(index, 1);
  402. },
  403. },
  404. };
  405. </script>
  406. <style lang="less" scoped>
  407. .checkboxSty {
  408. display: flex;
  409. flex-direction: column;
  410. }
  411. .listBoxStys {
  412. flex-shrink: 0;
  413. padding: 0px 10px;
  414. border-radius: 8px;
  415. border: 1px solid #eee;
  416. margin-right: 10px;
  417. margin-bottom: 6px;
  418. }
  419. .closeIcons {
  420. color: red;
  421. cursor: pointer;
  422. margin-left: 6px;
  423. }
  424. .ach {
  425. display: flex;
  426. align-items: center;
  427. overflow: hidden;
  428. }
  429. .clh {
  430. display: flex;
  431. align-items: center;
  432. flex-wrap: wrap;
  433. }
  434. </style>