Files
app-govern/pages/home/selectEngineering.vue

87 lines
2.5 KiB
Vue
Raw Normal View History

2023-08-23 16:22:08 +08:00
<template>
<Cn-page :loading='loading'>
<view slot='body'>
<view class='select-enineering'>
<uni-indexed-list
:options="engineeringListFilter"
:showSelect="false"
@click="confirm"
2023-08-24 15:35:45 +08:00
></uni-indexed-list>
2023-08-23 16:22:08 +08:00
</view>
</view>
</Cn-page>
</template>
<script>
import {pinyin} from 'pinyin-pro'
2023-08-24 15:35:45 +08:00
import {queryEngineering} from "@/common/api/engineering";
2023-08-23 16:22:08 +08:00
export default {
data() {
return {
loading: false,
2023-08-29 16:14:09 +08:00
engineeringList: [],
options: {}
2023-08-23 16:22:08 +08:00
}
},
computed: {
engineeringListFilter() {
let result = []
this.engineeringList.forEach((item) => {
let arr = pinyin(item.name[0], {toneType: 'none', type: 'array'})
let letter = arr[0][0].toUpperCase()
console.log(letter)
let index = result.findIndex((item) => item.letter === letter)
if (index === -1) {
result.push({
letter,
data: [item.name],
})
} else {
result[index].data.push(item.name)
}
})
return result
},
},
2023-08-29 16:14:09 +08:00
onLoad(options) {
this.options = options
2023-08-23 16:22:08 +08:00
this.engineeringList = uni.getStorageSync('engineeringList')
2023-08-31 16:14:15 +08:00
this.userInfo = uni.getStorageSync(this.$cacheKey.userInfo)
2023-08-23 16:22:08 +08:00
},
2023-08-24 15:35:45 +08:00
onShow() {
queryEngineering().then(res => {
this.engineeringList = res.data
})
},
onNavigationBarButtonTap(e) {
2023-08-31 16:14:15 +08:00
if (this.userInfo.authorities === 'app_vip_user' || this.userInfo.authorities === 'engineering_user') {
uni.navigateTo({
url: `/pages/engineering/new`,
})
} else {
uni.showToast({
title: '暂无权限',
icon: 'none',
})
}
2023-08-24 15:35:45 +08:00
},
2023-08-23 16:22:08 +08:00
methods: {
confirm(e) {
console.log(e)
let engineering = this.engineeringList.find((item) => item.name === e.item.name)
2023-09-06 10:56:10 +08:00
if (this.options.from === 'once') {
2023-08-29 16:14:09 +08:00
// 创建项目的时候选择工程 用完即删
2023-09-06 10:56:10 +08:00
uni.setStorageSync('onceSelectEngineering', engineering)
2023-08-29 16:14:09 +08:00
} else {
uni.setStorageSync('engineering', engineering)
}
2023-08-23 16:22:08 +08:00
uni.navigateBack()
},
}
}
</script>
<style lang='scss'>
.index {
padding: 34rpx;
}
</style>