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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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" 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="#43a1e0" style="transform:scale(0.75)" @change="changeSwitch">
  26. </switch>
  27. </view>
  28. </u-form>
  29. <view class="action">
  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 { reactive } from "vue";
  37. import { onLoad } from "@dcloudio/uni-app";
  38. import { addOrEditAddressQuery, addressToOrder } from "@/utils/network/api.js";
  39. import { request } 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. show: false,
  66. isDefault: false,
  67. });
  68. //switch 事件
  69. const changeSwitch = (e : any) => {
  70. console.log(e);
  71. state.formData.defaultAddress = e.detail.value ? 1 : 2;
  72. console.log(state.formData);
  73. };
  74. // 选择地区回调
  75. const regionConfirm = (e : any) => {
  76. state.formData.region = e.province.name + e.city.name + e.area.name;
  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(addOrEditAddressQuery, 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. request(code, options).then((res) => {
  109. // msg("新增地址成功");
  110. // uni.navigateBack({
  111. // delta: 1,
  112. // });
  113. let options2 = {
  114. type: 2,
  115. data: state.formData,
  116. method: "POST",
  117. showLoading: true,
  118. };
  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. request(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. </style>