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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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"
  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" v-model="state.formData.address" />
  17. </u-form-item>
  18. <u-form-item label="邮政编码">
  19. <u-input placeholder="邮政编码" :customStyle="btnGetCode" v-model="state.formData.postalCode" />
  20. </u-form-item>
  21. <view class="form-item forn-switch">
  22. <label>设置默认收货地址</label>
  23. <switch :checked="state.formData.defaultAddress==1" color="#43a1e0" style="transform:scale(0.75)"
  24. @change="changeSwitch"></switch>
  25. </view>
  26. </u-form>
  27. <view class="action">
  28. <button type="default" class="button-default" @click="deleteHandle()">删除</button>
  29. <button type="default" class="button" @click="savaHandle()">保存</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. //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.province.name + e.city.name + e.area.name;
  88. };
  89. const savaHandle = () => {
  90. state.formData.openId = getItem(StorageKeys.OpenId);
  91. queryAddOrEditAddress(addOrEditAddressQuery, 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. request(addressDelete, options).then((res) => {
  103. msg("删除地址成功");
  104. uni.navigateBack({
  105. delta: 1,
  106. });
  107. });
  108. } else {
  109. uni.navigateTo({
  110. url: `/subpackage/orders/essential-information?del=1`
  111. });
  112. }
  113. }
  114. /* 新增/编辑收货地址 */
  115. const queryAddOrEditAddress = (code, data) => {
  116. if (getItem(StorageKeys.OpenId)) {
  117. const options = {
  118. type: 2,
  119. data: data,
  120. method: "POST",
  121. showLoading: true,
  122. };
  123. request(code, options).then((res) => {
  124. msg("编辑地址成功");
  125. uni.navigateBack({
  126. delta: 1,
  127. });
  128. });
  129. } else {
  130. uni.$emit('updateData', state.formData)
  131. uni.navigateBack({
  132. delta: 1,
  133. });
  134. }
  135. };
  136. onLoad((option) => {
  137. state.formData = JSON.parse(option.content);
  138. });
  139. </script>
  140. <style lang="scss" scoped>
  141. .form-item {
  142. display: flex;
  143. justify-content: space-between;
  144. align-items: center;
  145. font-size: 30rpx;
  146. padding: 20rpx 0;
  147. }
  148. .form {
  149. padding: 30rpx;
  150. }
  151. .action {
  152. padding-left: 20rpx;
  153. padding-right: 20rpx;
  154. padding-bottom: 30rpx;
  155. display: flex;
  156. width: 90%;
  157. justify-content: space-between;
  158. .button::after {
  159. border: none;
  160. }
  161. .button-default::after {
  162. border: none;
  163. }
  164. .button {
  165. height: 80rpx;
  166. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  167. border-radius: 40rpx;
  168. font-size: 32rpx;
  169. font-weight: 400;
  170. color: #ffffff;
  171. line-height: 80rpx;
  172. width: 45%;
  173. }
  174. .button-default {
  175. height: 80rpx;
  176. background: rgba(0, 179, 139, .1);
  177. border-radius: 40rpx;
  178. font-size: 32rpx;
  179. font-weight: 400;
  180. color: #00B38B;
  181. line-height: 80rpx;
  182. width: 45%;
  183. }
  184. }
  185. .white-action {
  186. padding-left: 20rpx;
  187. padding-right: 20rpx;
  188. padding-bottom: 30rpx;
  189. .button {
  190. height: 80rpx;
  191. border-radius: 40rpx;
  192. background: #ffffff;
  193. box-shadow: 0rpx 4rpx 11rpx 1rpx rgba(223, 223, 223, 0.5);
  194. font-size: 32rpx;
  195. font-weight: 400;
  196. color: #666666;
  197. line-height: 80rpx;
  198. }
  199. }
  200. </style>