You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

addAddress.vue 5.6KB

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