您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

editAddress.vue 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. <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. 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="#43a1e0" style="transform:scale(0.75)"
  26. @change="changeSwitch"></switch>
  27. </view>
  28. </u-form>
  29. <view class="action">
  30. <button type="default" class="button-default" @click="deleteHandle()">删除</button>
  31. <button type="default" class="button" @click="savaHandle()">保存</button>
  32. </view>
  33. <u-picker mode="region" v-model="state.show" @confirm="regionConfirm"></u-picker>
  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. show: false,
  80. });
  81. //switch 事件
  82. const changeSwitch = (e : any) => {
  83. console.log(e);
  84. state.formData.defaultAddress = e.detail.value ? 1 : 2;
  85. console.log(state.formData);
  86. };
  87. // 选择地区回调
  88. const regionConfirm = (e : any) => {
  89. state.formData.region = e.province.name + e.city.name + e.area.name;
  90. };
  91. const savaHandle = () => {
  92. state.formData.openId = getItem(StorageKeys.OpenId);
  93. queryAddOrEditAddress(addOrEditAddressQuery, state.formData);
  94. };
  95. const deleteHandle = () => {
  96. if (getItem(StorageKeys.OpenId)) {
  97. state.formData.openId = getItem(StorageKeys.OpenId);
  98. const options = {
  99. type: 2,
  100. data: state.formData,
  101. method: "POST",
  102. showLoading: true,
  103. };
  104. request(addressDelete, options).then((res) => {
  105. msg("删除地址成功");
  106. uni.navigateBack({
  107. delta: 1,
  108. });
  109. });
  110. } else {
  111. uni.navigateTo({
  112. url: `/subpackage/orders/essential-information?del=1`
  113. });
  114. }
  115. }
  116. /* 新增/编辑收货地址 */
  117. const queryAddOrEditAddress = (code, data) => {
  118. if (getItem(StorageKeys.OpenId)) {
  119. const options = {
  120. type: 2,
  121. data: data,
  122. method: "POST",
  123. showLoading: true,
  124. };
  125. request(code, options).then((res) => {
  126. msg("编辑地址成功");
  127. setTimeout(() => {
  128. uni.navigateBack({
  129. delta: 1,
  130. });
  131. }, 1500)
  132. });
  133. } else {
  134. uni.$emit('updateData', state.formData)
  135. uni.navigateBack({
  136. delta: 1,
  137. });
  138. }
  139. };
  140. onLoad((option) => {
  141. state.formData = JSON.parse(option.content);
  142. });
  143. </script>
  144. <style lang="scss" scoped>
  145. .form-item {
  146. display: flex;
  147. justify-content: space-between;
  148. align-items: center;
  149. font-size: 30rpx;
  150. padding: 20rpx 0;
  151. }
  152. .form {
  153. padding: 30rpx;
  154. }
  155. .action {
  156. padding-left: 20rpx;
  157. padding-right: 20rpx;
  158. padding-bottom: 30rpx;
  159. display: flex;
  160. width: 90%;
  161. justify-content: space-between;
  162. .button::after {
  163. border: none;
  164. }
  165. .button-default::after {
  166. border: none;
  167. }
  168. .button {
  169. height: 80rpx;
  170. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  171. border-radius: 40rpx;
  172. font-size: 32rpx;
  173. font-weight: 400;
  174. color: #ffffff;
  175. line-height: 80rpx;
  176. width: 45%;
  177. }
  178. .button-default {
  179. height: 80rpx;
  180. background: rgba(0, 179, 139, .1);
  181. border-radius: 40rpx;
  182. font-size: 32rpx;
  183. font-weight: 400;
  184. color: #00B38B;
  185. line-height: 80rpx;
  186. width: 45%;
  187. }
  188. }
  189. .white-action {
  190. padding-left: 20rpx;
  191. padding-right: 20rpx;
  192. padding-bottom: 30rpx;
  193. .button {
  194. height: 80rpx;
  195. border-radius: 40rpx;
  196. background: #ffffff;
  197. box-shadow: 0rpx 4rpx 11rpx 1rpx rgba(223, 223, 223, 0.5);
  198. font-size: 32rpx;
  199. font-weight: 400;
  200. color: #666666;
  201. line-height: 80rpx;
  202. }
  203. }
  204. </style>