su-region-picker.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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: __emit }) {
  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 emits = __emit;
  60. const provinceList = areaData;
  61. const cityList = common_vendor.computed(() => {
  62. return areaData[state.currentIndex[0]].children;
  63. });
  64. const districtList = common_vendor.computed(() => {
  65. var _a;
  66. return (_a = cityList.value[state.currentIndex[1]]) == null ? void 0 : _a.children;
  67. });
  68. const pickstart = () => {
  69. state.moving = true;
  70. };
  71. const pickend = () => {
  72. state.moving = false;
  73. };
  74. const onCancel = () => {
  75. emits("cancel");
  76. };
  77. const change = (e) => {
  78. if (state.currentIndex[0] === e.detail.value[0] && state.currentIndex[1] === e.detail.value[1]) {
  79. state.currentIndex[2] = e.detail.value[2];
  80. return;
  81. } else {
  82. if (state.currentIndex[0] !== e.detail.value[0]) {
  83. e.detail.value[1] = 0;
  84. }
  85. e.detail.value[2] = 0;
  86. state.currentIndex = e.detail.value;
  87. }
  88. emits("change", state.currentIndex);
  89. };
  90. const onConfirm = (event = null) => {
  91. if (state.moving)
  92. return;
  93. let index = state.currentIndex;
  94. let province = provinceList[index[0]];
  95. let city = cityList.value[index[1]];
  96. let district = districtList.value[index[2]];
  97. let result = {
  98. province_name: province.name,
  99. province_id: province.id,
  100. city_name: city.name,
  101. city_id: city.id,
  102. district_name: district.name,
  103. district_id: district.id
  104. };
  105. if (event)
  106. emits(event, result);
  107. };
  108. return (_ctx, _cache) => {
  109. return {
  110. a: common_vendor.o(onCancel),
  111. b: common_vendor.o(($event) => onConfirm("confirm")),
  112. c: common_vendor.p({
  113. cancelColor: __props.cancelColor,
  114. confirmColor: __props.confirmColor,
  115. cancelText: __props.cancelText,
  116. confirmText: __props.confirmText,
  117. title: "选择区域"
  118. }),
  119. d: common_vendor.f(common_vendor.unref(provinceList), (province, k0, i0) => {
  120. return {
  121. a: common_vendor.t(province.name),
  122. b: common_vendor.s(getSizeByNameLength(province.name)),
  123. c: province.id
  124. };
  125. }),
  126. e: common_vendor.f(cityList.value, (city, k0, i0) => {
  127. return {
  128. a: common_vendor.t(city.name),
  129. b: common_vendor.s(getSizeByNameLength(city.name)),
  130. c: city.id
  131. };
  132. }),
  133. f: common_vendor.f(districtList.value, (district, k0, i0) => {
  134. return {
  135. a: common_vendor.t(district.name),
  136. b: common_vendor.s(getSizeByNameLength(district.name)),
  137. c: district.id
  138. };
  139. }),
  140. g: state.currentIndex,
  141. h: common_vendor.o(change),
  142. i: common_vendor.o(pickstart),
  143. j: common_vendor.o(pickend),
  144. k: common_vendor.o(onCancel),
  145. l: common_vendor.p({
  146. show: __props.show,
  147. round: "20"
  148. })
  149. };
  150. };
  151. }
  152. };
  153. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-124df58f"], ["__file", "D:/zx/mall-front-app/sheep/ui/su-region-picker/su-region-picker.vue"]]);
  154. wx.createComponent(Component);