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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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: `/subpackage/orders/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 if(!getItem(StorageKeys.OpenId)){
  162. console.log("1111",data)
  163. uni.$emit('updateData',data)
  164. msg("新增地址成功");
  165. uni.navigateBack({
  166. delta: 1,
  167. });
  168. }else{
  169. const options = {
  170. type: 2,
  171. data: data,
  172. method: "POST",
  173. showLoading: true,
  174. };
  175. request(code, options)
  176. .then((res) => {
  177. msg("新增地址成功");
  178. uni.navigateBack({
  179. delta: 1,
  180. });
  181. })
  182. .catch((err) => {
  183. console.log(err);
  184. });
  185. }
  186. };
  187. onLoad((option) => {
  188. state.formData.orderId = option.orderId
  189. });
  190. </script>
  191. <style lang="scss" scoped>
  192. .form-item{
  193. display: flex;
  194. justify-content: space-between;
  195. align-items: center;
  196. font-size: 30rpx;
  197. padding: 20rpx 0;
  198. }
  199. .form {
  200. padding: 30rpx;
  201. }
  202. .action {
  203. padding-left: 20rpx;
  204. padding-right: 20rpx;
  205. padding-bottom: 30rpx;
  206. .button {
  207. height: 80rpx;
  208. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  209. border-radius: 40rpx;
  210. font-size: 32rpx;
  211. font-weight: 400;
  212. color: #ffffff;
  213. line-height: 80rpx;
  214. }
  215. }
  216. .white-action {
  217. padding-left: 20rpx;
  218. padding-right: 20rpx;
  219. padding-bottom: 30rpx;
  220. .button {
  221. height: 80rpx;
  222. border-radius: 40rpx;
  223. background: #ffffff;
  224. box-shadow: 0rpx 4rpx 11rpx 1rpx rgba(223, 223, 223, 0.5);
  225. font-size: 32rpx;
  226. font-weight: 400;
  227. color: #666666;
  228. line-height: 80rpx;
  229. }
  230. }
  231. </style>