選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

addAddress.vue 5.4KB

1年前
6ヶ月前
1年前
10ヶ月前
6ヶ月前
10ヶ月前
1年前
6ヶ月前
1年前
1年前
6ヶ月前
1年前
6ヶ月前
1年前
1年前
7ヶ月前
6ヶ月前
1年前
6ヶ月前
1年前
6ヶ月前
1年前
6ヶ月前
10ヶ月前
1年前
7ヶ月前
1年前
7ヶ月前
7ヶ月前
1年前
7ヶ月前
1年前
1年前
1年前
1年前
6ヶ月前
1年前
6ヶ月前
1年前
6ヶ月前
1年前
6ヶ月前
10ヶ月前
1年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <view class="form">
  3. <u-form label-width="132rpx" :model="state.formData" ref="uForm" :label-style='labelStyle'>
  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" :height="80" maxlength="50" type='textarea' :auto-height="true"/>
  18. </u-form-item>
  19. <u-form-item label="邮政编码">
  20. <u-input placeholder="邮政编码" :customStyle="btnGetCode" v-model="state.formData.postalCode" maxlength="6"
  21. type="number" />
  22. </u-form-item>
  23. <view class="form-item forn-switch">
  24. <label>设置默认收货地址</label>
  25. <switch :checked="state.isDefault" color="#004576" style="transform:scale(0.75)" @change="changeSwitch">
  26. </switch>
  27. </view>
  28. </u-form>
  29. <view class="action">
  30. <button type="default" class="btns" @click="savaHandle()">保存</button>
  31. </view>
  32. </view>
  33. </template>
  34. <script setup lang="ts">
  35. import { reactive } from "vue";
  36. import { onLoad } from "@dcloudio/uni-app";
  37. import { addressAdd, updateReceive } from "@/utils/network/api.js";
  38. import {requestNew } from "@/utils/network/request.js";
  39. import { getItem, StorageKeys } from "@/utils/storage";
  40. import { msg, checkStr } from "@/utils/utils";
  41. const btnGetCode = {
  42. background: "#F1F1F1",
  43. "border-radius": "20rpx",
  44. padding: "10rpx 20rpx",
  45. height: "40px",
  46. };
  47. const labelStyle = {
  48. color: "#333",
  49. fontSize: "28rpx",
  50. }
  51. const textareaStyle = {
  52. background: "#F1F1F1",
  53. "border-radius": "20rpx",
  54. padding: "20rpx 10rpx",
  55. };
  56. const state = reactive({
  57. formData: {
  58. consignee: "",
  59. consigneeTel: "",
  60. region: "",
  61. address: "",
  62. postalCode: "",
  63. defaultAddress: 2,
  64. openId: '',
  65. orderId: '',
  66. whetherToMail:true,
  67. },
  68. isDefault: false,
  69. });
  70. //switch 事件
  71. const changeSwitch = (e : any) => {
  72. console.log(e);
  73. state.formData.defaultAddress = e.detail.value ? 1 : 2;
  74. console.log(state.formData);
  75. };
  76. // 选择地区回调
  77. const regionConfirm = (e : any) => {
  78. console.log("e", e.detail.value)
  79. state.formData.region = e.detail.value[0] + e.detail.value[1] + e.detail.value[2];
  80. };
  81. const savaHandle = () => {
  82. if (!state.formData.consignee) {
  83. msg('请输入收货人姓名');
  84. return;
  85. }
  86. if (!checkStr(state.formData.consigneeTel, 'mobile')) {
  87. msg('请输入正确手机号');
  88. return;
  89. }
  90. if (!state.formData.region) {
  91. msg('请输选择省市区');
  92. return;
  93. }
  94. if (!state.formData.address) {
  95. msg('请输入正确详细地址');
  96. return;
  97. }
  98. state.formData.openId = getItem(StorageKeys.OpenId);
  99. queryAddOrEditAddress(addressAdd, state.formData);
  100. };
  101. /* 新增/编辑收货地址 */
  102. const queryAddOrEditAddress = (code, data) => {
  103. if (state.formData.orderId) {
  104. console.log(data);
  105. let options = {
  106. type: 2,
  107. data: data,
  108. method: "POST",
  109. showLoading: true,
  110. };
  111. requestNew(code, options).then((res) => {
  112. let options2 = {
  113. type: 2,
  114. data: state.formData,
  115. method: "POST",
  116. showLoading: true,
  117. };
  118. requestNew(updateReceive, options2).then((res) => {
  119. console.log(res);
  120. uni.redirectTo({
  121. url: `/subpackage/orders/release-products?orderId=${state.formData.orderId}&clientFee=${getItem('clientFee')}&&id=${getItem('productId')}`,
  122. });
  123. })
  124. })
  125. .catch((err) => {
  126. console.log(err);
  127. });
  128. } else if (!getItem(StorageKeys.OpenId)) {
  129. console.log("1111", data)
  130. uni.$emit('updateData', data)
  131. msg("新增地址成功");
  132. uni.navigateBack({
  133. delta: 1,
  134. });
  135. } else {
  136. const options = {
  137. type: 2,
  138. data: data,
  139. method: "POST",
  140. showLoading: true,
  141. };
  142. requestNew(code, options)
  143. .then((res) => {
  144. msg("新增地址成功");
  145. uni.navigateBack({
  146. delta: 1,
  147. });
  148. })
  149. .catch((err) => {
  150. console.log(err);
  151. });
  152. }
  153. };
  154. onLoad((option) => {
  155. state.formData.orderId = option.orderId
  156. });
  157. </script>
  158. <style lang="scss" scoped>
  159. .form-item {
  160. display: flex;
  161. justify-content: space-between;
  162. align-items: center;
  163. font-size: 30rpx;
  164. padding: 20rpx 0;
  165. }
  166. .form {
  167. padding: 30rpx;
  168. }
  169. .action {
  170. padding-left: 20rpx;
  171. padding-right: 20rpx;
  172. padding-bottom: 30rpx;
  173. .btns {
  174. height: 80rpx;
  175. background: radial-gradient(at 0% 0%, #01243A 0%, #004576 100%);
  176. border-radius: 40rpx;
  177. font-size: 32rpx;
  178. font-weight: 400;
  179. color: #ffffff;
  180. line-height: 80rpx;
  181. width: 670rpx;
  182. margin: 0 auto;
  183. box-sizing: border-box;
  184. }
  185. }
  186. .white-action {
  187. padding-left: 20rpx;
  188. padding-right: 20rpx;
  189. padding-bottom: 30rpx;
  190. .button {
  191. height: 80rpx;
  192. border-radius: 40rpx;
  193. background: #ffffff;
  194. box-shadow: 0rpx 4rpx 11rpx 1rpx rgba(223, 223, 223, 0.5);
  195. font-size: 32rpx;
  196. font-weight: 400;
  197. color: #666666;
  198. line-height: 80rpx;
  199. }
  200. }
  201. .choice-picker {
  202. background: #F1F1F1;
  203. border-radius: 20rpx;
  204. padding: 10rpx 20rpx;
  205. height: 40px;
  206. color: rgb(135, 135, 135);
  207. }
  208. </style>