Files
dvcp_v2_wechat_app/src/components/pages/selectGird.vue

254 lines
6.6 KiB
Vue
Raw Normal View History

2022-02-15 15:38:20 +08:00
<template>
2022-06-14 18:23:20 +08:00
<div class="SelectGird">
<div class="header-middle">
2022-02-15 15:38:20 +08:00
<div class="hint">
2022-06-14 18:23:20 +08:00
<span v-for="(item, index) in selectList" :key="index">
<span v-if="index" style="margin:0 4px;" v-text="`/`"/>
<span style="color:#3F8DF5" @click="girdNameClick(item, index)" v-text="item.girdName"/>
</span>
2022-02-15 15:38:20 +08:00
</div>
<div class="showTypes">
<div v-if="options.length > 0">
<div class="cards" v-for="(item, index) in options" :key="index" @click="itemClick(item)">
<div class="imges">
<img src="./img/xzh.png" alt="" class="imgselect" v-if="item.isChecked"
@click.stop="girdClick(item, index)"/>
2022-06-14 18:23:20 +08:00
<img src="./img/xz.png" alt="" class="imgselect" v-else @click.stop="girdClick(item, index)"/>
2022-02-15 15:38:20 +08:00
<img src="./img/gird--select-icon.png" alt="" class="avatras"/>
</div>
2022-06-14 18:23:20 +08:00
<div class="rightes fill">
2022-02-15 15:38:20 +08:00
<div class="applicationNames fill">{{ item.girdName }}</div>
</div>
</div>
</div>
2022-06-15 10:33:55 +08:00
<AiEmpty :description="`暂无数据`" class="emptyWrap" v-else/>
2022-02-15 15:38:20 +08:00
</div>
</div>
2022-06-14 18:23:20 +08:00
<div class="subBtn flex">
<div v-if="clearable" class="cancel" @click="cancel">清空</div>
<div @click="submit">确定选择</div>
2022-02-15 15:38:20 +08:00
</div>
</div>
</template>
<script>
2022-06-14 18:23:20 +08:00
import {mapState} from "vuex";
2022-02-15 15:38:20 +08:00
export default {
name: 'selectGird',
appName: "网格选择",
data() {
return {
SelectGird: {},
allData: null,
2022-06-14 18:23:20 +08:00
options: [],
2022-02-15 15:38:20 +08:00
selectList: [],
parentGirdId: '',
2022-06-14 18:23:20 +08:00
query: {}
2022-02-15 15:38:20 +08:00
}
},
computed: {
2022-06-14 18:23:20 +08:00
...mapState(['user']),
//是否展示所有网格(随手拍)
isApply: v => v.query?.formType == 2,
clearable: v => v.query?.clearable,
selected: v => [v.query?.selected].flat(),
2022-02-15 15:38:20 +08:00
},
2022-06-14 18:23:20 +08:00
onLoad(query) {
this.query = query
2022-06-15 10:33:55 +08:00
this.getAllGrids()
2022-02-15 15:38:20 +08:00
},
methods: {
2022-06-14 18:23:20 +08:00
getAllGrids() {
2022-02-15 15:38:20 +08:00
this.selectList = []
2023-05-15 10:17:42 +08:00
let url = this.query.axiosUrl ? this.query.axiosUrl : `/app/appgirdinfo/listByInfo`
2022-06-15 10:33:55 +08:00
this.$instance.post(url).then(res => {
2022-02-15 15:38:20 +08:00
if (res?.data) {
2022-06-14 18:23:20 +08:00
let parents = res.data?.map(e => e.parentGirdId)
this.allData = res.data?.map(e => ({...e, hasChildren: parents.includes(e.id)}))
2022-02-15 15:38:20 +08:00
this.treeInit()
}
})
},
2022-06-14 18:23:20 +08:00
treeInit(isClick) {
let last = uni.getStorageSync("lastSelectedGrid")
if (!isClick && last && !this.isApply) {
this.$instance.post("/app/appgirdinfo/listFatherGirdInfo", null, {
params: {girdId: last}
}).then(res => {
if (res?.data) {
this.selectList = [{girdName: '可选范围', id: ''}, res.data.filter(e => !!this.allData.find(a => a.id == e.id))].flat()
this.getGridsByGridMemberAndParent({id: last})
}
})
} else {
2022-06-15 10:33:55 +08:00
this.options = this.allData.filter((e, i, arr) => !arr?.map(e => e.id).includes(e.parentGirdId))
2022-06-14 18:23:20 +08:00
this.options?.map((item) => item.isChecked = this.selected.includes(item.id))
let obj = {girdName: '可选范围', id: ''}
this.selectList.push(obj)
2022-02-15 15:38:20 +08:00
}
},
itemClick(row) {
2022-06-14 18:23:20 +08:00
if (row.hasChildren) {
let obj = {
girdName: row.girdName,
id: row.id,
2022-02-15 15:38:20 +08:00
}
2022-06-14 18:23:20 +08:00
this.selectList.push(obj)
this.getGridsByGridMemberAndParent(row)
}
},
getGridsByGridMemberAndParent(row) {
let {id: parentGirdId} = row
this.options = this.allData.filter(e => e.parentGirdId == parentGirdId)
this.options?.map((item) => item.isChecked = this.selected.includes(item.id))
2022-02-15 15:38:20 +08:00
},
girdNameClick(row, index) {
if (!index) { //第一级别
this.selectList = []
2022-06-14 18:23:20 +08:00
this.treeInit(true)
2022-02-15 15:38:20 +08:00
} else {
2022-06-14 18:23:20 +08:00
this.selectList.splice(index, 8)
this.getGridsByGridMemberAndParent(row)
2022-02-15 15:38:20 +08:00
}
},
girdClick(row, index) {
2022-06-14 18:23:20 +08:00
if (this.options[index].isChecked) {//取消
this.options[index].isChecked = false
2022-02-15 15:38:20 +08:00
this.SelectGird = {}
} else {
2022-06-14 18:23:20 +08:00
this.options?.map((item) => {
2022-02-15 15:38:20 +08:00
item.isChecked = false
})
2022-06-14 18:23:20 +08:00
this.options[index].isChecked = true
2022-02-15 15:38:20 +08:00
this.SelectGird = row
}
this.$forceUpdate()
},
2022-06-14 18:23:20 +08:00
submit() {
2022-02-15 15:38:20 +08:00
if (this.SelectGird.id != null) {
2022-06-15 10:33:55 +08:00
if (!this.isApply) {
2022-06-14 18:23:20 +08:00
uni.setStorageSync("lastSelectedGrid", this.SelectGird.parentGirdId)
}
2022-02-15 15:38:20 +08:00
uni.navigateBack({
success: () => {
2022-06-14 18:23:20 +08:00
uni.$emit("pagePicker:gird", this.SelectGird)
2022-02-15 15:38:20 +08:00
}
})
} else {
return this.$u.toast('请选择网格')
}
},
2022-06-14 18:23:20 +08:00
cancel() {
this.SelectGird = {}
uni.navigateBack({
success: () => {
uni.$emit("pagePicker:gird", this.SelectGird)
}
})
}
2022-02-15 15:38:20 +08:00
}
}
</script>
<style scoped lang="scss">
2022-06-14 18:23:20 +08:00
.SelectGird {
min-height: 100vh;
2022-02-15 15:38:20 +08:00
background: #fff;
padding-bottom: 140px;
2022-06-14 18:23:20 +08:00
box-sizing: border-box;
2022-02-15 15:38:20 +08:00
.header-middle {
2022-06-14 18:23:20 +08:00
.hint {
padding: 28px 20px 28px 32px;
line-height: 56px;
box-shadow: 0px 1px 0px 0px #e4e5e6;
font-size: 30px;
font-weight: 500;
word-break: break-all;
}
2022-02-15 15:38:20 +08:00
2022-06-14 18:23:20 +08:00
.showTypes {
2022-02-15 15:38:20 +08:00
.cards {
display: flex;
align-items: center;
height: 120px;
line-height: 120px;
// background: pink;
padding: 0 0 0 32px;
.imges {
display: flex;
align-items: center;
// width: 200px;
.imgselect {
width: 48px;
height: 48px;
vertical-align: middle;
}
.avatras {
width: 74px;
height: 74px;
border-radius: 8px;
margin-left: 36px;
}
}
img {
width: 74px;
height: 74px;
border-radius: 8px;
}
.rightes {
display: flex;
border-bottom: 1px solid #e4e5e6;
2022-06-14 18:23:20 +08:00
padding: 0 16px;
2022-02-15 15:38:20 +08:00
.applicationNames {
2022-06-14 18:23:20 +08:00
display: inline-block;
2022-02-15 15:38:20 +08:00
font-size: 36px;
font-weight: 500;
color: #333333;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
2022-06-14 18:23:20 +08:00
vertical-align: bottom;
2022-02-15 15:38:20 +08:00
}
}
}
}
}
.subBtn {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 118px;
background: #f4f8fb;
2022-06-14 18:23:20 +08:00
justify-content: flex-end;
2022-02-15 15:38:20 +08:00
div {
width: 192px;
height: 80px;
line-height: 80px;
text-align: center;
2022-06-14 18:23:20 +08:00
border: 2px solid #1365dd;
2022-02-15 15:38:20 +08:00
background: #1365dd;
border-radius: 4px;
font-size: 32px;
color: #fff;
2022-06-14 18:23:20 +08:00
margin-right: 32px;
2022-02-15 15:38:20 +08:00
2022-06-14 18:23:20 +08:00
&.cancel {
color: #333;
background: #fff;
border-color: #ddd;
}
2022-02-15 15:38:20 +08:00
}
}
}
</style>