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 5.0KB

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