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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. <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. 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. }
  109. /* 新增/编辑收货地址 */
  110. const queryAddOrEditAddress = (code, data) => {
  111. const options = {
  112. type: 2,
  113. data: data,
  114. method: "POST",
  115. showLoading: true,
  116. };
  117. request(code, options).then((res) => {
  118. msg("编辑地址成功");
  119. uni.navigateBack({
  120. delta: 1,
  121. });
  122. });
  123. };
  124. onLoad((option) => {
  125. state.formData = JSON.parse(option.content);
  126. });
  127. </script>
  128. <style lang="scss" scoped>
  129. .form-item {
  130. display: flex;
  131. justify-content: space-between;
  132. align-items: center;
  133. font-size: 30rpx;
  134. padding: 20rpx 0;
  135. }
  136. .form {
  137. padding: 30rpx;
  138. }
  139. .action {
  140. padding-left: 20rpx;
  141. padding-right: 20rpx;
  142. padding-bottom: 30rpx;
  143. display: flex;
  144. .button::after {
  145. border: none;
  146. }
  147. .button-default::after {
  148. border: none;
  149. }
  150. .button {
  151. height: 80rpx;
  152. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  153. border-radius: 40rpx;
  154. font-size: 32rpx;
  155. font-weight: 400;
  156. color: #ffffff;
  157. line-height: 80rpx;
  158. width: 45%;
  159. }
  160. .button-default {
  161. height: 80rpx;
  162. background: rgba(0, 179, 139, .1);
  163. border-radius: 40rpx;
  164. font-size: 32rpx;
  165. font-weight: 400;
  166. color: #00B38B;
  167. line-height: 80rpx;
  168. width: 45%;
  169. }
  170. }
  171. .white-action {
  172. padding-left: 20rpx;
  173. padding-right: 20rpx;
  174. padding-bottom: 30rpx;
  175. .button {
  176. height: 80rpx;
  177. border-radius: 40rpx;
  178. background: #ffffff;
  179. box-shadow: 0rpx 4rpx 11rpx 1rpx rgba(223, 223, 223, 0.5);
  180. font-size: 32rpx;
  181. font-weight: 400;
  182. color: #666666;
  183. line-height: 80rpx;
  184. }
  185. }
  186. </style>