region-module.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { ref, getCurrentInstance } from 'vue';
  2. export function useRegion(){
  3. const { proxy } = getCurrentInstance();
  4. const provinceOptions = ref([])
  5. const cityOptions = ref([])
  6. const areaOptions = ref([])
  7. const provinceValue = ref([])
  8. const provincAreaDetailInfoList = val => {
  9. proxy.$http.get('/sys/region/list', { params: { pid: val } }).then((res) => {
  10. if (res.msg = 'success') {
  11. provinceOptions.value = res.data.data || []
  12. }
  13. })
  14. }
  15. const cityAreaDetailInfoList = val => {
  16. proxy.$http.get('/sys/region/list', { params: { pid: val } }).then((res) => {
  17. if (res.msg = 'success') {
  18. cityOptions.value = res.data.data || []
  19. }
  20. })
  21. }
  22. const countyAreaDetailInfoList = val => {
  23. proxy.$http.get('/sys/region/list', { params: { pid: val } }).then((res) => {
  24. if (res.msg = 'success') {
  25. areaOptions.value = res.data.data || []
  26. }
  27. })
  28. }
  29. const regionChange = (val, type) => {
  30. if (type == 'province') {
  31. cityAreaDetailInfoList(val)
  32. } else if (type == 'city') {
  33. countyAreaDetailInfoList(val)
  34. }
  35. }
  36. return {
  37. provinceOptions,
  38. cityOptions,
  39. areaOptions,
  40. provinceValue,
  41. provincAreaDetailInfoList,
  42. cityAreaDetailInfoList,
  43. countyAreaDetailInfoList,
  44. regionChange
  45. }
  46. }