SelectSchool.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <div style="width:50%">
  3. <div class="selection-component row">
  4. <label class="selection-label">{{$t('formConfigP.school')+':'}}</label>
  5. <Row style="width:90%;">
  6. <Col :xs="18" :sm="6" :md="5" :lg="4">
  7. <Select v-model="schoolInfo.country.countryId" class="my-select" :placeholder="$t('formConfigP.country')" @on-change="getSelctValue('country',$event)" :disabled="$i18n.locale.indexOf('en') != -1">
  8. <Option v-for="item in countryData" :value="item.countryId" :key="item.sysAddID">{{ item.countryName }}</Option>
  9. </Select>
  10. </Col>
  11. <Col :xs="18" :sm="6" :md="5" :lg="4">
  12. <Select v-model="schoolInfo.province.provinceId" v-show="schoolInfo.country.countryId != 'TW'" class="my-select" :placeholder="$t('formConfigP.province')" :disabled="checkCountry == 2 || $i18n.locale.indexOf('en') != -1" clearable ref="province" @on-change="getSelctValue('province',$event)">
  13. <Option v-for="item in provinceData" :value="item.provinceId" :key="item.sysAddID">{{ item.provinceName }}</Option>
  14. </Select>
  15. </Col>
  16. <Col :xs="18" :sm="6" :md="5" :lg="4">
  17. <Select v-model="schoolInfo.city.cityId" class="my-select" :placeholder="$t('formConfigP.city')" :disabled="checkCountry == 2 || $i18n.locale.indexOf('en') != -1" clearable ref="city" @on-change="getSelctValue('city',$event)">
  18. <Option v-for="item in cityData" :value="item.cityId" :key="item.sysAddID">{{ item.cityName }}</Option>
  19. </Select>
  20. </Col>
  21. <Col :xs="18" :sm="6" :md="5" :lg="12">
  22. <Select v-model="schoolInfo.school.name" class="my-select" :placeholder="$t('formConfigP.school')" :disabled="checkCountry == 2 || $i18n.locale.indexOf('en') != -1" clearable ref="school" @on-change="getSelctValue('school',$event)" filterable :loading="loading" not-found-text="">
  23. <Option v-for="item in schoolData" :value="item.name" :key="item.sysAddID">{{ item.name }}</Option>
  24. </Select>
  25. </Col>
  26. </Row>
  27. </div>
  28. <div class="selection-component ">
  29. <label class="selection-label"></label>
  30. <Row style="width:90%; margin-top:20px;" v-if="checkCountry == 2 || $i18n.locale.indexOf('en') != -1">
  31. <Col :xs="24" :sm="6" :md="5" :lg="6">
  32. <Input v-model="schoolInfoInput.country" class="my-select" placeholder="country" style="width: 95%;" />
  33. </Col>
  34. <Col :xs="24" :sm="6" :md="5" :lg="6">
  35. <Input v-model="schoolInfoInput.city" class="my-select" placeholder="city" style="width: 95%" />
  36. </Col>
  37. <Col :xs="24" :sm="6" :md="5" :lg="12">
  38. <Input v-model="schoolInfoInput.school" class="my-select" placeholder="school" style="width: 90%;" @on-change="getInputValue" />
  39. </Col>
  40. </Row>
  41. </div>
  42. </div>
  43. </template>
  44. <script>
  45. export default {
  46. props: {
  47. },
  48. data() {
  49. return {
  50. model: "",
  51. zhCnData: [],
  52. zhTwData: [],
  53. enUsData: [],
  54. schoolData: [],
  55. schoolInfoInput: {
  56. country: '',
  57. province: '',
  58. city: '',
  59. school: '',
  60. },
  61. schoolInfo: {
  62. country: {},
  63. province: {},
  64. city: {},
  65. school: {},
  66. },
  67. loading: false
  68. };
  69. },
  70. methods: {
  71. getValue() {
  72. this.$emit("get-value", [
  73. this.model,
  74. this.selections.field
  75. ]);
  76. },
  77. getCountryInfo(data) {
  78. let result = [];
  79. let currentCountry = '';
  80. for (let i = 0; i < data.length; i++) {
  81. if (currentCountry != data[i].countryName && data[i].countryName != null && data[i].provinceName == null && data[i].cityName == null) {
  82. currentCountry = data[i].countryName;
  83. result.push(data[i]);
  84. }
  85. }
  86. return result;
  87. },
  88. getProvinceInfo(data, country) {
  89. let result = [];
  90. let currentProvince = '';
  91. for (let i = 0; i < data.length; i++) {
  92. if (currentProvince != data[i].provinceName && data[i].provinceName != null && data[i].countryId == country.countryId) {
  93. currentProvince = data[i].provinceName;
  94. result.push(data[i]);
  95. }
  96. }
  97. return result;
  98. },
  99. getCityInfo(data, province) {
  100. let result = [];
  101. let currentCity = '';
  102. if (province != undefined) {
  103. for (let i = 0; i < data.length; i++) {
  104. if (currentCity != data[i].cityName && data[i].cityName != null && data[i].provinceId == province.provinceId) {
  105. currentCity = data[i].cityName;
  106. result.push(data[i]);
  107. }
  108. }
  109. }
  110. return result;
  111. },
  112. getSchoolInfo(CountryId, ProvinceId, CityId) {
  113. let params = {
  114. CountryId: CountryId,
  115. ProvinceId: ProvinceId,
  116. CityId: CityId
  117. }
  118. this.loading = true;
  119. //发送请求获取学校列表
  120. this.$api.getSchoolList(params).then(
  121. (res) => {
  122. if (res.error == null) {
  123. if (res.result.data.length == 0 || !res.result.data) {
  124. alert("暂未收录此地区学校,请手动输入!");
  125. } else {
  126. this.schoolData = res.result.data;
  127. //this.schoolInfo.school = res.result.data[0];
  128. }
  129. } else {
  130. alert("服务器错误!");
  131. }
  132. this.loading = false;
  133. },
  134. (err) => {
  135. this.loading = false;
  136. }
  137. )
  138. },
  139. getSelctValue(flag, value) {
  140. if (flag == 'country') {
  141. this.$refs.school.clearSingleSelect();
  142. this.$refs.city.clearSingleSelect();
  143. this.$refs.province.clearSingleSelect();
  144. this.schoolInfo.province = {};
  145. this.schoolInfo.city = {};
  146. this.schoolInfo.school = {};
  147. } else if (flag == 'province') {
  148. this.$refs.school.clearSingleSelect();
  149. this.$refs.city.clearSingleSelect();
  150. this.schoolInfo.city = {};
  151. this.schoolInfo.school = {};
  152. } else if (flag == 'city') {
  153. this.$refs.school.clearSingleSelect();
  154. this.schoolInfo.school = {};
  155. this.getSchoolInfo(this.schoolInfo.country.countryId, this.schoolInfo.province.provinceId, this.schoolInfo.city.cityId);
  156. } else if (flag == 'school') {
  157. this.schoolInfo['checkCountry'] = this.checkCountry;
  158. this.$emit("school-info", this.schoolInfo);
  159. console.log(this.schoolInfo);
  160. }
  161. },
  162. getInputValue() {
  163. this.schoolInfoInput['checkCountry'] = this.checkCountry;
  164. this.$emit("school-info", this.schoolInfoInput);
  165. console.log(this.schoolInfo);
  166. }
  167. },
  168. computed: {
  169. countryData() {
  170. let countryInfo = [];
  171. if (this.$i18n.locale == 'zh-CN') {
  172. countryInfo = this.getCountryInfo(this.zhCnData);
  173. } else if (this.$i18n.locale == 'zh-TW') {
  174. countryInfo = this.getCountryInfo(this.zhTwData);
  175. } else if (this.$i18n.locale.indexOf('en') != -1) {
  176. countryInfo = this.getCountryInfo(this.enUsData);
  177. }
  178. return countryInfo;
  179. },
  180. provinceData() {
  181. let provinceInfo = [];
  182. if (this.$i18n.locale == 'zh-CN') {
  183. provinceInfo = this.getProvinceInfo(this.zhCnData, this.schoolInfo.country);
  184. } else if (this.$i18n.locale == 'zh-TW') {
  185. provinceInfo = this.getProvinceInfo(this.zhTwData, this.schoolInfo.country);
  186. } else if (this.$i18n.locale.indexOf('en') != -1) {
  187. provinceInfo = this.getProvinceInfo(this.enUsData, this.schoolInfo.country);
  188. }
  189. return provinceInfo;
  190. },
  191. cityData() {
  192. let cityInfo = [];
  193. if (this.$i18n.locale == 'zh-CN') {
  194. cityInfo = this.getCityInfo(this.zhCnData, this.schoolInfo.province);
  195. } else if (this.$i18n.locale == 'zh-TW') {
  196. cityInfo = this.getCityInfo(this.zhTwData, this.schoolInfo.province);
  197. } else if (this.$i18n.locale.indexOf('en') != -1) {
  198. cityInfo = this.getCityInfo(this.enUsData, this.schoolInfo.province);
  199. }
  200. return cityInfo;
  201. },
  202. checkCountry() {
  203. if (this.schoolInfo.country.countryId == undefined) {
  204. return 0;
  205. }
  206. if (this.schoolInfo.country.countryId == 'CN' || this.schoolInfo.country.countryId == 'TW') {
  207. return 1;
  208. } else {
  209. return 2;
  210. }
  211. }
  212. },
  213. mounted() {
  214. let area = require("@/static/area.json");
  215. for (let i = 0; i < area.length; i++) {
  216. if (area[i].lang == 'en-us') {
  217. this.enUsData.push(area[i]);
  218. } else if (area[i].lang == 'zh-tw') {
  219. this.zhTwData.push(area[i]);
  220. } else if (area[i].lang == 'zh-cn') {
  221. this.zhCnData.push(area[i]);
  222. }
  223. };
  224. }
  225. };
  226. </script>
  227. <style scoped>
  228. .selection-component {
  229. width: 100%;
  230. position: relative;
  231. display: flex;
  232. flex-direction: row;
  233. align-items: center;
  234. }
  235. .ivu-select-selection {
  236. width: 150px !important;
  237. }
  238. .selection-label {
  239. width: 120px;
  240. font-size: 15px;
  241. color: #67B6E5;
  242. }
  243. .my-select {
  244. width: 90%;
  245. }
  246. .my-select > > > .ivu-select-selection {
  247. border: 1px solid #67B6E5;
  248. }
  249. .my-select > > > .ivu-select-selected-value {
  250. color: #67B6E5;
  251. font-size: 15px;
  252. }
  253. .my-select > > > .ivu-select-input {
  254. color: #67B6E5;
  255. font-size: 13px;
  256. }
  257. </style>