123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <template>
- <div class="hc-header-cascader-box">
- <div class="project-name-box">
- {{ projectInfo?.projectAlias }} / {{ contractInfo?.name }}
- </div>
- <el-cascader
- ref="ElCascaderRef"
- v-model="contractId" class="hc-header-cascader"
- :clearable="userInfo?.role_id === '1123598816738675201'"
- :filterable="userInfo?.role_id === '1123598816738675201'"
- :options="projectContract"
- :props="projectProps" placeholder="请选择项目"
- @change="projectContractChange"
- />
- </div>
- </template>
- <script setup>
- import { onMounted, ref, watch } from 'vue'
- import { useAppStore } from '~src/store'
- import { initProjectContract } from '~sto/app'
- import { isNullES } from 'js-fast-way'
- //事件
- const emit = defineEmits(['change', 'send'])
- //状态
- const store = useAppStore()
- const userInfo = ref(store.getUserInfo)
- const projectProps = ref({
- value: 'id',
- label: 'projectAlias',
- children: 'contractInfoList',
- })
- //项目合同段
- const projectContract = ref(store.projectContract)
- const projectInfo = ref(store.projectInfo)
- const contractInfo = ref(store.contractInfo)
- const contractId = ref(store.contractId)
- //监听
- watch(() => [
- store.projectContract,
- store.projectInfo,
- store.contractInfo,
- store.projectId,
- store.contractId,
- ], ([arr, project, contract, pid, cid]) => {
- projectContract.value = arr
- projectInfo.value = project
- contractInfo.value = contract
- contractId.value = cid
- setSend(pid, cid)
- })
- //渲染完成
- onMounted(async () => {
- await initProjectContract()
- setSend(store.projectId, store.contractId)
- })
- const setSend = (pid, cid) => {
- if (isNullES(pid) || isNullES(cid)) {
- return
- }
- emit('send', {
- projectId: pid,
- contractId: cid,
- })
- }
- //项目被选择
- const ElCascaderRef = ref(null)
- const projectContractChange = (val) => {
- if (val) {
- const Nodes = ElCascaderRef.value.getCheckedNodes()
- const UserProjectInfo = Nodes[0].parent.data
- const UserContractInfo = Nodes[0].data
- //缓存项目数据
- store.setProjectId(val[0])
- store.setContractId(val[1])
- store.setProjectInfo(UserProjectInfo)
- store.setContractInfo(UserContractInfo)
- //更改界面更新
- projectInfo.value = UserProjectInfo
- contractInfo.value = UserContractInfo
- window.$message?.info('切换了项目,数据更新中')
- emit('send', {
- projectId: val[0],
- contractId: val[1],
- })
- emit('change')
- }
- }
- </script>
- <style lang="scss">
- .hc-header-cascader-box {
- position: relative;
- margin-right: 20px;
- .project-name-box {
- position: relative;
- max-width: 340px;
- padding-right: 20px;
- overflow: hidden;
- z-index: -1;
- height: 1px;
- }
- .el-cascader.hc-header-cascader {
- width: 100%;
- .el-input .el-input__wrapper {
- border-radius: 104px;
- height: 28px;
- }
- }
- }
- </style>
|