addEditAddress.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. "use strict";
  2. var common_vendor = require("../common/vendor.js");
  3. var api_common = require("../api/common.js");
  4. var api_userAddress = require("../api/userAddress.js");
  5. require("../common/request.js");
  6. const _sfc_main = {
  7. components: {},
  8. data() {
  9. return {
  10. content: null,
  11. type: null,
  12. addressId: null,
  13. isDefault: false,
  14. addressList: [[], [], []],
  15. multiIndex: [0, 0, 0],
  16. address: [],
  17. form: {
  18. realName: null,
  19. phone: null,
  20. detail: null,
  21. address: null,
  22. isDefault: 0
  23. }
  24. };
  25. },
  26. onLoad(option) {
  27. this.type = option.type;
  28. if (this.type == "edit") {
  29. common_vendor.index.setNavigationBarTitle({
  30. title: "\u4FEE\u6539\u6536\u8D27\u5730\u5740"
  31. });
  32. this.addressId = option.addressId;
  33. this.getAddressById();
  34. } else {
  35. common_vendor.index.setNavigationBarTitle({
  36. title: "\u65B0\u589E\u6536\u8D27\u5730\u5740"
  37. });
  38. }
  39. this.getCitys();
  40. },
  41. methods: {
  42. parseAddress() {
  43. if (this.content == null || this.content == "") {
  44. common_vendor.index.showToast({
  45. icon: "none",
  46. title: "\u8BF7\u8F93\u5165\u5730\u5740\u4FE1\u606F"
  47. });
  48. return;
  49. }
  50. var data = { content: this.content };
  51. api_userAddress.parseAddress(data).then((res) => {
  52. if (res.code == 200) {
  53. this.form.realName = res.data.name;
  54. this.form.phone = res.data.mobile;
  55. this.form.address = res.data.provinceName + res.data.cityName + res.data.expAreaName;
  56. this.form.province = res.data.provinceName;
  57. this.form.city = res.data.cityName;
  58. this.form.district = res.data.expAreaName;
  59. this.form.detail = res.data.streetName + res.data.address;
  60. this.form.detail = this.form.detail.replace(/\s+/g, "");
  61. } else {
  62. common_vendor.index.showToast({
  63. icon: "none",
  64. title: res.msg
  65. });
  66. }
  67. }, (rej) => {
  68. });
  69. },
  70. getAddressById() {
  71. var data = { addressId: this.addressId };
  72. api_userAddress.getAddressById(data).then((res) => {
  73. if (res.code == 200) {
  74. this.form = res.data;
  75. this.isDefault = this.form.isDefault == 1 ? true : false;
  76. this.form.address = this.form.province + this.form.city + this.form.district;
  77. } else {
  78. common_vendor.index.showToast({
  79. icon: "none",
  80. title: res.msg
  81. });
  82. }
  83. }, (rej) => {
  84. });
  85. },
  86. submit() {
  87. if (this.type == "add") {
  88. this.addAddress();
  89. } else if (this.type == "edit") {
  90. this.editAddress();
  91. }
  92. },
  93. editAddress() {
  94. this.form.isDefault = this.isDefault ? 1 : 0;
  95. api_userAddress.editAddress(this.form).then((res) => {
  96. if (res.code == 200) {
  97. common_vendor.index.showToast({
  98. icon: "success",
  99. title: "\u64CD\u4F5C\u6210\u529F"
  100. });
  101. setTimeout(function() {
  102. common_vendor.index.$emit("refreshAddress");
  103. common_vendor.index.navigateBack({
  104. delta: 1
  105. });
  106. }, 500);
  107. } else {
  108. common_vendor.index.showToast({
  109. icon: "none",
  110. title: res.msg
  111. });
  112. }
  113. }, (rej) => {
  114. });
  115. },
  116. addAddress() {
  117. this.form.isDefault = this.isDefault ? 1 : 0;
  118. api_userAddress.addAddress(this.form).then((res) => {
  119. if (res.code == 200) {
  120. common_vendor.index.showToast({
  121. icon: "success",
  122. title: "\u64CD\u4F5C\u6210\u529F"
  123. });
  124. setTimeout(function() {
  125. common_vendor.index.$emit("refreshAddress");
  126. common_vendor.index.navigateBack({
  127. delta: 1
  128. });
  129. }, 500);
  130. } else {
  131. common_vendor.index.showToast({
  132. icon: "none",
  133. title: res.msg
  134. });
  135. }
  136. }, (rej) => {
  137. });
  138. },
  139. pickerChange(e) {
  140. this.multiIndex = e.detail.value;
  141. this.form.address = this.addressList[0][this.multiIndex[0]].n + this.addressList[1][this.multiIndex[1]].n + this.addressList[2][this.multiIndex[2]].n;
  142. this.form.province = this.addressList[0][this.multiIndex[0]].n;
  143. this.form.city = this.addressList[1][this.multiIndex[1]].n;
  144. this.form.district = this.addressList[2][this.multiIndex[2]].n;
  145. this.form.cityId = this.addressList[1][this.multiIndex[1]].v;
  146. },
  147. pickerColumnchange(e) {
  148. if (e.detail.column === 0) {
  149. this.multiIndex[0] = e.detail.value;
  150. this.addressList[1] = this.address[this.multiIndex[0]].c;
  151. this.addressList[2] = this.address[this.multiIndex[0]].c[0].c;
  152. this.multiIndex.splice(1, 1, 0);
  153. this.multiIndex.splice(2, 1, 0);
  154. }
  155. if (e.detail.column === 1) {
  156. this.multiIndex[1] = e.detail.value;
  157. this.addressList[2] = this.address[this.multiIndex[0]].c[this.multiIndex[1]].c;
  158. this.multiIndex.splice(2, 1, 0);
  159. }
  160. if (e.detail.column === 2) {
  161. this.multiIndex[2] = e.detail.value;
  162. }
  163. },
  164. getCitys() {
  165. api_common.getCitys().then((res) => {
  166. if (res.code == 200) {
  167. this.address = res.data;
  168. for (var i = 0; i < this.address.length; i++) {
  169. this.addressList[0].push(this.address[i]);
  170. }
  171. for (var i = 0; i < this.address[0].c.length; i++) {
  172. this.addressList[1].push(this.address[0].c[i]);
  173. }
  174. for (var i = 0; i < this.address[0].c[0].c.length; i++) {
  175. this.addressList[2].push(this.address[0].c[0].c[i]);
  176. }
  177. } else {
  178. common_vendor.index.showToast({
  179. icon: "none",
  180. title: "\u8BF7\u6C42\u5931\u8D25"
  181. });
  182. }
  183. }, (rej) => {
  184. });
  185. }
  186. }
  187. };
  188. if (!Array) {
  189. const _easycom_u_switch2 = common_vendor.resolveComponent("u-switch");
  190. _easycom_u_switch2();
  191. }
  192. const _easycom_u_switch = () => "../uni_modules/uview-plus/components/u-switch/u-switch.js";
  193. if (!Math) {
  194. _easycom_u_switch();
  195. }
  196. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  197. return {
  198. a: $data.form.realName,
  199. b: common_vendor.o(($event) => $data.form.realName = $event.detail.value),
  200. c: $data.form.phone,
  201. d: common_vendor.o(($event) => $data.form.phone = $event.detail.value),
  202. e: $data.form.address,
  203. f: common_vendor.o(($event) => $data.form.address = $event.detail.value),
  204. g: $data.multiIndex,
  205. h: $data.addressList,
  206. i: common_vendor.o((...args) => $options.pickerChange && $options.pickerChange(...args)),
  207. j: common_vendor.o((...args) => $options.pickerColumnchange && $options.pickerColumnchange(...args)),
  208. k: $data.form.detail,
  209. l: common_vendor.o(($event) => $data.form.detail = $event.detail.value),
  210. m: $data.content,
  211. n: common_vendor.o(($event) => $data.content = $event.detail.value),
  212. o: common_vendor.o(($event) => $options.parseAddress()),
  213. p: common_vendor.o(($event) => $data.isDefault = $event),
  214. q: common_vendor.p({
  215. activeColor: "#C39A58",
  216. modelValue: $data.isDefault
  217. }),
  218. r: common_vendor.o(($event) => $options.submit())
  219. };
  220. }
  221. var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "E:/Project/2023/\u95EE\u8BCA\u5E73\u53F0/his_user_miniapp/pages_user/addEditAddress.vue"]]);
  222. wx.createPage(MiniProgramPage);