|
@@ -47,7 +47,7 @@
|
|
|
<view class="form_group">
|
|
|
<view class="group_title">店铺名称:</view>
|
|
|
<view class="group_box">
|
|
|
- <input type="text" class="form_ctrl" placeholder="请输入营业执照全称" maxlength="20" required="" v-model="addrRequest.contact_shop" />
|
|
|
+ <uni-combox v-model="addrRequest.contact_shop" :candidates="searchResults" @input="onSearchInput" @change="onSearchChange" placeholder="请输入营业执照全称"> </uni-combox>
|
|
|
</view>
|
|
|
</view>
|
|
|
<view class="form_group">
|
|
@@ -98,6 +98,15 @@
|
|
|
import { getProvinces, getMyCity, getAreas, getProvincesIndex, getCityIndex, getAreaIndex } from "../../utils/city";
|
|
|
import Empty from "@/components/Empty/Empty.vue";
|
|
|
|
|
|
+// 防抖函数
|
|
|
+function debounce(func, wait) {
|
|
|
+ let timeout;
|
|
|
+ return function (...args) {
|
|
|
+ clearTimeout(timeout);
|
|
|
+ timeout = setTimeout(() => func.apply(this, args), wait);
|
|
|
+ };
|
|
|
+}
|
|
|
+
|
|
|
export default {
|
|
|
components: { Empty },
|
|
|
data() {
|
|
@@ -139,6 +148,10 @@ export default {
|
|
|
{ key: 2, label: "连锁" },
|
|
|
{ key: 3, label: "诊所、社康等" },
|
|
|
],
|
|
|
+ //获取的默认地址
|
|
|
+ defaultAddr: {},
|
|
|
+ //远程搜索返回的数据
|
|
|
+ searchResults: [],
|
|
|
};
|
|
|
},
|
|
|
onLoad(param) {
|
|
@@ -146,6 +159,7 @@ export default {
|
|
|
this.autoShowForm = param.type == "create" ? true : false;
|
|
|
// 获取列表
|
|
|
this.getList();
|
|
|
+ this.get_remark_addr();
|
|
|
},
|
|
|
onReady() {
|
|
|
if (this.autoShowForm) {
|
|
@@ -167,6 +181,49 @@ export default {
|
|
|
this.addrRequest.contact_area = this.cityArray[2][this.cityValue[2]];
|
|
|
},
|
|
|
methods: {
|
|
|
+ onSearchInput: debounce(function (inputVal, isSelect) {
|
|
|
+ console.log("搜索关键字:", this.addrRequest.contact_shop);
|
|
|
+ console.log("是否选择:", isSelect);
|
|
|
+ if (isSelect) return;
|
|
|
+ if (this.addrRequest.contact_shop.trim() === "" || this.addrRequest.contact_shop.length < 2) {
|
|
|
+ this.searchResults = [];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.$http.request("api/custom_addr/get_guess_addr", { contact_shop: this.addrRequest.contact_shop }).then((callback) => {
|
|
|
+ // 获取成功
|
|
|
+ if (callback.code == "success") {
|
|
|
+ this.searchResults = callback.data.map((item, index) => ({
|
|
|
+ text: item.contact_shop,
|
|
|
+ value: index,
|
|
|
+ ...item,
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }, 300),
|
|
|
+ onSearchChange(event) {
|
|
|
+ if (event.shop_type !== 0) this.addrRequest.shop_type = event.shop_type;
|
|
|
+ this.addrRequest.contact_addr = event.contact_addr;
|
|
|
+ const { contact_province, contact_city, contact_area } = event;
|
|
|
+ const provinces = getProvincesIndex(contact_province);
|
|
|
+ const city = getCityIndex(contact_city, provinces.city, provinces.index);
|
|
|
+ const area = getAreaIndex(contact_area, city.area);
|
|
|
+ this.cityValue = [provinces.index, city.index, area.index];
|
|
|
+ this.cityArray.splice(1, 1, provinces.city);
|
|
|
+ this.cityArray.splice(2, 1, city.area);
|
|
|
+ this.addrRequest.contact_province = contact_province;
|
|
|
+ this.addrRequest.contact_area = contact_area;
|
|
|
+ this.addrRequest.contact_city = contact_city;
|
|
|
+ },
|
|
|
+ //获取get_remark_addr
|
|
|
+ get_remark_addr() {
|
|
|
+ this.$http.request("api/custom_addr/get_remark_addr").then((callback) => {
|
|
|
+ // 获取成功
|
|
|
+ if (callback.code == "success") {
|
|
|
+ // 通知地址变更
|
|
|
+ this.defaultAddr = callback.data;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
// 获取列表
|
|
|
getList() {
|
|
|
// 登录提示
|
|
@@ -185,16 +242,31 @@ export default {
|
|
|
openForm(item) {
|
|
|
if (!item) {
|
|
|
this.addrRequest.id = 0;
|
|
|
- this.addrRequest.contact_name = "";
|
|
|
- this.addrRequest.contact_phone = "";
|
|
|
- this.addrRequest.contact_shop = "";
|
|
|
- this.addrRequest.contact_addr = "";
|
|
|
+ this.addrRequest.contact_name = this.defaultAddr.contact_name;
|
|
|
+ this.addrRequest.contact_phone = this.defaultAddr.contact_phone;
|
|
|
+ this.addrRequest.contact_shop = this.defaultAddr.contact_shop;
|
|
|
+ this.addrRequest.contact_addr = this.defaultAddr.contact_addr;
|
|
|
this.addrRequest.is_default = 0;
|
|
|
- this.addrRequest.shop_type = 1;
|
|
|
- this.cityValue = [0, 0, 0];
|
|
|
- this.addrRequest.contact_province = "请选择";
|
|
|
- this.addrRequest.contact_city = "请选择";
|
|
|
- this.addrRequest.contact_area = "请选择";
|
|
|
+ this.addrRequest.shop_type = this.defaultAddr.shop_type == "" ? 1 : this.defaultAddr.shop_type;
|
|
|
+ const { contact_province, contact_city, contact_area } = this.defaultAddr;
|
|
|
+ if (contact_province == "") {
|
|
|
+ this.cityValue = [0, 0, 0];
|
|
|
+ this.addrRequest.contact_province = "请选择";
|
|
|
+ this.addrRequest.contact_city = "请选择";
|
|
|
+ this.addrRequest.contact_area = "请选择";
|
|
|
+ } else {
|
|
|
+ const provinces = getProvincesIndex(contact_province);
|
|
|
+ const city = getCityIndex(contact_city, provinces.city, provinces.index);
|
|
|
+ const area = getAreaIndex(contact_area, city.area);
|
|
|
+ this.cityValue = [provinces.index, city.index, area.index];
|
|
|
+ this.cityArray.splice(1, 1, provinces.city);
|
|
|
+ this.cityArray.splice(2, 1, city.area);
|
|
|
+ this.addrRequest.contact_province = contact_province;
|
|
|
+ this.addrRequest.contact_area = contact_area;
|
|
|
+ this.addrRequest.contact_city = contact_city;
|
|
|
+ if (contact_area == "") this.addrRequest.contact_area = "请选择";
|
|
|
+ if (contact_city == "") this.addrRequest.contact_city = "请选择";
|
|
|
+ }
|
|
|
} else {
|
|
|
if (!item.shop_type) item.shop_type = 1;
|
|
|
const _cloneItem = JSON.parse(JSON.stringify(item));
|
|
@@ -441,9 +513,9 @@ export default {
|
|
|
background: #ffffff;
|
|
|
.form_group {
|
|
|
display: block;
|
|
|
- overflow: hidden;
|
|
|
line-height: 60rpx;
|
|
|
padding: 20rpx 35rpx;
|
|
|
+ height: 56rpx;
|
|
|
.group_title {
|
|
|
float: left;
|
|
|
width: 160rpx;
|