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

addAddress.vue 5.5KB

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