su-region-picker.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. "use strict";
  2. const common_vendor = require("../../../common/vendor.js");
  3. if (!Array) {
  4. const _easycom_su_toolbar2 = common_vendor.resolveComponent("su-toolbar");
  5. const _easycom_su_popup2 = common_vendor.resolveComponent("su-popup");
  6. (_easycom_su_toolbar2 + _easycom_su_popup2)();
  7. }
  8. const _easycom_su_toolbar = () => "../su-toolbar/su-toolbar.js";
  9. const _easycom_su_popup = () => "../su-popup/su-popup.js";
  10. if (!Math) {
  11. (_easycom_su_toolbar + _easycom_su_popup)();
  12. }
  13. const _sfc_main = {
  14. __name: "su-region-picker",
  15. props: {
  16. show: {
  17. type: Boolean,
  18. default: false
  19. },
  20. // "取消"按钮的颜色
  21. cancelColor: {
  22. type: String,
  23. default: "#6666"
  24. },
  25. // "确定"按钮的颜色
  26. confirmColor: {
  27. type: String,
  28. default: "var(--ui-BG-Main)"
  29. },
  30. // 取消按钮的文字
  31. cancelText: {
  32. type: String,
  33. default: "取消"
  34. },
  35. // 确认按钮的文字
  36. confirmText: {
  37. type: String,
  38. default: "确认"
  39. }
  40. },
  41. emits: ["confirm", "cancel", "change"],
  42. setup(__props, { emit: emits }) {
  43. const areaData = common_vendor.index.getStorageSync("areaData");
  44. const getSizeByNameLength = (name) => {
  45. let length = name.length;
  46. if (length <= 7)
  47. return "";
  48. if (length < 9) {
  49. return "font-size:28rpx";
  50. } else {
  51. return "font-size: 24rpx";
  52. }
  53. };
  54. const state = common_vendor.reactive({
  55. currentIndex: [0, 0, 0],
  56. moving: false
  57. // 列是否还在滑动中,微信小程序如果在滑动中就点确定,结果可能不准确
  58. });
  59. const provinceList = areaData;
  60. const cityList = common_vendor.computed(() => {
  61. return areaData[state.currentIndex[0]].children;
  62. });
  63. const districtList = common_vendor.computed(() => {
  64. var _a;
  65. return (_a = cityList.value[state.currentIndex[1]]) == null ? void 0 : _a.children;
  66. });
  67. const pickstart = () => {
  68. state.moving = true;
  69. };
  70. const pickend = () => {
  71. state.moving = false;
  72. };
  73. const onCancel = () => {
  74. emits("cancel");
  75. };
  76. const change = (e) => {
  77. if (state.currentIndex[0] === e.detail.value[0] && state.currentIndex[1] === e.detail.value[1]) {
  78. state.currentIndex[2] = e.detail.value[2];
  79. return;
  80. } else {
  81. if (state.currentIndex[0] !== e.detail.value[0]) {
  82. e.detail.value[1] = 0;
  83. }
  84. e.detail.value[2] = 0;
  85. state.currentIndex = e.detail.value;
  86. }
  87. emits("change", state.currentIndex);
  88. };
  89. const onConfirm = (event = null) => {
  90. if (state.moving)
  91. return;
  92. let index = state.currentIndex;
  93. let province = provinceList[index[0]];
  94. let city = cityList.value[index[1]];
  95. let district = districtList.value[index[2]];
  96. let result = {
  97. province_name: province.name,
  98. province_id: province.id,
  99. city_name: city.name,
  100. city_id: city.id,
  101. district_name: district.name,
  102. district_id: district.id
  103. };
  104. if (event)
  105. emits(event, result);
  106. };
  107. return (_ctx, _cache) => {
  108. return {
  109. a: common_vendor.o(onCancel),
  110. b: common_vendor.o(($event) => onConfirm("confirm")),
  111. c: common_vendor.p({
  112. cancelColor: __props.cancelColor,
  113. confirmColor: __props.confirmColor,
  114. cancelText: __props.cancelText,
  115. confirmText: __props.confirmText,
  116. title: "选择区域"
  117. }),
  118. d: common_vendor.f(common_vendor.unref(provinceList), (province, k0, i0) => {
  119. return {
  120. a: common_vendor.t(province.name),
  121. b: common_vendor.s(getSizeByNameLength(province.name)),
  122. c: province.id
  123. };
  124. }),
  125. e: common_vendor.f(common_vendor.unref(cityList), (city, k0, i0) => {
  126. return {
  127. a: common_vendor.t(city.name),
  128. b: common_vendor.s(getSizeByNameLength(city.name)),
  129. c: city.id
  130. };
  131. }),
  132. f: common_vendor.f(common_vendor.unref(districtList), (district, k0, i0) => {
  133. return {
  134. a: common_vendor.t(district.name),
  135. b: common_vendor.s(getSizeByNameLength(district.name)),
  136. c: district.id
  137. };
  138. }),
  139. g: state.currentIndex,
  140. h: common_vendor.o(change),
  141. i: common_vendor.o(pickstart),
  142. j: common_vendor.o(pickend),
  143. k: common_vendor.o(onCancel),
  144. l: common_vendor.p({
  145. show: __props.show,
  146. round: "20"
  147. })
  148. };
  149. };
  150. }
  151. };
  152. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-124df58f"], ["__file", "/Users/RuHu.Xu/Desktop/mall-newfeifan-zx-app/sheep/ui/su-region-picker/su-region-picker.vue"]]);
  153. wx.createComponent(Component);