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.

editAddress.vue 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <view class="form">
  3. <u-form label-width="132rpx" :model="state.formData" ref="uForm">
  4. <u-form-item label="收货人">
  5. <u-input placeholder="名字" :customStyle="btnGetCode" v-model="state.formData.consignee" />
  6. </u-form-item>
  7. <u-form-item label="手机号">
  8. <u-input placeholder="手机号" :customStyle="btnGetCode" type="number"
  9. v-model="state.formData.consigneeTel" />
  10. </u-form-item>
  11. <u-form-item label="所在地区">
  12. <u-input :customStyle="btnGetCode" type="select" :select-open="state.show"
  13. v-model="state.formData.region" placeholder="省 市 区" @click="state.show = true"></u-input>
  14. </u-form-item>
  15. <u-form-item label="详细地址">
  16. <u-input placeholder="小区楼栋/乡村名称" :customStyle="textareaStyle" v-model="state.formData.address" />
  17. </u-form-item>
  18. <u-form-item label="邮政编码">
  19. <u-input placeholder="邮政编码" :customStyle="btnGetCode" v-model="state.formData.postalCode" />
  20. </u-form-item>
  21. <view class="form-item forn-switch">
  22. <label>设置默认收货地址</label>
  23. <switch :checked="state.formData.defaultAddress==1" color="#43a1e0" style="transform:scale(0.75)"
  24. @change="changeSwitch"></switch>
  25. </view>
  26. </u-form>
  27. <view class="action">
  28. <button type="default" class="button-default" @click="deleteHandle()">删除</button>
  29. <button type="default" class="button" @click="savaHandle()">保存</button>
  30. </view>
  31. <u-picker mode="region" v-model="state.show" @confirm="regionConfirm"></u-picker>
  32. </view>
  33. </template>
  34. <script setup lang="ts">
  35. import {
  36. reactive
  37. } from "vue";
  38. import {
  39. onLoad
  40. } from "@dcloudio/uni-app";
  41. import {
  42. addOrEditAddressQuery,
  43. addressDelete
  44. } from "@/utils/network/api.js";
  45. import {
  46. request
  47. } from "@/utils/network/request.js";
  48. import {
  49. getItem,
  50. StorageKeys
  51. } from "@/utils/storage";
  52. import {
  53. msg
  54. } from "@/utils/utils";
  55. const btnGetCode = {
  56. background: "#F1F1F1",
  57. "border-radius": "20rpx",
  58. padding: "10rpx 20rpx",
  59. height: "40px",
  60. };
  61. const textareaStyle = {
  62. background: "#F1F1F1",
  63. "border-radius": "20rpx",
  64. padding: "20rpx 10rpx",
  65. };
  66. const state = reactive({
  67. formData: {
  68. consignee: "",
  69. consigneeTel: "",
  70. region: "",
  71. address: "",
  72. postalCode: "",
  73. defaultAddress: 2,
  74. openId: undefined,
  75. id: undefined,
  76. },
  77. show: false,
  78. });
  79. //switch 事件
  80. const changeSwitch = (e : any) => {
  81. console.log(e);
  82. state.formData.defaultAddress = e.detail.value ? 1 : 2;
  83. console.log(state.formData);
  84. };
  85. // 选择地区回调
  86. const regionConfirm = (e : any) => {
  87. state.formData.region = e.province.name + e.city.name + e.area.name;
  88. };
  89. const savaHandle = () => {
  90. state.formData.openId = getItem(StorageKeys.OpenId);
  91. queryAddOrEditAddress(addOrEditAddressQuery, state.formData);
  92. };
  93. const deleteHandle = () => {
  94. if (getItem(StorageKeys.OpenId)) {
  95. state.formData.openId = getItem(StorageKeys.OpenId);
  96. const options = {
  97. type: 2,
  98. data: state.formData,
  99. method: "POST",
  100. showLoading: true,
  101. };
  102. request(addressDelete, options).then((res) => {
  103. msg("删除地址成功");
  104. uni.navigateBack({
  105. delta: 1,
  106. });
  107. });
  108. } else {
  109. uni.navigateTo({
  110. url: `/subpackage/orders/essential-information?del=1`
  111. });
  112. }
  113. }
  114. /* 新增/编辑收货地址 */
  115. const queryAddOrEditAddress = (code, data) => {
  116. if (getItem(StorageKeys.OpenId)) {
  117. const options = {
  118. type: 2,
  119. data: data,
  120. method: "POST",
  121. showLoading: true,
  122. };
  123. request(code, options).then((res) => {
  124. msg("编辑地址成功");
  125. setTimeout(() => {
  126. uni.navigateBack({
  127. delta: 1,
  128. });
  129. }, 1500)
  130. });
  131. } else {
  132. uni.$emit('updateData', state.formData)
  133. uni.navigateBack({
  134. delta: 1,
  135. });
  136. }
  137. };
  138. onLoad((option) => {
  139. state.formData = JSON.parse(option.content);
  140. });
  141. </script>
  142. <style lang="scss" scoped>
  143. .form-item {
  144. display: flex;
  145. justify-content: space-between;
  146. align-items: center;
  147. font-size: 30rpx;
  148. padding: 20rpx 0;
  149. }
  150. .form {
  151. padding: 30rpx;
  152. }
  153. .action {
  154. padding-left: 20rpx;
  155. padding-right: 20rpx;
  156. padding-bottom: 30rpx;
  157. display: flex;
  158. width: 90%;
  159. justify-content: space-between;
  160. .button::after {
  161. border: none;
  162. }
  163. .button-default::after {
  164. border: none;
  165. }
  166. .button {
  167. height: 80rpx;
  168. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  169. border-radius: 40rpx;
  170. font-size: 32rpx;
  171. font-weight: 400;
  172. color: #ffffff;
  173. line-height: 80rpx;
  174. width: 45%;
  175. }
  176. .button-default {
  177. height: 80rpx;
  178. background: rgba(0, 179, 139, .1);
  179. border-radius: 40rpx;
  180. font-size: 32rpx;
  181. font-weight: 400;
  182. color: #00B38B;
  183. line-height: 80rpx;
  184. width: 45%;
  185. }
  186. }
  187. .white-action {
  188. padding-left: 20rpx;
  189. padding-right: 20rpx;
  190. padding-bottom: 30rpx;
  191. .button {
  192. height: 80rpx;
  193. border-radius: 40rpx;
  194. background: #ffffff;
  195. box-shadow: 0rpx 4rpx 11rpx 1rpx rgba(223, 223, 223, 0.5);
  196. font-size: 32rpx;
  197. font-weight: 400;
  198. color: #666666;
  199. line-height: 80rpx;
  200. }
  201. }
  202. </style>