u-city-select.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. "use strict";
  2. const components_uCitySelect_province = require("./province.js");
  3. const components_uCitySelect_city = require("./city.js");
  4. const components_uCitySelect_area = require("./area.js");
  5. const common_vendor = require("../../common/vendor.js");
  6. const _sfc_main = {
  7. name: "u-city-select",
  8. props: {
  9. // 通过双向绑定控制组件的弹出与收起
  10. modelValue: {
  11. type: Boolean,
  12. default: false
  13. },
  14. // 默认显示的地区,可传类似["河北省", "秦皇岛市", "北戴河区"]
  15. defaultRegion: {
  16. type: Array,
  17. default() {
  18. return [];
  19. }
  20. },
  21. // 默认显示地区的编码,defaultRegion和areaCode同时存在,areaCode优先,可传类似["13", "1303", "130304"]
  22. areaCode: {
  23. type: Array,
  24. default() {
  25. return [];
  26. }
  27. },
  28. // 是否允许通过点击遮罩关闭Picker
  29. maskCloseAble: {
  30. type: Boolean,
  31. default: true
  32. },
  33. // 弹出的z-index值
  34. zIndex: {
  35. type: [String, Number],
  36. default: 0
  37. }
  38. },
  39. data() {
  40. return {
  41. cityValue: "",
  42. isChooseP: false,
  43. //是否已经选择了省
  44. province: 0,
  45. //省级下标
  46. provinces: components_uCitySelect_province.provinceData,
  47. isChooseC: false,
  48. //是否已经选择了市
  49. city: 0,
  50. //市级下标
  51. citys: components_uCitySelect_city.cityData[0],
  52. isChooseA: false,
  53. //是否已经选择了区
  54. area: 0,
  55. //区级下标
  56. areas: components_uCitySelect_area.areaData[0][0],
  57. tabsIndex: 0
  58. };
  59. },
  60. mounted() {
  61. this.init();
  62. },
  63. computed: {
  64. isChange() {
  65. return this.tabsIndex > 1;
  66. },
  67. genTabsList() {
  68. let tabsList = [{
  69. name: "请选择"
  70. }];
  71. if (this.isChooseP) {
  72. tabsList[0]["name"] = this.provinces[this.province]["label"];
  73. tabsList[1] = {
  74. name: "请选择"
  75. };
  76. }
  77. if (this.isChooseC) {
  78. tabsList[1]["name"] = this.citys[this.city]["label"];
  79. tabsList[2] = {
  80. name: "请选择"
  81. };
  82. }
  83. if (this.isChooseA) {
  84. tabsList[2]["name"] = this.areas[this.area]["label"];
  85. }
  86. return tabsList;
  87. },
  88. uZIndex() {
  89. return this.zIndex ? this.zIndex : this.$u.zIndex.popup;
  90. }
  91. },
  92. emits: ["city-change"],
  93. methods: {
  94. init() {
  95. if (this.areaCode.length == 3) {
  96. this.setProvince("", this.areaCode[0]);
  97. this.setCity("", this.areaCode[1]);
  98. this.setArea("", this.areaCode[2]);
  99. } else if (this.defaultRegion.length == 3) {
  100. this.setProvince(this.defaultRegion[0], "");
  101. this.setCity(this.defaultRegion[1], "");
  102. this.setArea(this.defaultRegion[2], "");
  103. }
  104. },
  105. setProvince(label = "", value = "") {
  106. this.provinces.map((v, k) => {
  107. if (value ? v.value == value : v.label == label) {
  108. this.provinceChange(k);
  109. }
  110. });
  111. },
  112. setCity(label = "", value = "") {
  113. this.citys.map((v, k) => {
  114. if (value ? v.value == value : v.label == label) {
  115. this.cityChange(k);
  116. }
  117. });
  118. },
  119. setArea(label = "", value = "") {
  120. this.areas.map((v, k) => {
  121. if (value ? v.value == value : v.label == label) {
  122. this.isChooseA = true;
  123. this.area = k;
  124. }
  125. });
  126. },
  127. close() {
  128. this.$emit("update:modelValue", false);
  129. this.$emit("close");
  130. },
  131. tabsChange(value) {
  132. this.tabsIndex = value.index;
  133. },
  134. provinceChange(index) {
  135. this.isChooseP = true;
  136. this.isChooseC = false;
  137. this.isChooseA = false;
  138. this.province = index;
  139. this.citys = components_uCitySelect_city.cityData[index];
  140. this.tabsIndex = 1;
  141. },
  142. cityChange(index) {
  143. this.isChooseC = true;
  144. this.isChooseA = false;
  145. this.city = index;
  146. this.areas = components_uCitySelect_area.areaData[this.province][index];
  147. this.tabsIndex = 2;
  148. },
  149. areaChange(index) {
  150. this.isChooseA = true;
  151. this.area = index;
  152. let result = {};
  153. result.province = this.provinces[this.province];
  154. result.city = this.citys[this.city];
  155. result.area = this.areas[this.area];
  156. this.$emit("city-change", result);
  157. this.close();
  158. }
  159. }
  160. };
  161. if (!Array) {
  162. const _easycom_u_tabs2 = common_vendor.resolveComponent("u-tabs");
  163. const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  164. const _easycom_u_cell2 = common_vendor.resolveComponent("u-cell");
  165. const _easycom_u_cell_group2 = common_vendor.resolveComponent("u-cell-group");
  166. const _easycom_u_popup2 = common_vendor.resolveComponent("u-popup");
  167. (_easycom_u_tabs2 + _easycom_u_icon2 + _easycom_u_cell2 + _easycom_u_cell_group2 + _easycom_u_popup2)();
  168. }
  169. const _easycom_u_tabs = () => "../../node-modules/uview-plus/components/u-tabs/u-tabs.js";
  170. const _easycom_u_icon = () => "../../node-modules/uview-plus/components/u-icon/u-icon.js";
  171. const _easycom_u_cell = () => "../../node-modules/uview-plus/components/u-cell/u-cell.js";
  172. const _easycom_u_cell_group = () => "../../node-modules/uview-plus/components/u-cell-group/u-cell-group.js";
  173. const _easycom_u_popup = () => "../../node-modules/uview-plus/components/u-popup/u-popup.js";
  174. if (!Math) {
  175. (_easycom_u_tabs + _easycom_u_icon + _easycom_u_cell + _easycom_u_cell_group + _easycom_u_popup)();
  176. }
  177. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  178. return common_vendor.e({
  179. a: $props.modelValue
  180. }, $props.modelValue ? {
  181. b: common_vendor.sr("tabs", "20d8d7b0-1,20d8d7b0-0"),
  182. c: common_vendor.o($options.tabsChange),
  183. d: common_vendor.p({
  184. list: $options.genTabsList,
  185. scrollable: true,
  186. current: $data.tabsIndex
  187. })
  188. } : {}, {
  189. e: common_vendor.f($data.provinces, (item, index, i0) => {
  190. return common_vendor.e({
  191. a: $data.isChooseP && $data.province === index
  192. }, $data.isChooseP && $data.province === index ? {
  193. b: "20d8d7b0-4-" + i0 + "," + ("20d8d7b0-3-" + i0),
  194. c: common_vendor.p({
  195. size: "17",
  196. name: "checkbox-mark"
  197. })
  198. } : {}, {
  199. d: index,
  200. e: common_vendor.o(($event) => $options.provinceChange(index), index),
  201. f: "20d8d7b0-3-" + i0 + ",20d8d7b0-2",
  202. g: common_vendor.p({
  203. title: item.label,
  204. arrow: false,
  205. index
  206. })
  207. });
  208. }),
  209. f: $data.isChooseP
  210. }, $data.isChooseP ? {
  211. g: common_vendor.f($data.citys, (item, index, i0) => {
  212. return common_vendor.e({
  213. a: $data.isChooseC && $data.city === index
  214. }, $data.isChooseC && $data.city === index ? {
  215. b: "20d8d7b0-7-" + i0 + "," + ("20d8d7b0-6-" + i0),
  216. c: common_vendor.p({
  217. size: "17",
  218. name: "checkbox-mark"
  219. })
  220. } : {}, {
  221. d: index,
  222. e: common_vendor.o(($event) => $options.cityChange(index), index),
  223. f: "20d8d7b0-6-" + i0 + ",20d8d7b0-5",
  224. g: common_vendor.p({
  225. title: item.label,
  226. arrow: false,
  227. index
  228. })
  229. });
  230. })
  231. } : {}, {
  232. h: $data.isChooseC
  233. }, $data.isChooseC ? {
  234. i: common_vendor.f($data.areas, (item, index, i0) => {
  235. return common_vendor.e({
  236. a: $data.isChooseA && $data.area === index
  237. }, $data.isChooseA && $data.area === index ? {
  238. b: "20d8d7b0-10-" + i0 + "," + ("20d8d7b0-9-" + i0),
  239. c: common_vendor.p({
  240. size: "17",
  241. name: "checkbox-mark"
  242. })
  243. } : {}, {
  244. d: index,
  245. e: common_vendor.o(($event) => $options.areaChange(index), index),
  246. f: "20d8d7b0-9-" + i0 + ",20d8d7b0-8",
  247. g: common_vendor.p({
  248. title: item.label,
  249. arrow: false,
  250. index
  251. })
  252. });
  253. })
  254. } : {}, {
  255. j: $options.isChange ? 1 : "",
  256. k: common_vendor.o($options.close),
  257. l: common_vendor.p({
  258. show: $props.modelValue,
  259. mode: "bottom",
  260. popup: false,
  261. mask: true,
  262. closeable: true,
  263. ["safe-area-inset-bottom"]: true,
  264. ["close-icon-color"]: "#ffffff",
  265. ["z-index"]: $options.uZIndex,
  266. maskCloseAble: $props.maskCloseAble
  267. })
  268. });
  269. }
  270. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "C:/Users/Administrator/Desktop/srcaaa/components/u-city-select/u-city-select.vue"]]);
  271. wx.createComponent(Component);