Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

addAddress.vue 5.5KB

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