租房小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

275 lines
8.2 KiB

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