爱简收旧衣按件回收前端代码仓库
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.

412 lines
14 KiB

  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const pages_subcomponent_regionData = require("./region-data.js");
  4. const pages_mixins_pullRefreshMixin = require("../mixins/pullRefreshMixin.js");
  5. const _sfc_main = {
  6. mixins: [pages_mixins_pullRefreshMixin.pullRefreshMixin],
  7. data() {
  8. return {
  9. statusBarHeight: 0,
  10. addressList: [
  11. {
  12. name: "郑文锦",
  13. phone: "18108341643",
  14. address: "海南省海口市秀英区秀英街道5单元183室",
  15. defaultFlag: "Y"
  16. },
  17. {
  18. name: "周俊",
  19. phone: "13293992217",
  20. address: "贵州省遵义市道真仡佬族苗族自治县洛龙镇5幢172室",
  21. defaultFlag: "N"
  22. },
  23. {
  24. name: "何炜",
  25. phone: "18108341643",
  26. address: "新疆维吾尔自治区乌鲁木齐市沙依巴克区仓房沟片区街道4单元50室",
  27. defaultFlag: "N"
  28. },
  29. {
  30. name: "赵晓艳",
  31. phone: "15022123314",
  32. address: "海南省海口市秀英区秀英街道5单元183室",
  33. defaultFlag: "N"
  34. },
  35. {
  36. name: "冯云",
  37. phone: "15731435825",
  38. address: "甘肃省兰州市城关区滑源路街道13幢199室",
  39. defaultFlag: "N"
  40. },
  41. {
  42. name: "钱皓皓",
  43. phone: "18734717201",
  44. address: "西藏自治区拉萨市堆龙德庆县东嘎镇7单元94室",
  45. defaultFlag: "N"
  46. }
  47. ],
  48. batchMode: false,
  49. selectedIndexes: [],
  50. showAddressModal: false,
  51. showRegionPicker: false,
  52. form: {
  53. name: "",
  54. phone: "",
  55. region: [],
  56. address: "",
  57. addressDetails: ""
  58. },
  59. provinces: pages_subcomponent_regionData.regionData,
  60. cities: [],
  61. districts: [],
  62. regionIndex: [0, 0, 0],
  63. mode: ""
  64. };
  65. },
  66. watch: {
  67. regionIndex: {
  68. handler(val) {
  69. var _a, _b, _c, _d;
  70. let pIdx = val[0] < this.provinces.length ? val[0] : 0;
  71. let cIdx = val[1] < (((_b = (_a = this.provinces[pIdx]) == null ? void 0 : _a.children) == null ? void 0 : _b.length) || 0) ? val[1] : 0;
  72. this.cities = ((_c = this.provinces[pIdx]) == null ? void 0 : _c.children) || [];
  73. this.districts = ((_d = this.cities[cIdx]) == null ? void 0 : _d.children) || [];
  74. },
  75. immediate: true
  76. }
  77. },
  78. onPullDownRefresh() {
  79. this.getAddressList(() => {
  80. common_vendor.index.stopPullDownRefresh();
  81. });
  82. },
  83. onLoad(options) {
  84. var _a, _b;
  85. this.statusBarHeight = common_vendor.index.getSystemInfoSync().statusBarHeight;
  86. this.cities = ((_a = this.provinces[0]) == null ? void 0 : _a.children) || [];
  87. this.districts = ((_b = this.cities[0]) == null ? void 0 : _b.children) || [];
  88. this.regionIndex = [0, 0, 0];
  89. this.getAddressList();
  90. this.mode = options.mode || "";
  91. },
  92. methods: {
  93. async onRefresh() {
  94. await new Promise((resolve) => setTimeout(resolve, 1e3));
  95. common_vendor.index.stopPullRefresh();
  96. },
  97. getAddressList(callback) {
  98. this.$api("getAddressList", {}, (res) => {
  99. if (res && res.result && res.result.records) {
  100. this.addressList = res.result.records;
  101. }
  102. if (typeof callback === "function")
  103. callback();
  104. });
  105. },
  106. goBack() {
  107. common_vendor.index.navigateBack();
  108. },
  109. startBatchDelete() {
  110. this.batchMode = true;
  111. this.selectedIndexes = [];
  112. },
  113. cancelBatchDelete() {
  114. this.batchMode = false;
  115. this.selectedIndexes = [];
  116. },
  117. selectItem(index) {
  118. if (!this.batchMode)
  119. return;
  120. const idx = this.selectedIndexes.indexOf(index);
  121. if (idx > -1) {
  122. this.selectedIndexes.splice(idx, 1);
  123. } else {
  124. this.selectedIndexes.push(index);
  125. }
  126. },
  127. confirmDelete() {
  128. if (this.selectedIndexes.length === 0)
  129. return;
  130. common_vendor.index.showModal({
  131. title: "提示",
  132. content: "确定要删除选中的地址吗?",
  133. success: (res) => {
  134. if (res.confirm) {
  135. this.selectedIndexes.sort((a, b) => b - a).forEach((index) => {
  136. this.addressList.splice(index, 1);
  137. });
  138. this.batchMode = false;
  139. this.selectedIndexes = [];
  140. }
  141. }
  142. });
  143. },
  144. editAddress(item) {
  145. var _a, _b;
  146. this.showAddressModal = true;
  147. this.form = {
  148. id: item.id,
  149. name: item.name,
  150. phone: item.phone,
  151. region: [],
  152. address: item.address,
  153. addressDetails: item.addressDetails,
  154. defaultFlag: item.defaultFlag
  155. };
  156. this.regionIndex = [0, 0, 0];
  157. this.cities = ((_a = this.provinces[0]) == null ? void 0 : _a.children) || [];
  158. this.districts = ((_b = this.cities[0]) == null ? void 0 : _b.children) || [];
  159. },
  160. goToAddAddress() {
  161. var _a, _b;
  162. this.showAddressModal = true;
  163. this.form = {
  164. id: void 0,
  165. name: "",
  166. phone: "",
  167. region: [],
  168. address: "",
  169. addressDetails: ""
  170. };
  171. this.regionIndex = [0, 0, 0];
  172. this.cities = ((_a = this.provinces[0]) == null ? void 0 : _a.children) || [];
  173. this.districts = ((_b = this.cities[0]) == null ? void 0 : _b.children) || [];
  174. },
  175. selectAddress(address) {
  176. if (this.mode === "select") {
  177. common_vendor.index.$emit("addressSelected", {
  178. id: address.id,
  179. name: address.name,
  180. phone: address.phone,
  181. address: address.address,
  182. addressDetails: address.addressDetails
  183. });
  184. common_vendor.index.navigateBack();
  185. }
  186. },
  187. closeAddressModal() {
  188. this.showAddressModal = false;
  189. },
  190. saveAddress() {
  191. if (!this.form.name)
  192. return common_vendor.index.showToast({ title: "请输入联系人", icon: "none" });
  193. if (!this.form.phone)
  194. return common_vendor.index.showToast({ title: "请输入手机号", icon: "none" });
  195. if (!this.form.address)
  196. return common_vendor.index.showToast({ title: "请选择地区", icon: "none" });
  197. if (!this.form.addressDetails)
  198. return common_vendor.index.showToast({ title: "请输入详细地址", icon: "none" });
  199. const params = {
  200. name: this.form.name,
  201. phone: this.form.phone,
  202. address: this.form.address,
  203. addressDetails: this.form.addressDetails,
  204. defaultFlag: this.form.defaultFlag
  205. };
  206. if (this.form.id)
  207. params.id = this.form.id;
  208. this.$api("saveOrUpdateAddress", params, (res) => {
  209. if (res.code == 200) {
  210. common_vendor.index.showToast({ title: "保存成功", icon: "success" });
  211. this.closeAddressModal();
  212. this.getAddressList();
  213. }
  214. });
  215. },
  216. onRegionChange(e) {
  217. let [pIdx, cIdx, dIdx] = e.detail.value;
  218. if (pIdx !== this.regionIndex[0]) {
  219. cIdx = 0;
  220. dIdx = 0;
  221. } else if (cIdx !== this.regionIndex[1]) {
  222. dIdx = 0;
  223. }
  224. this.regionIndex = [pIdx, cIdx, dIdx];
  225. },
  226. confirmRegion() {
  227. const province = this.provinces[this.regionIndex[0]];
  228. const city = this.cities[this.regionIndex[1]];
  229. const district = this.districts[this.regionIndex[2]];
  230. this.form.region = [
  231. (province == null ? void 0 : province.code) || "",
  232. (city == null ? void 0 : city.code) || "",
  233. (district == null ? void 0 : district.code) || ""
  234. ];
  235. this.form.address = [
  236. (province == null ? void 0 : province.name) || "",
  237. (city == null ? void 0 : city.name) || "",
  238. (district == null ? void 0 : district.name) || ""
  239. ].filter(Boolean).join(" ");
  240. this.showRegionPicker = false;
  241. },
  242. setDefault(id) {
  243. const address = this.addressList.find((item) => item.id === id);
  244. const defaultFlag = address.defaultFlag === "Y" ? "N" : "Y";
  245. this.$api("updateDefaultAddress", {
  246. id
  247. }, (res) => {
  248. if (res.code == 200) {
  249. common_vendor.index.showToast({
  250. title: defaultFlag === "Y" ? "设置成功" : "已取消默认",
  251. icon: "success"
  252. });
  253. this.getAddressList();
  254. }
  255. });
  256. },
  257. deleteAddress(id) {
  258. common_vendor.index.showModal({
  259. title: "提示",
  260. content: "确定要删除该地址吗?",
  261. success: (res) => {
  262. if (res.confirm) {
  263. this.$api("deleteAddress", { id }, (res2) => {
  264. if (res2.code == 200) {
  265. common_vendor.index.showToast({
  266. title: "删除成功",
  267. icon: "success"
  268. });
  269. this.getAddressList();
  270. }
  271. });
  272. }
  273. }
  274. });
  275. },
  276. initRegionPicker() {
  277. var _a, _b;
  278. if (this.form.region.length > 0) {
  279. const [provinceCode, cityCode, districtCode] = this.form.region;
  280. const provinceIndex = this.provinces.findIndex((p) => p.code === provinceCode);
  281. if (provinceIndex > -1) {
  282. this.cities = this.provinces[provinceIndex].children || [];
  283. if (this.cities.length === 0) {
  284. this.cities = [{ code: "", name: "请选择" }];
  285. }
  286. const cityIndex = this.cities.findIndex((c) => c.code === cityCode);
  287. if (cityIndex > -1) {
  288. this.districts = this.cities[cityIndex].children || [];
  289. if (this.districts.length === 0) {
  290. this.districts = [{ code: "", name: "请选择" }];
  291. }
  292. const districtIndex = this.districts.findIndex((d) => d.code === districtCode);
  293. this.regionIndex = [
  294. provinceIndex,
  295. cityIndex,
  296. districtIndex > -1 ? districtIndex : 0
  297. ];
  298. return;
  299. }
  300. }
  301. }
  302. this.cities = ((_a = this.provinces[0]) == null ? void 0 : _a.children) || [];
  303. if (this.cities.length === 0) {
  304. this.cities = [{ code: "", name: "请选择" }];
  305. }
  306. this.districts = ((_b = this.cities[0]) == null ? void 0 : _b.children) || [];
  307. if (this.districts.length === 0) {
  308. this.districts = [{ code: "", name: "请选择" }];
  309. }
  310. this.regionIndex = [0, 0, 0];
  311. }
  312. }
  313. };
  314. if (!Array) {
  315. const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
  316. _easycom_uni_icons2();
  317. }
  318. const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
  319. if (!Math) {
  320. _easycom_uni_icons();
  321. }
  322. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  323. return common_vendor.e({
  324. a: common_vendor.p({
  325. type: "left",
  326. size: "20"
  327. }),
  328. b: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)),
  329. c: $data.statusBarHeight + 88 + "rpx",
  330. d: $data.statusBarHeight + "px",
  331. e: common_vendor.f($data.addressList, (item, index, i0) => {
  332. return common_vendor.e({
  333. a: common_vendor.t(item.name),
  334. b: common_vendor.t(item.phone),
  335. c: item.defaultFlag === "Y"
  336. }, item.defaultFlag === "Y" ? {} : {}, {
  337. d: common_vendor.t(item.address),
  338. e: common_vendor.t(item.addressDetails),
  339. f: item.defaultFlag === "Y"
  340. }, item.defaultFlag === "Y" ? {} : {}, {
  341. g: item.defaultFlag === "Y" ? 1 : "",
  342. h: item.defaultFlag === "Y" ? 1 : "",
  343. i: common_vendor.o(($event) => $options.setDefault(item.id), index),
  344. j: "d2c808da-1-" + i0,
  345. k: common_vendor.o(($event) => $options.editAddress(item), index),
  346. l: "d2c808da-2-" + i0,
  347. m: common_vendor.o(($event) => $options.deleteAddress(item.id), index),
  348. n: common_vendor.o(($event) => $options.selectAddress(item), index),
  349. o: index
  350. });
  351. }),
  352. f: common_vendor.p({
  353. type: "compose",
  354. size: "22",
  355. color: "#bbb"
  356. }),
  357. g: common_vendor.p({
  358. type: "trash",
  359. size: "22",
  360. color: "#bbb"
  361. }),
  362. h: common_vendor.o((...args) => $options.goToAddAddress && $options.goToAddAddress(...args)),
  363. i: $data.showAddressModal
  364. }, $data.showAddressModal ? {
  365. j: common_vendor.o((...args) => $options.closeAddressModal && $options.closeAddressModal(...args))
  366. } : {}, {
  367. k: $data.showAddressModal
  368. }, $data.showAddressModal ? {
  369. l: common_vendor.o((...args) => $options.closeAddressModal && $options.closeAddressModal(...args)),
  370. m: common_vendor.t($data.form.id ? "编辑地址" : "新建地址"),
  371. n: $data.form.name,
  372. o: common_vendor.o(($event) => $data.form.name = $event.detail.value),
  373. p: $data.form.phone,
  374. q: common_vendor.o(($event) => $data.form.phone = $event.detail.value),
  375. r: common_vendor.t($data.form.address || "选择省市区街道"),
  376. s: !$data.form.address ? 1 : "",
  377. t: common_vendor.o(($event) => $data.showRegionPicker = true),
  378. v: $data.form.addressDetails,
  379. w: common_vendor.o(($event) => $data.form.addressDetails = $event.detail.value),
  380. x: common_vendor.o((...args) => $options.saveAddress && $options.saveAddress(...args))
  381. } : {}, {
  382. y: $data.showRegionPicker
  383. }, $data.showRegionPicker ? {
  384. z: common_vendor.o(($event) => $data.showRegionPicker = false),
  385. A: common_vendor.f($data.provinces, (item, index, i0) => {
  386. return {
  387. a: common_vendor.t(item.name),
  388. b: index
  389. };
  390. }),
  391. B: common_vendor.f($data.cities, (item, index, i0) => {
  392. return {
  393. a: common_vendor.t(item.name),
  394. b: index
  395. };
  396. }),
  397. C: common_vendor.f($data.districts, (item, index, i0) => {
  398. return {
  399. a: common_vendor.t(item.name),
  400. b: index
  401. };
  402. }),
  403. D: $data.regionIndex,
  404. E: common_vendor.o((...args) => $options.onRegionChange && $options.onRegionChange(...args)),
  405. F: common_vendor.o((...args) => $options.confirmRegion && $options.confirmRegion(...args))
  406. } : {}, {
  407. G: $data.statusBarHeight + 88 + "rpx"
  408. });
  409. }
  410. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-d2c808da"]]);
  411. wx.createPage(MiniProgramPage);
  412. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/subcomponent/select.js.map