Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

addAddress.vue 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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
  6. placeholder="名字"
  7. :customStyle="btnGetCode"
  8. v-model="state.formData.consignee"
  9. />
  10. </u-form-item>
  11. <u-form-item label="手机号">
  12. <u-input
  13. placeholder="手机号"
  14. :customStyle="btnGetCode"
  15. type="number"
  16. v-model="state.formData.consigneeTel"
  17. />
  18. </u-form-item>
  19. <u-form-item label="所在地区">
  20. <u-input
  21. :customStyle="btnGetCode"
  22. type="select"
  23. :select-open="state.show"
  24. v-model="state.formData.region"
  25. placeholder="省 市 区"
  26. @click="state.show = true"
  27. ></u-input>
  28. </u-form-item>
  29. <u-form-item label="详细地址">
  30. <u-input
  31. placeholder="小区楼栋/乡村名称"
  32. :customStyle="textareaStyle"
  33. type="textarea"
  34. v-model="state.formData.address"
  35. />
  36. </u-form-item>
  37. <u-form-item label="邮政编码">
  38. <u-input
  39. placeholder="邮政编码"
  40. :customStyle="btnGetCode"
  41. v-model="state.formData.postalCode"
  42. />
  43. </u-form-item>
  44. <u-form-item label-width="240rpx" label="设置默认收货地址">
  45. <u-switch
  46. v-model="state.formData.defaultAddress"
  47. active-color="#25D8C9"
  48. :active-value="1"
  49. :inactive-value="2"
  50. ></u-switch>
  51. </u-form-item>
  52. </u-form>
  53. <view class="action">
  54. <button type="default" class="button" @click="savaHandle()">保存</button>
  55. </view>
  56. <u-picker
  57. mode="region"
  58. v-model="state.show"
  59. @confirm="regionConfirm"
  60. ></u-picker>
  61. </view>
  62. </template>
  63. <script setup lang="ts">
  64. import { reactive } from "vue";
  65. import { onLoad } from "@dcloudio/uni-app";
  66. import { addOrEditAddressQuery } from "@/utils/network/api.js";
  67. import { request } from "@/utils/network/request.js";
  68. import { getItem, StorageKeys } from "@/utils/storage";
  69. import { msg } from "@/utils/utils";
  70. const btnGetCode = {
  71. background: "#F1F1F1",
  72. "border-radius": "20rpx",
  73. padding: "10rpx 20rpx",
  74. height: "40px",
  75. };
  76. const textareaStyle = {
  77. background: "#F1F1F1",
  78. "border-radius": "20rpx",
  79. padding: "20rpx 10rpx",
  80. };
  81. const state = reactive({
  82. formData: {
  83. consignee: "",
  84. consigneeTel: "",
  85. region: "",
  86. address: "",
  87. postalCode: "",
  88. defaultAddress: 2,
  89. openId: undefined,
  90. id: undefined,
  91. },
  92. show: false,
  93. });
  94. // 选择地区回调
  95. const regionConfirm = (e: any) => {
  96. state.formData.region = e.province.name + e.city.name + e.area.name;
  97. };
  98. const savaHandle = () => {
  99. state.formData.openId = getItem(StorageKeys.OpenId);
  100. queryAddOrEditAddress(addOrEditAddressQuery, state.formData);
  101. };
  102. const submit = (e: any) => {
  103. console.log("提交内容", e);
  104. // const code = "IF01001202209060883" //请求编码
  105. // const options = {
  106. // type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
  107. // data: e, //请求参数
  108. // method: 'POST|GET', //提交方式(默认POST)
  109. // showLoading: true, //是否显示加载中(默认显示)
  110. // }
  111. // request(code, options).then((res) => {
  112. // uni.showToast({
  113. // icon: 'none',
  114. // title: hint
  115. // })
  116. // })
  117. };
  118. /* 新增/编辑收货地址 */
  119. const queryAddOrEditAddress = (code, data) => {
  120. const options = {
  121. type: 2,
  122. data: data,
  123. method: "POST",
  124. showLoading: true,
  125. };
  126. request(code, options)
  127. .then((res) => {
  128. msg("新增地址成功");
  129. uni.navigateBack({
  130. delta: 1,
  131. });
  132. })
  133. .catch((err) => {
  134. console.log(err);
  135. });
  136. };
  137. onLoad(() => {});
  138. </script>
  139. <style lang="scss" scoped>
  140. .form {
  141. padding: 30rpx;
  142. }
  143. .action {
  144. padding-left: 20rpx;
  145. padding-right: 20rpx;
  146. padding-bottom: 30rpx;
  147. .button {
  148. height: 80rpx;
  149. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  150. border-radius: 40rpx;
  151. font-size: 32rpx;
  152. font-weight: 400;
  153. color: #ffffff;
  154. line-height: 80rpx;
  155. }
  156. }
  157. .white-action {
  158. padding-left: 20rpx;
  159. padding-right: 20rpx;
  160. padding-bottom: 30rpx;
  161. .button {
  162. height: 80rpx;
  163. border-radius: 40rpx;
  164. background: #ffffff;
  165. box-shadow: 0rpx 4rpx 11rpx 1rpx rgba(223, 223, 223, 0.5);
  166. font-size: 32rpx;
  167. font-weight: 400;
  168. color: #666666;
  169. line-height: 80rpx;
  170. }
  171. }
  172. </style>