addAddress.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. "use strict";
  2. const common_vendor = require("../common/vendor.js");
  3. const api_order = require("../api/order.js");
  4. const common_assets = require("../common/assets.js");
  5. const EvanSwitch = () => "../components/evan-switch/evan-switch.js";
  6. const _sfc_main = {
  7. components: {
  8. EvanSwitch
  9. },
  10. data() {
  11. return {
  12. content: null,
  13. type: null,
  14. addressId: null,
  15. // isDefault: false,
  16. multiIndex: [0, 0, 0],
  17. address: [],
  18. addressList: [
  19. [],
  20. [],
  21. []
  22. ],
  23. form: {
  24. realName: null,
  25. phone: null,
  26. addressId: null,
  27. province: null,
  28. city: null,
  29. district: null,
  30. // cityIds:null,
  31. // postCode:null,
  32. // longitude:null,
  33. // latitude:null,
  34. detail: null,
  35. // address: null,
  36. isDefault: 0
  37. }
  38. };
  39. },
  40. onLoad(option) {
  41. console.log("option", option);
  42. this.type = option.type;
  43. if (this.type == "edit") {
  44. common_vendor.index.setNavigationBarTitle({
  45. title: "修改收货地址"
  46. });
  47. this.form.addressId = option.addressId;
  48. this.addressId = option.addressId;
  49. this.getAddressById();
  50. } else {
  51. common_vendor.index.setNavigationBarTitle({
  52. title: "新增收货地址"
  53. });
  54. }
  55. this.getCitys();
  56. },
  57. methods: {
  58. logChange(value) {
  59. console.log("isDefault 新值:", value);
  60. },
  61. parseAddress() {
  62. if (this.content == null || this.content == "") {
  63. common_vendor.index.showToast({
  64. icon: "none",
  65. title: "请输入地址信息"
  66. });
  67. return;
  68. }
  69. var data = {
  70. content: this.content
  71. };
  72. api_order.parseAddress(data).then(
  73. (res) => {
  74. if (res.code == 200) {
  75. this.form.realName = res.data.name;
  76. this.form.phone = res.data.mobile;
  77. this.form.address = res.data.provinceName + res.data.cityName + res.data.expAreaName;
  78. this.form.province = res.data.provinceName;
  79. this.form.city = res.data.cityName;
  80. this.form.district = res.data.expAreaName;
  81. this.form.detail = res.data.streetName + res.data.address;
  82. } else {
  83. common_vendor.index.showToast({
  84. icon: "none",
  85. title: res.msg
  86. });
  87. }
  88. },
  89. (rej) => {
  90. }
  91. );
  92. },
  93. getAddressById() {
  94. var data = {
  95. addressId: this.addressId
  96. };
  97. api_order.getAddressById(data).then(
  98. (res) => {
  99. if (res.code == 200) {
  100. this.form = res.data;
  101. console.log(" this.form", this.form);
  102. this.isDefault = this.form.isDefault == 1 ? true : false;
  103. this.form.address = this.form.province + this.form.city + this.form.district;
  104. } else {
  105. common_vendor.index.showToast({
  106. icon: "none",
  107. title: res.msg
  108. });
  109. }
  110. },
  111. (rej) => {
  112. }
  113. );
  114. },
  115. submit() {
  116. console.log("提交数据:", JSON.stringify(this.form));
  117. if (this.type == "add") {
  118. this.addAddress();
  119. } else if (this.type == "edit") {
  120. this.editAddress();
  121. }
  122. },
  123. editAddress() {
  124. this.form.isDefault = this.isDefault ? 1 : 0;
  125. api_order.editAddress(submitData).then(
  126. (res) => {
  127. if (res.code == 200) {
  128. common_vendor.index.showToast({
  129. icon: "success",
  130. title: "操作成功"
  131. });
  132. setTimeout(function() {
  133. common_vendor.index.$emit("refreshAddress");
  134. common_vendor.index.navigateBack({
  135. delta: 1
  136. });
  137. }, 500);
  138. } else {
  139. common_vendor.index.showToast({
  140. icon: "none",
  141. title: res.msg
  142. });
  143. }
  144. },
  145. (rej) => {
  146. }
  147. );
  148. },
  149. addAddress() {
  150. this.form.isDefault = this.isDefault ? 1 : 0;
  151. api_order.addAddress(this.form).then(
  152. (res) => {
  153. if (res.code == 200) {
  154. common_vendor.index.showToast({
  155. icon: "success",
  156. title: "操作成功"
  157. });
  158. setTimeout(function() {
  159. common_vendor.index.$emit("refreshAddress");
  160. common_vendor.index.navigateBack({
  161. delta: 1
  162. });
  163. }, 500);
  164. } else {
  165. common_vendor.index.showToast({
  166. icon: "none",
  167. title: res.msg
  168. });
  169. }
  170. },
  171. (rej) => {
  172. }
  173. );
  174. },
  175. // 地区选择
  176. pickerChange(e) {
  177. this.multiIndex = e.detail.value;
  178. this.form.address = this.addressList[0][this.multiIndex[0]].n + this.addressList[1][this.multiIndex[1]].n + this.addressList[2][this.multiIndex[2]].n;
  179. this.form.province = this.addressList[0][this.multiIndex[0]].n;
  180. this.form.city = this.addressList[1][this.multiIndex[1]].n;
  181. this.form.district = this.addressList[2][this.multiIndex[2]].n;
  182. this.form.cityId = this.addressList[1][this.multiIndex[1]].v;
  183. },
  184. pickerColumnchange(e) {
  185. if (e.detail.column === 0) {
  186. this.multiIndex[0] = e.detail.value;
  187. this.addressList[1] = this.address[this.multiIndex[0]].c;
  188. this.addressList[2] = this.address[this.multiIndex[0]].c[0].c;
  189. this.multiIndex.splice(1, 1, 0);
  190. this.multiIndex.splice(2, 1, 0);
  191. }
  192. if (e.detail.column === 1) {
  193. this.multiIndex[1] = e.detail.value;
  194. this.addressList[2] = this.address[this.multiIndex[0]].c[this.multiIndex[1]].c;
  195. this.multiIndex.splice(2, 1, 0);
  196. }
  197. if (e.detail.column === 2) {
  198. this.multiIndex[2] = e.detail.value;
  199. }
  200. },
  201. getCitys() {
  202. api_order.getCitys().then(
  203. (res) => {
  204. if (res.code == 200) {
  205. this.address = res.data;
  206. for (var i = 0; i < this.address.length; i++) {
  207. this.addressList[0].push(this.address[i]);
  208. }
  209. for (var i = 0; i < this.address[0].c.length; i++) {
  210. this.addressList[1].push(this.address[0].c[i]);
  211. }
  212. for (var i = 0; i < this.address[0].c[0].c.length; i++) {
  213. this.addressList[2].push(this.address[0].c[0].c[i]);
  214. }
  215. } else {
  216. common_vendor.index.showToast({
  217. icon: "none",
  218. title: "请求失败"
  219. });
  220. }
  221. },
  222. (rej) => {
  223. }
  224. );
  225. }
  226. }
  227. };
  228. if (!Array) {
  229. const _easycom_evan_switch2 = common_vendor.resolveComponent("evan-switch");
  230. _easycom_evan_switch2();
  231. }
  232. const _easycom_evan_switch = () => "../components/evan-switch/evan-switch.js";
  233. if (!Math) {
  234. _easycom_evan_switch();
  235. }
  236. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  237. return {
  238. a: $data.content,
  239. b: common_vendor.o(($event) => $data.content = $event.detail.value),
  240. c: common_vendor.o(($event) => $options.parseAddress()),
  241. d: $data.form.realName,
  242. e: common_vendor.o(($event) => $data.form.realName = $event.detail.value),
  243. f: $data.form.phone,
  244. g: common_vendor.o(($event) => $data.form.phone = $event.detail.value),
  245. h: $data.form.address,
  246. i: common_vendor.o(($event) => $data.form.address = $event.detail.value),
  247. j: common_assets._imports_0$11,
  248. k: $data.multiIndex,
  249. l: $data.addressList,
  250. m: common_vendor.o((...args) => $options.pickerChange && $options.pickerChange(...args)),
  251. n: common_vendor.o((...args) => $options.pickerColumnchange && $options.pickerColumnchange(...args)),
  252. o: $data.form.detail,
  253. p: common_vendor.o(($event) => $data.form.detail = $event.detail.value),
  254. q: common_vendor.o($options.logChange),
  255. r: common_vendor.o(($event) => _ctx.isDefault = $event),
  256. s: common_vendor.p({
  257. activeColor: "#0bb3f2",
  258. inactiveColor: "rgba(0, 0, 0, 0.1)",
  259. modelValue: _ctx.isDefault
  260. }),
  261. t: common_vendor.o(($event) => $options.submit())
  262. };
  263. }
  264. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  265. wx.createPage(MiniProgramPage);