Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <view class="form">
  3. <u-form label-width="120rpx" :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" type="textarea"
  17. v-model="state.formData.address" />
  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. <u-form-item label-width="240rpx" label="设置默认收货地址">
  23. <u-switch v-model="state.formData.defaultAddress" active-color="#25D8C9" :active-value="1"
  24. :inactive-value="2"></u-switch>
  25. </u-form-item>
  26. </u-form>
  27. <view class="action">
  28. <button type="default" class="button" @click="savaHandle()">保存</button>
  29. <button style="margin-top: 30rpx;" type="default" class="button-default" @click="deleteHandle()">删除</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. // 选择地区回调
  80. const regionConfirm = (e: any) => {
  81. state.formData.region = e.province.name + e.city.name + e.area.name;
  82. };
  83. const savaHandle = () => {
  84. state.formData.openId = getItem(StorageKeys.OpenId);
  85. queryAddOrEditAddress(addOrEditAddressQuery, state.formData);
  86. };
  87. const deleteHandle = () => {
  88. state.formData.openId = getItem(StorageKeys.OpenId);
  89. const options = {
  90. type: 2,
  91. data: state.formData,
  92. method: "POST",
  93. showLoading: true,
  94. };
  95. request(addressDelete, options).then((res) => {
  96. msg("删除地址成功");
  97. uni.navigateBack({
  98. delta: 1,
  99. });
  100. });
  101. }
  102. /* 新增/编辑收货地址 */
  103. const queryAddOrEditAddress = (code, data) => {
  104. const options = {
  105. type: 2,
  106. data: data,
  107. method: "POST",
  108. showLoading: true,
  109. };
  110. request(code, options).then((res) => {
  111. msg("编辑地址成功");
  112. uni.navigateBack({
  113. delta: 1,
  114. });
  115. });
  116. };
  117. onLoad((option) => {
  118. state.formData = JSON.parse(option.content);
  119. });
  120. </script>
  121. <style lang="scss" scoped>
  122. .form {
  123. padding: 30rpx;
  124. }
  125. .action {
  126. padding-left: 20rpx;
  127. padding-right: 20rpx;
  128. padding-bottom: 30rpx;
  129. .button {
  130. height: 80rpx;
  131. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  132. border-radius: 40rpx;
  133. font-size: 32rpx;
  134. font-weight: 400;
  135. color: #ffffff;
  136. line-height: 80rpx;
  137. }
  138. .button-default {
  139. height: 80rpx;
  140. background: #ccc;
  141. border-radius: 40rpx;
  142. font-size: 32rpx;
  143. font-weight: 400;
  144. color: #333;
  145. line-height: 80rpx;
  146. }
  147. }
  148. .white-action {
  149. padding-left: 20rpx;
  150. padding-right: 20rpx;
  151. padding-bottom: 30rpx;
  152. .button {
  153. height: 80rpx;
  154. border-radius: 40rpx;
  155. background: #ffffff;
  156. box-shadow: 0rpx 4rpx 11rpx 1rpx rgba(223, 223, 223, 0.5);
  157. font-size: 32rpx;
  158. font-weight: 400;
  159. color: #666666;
  160. line-height: 80rpx;
  161. }
  162. }
  163. </style>