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 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. 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. uni.navigateBack({
  127. delta: 1,
  128. });
  129. });
  130. }else{
  131. uni.$emit('updateData',state.formData)
  132. uni.navigateBack({
  133. delta: 1,
  134. });
  135. }
  136. };
  137. onLoad((option) => {
  138. state.formData = JSON.parse(option.content);
  139. });
  140. </script>
  141. <style lang="scss" scoped>
  142. .form-item {
  143. display: flex;
  144. justify-content: space-between;
  145. align-items: center;
  146. font-size: 30rpx;
  147. padding: 20rpx 0;
  148. }
  149. .form {
  150. padding: 30rpx;
  151. }
  152. .action {
  153. padding-left: 20rpx;
  154. padding-right: 20rpx;
  155. padding-bottom: 30rpx;
  156. display: flex;
  157. .button::after {
  158. border: none;
  159. }
  160. .button-default::after {
  161. border: none;
  162. }
  163. .button {
  164. height: 80rpx;
  165. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  166. border-radius: 40rpx;
  167. font-size: 32rpx;
  168. font-weight: 400;
  169. color: #ffffff;
  170. line-height: 80rpx;
  171. width: 45%;
  172. }
  173. .button-default {
  174. height: 80rpx;
  175. background: rgba(0, 179, 139, .1);
  176. border-radius: 40rpx;
  177. font-size: 32rpx;
  178. font-weight: 400;
  179. color: #00B38B;
  180. line-height: 80rpx;
  181. width: 45%;
  182. }
  183. }
  184. .white-action {
  185. padding-left: 20rpx;
  186. padding-right: 20rpx;
  187. padding-bottom: 30rpx;
  188. .button {
  189. height: 80rpx;
  190. border-radius: 40rpx;
  191. background: #ffffff;
  192. box-shadow: 0rpx 4rpx 11rpx 1rpx rgba(223, 223, 223, 0.5);
  193. font-size: 32rpx;
  194. font-weight: 400;
  195. color: #666666;
  196. line-height: 80rpx;
  197. }
  198. }
  199. </style>