123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- <template>
- <view class="form">
- <u-form label-width="132rpx" :model="state.formData" ref="uForm">
- <u-form-item label="收货人">
- <u-input placeholder="名字" :customStyle="btnGetCode" v-model="state.formData.consignee" maxlength="20" />
- </u-form-item>
- <u-form-item label="手机号">
- <u-input placeholder="手机号" :customStyle="btnGetCode" type="number" v-model="state.formData.consigneeTel"
- maxlength="11" />
- </u-form-item>
- <u-form-item label="所在地区">
- <u-input :customStyle="btnGetCode" type="select" :select-open="state.show"
- v-model="state.formData.region" placeholder="省 市 区" @click="state.show = true"></u-input>
- </u-form-item>
-
- <u-form-item label="详细地址">
- <u-input placeholder="小区楼栋/乡村名称" :customStyle="textareaStyle" v-model="state.formData.address"
- maxlength="50" />
- </u-form-item>
- <u-form-item label="邮政编码">
- <u-input placeholder="邮政编码" :customStyle="btnGetCode" v-model="state.formData.postalCode"
- maxlength="20" />
- </u-form-item>
- <!-- <u-form-item label-width="240rpx" label="设置默认收货地址"> -->
- <!-- <u-switch
- v-model="state.formData.defaultAddress"
- active-color="#25D8C9"
- :active-value="1"
- :inactive-value="2"
- ></u-switch> -->
- <!-- </u-form-item> -->
- <view class="form-item forn-switch">
- <label>设置默认收货地址</label>
- <switch :checked="state.isDefault" color="#43a1e0" style="transform:scale(0.75)" @change="changeSwitch">
- </switch>
- </view>
-
- </u-form>
-
- <view class="action">
- <button type="default" class="button" @click="savaHandle()">保存</button>
- </view>
- <u-picker mode="region" v-model="state.show" @confirm="regionConfirm"></u-picker>
- </view>
- </template>
-
- <script setup lang="ts">
- import { reactive } from "vue";
- import { onLoad } from "@dcloudio/uni-app";
- import { addOrEditAddressQuery, addressToOrder } from "@/utils/network/api.js";
- import { request } from "@/utils/network/request.js";
- import { getItem, StorageKeys } from "@/utils/storage";
- import { msg, checkStr } from "@/utils/utils";
- const btnGetCode = {
- background: "#F1F1F1",
- "border-radius": "20rpx",
- padding: "10rpx 20rpx",
- height: "40px",
- };
-
- const textareaStyle = {
- background: "#F1F1F1",
- "border-radius": "20rpx",
- padding: "20rpx 10rpx",
- };
-
- const state = reactive({
- formData: {
- consignee: "",
- consigneeTel: "",
- region: "",
- address: "",
- postalCode: "",
- defaultAddress: 2,
- openId: '',
- orderId: '',
- whetherToMail: 0,
- },
- show: false,
- isDefault: false,
- });
-
- //switch 事件
- const changeSwitch = (e : any) => {
- console.log(e);
- state.formData.defaultAddress = e.detail.value ? 1 : 2;
- console.log(state.formData);
- };
- // 选择地区回调
- const regionConfirm = (e : any) => {
- state.formData.region = e.province.name + e.city.name + e.area.name;
- };
-
- const savaHandle = () => {
- if (!state.formData.consignee) {
- msg('请输入收货人姓名');
- return;
- }
- if (!checkStr(state.formData.consigneeTel, 'mobile')) {
- msg('请输入正确手机号');
- return;
- }
- if (!state.formData.region) {
- msg('请输选择省市区');
- return;
- }
- if (!state.formData.address) {
- msg('请输入正确详细地址');
- return;
- }
- state.formData.openId = getItem(StorageKeys.OpenId);
-
- queryAddOrEditAddress(addOrEditAddressQuery, state.formData);
- };
-
- /* 新增/编辑收货地址 */
- const queryAddOrEditAddress = (code, data) => {
- if (state.formData.orderId) {
- console.log(data);
- let options = {
- type: 2,
- data: data,
- method: "POST",
- showLoading: true,
- };
- request(code, options).then((res) => {
- // msg("新增地址成功");
- // uni.navigateBack({
- // delta: 1,
- // });
- let options2 = {
- type: 2,
- data: state.formData,
- method: "POST",
- showLoading: true,
- };
- request(addressToOrder, options2).then((res) => {
- console.log(res);
- uni.redirectTo({
- url: `/subpackage/orders/release-products?orderId=${state.formData.orderId}&clientFee=${getItem('clientFee')}&&id=${getItem('productId')}`,
- });
- })
- })
- .catch((err) => {
- console.log(err);
- });
-
- } else if (!getItem(StorageKeys.OpenId)) {
- console.log("1111", data)
- uni.$emit('updateData', data)
- msg("新增地址成功");
- uni.navigateBack({
- delta: 1,
- });
- } else {
- const options = {
- type: 2,
- data: data,
- method: "POST",
- showLoading: true,
- };
- request(code, options)
- .then((res) => {
- msg("新增地址成功");
- uni.navigateBack({
- delta: 1,
- });
- })
- .catch((err) => {
- console.log(err);
- });
- }
-
- };
-
- onLoad((option) => {
- state.formData.orderId = option.orderId
- });
- </script>
-
- <style lang="scss" scoped>
- .form-item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- font-size: 30rpx;
- padding: 20rpx 0;
- }
-
- .form {
- padding: 30rpx;
- }
-
- .action {
- padding-left: 20rpx;
- padding-right: 20rpx;
- padding-bottom: 30rpx;
-
- .button {
- height: 80rpx;
- background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
- border-radius: 40rpx;
- font-size: 32rpx;
- font-weight: 400;
- color: #ffffff;
- line-height: 80rpx;
- }
- }
-
- .white-action {
- padding-left: 20rpx;
- padding-right: 20rpx;
- padding-bottom: 30rpx;
-
- .button {
- height: 80rpx;
- border-radius: 40rpx;
- background: #ffffff;
- box-shadow: 0rpx 4rpx 11rpx 1rpx rgba(223, 223, 223, 0.5);
- font-size: 32rpx;
- font-weight: 400;
- color: #666666;
- line-height: 80rpx;
- }
- }
- </style>
|