busIns.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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 v-model="sujectArray" class="checkboxSty"
  53. @change="handleCheckedCitiesChange">
  54. <el-checkbox
  55. v-for="(item, index) in newSujectOption"
  56. :label="item.newId"
  57. :key="index"
  58. >{{ item.subjectName }}</el-checkbox
  59. >
  60. </el-checkbox-group>
  61. <div style="display: block; text-align: center; margin-top: 10px">
  62. <el-button size="mini" type="primary" @click="submitSujectArray"
  63. >确定</el-button
  64. >
  65. </div>
  66. <el-button slot="reference" style="margin-left: 12px" @click="getMessage"
  67. >请选择科目</el-button
  68. >
  69. </el-popover>
  70. </div>
  71. <div v-else>
  72. <div :class="changeHeight ? 'ach' : 'clh'">
  73. <div
  74. v-for="(item, index) in newSujectApis"
  75. :key="index"
  76. class="listBoxStys"
  77. >
  78. {{
  79. item.educationName +
  80. " - " +
  81. item.projectName +
  82. " - " +
  83. item.businessName +
  84. " - " +
  85. item.subjectName
  86. }}
  87. <i class="el-icon-error closeIcons" @click="closeType(index)"></i>
  88. </div>
  89. </div>
  90. <el-button
  91. size="mini"
  92. v-if="newSujectApis.length > 1"
  93. @click="changeType"
  94. >{{ changeHeight ? "展开" : "关闭" }}</el-button
  95. >
  96. <!-- <span v-if="newSujectApis.length === 0">未选项目类型</span> -->
  97. </div>
  98. </el-form-item>
  99. </el-form>
  100. </div>
  101. </template>
  102. <script>
  103. export default {
  104. props: ["typeBus", "sujectApisTable", "newSujectApisTable"],
  105. data() {
  106. return {
  107. isIndeterminate: false,
  108. checkAll: false,
  109. changeHeight: false,
  110. eduTypeOptions: [], //教育类型数据
  111. projectTypeOptions: [], //项目类型数据
  112. courTypeOptions: [], //业务层次数据
  113. newCourTypeOptions: [], //当前业务层次数据
  114. sujectOption: [], //科目数据
  115. newSujectOption: [], //当前科目数据数据
  116. eduType: "", //当前选中教育类型
  117. courType: "", //当前选中业务层次
  118. sujectApis: [], //当前存在的科目
  119. newSujectApis: [],
  120. sujectArray: [], //选中的科目
  121. listData: {},
  122. listitem: [
  123. {
  124. label: "适用业务层级",
  125. scope: "buss",
  126. },
  127. {
  128. label: "",
  129. scope: "activeBox",
  130. },
  131. ],
  132. };
  133. },
  134. watch: {
  135. sujectApisTable: {
  136. handler(newVal, oldVal) {
  137. this.sujectApis = newVal;
  138. },
  139. // 立即处理 进入页面就触发
  140. immediate: true,
  141. },
  142. newSujectApisTable: {
  143. handler(newVal, oldVal) {
  144. this.newSujectApis = newVal;
  145. },
  146. // 立即处理 进入页面就触发
  147. immediate: true,
  148. },
  149. },
  150. mounted() {
  151. this.getDict();
  152. },
  153. methods: {
  154. handleCheckedCitiesChange() {
  155. let nid = this.newSujectOption.map((item) => {
  156. return item.newId;
  157. });
  158. this.checkAll = this.sujectArray.length === nid.length;
  159. this.isIndeterminate =
  160. this.sujectArray.length > 0 && this.sujectArray.length < nid.length;
  161. },
  162. setFunc(arr) {
  163. var arrays = [];
  164. for (let i = 0; i < arr.length; i++) {
  165. if (!arrays.includes(arr[i])) {
  166. arrays.push(arr[i]);
  167. }
  168. }
  169. return arrays;
  170. },
  171. handleCheckAllChange(val) {
  172. if (val) {
  173. let nid = this.newSujectOption.map((item) => {
  174. return item.newId;
  175. });
  176. let arrays = this.sujectArray.concat(nid);
  177. this.sujectArray = this.setFunc(arrays);
  178. this.isIndeterminate = false;
  179. } else {
  180. let nid = this.newSujectOption.map((item) => {
  181. return item.newId;
  182. });
  183. let newArr = [];
  184. this.sujectArray.forEach((item) => {
  185. if (!nid.includes(item)) {
  186. newArr.push(item);
  187. }
  188. });
  189. this.sujectArray = newArr;
  190. this.isIndeterminate = false;
  191. }
  192. },
  193. getMessage() {
  194. if (!this.courType) {
  195. this.$message.warning("请先选择业务层级");
  196. }
  197. },
  198. changeTypes() {
  199. var self = this;
  200. var arrays = [];
  201. this.sujectApis.map((item, index) => {
  202. this.courTypeOptions.map((items) => {
  203. if (items.id === item.split("-").map(Number)[0]) {
  204. var obj = {
  205. type: self.typeBus,
  206. educationTypeId: items.educationId,
  207. educationName: items.educationName,
  208. projectId: items.projectId,
  209. projectName: items.projectName,
  210. businessId: items.id,
  211. businessName: items.businessName,
  212. };
  213. self.sujectOption.map((i) => {
  214. if (
  215. i.id === item.split("-").map(Number)[1] &&
  216. i.courseArrays.indexOf(items.projectId) !== -1
  217. ) {
  218. obj.subjectName = i.subjectName;
  219. obj.subjectId = i.id;
  220. }
  221. });
  222. arrays.push(obj);
  223. }
  224. });
  225. });
  226. this.newSujectApis = arrays;
  227. },
  228. getDict() {
  229. this.$api.inquireCourseEducationType({ status: 1 }).then((res) => {
  230. this.eduTypeOptions = res.rows;
  231. });
  232. this.$api.inquireCourseProjectType({ status: 1 }).then((res) => {
  233. this.projectTypeOptions = res.rows;
  234. });
  235. this.$api.inquirebusinessList({ status: 1 }).then((res) => {
  236. this.courTypeOptions = res.rows;
  237. this.newCourTypeOptions = res.rows;
  238. });
  239. this.$api.inquireCourseSubject({ status: 1 }).then((res) => {
  240. res.rows.map((item, index) => {
  241. var array = [];
  242. item.courseProjectTypes.map((items, indexs) => {
  243. array.push(items.id);
  244. });
  245. item.courseArrays = array;
  246. });
  247. this.sujectOption = res.rows;
  248. });
  249. },
  250. changeType() {
  251. this.changeHeight = !this.changeHeight;
  252. },
  253. changeEduType() {
  254. if (!(this.courType === undefined || this.courType === "")) {
  255. this.courType = "";
  256. }
  257. var arrays = [];
  258. this.courTypeOptions.map((item) => {
  259. if (item.educationId === this.eduType) {
  260. arrays.push(item);
  261. }
  262. });
  263. this.newCourTypeOptions = arrays;
  264. },
  265. changecourseType() {
  266. this.newCourTypeOptions.map((item, index) => {
  267. if (item.id === this.courType) {
  268. this.eduType = item.educationId;
  269. var array = [];
  270. this.sujectOption.map((items, indexs) => {
  271. if (items.courseArrays.indexOf(item.projectId) !== -1) {
  272. array.push(items);
  273. }
  274. });
  275. this.newSujectOption = array;
  276. }
  277. });
  278. var arrays = [];
  279. this.courTypeOptions.map((item) => {
  280. if (item.educationId === this.eduType) {
  281. arrays.push(item);
  282. }
  283. });
  284. this.newCourTypeOptions = arrays;
  285. this.$refs.popovers[0].doClose();
  286. this.$emit("amdis", this.courType);
  287. },
  288. submitSujectArray() {
  289. var self = this;
  290. this.sujectApis = this.sujectApis.filter((item, index) => {
  291. return item.split("-").map(Number)[0] !== Number(self.courType);
  292. });
  293. for (let i = 0; i < this.sujectArray.length; i++) {
  294. this.sujectApis.push(this.sujectArray[i]);
  295. }
  296. this.$refs.popovers[0].doClose();
  297. this.changeTypes();
  298. },
  299. hideHandle() {},
  300. showHandle() {
  301. var array = [];
  302. for (let i = 0; i < this.sujectApis.length; i++) {
  303. if (
  304. this.sujectApis[i].split("-").map(Number)[0] === Number(this.courType)
  305. ) {
  306. array.push(this.sujectApis[i]);
  307. }
  308. }
  309. this.sujectArray = array;
  310. if (!this.newSujectOption.length) {
  311. this.$message.warning("该业务层次暂无关联科目");
  312. this.$refs.popovers[0].doClose();
  313. return;
  314. }
  315. this.newSujectOption.map((item) => {
  316. item.newId = this.courType + "-" + item.id;
  317. });
  318. this.handleCheckedCitiesChange();
  319. },
  320. closeType(index) {
  321. this.sujectApis.splice(index, 1);
  322. this.changeTypes();
  323. },
  324. },
  325. };
  326. </script>
  327. <style lang="less" scoped>
  328. .checkboxSty{
  329. display: flex;
  330. flex-direction: column;
  331. }
  332. .listBoxStys {
  333. flex-shrink: 0;
  334. padding: 0px 10px;
  335. border-radius: 8px;
  336. border: 1px solid #eee;
  337. margin-right: 10px;
  338. margin-bottom: 6px;
  339. }
  340. .closeIcons {
  341. color: red;
  342. cursor: pointer;
  343. margin-left: 6px;
  344. }
  345. .ach {
  346. display: flex;
  347. align-items: center;
  348. overflow: hidden;
  349. }
  350. .clh {
  351. display: flex;
  352. align-items: center;
  353. flex-wrap: wrap;
  354. }
  355. </style>