addEditAddress.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <template>
  2. <view class="container">
  3. <uv-navbar title="添加收货地址" placeholder autoBack></uv-navbar>
  4. <form @submit="formSubmit">
  5. <view class="u-bg-fff">
  6. <view class="u-plr30">
  7. <view class="v-flex-center border v-border-one-one ht104">
  8. <view class="wt140 u-font28 u-1A1A1A">收货人:</view>
  9. <input
  10. class="u-ml10"
  11. maxlength="8"
  12. name="receiverName"
  13. :value="dataform.receiverName"
  14. placeholder-style="color: #d9d9d9;font-weight: 400;font-size: 26rpx; "
  15. placeholder="请填写收货人姓名"
  16. />
  17. </view>
  18. <view class="v-flex-center border v-border-one-one ht104">
  19. <view class="wt140 u-font28 u-1A1A1A">手机号码:</view>
  20. <input
  21. class="u-ml10"
  22. type="number"
  23. name="receiverPhone"
  24. maxlength="11"
  25. :value="dataform.receiverPhone"
  26. placeholder-style="color: #d9d9d9;font-weight: 400;font-size: 26rpx; "
  27. placeholder="请输入手机号码"
  28. />
  29. </view>
  30. <view
  31. class="v-flex-center border u-border-one-one ht104"
  32. @click="pickerRef.open()"
  33. >
  34. <view class="wt140 u-font28 u-1A1A1A">所在地区:</view>
  35. <input
  36. class="u-ml10"
  37. placeholder-style="color: #d9d9d9;font-weight: 400;font-size: 26rpx; "
  38. placeholder="请选择地区"
  39. disabled
  40. :value="
  41. dataform.provinceName +
  42. '' +
  43. dataform.cityName +
  44. '' +
  45. dataform.areaName
  46. "
  47. />
  48. <image
  49. class="tiaozhuan u-ml25"
  50. :src="$handleImageUrl('/czd/tiaozhuan.png')"
  51. mode=""
  52. ></image>
  53. </view>
  54. <view class="address-detail-container">
  55. <view class="wt140 u-font28 u-1A1A1A">详细地址:</view>
  56. <textarea
  57. class="address-textarea"
  58. maxlength="50"
  59. name="detailAddress"
  60. placeholder-style="color: #d9d9d9;font-weight: 400;font-size: 26rpx; "
  61. v-model="dataform.detailAddress"
  62. placeholder="请输入详细地址信息,如道路、门牌号、小区、楼栋号、单元室等"
  63. ></textarea>
  64. </view>
  65. </view>
  66. </view>
  67. <view class="default border u-mt20 u-bg-fff u-flex-center-sb">
  68. <view>设为默认收货地址</view>
  69. <view>
  70. <switch
  71. @change="isDefault"
  72. color="#FA6138"
  73. :checked="dataform.defaultStatus"
  74. style="transform: scale(0.7)"
  75. ></switch>
  76. </view>
  77. </view>
  78. <view class="u-plr30 mt104">
  79. <button class="u-btn-two" form-type="submit">保存</button>
  80. </view>
  81. </form>
  82. <!-- 地区选择 -->
  83. <RegionSelection ref="pickerRef" @confirm="areaConfirm"/>
  84. </view>
  85. </template>
  86. <script setup>
  87. import { ref } from "vue";
  88. import { onLoad } from "@dcloudio/uni-app";
  89. import {
  90. useraddressAdd_Api,
  91. useraddressEdit_Api,
  92. useraddressInfo_Api,
  93. } from "@/api/userInfo.js";
  94. import $mConfig from "@/config/global.config";
  95. const pickerRef = ref(null);
  96. const dataform = ref({
  97. receiverName: "", //收货人姓名
  98. receiverPhone: "", //联系电话
  99. provinceName: "", //省的名称
  100. provinceCode: "", //省编号
  101. cityCode: "", //市编号
  102. cityName: "", //市名称
  103. areaName: "", //区名称
  104. areaCode: "", //区编号
  105. detailAddress: "", //详细地址
  106. defaultStatus: false, //是否是默认
  107. });
  108. // 地区选择器确认事件
  109. const areaConfirm = (e) => {
  110. dataform.value = {
  111. ...dataform.value,
  112. ...e,
  113. }
  114. };
  115. const formSubmit = (e) => {
  116. let target = e.detail.value;
  117. if (!target.receiverName) {
  118. uni.$uv.toast("请输入收货人姓名");
  119. return false;
  120. }
  121. if (!target.receiverPhone) {
  122. uni.$uv.toast("请输入联系电话");
  123. return false;
  124. }
  125. if (!target.receiverPhone.match($mConfig.telRegex)) {
  126. uni.$uv.toast("请输入正确手机号");
  127. return false;
  128. }
  129. if (!dataform.value.provinceCode) {
  130. uni.$uv.toast("请选择省市区");
  131. return false;
  132. }
  133. if (!target.detailAddress) {
  134. uni.$uv.toast("请输入详细地址");
  135. return false;
  136. }
  137. dataform.value.receiverName = target.receiverName;
  138. dataform.value.receiverPhone = target.receiverPhone;
  139. dataform.value.detailAddress = target.detailAddress;
  140. // console.log(" this.dataform = ", dataform.value);
  141. let url = dataform.value.id ? useraddressEdit_Api : useraddressAdd_Api;
  142. uni.showLoading({
  143. title: "提交中",
  144. mask: true,
  145. });
  146. url(dataform.value)
  147. .then((res) => {
  148. uni.hideLoading();
  149. if (res.code == 200) {
  150. uni.showToast({
  151. title: dataform.value.id ? "修改成功" : "添加成功",
  152. icon: "none",
  153. duration: 3000,
  154. success() {
  155. setTimeout(() => {
  156. uni.navigateBack({
  157. delta: 1,
  158. });
  159. }, 1000);
  160. },
  161. });
  162. }
  163. })
  164. .catch((err) => {
  165. // uni.hideLoading();
  166. console.log(err);
  167. });
  168. };
  169. // 是否设置默认地址
  170. const isDefault = (e) => {
  171. dataform.value.defaultStatus = e.detail.value;
  172. };
  173. onLoad((options) => {
  174. if (options.id) {
  175. useraddressInfo_Api(options.id).then(async (res) => {
  176. if (res.code == 200) {
  177. dataform.value = res.data;
  178. }
  179. });
  180. }
  181. });
  182. </script>
  183. <style lang="scss">
  184. page {
  185. background-color: #f5f5f5;
  186. }
  187. .container {
  188. .u-bg-fff {
  189. background-color: #fff;
  190. margin-top: 20rpx;
  191. border-radius: 20rpx;
  192. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
  193. }
  194. .u-plr30 {
  195. padding: 0 30rpx;
  196. }
  197. .v-flex-center {
  198. display: flex;
  199. align-items: center;
  200. }
  201. .border {
  202. border-bottom: 1rpx solid #e7e7e7;
  203. }
  204. .v-border-one-one {
  205. &:last-child {
  206. border-bottom: none;
  207. }
  208. }
  209. .ht104 {
  210. height: 104rpx;
  211. line-height: 104rpx;
  212. }
  213. .ht132 {
  214. height: 132rpx;
  215. padding: 20rpx 0;
  216. }
  217. .wt140 {
  218. width: 140rpx;
  219. flex-shrink: 0;
  220. }
  221. .u-font28 {
  222. font-size: 28rpx;
  223. }
  224. .u-1A1A1A {
  225. color: #1a1a1a;
  226. }
  227. .u-ml10 {
  228. margin-left: 10rpx;
  229. }
  230. .u-ml25 {
  231. margin-left: 25rpx;
  232. }
  233. .tiaozhuan {
  234. width: 25rpx;
  235. height: 25rpx;
  236. }
  237. input {
  238. width: calc(100% - 175rpx);
  239. height: 100%;
  240. font-size: 28rpx;
  241. color: #1a1a1a;
  242. }
  243. textarea {
  244. width: calc(100% - 175rpx);
  245. height: 90rpx;
  246. font-size: 28rpx;
  247. color: #1a1a1a;
  248. padding: 10rpx;
  249. box-sizing: border-box;
  250. background: #f8f8f8;
  251. border-radius: 10rpx;
  252. }
  253. .iconfont {
  254. font-family: "iconfont" !important;
  255. font-size: 28rpx;
  256. font-style: normal;
  257. color: #999;
  258. }
  259. .default {
  260. padding: 38rpx 30rpx;
  261. background-color: #fff;
  262. margin: 20rpx 0;
  263. border-radius: 20rpx;
  264. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
  265. display: flex;
  266. justify-content: space-between;
  267. align-items: center;
  268. font-size: 28rpx;
  269. color: #1a1a1a;
  270. }
  271. .u-mt20 {
  272. margin-top: 20rpx;
  273. }
  274. .u-flex-center-sb {
  275. display: flex;
  276. justify-content: space-between;
  277. align-items: center;
  278. }
  279. .mt104 {
  280. margin-top: 104rpx;
  281. padding: 0 30rpx;
  282. }
  283. .u-btn-two {
  284. width: 100%;
  285. height: 88rpx;
  286. line-height: 88rpx;
  287. border-radius: 44rpx;
  288. font-size: 32rpx;
  289. font-weight: 500;
  290. text-align: center;
  291. // background: linear-gradient(90deg, #ff6b35, #fa6138);
  292. background: #e93534;
  293. box-shadow: 0 10rpx 20rpx rgba(250, 97, 56, 0.3);
  294. }
  295. .address-detail-container {
  296. padding: 20rpx 0;
  297. display: flex;
  298. align-items: flex-start;
  299. .wt140 {
  300. padding-top: 10rpx;
  301. }
  302. }
  303. .address-textarea {
  304. flex: 1;
  305. // margin-left: 10rpx;
  306. height: 160rpx;
  307. padding: 10rpx 0;
  308. box-sizing: border-box;
  309. background: #ffffff;
  310. border-radius: 10rpx;
  311. font-size: 28rpx;
  312. color: #1a1a1a;
  313. line-height: 1.4;
  314. }
  315. }
  316. </style>