| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- <template>
- <view class="container">
- <!-- 顶部选择校区区域 -->
- <view class="top">
- <uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" styleType="text" activeColor="#6FB6B8"></uni-segmented-control>
- </view>
- <view class="gap"></view>
- <!-- 主体内容区域 -->
- <view class="body">
- <!-- 左边区域 -->
- <view class="body_left">
- <view class="body_left_item" :class="{ active: active_left === index }" v-for="(item, index) in leftList" :key="index" @click="handleChange(index)">
- {{ item }}
- </view>
- </view>
- <!-- 右边区域 -->
- <view class="body_right">
- <view class="body_right_item" :class="{ active: active_right === index }" v-for="(item, index) in rightList" :key="index" @click="handleChange2(index)">
- {{ item.name }}
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- // 顶部分段器选项数组
- items: [],
- // 分段器当前索引
- current: 0,
- // 校区ID
- schoolId: 0,
- // 楼栋Id
- buildId: null,
- // 地址Id
- addressId: null,
- // 左边分类数组
- leftList: [],
- // 左边分类数组当前索引
- active_left: 0,
- // 右边分类数组
- rightList: [],
- // 右边分类数组当前索引
- active_right: null,
- // 报修区域数组
- areaTreeList: [],
- // 校区数组
- schoolList: [],
- // 密匙
- key: 'ee7d39a2cc41bd2ffca08d3aa3fe5fe5'
- }
- },
- onLoad(options) {
- if (options.schoolId) {
- this.schoolId = options.schoolId
- this.buildId = options.buildId
- this.addressId = options.addressId
- }
- this.getSchoolList()
- },
- methods: {
- // 获取当前定位位置信息
- getLocationData() {
- uni.showLoading({
- title: '定位中,请稍后',
- mask: true
- })
- uni.getLocation({
- type: 'gcj02',
- success: (res) => {
- // 获取详细地址
- uni.request({
- url: `https://api.tianditu.gov.cn/geocoder?postStr={'lon':${res.longitude},'lat':${res.latitude},'ver':1}&type=geocode&tk=${this.key}`,
- success: (res) => {
- // console.log(res)
- let address = res.data.result.formatted_address
- if (address.indexOf('南昌市') !== -1) {
- this.current = 0
- } else {
- this.current = 1
- }
- this.schoolId = this.schoolList[this.current].id
- this.getRepairAreaTree()
- },
- fail: () => {
- uni.showModal({
- title: '提示',
- content: '定位失败,请手动选择校区',
- showCancel: false,
- confirmText: '确定',
- success: (res) => {
- if (res.confirm) {
- this.current = 0
- this.schoolId = this.schoolList[this.current].id
- this.getRepairAreaTree()
- }
- }
- })
- },
- complete: () => {
- uni.hideLoading()
- }
- })
- }
- })
- },
- // 获取校区数据
- async getSchoolList() {
- const res = await this.$myRequest_repairs({
- url: '/repairArea/queryRepairSchools'
- })
- // console.log(res)
- if (res.code === '200') {
- this.schoolList = res.data
- // 获取之前选择过的校区
- this.schoolList.forEach((ele, index) => {
- if (ele.id == this.schoolId) {
- this.current = index
- }
- })
- this.items = this.schoolList.map((ele) => ele.name)
- let schoolAddress = uni.getStorageSync('schoolAddress')
- if (schoolAddress) {
- this.items.forEach((ele, index) => {
- if (ele === schoolAddress) {
- this.current = index
- }
- })
- this.schoolId = this.schoolList[this.current].id
- this.getRepairAreaTree()
- } else {
- this.getLocationData()
- }
- }
- },
- // 获取区域数据
- async getRepairAreaTree() {
- const res = await this.$myRequest_repairs({
- url: '/repairArea/queryRepairAreaTree',
- data: {
- schoolId: this.schoolId
- }
- })
- // console.log(res)
- if (res.code === '200') {
- this.areaTreeList = res.data
- // 获取之前选择过的楼栋
- this.areaTreeList.forEach((ele, index) => {
- if (ele.id == this.buildId) {
- this.active_left = index
- }
- })
- this.leftList = this.areaTreeList.map((ele) => ele.name)
- this.rightList = this.areaTreeList[this.active_left].children || []
- // 获取之前选择过的地址
- this.rightList.forEach((ele, index) => {
- if (ele.id == this.addressId) {
- this.active_right = index
- }
- })
- }
- },
- // 顶部分段器切换选项回调
- onClickItem(e) {
- this.active_left = 0
- this.active_right = null
- this.buildId = null
- this.addressId = null
- if (this.current != e.currentIndex) {
- this.current = e.currentIndex
- this.schoolId = this.schoolList[this.current].id
- this.getRepairAreaTree()
- }
- },
- // 左边数组切换回调
- handleChange(index) {
- this.active_left = index
- this.active_right = null
- this.rightList = this.areaTreeList[this.active_left].children || []
- },
- // 右边数组切换回调
- handleChange2(index) {
- this.active_right = index
- const repairsArea = this.items[this.current] + this.leftList[this.active_left] + this.rightList[this.active_right].name
- uni.setStorageSync('schoolAddress', this.items[this.current])
- uni.$emit('addRepairsArea', {
- data: repairsArea,
- schoolId: this.schoolId,
- buildId: this.areaTreeList[this.active_left].id,
- addressId: this.rightList[this.active_right].id
- })
- uni.navigateBack(1)
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .container {
- width: 100vw;
- height: 100vh;
- .top {
- height: 100rpx;
- }
- .gap {
- height: 10rpx;
- background-color: #f2f2f2;
- }
- .body {
- display: flex;
- height: calc(100vh - 110rpx);
- .body_left {
- box-sizing: border-box;
- padding: 15rpx;
- width: 198rpx;
- border-right: 1rpx solid #ccc;
- overflow-y: auto;
- .body_left_item {
- width: 100%;
- height: 80rpx;
- line-height: 80rpx;
- text-align: center;
- font-size: 28rpx;
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- }
- .active {
- color: #6fb6b8;
- }
- }
- .body_right {
- box-sizing: border-box;
- padding: 30rpx 40rpx;
- width: 552rpx;
- overflow-y: auto;
- .body_right_item {
- float: left;
- box-sizing: border-box;
- margin: 0 12rpx 28rpx 0;
- padding: 10rpx 30rpx;
- height: 50rpx;
- line-height: 30rpx;
- text-align: center;
- color: #808080;
- font-size: 28rpx;
- border-radius: 53rpx;
- background-color: #e6e6e6;
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- }
- .active {
- color: #fff;
- background-color: #6fb6b8;
- }
- }
- }
- }
- ::v-deep .segmented-control {
- height: 100rpx;
- }
- </style>
|