WebApp【公共组件库】@前端(For Git Submodule)
Tevin
2021-03-29 1bd2c493c9cbe47d10e4ba045d5c4635fd4eccef
forms/chinaArea/CChinaArea.vue
@@ -1,5 +1,5 @@
/**
 * CChinaArea
 * CChinaArea - 表单项,中国地址三级联动
 * @author Tevin
 */
@@ -16,14 +16,14 @@
            <view @tap="evt=>handleOpen(evt)">
                <AtInput
                    ref="input"
                    :name="itemData.name"
                    :title="itemData.label"
                    :required="itemData.required"
                    :error="itemData.error"
                    :name="itemRes.name"
                    :title="itemRes.label"
                    :required="itemRes.required"
                    :error="itemRes.error"
                    :placeholder="placeholder"
                    :value="selected"
                >
                    <view class="at-icon at-icon-chevron-right" />
                    <AtIcon :value="loading ? 'loading':'chevron-right'" />
                </AtInput>
            </view>
        </picker>
@@ -31,7 +31,7 @@
</template>
<script>
import { AtInput } from 'taro-ui-vue';
import { AtInput, AtIcon } from 'taro-ui-vue';
import ChinaLocations from './ChinaLocations';
import './cChinaArea.scss';
@@ -41,10 +41,18 @@
    name: 'CChinaArea',
    components: {
        AtInput,
        AtIcon,
    },
    props: {
        // 表单数据资源(表单组件内部机制专用)
        itemRes: Object,
        // 当地址获取经纬度时,设置加载中显示状态
        loading: {
            type: Boolean,
            default: false,
        },
        // 占位提示
        placeholder: String,
        itemData: Object,
    },
    data() {
        return {
@@ -54,7 +62,7 @@
    },
    computed: {
        selected() {
            const curVal = this.itemData.formData[this.itemData.name];
            const curVal = this.itemRes.formData[this.itemRes.name];
            if (curVal && curVal.length === 3) {
                return getRegionNames(curVal).join(' / ');
            } else {
@@ -69,7 +77,7 @@
                evt.preventDefault();
                return;
            }
            const curVal = this.itemData.formData[this.itemData.name];
            const curVal = this.itemRes.formData[this.itemRes.name];
            const range = [
                locationTree,
                locationTree[0].children,
@@ -81,7 +89,7 @@
                // 省
                if (curVal[0]) {
                    const proviceIndex = locationTree.findIndex(
                        (provice) => provice.code === curVal[0]
                        provice => provice.code === curVal[0]
                    );
                    if (proviceIndex >= 0) {
                        range[1] = locationTree[proviceIndex].children;
@@ -89,7 +97,9 @@
                        current[0] = proviceIndex;
                        // 市
                        if (curVal[1]) {
                            const cityIndex = range[1].findIndex((city) => city.code === curVal[1]);
                            const cityIndex = range[1].findIndex(
                                city => city.code === curVal[1]
                            );
                            if (cityIndex >= 0) {
                                range[2] = range[1].children[cityIndex].children;
                                current[1] = cityIndex;
@@ -97,7 +107,7 @@
                            // 区
                            if (curVal[2]) {
                                const areaIndex = range[2].findIndex(
                                    (area) => area.code === curVal[2]
                                    area => area.code === curVal[2]
                                );
                                if (areaIndex >= 0) {
                                    current[2] === areaIndex;
@@ -131,7 +141,7 @@
            codes[1] = city.value;
            const area = city.children[detail[2]];
            codes[2] = area.value;
            this.itemData.onChange(codes);
            this.itemRes.onChange(codes);
        },
    },
    mounted() {},