shuishen
2023-02-23 f5d288347e559a36fa4dc33ff528ddc05a4f3902
商业排序
1 files modified
85 ■■■■■ changed files
src/views/house/index.vue 85 ●●●●● patch | view | raw | blame | history
src/views/house/index.vue
@@ -2,7 +2,7 @@
 * @Author: shuishen 1109946754@qq.com
 * @Date: 2022-08-18 16:18:17
 * @LastEditors: shuishen 1109946754@qq.com
 * @LastEditTime: 2023-02-23 08:57:03
 * @LastEditTime: 2023-02-23 10:57:03
 * @FilePath: \srs-police-affairs\src\views\house\index.vue
 * @Description: 小区-栋-层-房屋
 * 
@@ -304,8 +304,9 @@
                        <el-table :data="businessData" style="width: 100%"
                            :header-cell-style="{ 'text-align': 'center', 'background-color': '#203c60', 'borderColor': '#324e75' }"
                            :cell-style="{ 'text-align': 'center', 'borderColor': '#324e75' }"
                            :row-class-name="tableRowClassName" @row-click="deepDataRowClick($event, 'business')">
                            <el-table-column prop="name" label="名称" width="180"
                            :row-class-name="tableRowClassName" @row-click="deepDataRowClick($event, 'business')"
                            @sort-change="sortDevName">
                            <el-table-column sortable="custom" prop="name" label="名称" width="180"
                                :show-overflow-tooltip="true"></el-table-column>
                            <el-table-column prop="x" label="经度" width="100"></el-table-column>
                            <el-table-column prop="y" label="纬度" width="100"></el-table-column>
@@ -936,7 +937,6 @@
        },
        buildingClick (item, aoiArr) {
            console.log(item, 456)
            this.unitHouseChoosed = []
            this.pictLoading = true
            if (!aoiArr) {
@@ -1385,6 +1385,83 @@
                })
        },
        /**
         * @description: 小区商业排序
         * @return {*}
         */
        sortDevName ({ prop, order }) {
            this.businessData.sort(this.compare(prop, order))
        },
        compare (property, order) {
            if (order == 'ascending') {
                return (a, b) => {
                    var value1 = a[property]
                    var value2 = b[property]
                    const char1Type = this.getChartType(value1)
                    const char2Type = this.getChartType(value2)
                    // 类型相同的逐个比较字符
                    if (char1Type[0] === char2Type[0]) {
                        if (value1 === value2) {
                            return char1Type[1] - char2Type[1]
                        } else {
                            if (char1Type[0] === 'zh') {
                                return value1.localeCompare(value2)
                            } else if (char1Type[0] === 'en') {
                                return value1.charCodeAt(0) - value2.charCodeAt(0)
                            } else {
                                return value1 - value2
                            }
                        }
                    } else {
                        return char1Type[1] - char2Type[1]
                    }
                }
            } else {
                return (a, b) => {
                    var value1 = a[property]
                    var value2 = b[property]
                    const char1Type = this.getChartType(value1)
                    const char2Type = this.getChartType(value2)
                    // 类型相同的逐个比较字符
                    if (char1Type[0] === char2Type[0]) {
                        if (value1 === value2) {
                            return char2Type[1] - char1Type[1]
                        } else {
                            if (char1Type[0] === 'zh') {
                                return value2.localeCompare(value1)
                            } else if (char1Type[0] === 'en') {
                                return value2.charCodeAt(0) - value1.charCodeAt(0)
                            } else {
                                return value2 - value1
                            }
                        }
                    } else {
                        return char2Type[1] - char1Type[1]
                    }
                }
            }
        },
        getChartType (char) {
            // 数字可按照排序的要求进行自定义,我这边产品的要求是
            // 数字(0->9)->大写字母(A->Z)->小写字母(a->z)->中文拼音(a->z)
            if (/^[\u4e00-\u9fa5]$/.test(char.trim().charAt(0))) {
                return ['zh', 300]
            }
            if (/^[a-zA-Z]$/.test(char.trim().charAt(0))) {
                return ['en', 200]
            }
            if (/^[0-9]$/.test(char.trim().charAt(0))) {
                return ['number', 100]
            }
            return ['others', 999]
        }
    },
    destroyed () {