Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

editAddress.vue 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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" maxlength="20" />
  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. <picker mode="region" :value="state.formData.region" @change="regionConfirm">
  13. <view class="choice-picker">{{state.formData.region?state.formData.region:"请选择"}}</view>
  14. </picker>
  15. </u-form-item>
  16. <u-form-item label="详细地址">
  17. <u-input placeholder="小区楼栋/乡村名称" :customStyle="textareaStyle" v-model="state.formData.address" maxlength="50" />
  18. </u-form-item>
  19. <u-form-item label="邮政编码">
  20. <u-input placeholder="邮政编码" :customStyle="btnGetCode" v-model="state.formData.postalCode" type="number"
  21. maxlength="6" />
  22. </u-form-item>
  23. <view class="form-item forn-switch">
  24. <label>设置默认收货地址</label>
  25. <switch :checked="state.formData.defaultAddress==1" color="#004576" style="transform:scale(0.75)"
  26. @change="changeSwitch"></switch>
  27. </view>
  28. </u-form>
  29. <view class="action">
  30. <button type="default" class="btns" @click="savaHandle()">保存</button>
  31. <button type="default" class="btns del" @click="deleteHandle()">删除</button>
  32. </view>
  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. addressAdd,
  44. addressDeleteNew
  45. } from "@/utils/network/api.js";
  46. import {
  47. request, requestNew
  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. });
  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.detail.value[0] + e.detail.value[1] + e.detail.value[2];
  88. };
  89. const savaHandle = () => {
  90. state.formData.openId = getItem(StorageKeys.OpenId);
  91. queryAddOrEditAddress(addressAdd, 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. console.log(options, '删除请求参数');
  103. requestNew(addressDeleteNew, options).then((res) => {
  104. console.log(res, '删除');
  105. msg("删除地址成功");
  106. setTimeout(() => {
  107. uni.navigateBack({
  108. delta: 1,
  109. });
  110. }, 1500)
  111. });
  112. } else {
  113. uni.navigateTo({
  114. url: `/subpackage/orders/essential-information?del=1`
  115. });
  116. }
  117. }
  118. /* 新增/编辑收货地址 */
  119. const queryAddOrEditAddress = (code, data) => {
  120. if (getItem(StorageKeys.OpenId)) {
  121. const options = {
  122. type: 2,
  123. data: data,
  124. method: "POST",
  125. showLoading: true,
  126. };
  127. requestNew(code, options).then((res) => {
  128. msg("编辑地址成功");
  129. setTimeout(() => {
  130. uni.navigateBack({
  131. delta: 1,
  132. });
  133. }, 1500)
  134. });
  135. } else {
  136. uni.$emit('updateData', state.formData)
  137. uni.navigateBack({
  138. delta: 1,
  139. });
  140. }
  141. };
  142. onLoad((option) => {
  143. state.formData = JSON.parse(option.content);
  144. });
  145. </script>
  146. <style lang="scss" scoped>
  147. .form-item {
  148. display: flex;
  149. justify-content: space-between;
  150. align-items: center;
  151. font-size: 30rpx;
  152. padding: 20rpx 0;
  153. }
  154. .form {
  155. padding: 30rpx;
  156. }
  157. .action {
  158. padding-left: 20rpx;
  159. padding-right: 20rpx;
  160. padding-bottom: 30rpx;
  161. .button::after {
  162. border: none;
  163. }
  164. .button-default::after {
  165. border: none;
  166. }
  167. .btns {
  168. height: 80rpx;
  169. background: radial-gradient(at 0% 0%, #01243A 0%, #004576 100%);
  170. border-radius: 40rpx;
  171. font-size: 32rpx;
  172. font-weight: 400;
  173. color: #ffffff;
  174. line-height: 80rpx;
  175. width: 670rpx;
  176. margin: 0 auto;
  177. box-sizing: border-box;
  178. &.del {
  179. background: #fff;
  180. border: 2rpx solid #DCDCDC;
  181. color: #666666;
  182. margin-top: 30rpx;
  183. }
  184. }
  185. .button-default {
  186. height: 80rpx;
  187. background: rgba(0, 179, 139, .1);
  188. border-radius: 40rpx;
  189. font-size: 32rpx;
  190. font-weight: 400;
  191. color: #00B38B;
  192. line-height: 80rpx;
  193. width: 45%;
  194. }
  195. }
  196. .white-action {
  197. padding-left: 20rpx;
  198. padding-right: 20rpx;
  199. padding-bottom: 30rpx;
  200. .button {
  201. height: 80rpx;
  202. border-radius: 40rpx;
  203. background: #ffffff;
  204. box-shadow: 0rpx 4rpx 11rpx 1rpx rgba(223, 223, 223, 0.5);
  205. font-size: 32rpx;
  206. font-weight: 400;
  207. color: #666666;
  208. line-height: 80rpx;
  209. }
  210. }
  211. .choice-picker {
  212. background: #F1F1F1;
  213. border-radius: 20rpx;
  214. padding: 10rpx 20rpx;
  215. height: 40px;
  216. color: black;
  217. }
  218. </style>