ocCategorySelection.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <style>
  2. ion-modal {
  3. --height: 50%;
  4. --border-radius: 16px;
  5. --box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  6. }
  7. ion-modal::part(backdrop) {
  8. background: rgba(209, 213, 219);
  9. opacity: 1;
  10. }
  11. ion-modal ion-toolbar {
  12. --background: white;
  13. --color: white;
  14. }
  15. ion-toolbar {
  16. padding-left: 0 !important;
  17. padding-right: 0 !important;
  18. --padding-start: 0;
  19. --padding-end: 0;
  20. }
  21. ion-toolbar ion-item:first-child {
  22. --inner-border-width: 0 0 0 0;
  23. text-align: center;
  24. }
  25. ion-toolbar ion-item:last-child {
  26. --padding-start: 0;
  27. --inner-padding-end: 0;
  28. }
  29. ion-segment {
  30. width: 100%;
  31. --background: #ffffff;
  32. }
  33. ion-segment-button {
  34. --indicator-color: rgba(254, 255, 255, 0.97);
  35. --color: #000000;
  36. --color-checked: #1a65eb;
  37. --background-hover: rgba(47, 107, 215, 0.98);
  38. --border-width: 0 0 0 0;
  39. --indicator-box-shadow: 0 0 0 0;
  40. }
  41. /*!* Material Design styles *!*/
  42. /*ion-segment-button.md {*/
  43. /* --color: #000;*/
  44. /* --color-checked: #1a65eb;*/
  45. /* --border-radius: 0px;*/
  46. /* --border-width: 0 0 0 0;*/
  47. /*}*/
  48. /*!* iOS styles *!*/
  49. /*ion-segment-button.ios {*/
  50. /* --color: #000;*/
  51. /* --color-checked: #1a65eb;*/
  52. /* --border-radius: 0px;*/
  53. /* --border-width: 0 0 0 0;*/
  54. /*}*/
  55. .custom-scroll {
  56. overflow-y: auto; /* 显示垂直滚动条 */
  57. max-height: 200px; /* 设置最大高度,超出部分会出现滚动条 */
  58. }
  59. /* 可以根据需要自定义滚动条的样式 */
  60. .custom-scroll::-webkit-scrollbar {
  61. width: 8px;
  62. }
  63. .custom-scroll::-webkit-scrollbar-thumb {
  64. background-color: #888;
  65. border-radius: 4px;
  66. }
  67. .custom-scroll::-webkit-scrollbar-thumb:hover {
  68. background-color: #555;
  69. }
  70. </style>
  71. <template>
  72. <ion-button id="open-modal" style="color: #02a6f1;font-size: 15px;" fill="clear" @click="loadOccupationalID">选择
  73. </ion-button>
  74. <ion-page>
  75. <ion-content class="ion-padding">
  76. <ion-modal trigger="open-modal" :backdrop-dismiss="false" :is-open="isOpen" :initial-breakpoint="1"
  77. :breakpoints="[0, 1]">
  78. <ion-toolbar>
  79. <ion-item>
  80. <ion-buttons slot="start">
  81. <ion-button fill="clear" @click="onCancel">取消</ion-button>
  82. </ion-buttons>
  83. <ion-label style="font-size: 12px;white-space: pre-wrap; word-wrap: break-word;">
  84. {{ selectOccupationInfo.text }}
  85. </ion-label>
  86. <ion-buttons slot="end">
  87. <ion-button fill="clear" :disabled="selectOccupationInfo.value==''" @click="onConfirm">确定</ion-button>
  88. </ion-buttons>
  89. </ion-item>
  90. <ion-item>
  91. <ion-segment value="0">
  92. <ion-segment-button v-for="(item,key) in selectModelList" :key="key" @click="onSelectType(item.index)"
  93. :disabled="item.disabled" :value="item.index">
  94. <ion-label :style="{color:item.isSelect?'#1a65eb':'#000000'}">{{ item.name }}</ion-label>
  95. </ion-segment-button>
  96. </ion-segment>
  97. </ion-item>
  98. </ion-toolbar>
  99. <div class="bw-vue-list">
  100. <div class="list-content">
  101. <ion-list class="custom-scroll" v-show="selectModelList[selectType.one].isSelect">
  102. <ion-item v-for="(item, index) in selectModelList[selectType.one].occupationList" :key="index">
  103. <ion-label :style="{color:item.isSelect?'#1a65eb':'#000000'}"
  104. @click="onSelect(item,selectType.one)">
  105. {{ item.occupationalName }}
  106. </ion-label>
  107. </ion-item>
  108. </ion-list>
  109. <ion-list class="custom-scroll" v-show="selectModelList[selectType.two].isSelect">
  110. <ion-item v-for="(item, index) in selectModelList[selectType.two].occupationList" :key="index">
  111. <ion-label :style="{color:item.isSelect?'#1a65eb':'#000000'}"
  112. @click="onSelect(item,selectType.two)">
  113. {{ item.occupationalName }}
  114. </ion-label>
  115. </ion-item>
  116. </ion-list>
  117. </div>
  118. </div>
  119. </ion-modal>
  120. </ion-content>
  121. </ion-page>
  122. </template>
  123. <script lang="ts">
  124. import {defineComponent, reactive, ref} from 'vue';
  125. import {getOccupationCategoryList} from "@/api/recommendmgt";
  126. export default defineComponent({
  127. name: "ocCategorySelection",
  128. props: {
  129. OccupationalID: {type: String, default: ''},
  130. },
  131. setup(props, context) {
  132. const selectType = {
  133. one: 0,
  134. two: 1,
  135. }
  136. const isOpen = ref(false);
  137. const selectModelList = reactive([
  138. {
  139. index: 0,
  140. name: '资格类别',
  141. isSelect: false,
  142. disabled: true,
  143. occupationalName: '',
  144. occupationalID: '',
  145. occupationList: [] as any
  146. },
  147. {
  148. index: 1,
  149. name: '资格名称',
  150. isSelect: false,
  151. disabled: true,
  152. occupationalName: '',
  153. occupationalID: '',
  154. occupationList: [] as any
  155. }]);
  156. const selectOccupationInfo = reactive({value: '', text: ''})
  157. const occupationalCategoryList = ref();
  158. const loadOccupationalID = () => {
  159. getOccupationCategoryList().then(data => {
  160. occupationalCategoryList.value = data;
  161. if (!props.OccupationalID) {
  162. selectModelList[selectType.one].isSelect = true;
  163. selectModelList[selectType.one].disabled = false;
  164. selectModelList[selectType.one].occupationalName = '';
  165. selectModelList[selectType.one].occupationalID = '';
  166. selectModelList[selectType.one].occupationList = occupationalCategoryList.value.filter((x: any) => x.occupationalLevel == "1")
  167. .map((x: any) => ({
  168. ...x,
  169. isSelect: false
  170. }));
  171. }
  172. else {
  173. const twoInfo = occupationalCategoryList.value.find((x: any) => x.occupationalLevel == "2" && x.occupationalID == props.OccupationalID);
  174. const oneInfo = occupationalCategoryList.value.find((x: any) => x.occupationalLevel == "1" && x.occupationalID == twoInfo.parentOccupationalID);
  175. selectModelList[selectType.one].isSelect = false;
  176. selectModelList[selectType.one].disabled = false;
  177. selectModelList[selectType.one].occupationalName = oneInfo.occupationalName;
  178. selectModelList[selectType.one].occupationalID = oneInfo.occupationalID;
  179. selectModelList[selectType.one].occupationList = occupationalCategoryList.value.filter((x: any) => x.occupationalLevel == "1")
  180. .map((x: any) => ({
  181. ...x,
  182. isSelect: false
  183. }));
  184. selectModelList[selectType.one].occupationList.find((x: any) => x.occupationalID == oneInfo.occupationalID).isSelect = true;
  185. selectModelList[selectType.two].isSelect = true;
  186. selectModelList[selectType.two].disabled = false;
  187. selectModelList[selectType.two].occupationalName = twoInfo.occupationalName;
  188. selectModelList[selectType.two].occupationalID = twoInfo.occupationalID;
  189. selectModelList[selectType.two].occupationList = occupationalCategoryList.value.filter((x: any) => x.occupationalLevel == "2"
  190. && x.parentOccupationalID == oneInfo.occupationalID).map((x: any) => ({
  191. ...x,
  192. isSelect: false
  193. }));
  194. selectModelList[selectType.two].occupationList.find((x: any) => x.occupationalID == twoInfo.occupationalID).isSelect = true;
  195. getSelectOccupation();
  196. }
  197. });
  198. isOpen.value = true;
  199. }
  200. const onSelectType = (type: number) => {
  201. if (selectType.one == type) {
  202. selectModelList.map(x => {
  203. x.isSelect = false,
  204. x.disabled = true,
  205. x.occupationalName = '',
  206. x.occupationalID = '',
  207. x.occupationList = []
  208. });
  209. selectModelList[selectType.one].isSelect = true;
  210. selectModelList[selectType.one].disabled = false;
  211. selectModelList[selectType.one].occupationList = occupationalCategoryList.value.filter((x: any) => x.occupationalLevel == "1")
  212. .map((x: any) => ({
  213. ...x,
  214. isSelect: false
  215. }));
  216. }
  217. if (selectType.two == type) {
  218. selectModelList[selectType.one].isSelect = false;
  219. selectModelList[selectType.two].isSelect = true;
  220. selectModelList[selectType.two].disabled = false;
  221. selectModelList[selectType.two].occupationalName = '';
  222. selectModelList[selectType.two].occupationalID = '';
  223. selectModelList[selectType.two].occupationList = occupationalCategoryList.value.filter((x: any) => x.occupationalLevel == "2"
  224. && x.parentOccupationalID == selectModelList[selectType.one].occupationalID).map((x: any) => ({
  225. ...x,
  226. isSelect: false
  227. }));
  228. }
  229. getSelectOccupation();
  230. }
  231. const onSelect = (item: any, type: any) => {
  232. selectModelList[type].occupationList.forEach((x: any) => {
  233. x.isSelect = x.occupationalID == item.occupationalID;
  234. });
  235. selectModelList[type].occupationalName = item.occupationalName;
  236. selectModelList[type].occupationalID = item.occupationalID;
  237. if (type == selectType.one) {
  238. onSelectType(selectType.two);
  239. }
  240. getSelectOccupation();
  241. }
  242. const getSelectOccupation = () => {
  243. selectOccupationInfo.text = selectModelList.filter(x => x.occupationalName != '').map(x => x.occupationalName).join("-");
  244. selectOccupationInfo.value = selectModelList[selectType.two].occupationalID;
  245. }
  246. const onCancel = () => {
  247. isOpen.value = false;
  248. }
  249. const onConfirm = () => {
  250. isOpen.value = false;
  251. context.emit("SetOccupationalID", selectOccupationInfo);
  252. }
  253. return {
  254. isOpen,
  255. selectType,
  256. selectModelList,
  257. selectOccupationInfo,
  258. loadOccupationalID,
  259. onSelectType,
  260. onSelect,
  261. onCancel,
  262. onConfirm,
  263. };
  264. }
  265. })
  266. </script>