123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 |
- <template>
- <view class="page">
- <view class="content">
- <view class="title">
- <text class="title-left">{{ i18n.contacts }}</text>
- </view>
- <!-- 注意,如果需要兼容微信小程序,最好通过setRules方法设置rules规则 -->
- <u--form labelPosition="left" :model="model1" ref="uForm">
- <u-form-item labelWidth="150rpx" @click="showDialog = true" :label="i18n.country" borderBottom
- ref="item1">
- <u--input v-model="model1.userInfo.country" disabled disabledColor="#ffffff"
- :placeholder="i18n.selection" border="none"></u--input>
- <u-icon slot="right" name="arrow-right"></u-icon>
- </u-form-item>
- <u-form-item labelWidth="150rpx" :label="i18n.name" borderBottom ref="item1">
- <u--input v-model="model1.userInfo.name" :placeholder="i18n.goods" border="none"></u--input>
- </u-form-item>
- <!--
- <view class="item u-flex ">
- <text class="left">{{i18n.phone}}</text>
- <view class="right" style="display: flex;">
- <input style="width: 100rpx;" type="text" placeholder="(+86)"
- v-model="model1.userInfo.phonecode" />
- <text style="margin-right: 20rpx;">-</text>
- <u--input v-model="model1.userInfo.phone" :placeholder="i18n.pleasePhone"
- border="none"></u--input>
- </view>
- </view> -->
- <u-form-item labelWidth="150rpx" :label="i18n.phone" borderBottom ref="item1">
- <!-- <u--input v-model="model1.userInfo.phone" :placeholder="i18n.pleasePhoneNumber"
- border="none"></u--input> -->
- <view class="right" style="display: flex;">
- <input style="width: 100rpx;" type="text" placeholder="(+86)"
- v-model="model1.userInfo.phonecode" />
- <!-- <u--input style="width: 100rpx;" v-model="model1.userInfo.phonecode" placeholder="(+86)" border="none"></u--input> -->
- <text style="margin-right: 20rpx;">-</text>
- <u--input v-model="model1.userInfo.phone" :placeholder="i18n.pleasePhone"
- border="none"></u--input>
- </view>
- </u-form-item>
- <u-form-item labelWidth="150rpx" :label="i18n.postalCode" borderBottom ref="item1">
- <u--input v-model="model1.userInfo.zip_code" :placeholder="i18n.PleacePostalCode"
- border="none"></u--input>
- </u-form-item>
- <u-form-item labelWidth="150rpx" :label="i18n.city" borderBottom @click="openCity" ref="item1">
- <u--input v-model="model1.userInfo.city" disabled disabledColor="#ffffff"
- :placeholder="i18n.township" border="none"></u--input>
- <u-icon slot="right" name="arrow-right"></u-icon>
- </u-form-item>
- <u-form-item labelWidth="150rpx" :label="i18n.detailed" borderBottom ref="item1">
- <u--input v-model="model1.userInfo.detailed" :placeholder="i18n.sect" border="none"></u--input>
- </u-form-item>
- <u-form-item labelWidth="150rpx" :label="i18n.companyName" borderBottom ref="item1">
- <u--input v-model="model1.userInfo.companyName" :placeholder="i18n.company"
- border="none"></u--input>
- </u-form-item>
- <u-form-item labelWidth="150rpx" :label="i18n.email" borderBottom ref="item1">
- <u--input v-model="model1.userInfo.email" :placeholder="i18n.pleaseEmail" border="none"></u--input>
- </u-form-item>
- <view style="
- display: flex;
- justify-content: space-between;
- align-items: center;
- ">
- <view class="item-left">
- <image src="../../static/mine/330.png" class="address-icon" mode=""></image>
- <text>{{ i18n.addressBook }}</text>
- </view>
- <text style="font-size: 24rpx; color: #333" @click="empty">{{
- i18n.empty
- }}</text>
- </view>
- </u--form>
- </view>
- <!-- <SelectCity :show="show" @close="close" :countryId="country.id" /> -->
- <view class="footer">
- <button class="save" @click="submit">{{ i18n.preserve }}</button>
- </view>
- <u-picker :show="show" :columns="cityList" keyName="name" @confirm="countrycConfirm" @cancel="show = false"
- :closeOnClickOverlay="true" @close="close">
- <view class="" slot="input">
- <u--input placeholder="请输入想要搜索的地址" border="surround" v-model="keyword1" @change="changecity"></u--input>
- </view>
- </u-picker>
- <u-picker :show="showDialog" :columns="columns" keyName="name" @cancel="showDialog = false"
- :closeOnClickOverlay="true" @confirm="confirm" @close="close">
- <view class="" slot="input">
- <u--input placeholder="请输入想要搜索的地址" border="surround" v-model="keyword" @change="changeinput"></u--input>
- </view>
- </u-picker>
- </view>
- </template>
- <script>
- import SelectCity from "../addEditAddress/component/selectCity.vue";
- export default {
- components: {
- SelectCity,
- },
- computed: {
- i18n() {
- return this.$t("index");
- },
- },
- data() {
- return {
- show: false, //城市弹窗
- showDialog: false, //国家弹窗
- //表单数据
- model1: {
- userInfo: {
- name: "",
- phone: "",
- country: "",
- postalCode: "",
- city: "",
- detailed: "",
- email: "",
- companyName: "",
- zip_code: "",
- },
- },
- selectedCity: {}, //选中的城市
- columns: [], //获取到的国家数据
- country: {}, //选中的国家数据
- cityList: [
- []
- ], //选中国家之后的城市数据
- newlist: [],
- newcitylist: [
- []
- ],
- addressId: "", //编辑的地址id
- rules: {
- "userInfo.name": {
- type: "string",
- required: true,
- message: "请填写姓名",
- trigger: ["blur", "change"],
- },
- "userInfo.sex": {
- type: "string",
- max: 1,
- required: true,
- message: "请选择男或女",
- trigger: ["blur", "change"],
- },
- },
- keyword:'',
- keyword1:''
- };
- },
- onLoad(options) {
- if (options.id) {
- this.addressId = options.id;
- this.getAddressDetail(options.id);
- } else {
- uni.setNavigationBarTitle({
- title: this.i18n.newAddress,
- });
- }
- },
- methods: {
- changeinput(e) {
- console.log(e);
- console.log(this.columns);
- this.columns = this.newlist
- var list = [
- []
- ]
- this.columns[0].forEach(item => {
- if (item.name.indexOf(e) != -1) {
- list[0].push(item)
- }
- })
- this.columns = list
- },
- changecity(e) {
- this.cityList = this.newcitylist
- console.log(this.cityList);
- var list = [
- []
- ]
- this.cityList[0].forEach(item => {
- if (item.name.indexOf(e) != -1) {
- list[0].push(item)
- }
- })
- this.cityList = list
- },
- //回显数据
- getAddressDetail(id) {
- uni.setNavigationBarTitle({
- title: "编辑地址",
- });
- uni.$u.http.get(`/api/address/${id}`).then((res) => {
- this.model1.userInfo.city = res.province_name;
- this.model1.userInfo.name = res.name;
- this.model1.userInfo.phone = res.mobile;
- this.model1.userInfo.detailed = res.address;
- this.model1.userInfo.companyName = res.company_name;
- this.model1.userInfo.is_default = res.is_default;
- this.model1.userInfo.country = res.country_name;
- this.model1.userInfo.email = res.email;
- this.country.id = res.country_id;
- this.selectedCity.id = res.province_id;
- this.model1.userInfo.zip_code = res.zip_code;
- this.model1.userInfo.phonecode = res.global_roaming;
- });
- },
- //清空输入
- empty() {
- this.model1.userInfo = {
- name: "",
- phone: "",
- country: "",
- postalCode: "",
- city: "",
- detailed: "",
- email: "",
- companyName: "",
- zip_code: "",
- phonecode: '',
- };
- },
- //选择国家
- confirm(e) {
- this.country = e.value[0];
- this.model1.userInfo.country = this.country.name;
- this.getCityList(this.country.id);
- this.showDialog = false;
- this.keyword = ''
- },
- //打开选择城市的弹窗
- openCity() {
- //判断是否选择国家
- if (JSON.stringify(this.country) != "{}") {
- //判断选中的国家有没有城市数据
- if (this.cityList[0].length > 0) {
- this.show = true;
- } else {
- uni.$u.toast("该国家没有城市数据,请直接填写详细地址");
- }
- } else {
- uni.$u.toast("请先选择国家");
- }
- },
- //选择国家
- countrycConfirm(e) {
- this.selectedCity = e.value[0];
- this.model1.userInfo.city = this.selectedCity.name;
- this.show = false;
- this.keyword1 = ''
- },
- submit() {
- const obj = {
- mobile: this.model1.userInfo.phone,
- name: this.model1.userInfo.name,
- country_id: this.country.id,
- province_id: this.selectedCity.id,
- address: this.model1.userInfo.detailed,
- company_name: this.model1.userInfo.companyName,
- email: this.model1.userInfo.email,
- zip_code: this.model1.userInfo.zip_code,
- global_roaming: this.model1.userInfo.phonecode,
- };
- if (this.addressId) {
- uni.$u.http.put(`/api/address/${this.addressId}`, obj).then((res) => {
- uni.navigateBack({
- delta: 1,
- });
- });
- } else {
- uni.$u.http.post(`/api/address`, obj).then((res) => {
- uni.navigateBack({
- delta: 1,
- });
- });
- }
- },
- //关闭弹窗
- close() {
- this.show = false;
- this.showDialog = false;
- this.keyword = ''
- this.keyword1 = ''
- },
- // 获取所有国家
- getCountryList() {
- uni.$u.http.get(`/api/area?is_domestic=0&pid=`).then((res) => {
- this.columns = [res];
- this.newlist = [res];
- });
- },
- // getCountryList() {
- // uni.$u.http.get(`/api/container/country`).then((res) => {
- // this.columns = [res];
- // });
- // },
- //根据国家获取城市
- getCityList(num) {
- uni.$u.http.get(`/api/area/tree?pid=${num}`).then((res) => {
- this.cityList = [res];
- this.newcitylist = [res];
- });
- },
- },
- mounted() {
- this.getCountryList();
- },
- onReady() {
- //如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
- this.$refs.uForm.setRules(this.rules);
- },
- };
- </script>
- <style lang="scss" scoped>
- .page {
- padding: 20rpx 24rpx;
- .content {
- background-color: #fff;
- border-radius: 16rpx;
- padding: 0 24rpx;
- .title {
- display: flex;
- justify-content: space-between;
- align-items: center;
- height: 100rpx;
- border-bottom: 2rpx solid rgba(151, 151, 151, 0.1);
- .title-left {
- font-size: 32rpx;
- color: #333;
- font-weight: 600;
- }
- .title-icon {
- width: 26rpx;
- height: 26rpx;
- margin-right: 10rpx;
- }
- .title-right {
- display: flex;
- align-items: center;
- font-size: 24rpx;
- color: rgba(51, 51, 51, 0.6);
- }
- }
- .company {
- height: 102rpx;
- display: flex;
- align-items: center;
- border-bottom: 2rpx solid rgba(151, 151, 151, 0.1);
- }
- }
- .item-left {
- font-size: 24rpx;
- color: #333;
- display: flex;
- align-items: center;
- height: 86rpx;
- .address-icon {
- width: 26rpx;
- height: 26rpx;
- margin-right: 10rpx;
- }
- }
- .footer {
- background-color: #fff;
- position: fixed;
- bottom: 0;
- height: 146rpx;
- width: 750rpx;
- left: 0;
- padding-top: 20rpx;
- .save {
- width: 702rpx;
- margin: 0 auto;
- background-color: #f83224;
- color: #fff;
- border-radius: 40rpx;
- }
- }
- }
- </style>
|