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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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"
  18. maxlength="50" />
  19. </u-form-item>
  20. <u-form-item label="邮政编码">
  21. <u-input placeholder="邮政编码" :customStyle="btnGetCode" v-model="state.formData.postalCode" type="number"
  22. maxlength="6" />
  23. </u-form-item>
  24. <view class="form-item forn-switch">
  25. <label>设置默认收货地址</label>
  26. <switch :checked="state.formData.defaultAddress==1" color="#43a1e0" style="transform:scale(0.75)"
  27. @change="changeSwitch"></switch>
  28. </view>
  29. </u-form>
  30. <view class="action">
  31. <button type="default" class="button-default" @click="deleteHandle()">删除</button>
  32. <button type="default" class="button" @click="savaHandle()">保存</button>
  33. </view>
  34. </view>
  35. </template>
  36. <script setup lang="ts">
  37. import {
  38. reactive
  39. } from "vue";
  40. import {
  41. onLoad
  42. } from "@dcloudio/uni-app";
  43. import {
  44. addOrEditAddressQuery,
  45. addressDelete
  46. } from "@/utils/network/api.js";
  47. import {
  48. request
  49. } from "@/utils/network/request.js";
  50. import {
  51. getItem,
  52. StorageKeys
  53. } from "@/utils/storage";
  54. import {
  55. msg
  56. } from "@/utils/utils";
  57. const btnGetCode = {
  58. background: "#F1F1F1",
  59. "border-radius": "20rpx",
  60. padding: "10rpx 20rpx",
  61. height: "40px",
  62. };
  63. const textareaStyle = {
  64. background: "#F1F1F1",
  65. "border-radius": "20rpx",
  66. padding: "20rpx 10rpx",
  67. };
  68. const state = reactive({
  69. formData: {
  70. consignee: "",
  71. consigneeTel: "",
  72. region: "",
  73. address: "",
  74. postalCode: "",
  75. defaultAddress: 2,
  76. openId: undefined,
  77. id: undefined,
  78. },
  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.detail.value[0] + e.detail.value[1] + e.detail.value[2];
  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. .choice-picker{
  204. background: #F1F1F1;
  205. border-radius: 20rpx;
  206. padding: 10rpx 20rpx;
  207. height: 40px;
  208. color:black;
  209. }
  210. </style>