project.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <hc-sys class="hc-my-project-page" navBarUi='my-project-nav-bar'>
  3. <template #navBar>
  4. <hc-nav-back-bar title="项目管理">
  5. <text @click="setDataClick">设置</text>
  6. </hc-nav-back-bar>
  7. </template>
  8. <view class="hc-parting-line"/>
  9. <uni-collapse class="hc-my-project-collapse" v-model="projectId" accordion>
  10. <template v-for="item in dataLists">
  11. <uni-collapse-item :name="item.id">
  12. <template v-slot:title>
  13. <view class="my-project-bar">
  14. <view class="icon">
  15. <text class="i-ri-folder-2-line"/>
  16. </view>
  17. <view class="name">{{item.projectName}}</view>
  18. </view>
  19. </template>
  20. <view class="my-contract-bar">
  21. <template v-for="items in item.contractInfoList">
  22. <view class="item-bar"
  23. :class="items.id === contractId ? 'is-select':''"
  24. @click="contractClick(item, items)"
  25. >
  26. <view class="icon">
  27. <text class="i-ri-star-fill" v-if="items.id === contractId"/>
  28. </view>
  29. <view class="name">{{items.contractName}}</view>
  30. </view>
  31. </template>
  32. </view>
  33. </uni-collapse-item>
  34. </template>
  35. </uni-collapse>
  36. <!-- 普通弹窗 -->
  37. <uni-popup ref="popupRef" class="hc-popup" type="bottom">
  38. <view class="hc-popup-content">
  39. <view class="title">确认该合同段为登录进入系统的默认项目?</view>
  40. <view class="popup-btn-bar">
  41. <button type="primary" class="popup-btn c1" @click="setProjectClick">设置为默认项目</button>
  42. </view>
  43. <view class="popup-btn-bar">
  44. <button type="primary" class="popup-btn c3" @click="cancelPopup">关闭</button>
  45. </view>
  46. </view>
  47. </uni-popup>
  48. </hc-sys>
  49. </template>
  50. <script setup>
  51. import {ref, onMounted, nextTick} from "vue";
  52. import {useAppStore} from "@/store";
  53. import mainApi from "~api/user/project";
  54. import {errorToast, successToast} from "@/utils/tools";
  55. import {deepClone, getArrValue} from "js-fast-way";
  56. import {getProjectContract} from "@/store/user";
  57. //初始变量
  58. const store = useAppStore()
  59. const userInfo = ref(store.userInfo);
  60. const projectInfo = ref({pid: '', cid: ''});
  61. const projectId = ref('');
  62. const contractId = ref('');
  63. //渲染完成
  64. onMounted(() => {
  65. projectInfo.value = deepClone({
  66. pid: store.projectId,
  67. cid: store.contractId
  68. })
  69. getProjectAndContract()
  70. })
  71. //获取项目以及合同段数据
  72. const dataLists = ref([])
  73. const getProjectAndContract = async () => {
  74. const {pid, cid } = projectInfo.value
  75. uni.showLoading({title: '获取数据中...', mask: true});
  76. const { data } = await mainApi.getProjectAndContract()
  77. dataLists.value = getArrValue(data)
  78. uni.hideLoading();
  79. await nextTick(() => {
  80. projectId.value = pid
  81. contractId.value = cid
  82. })
  83. }
  84. //合同段点击
  85. const contractClick = ({id: pid}, {id: cid}) => {
  86. projectId.value = pid
  87. contractId.value = cid
  88. }
  89. //设置项目
  90. const popupRef = ref(null)
  91. const setDataClick = () => {
  92. popupRef.value?.open()
  93. }
  94. //设置默认项目
  95. const setProjectClick = async () => {
  96. const pid = projectId.value, cid = contractId.value
  97. if (!pid || !cid) {
  98. cancelPopup()
  99. errorToast('请先选择项目和合同段')
  100. return
  101. }
  102. uni.showLoading({title: '设置中...', mask: true});
  103. cancelPopup()
  104. const { error, code, msg } = await mainApi.setDefaultProject({
  105. projectId: projectId.value,
  106. contractId: contractId.value,
  107. })
  108. if (!error && code === 200) {
  109. await getProjectContract()
  110. uni.hideLoading();
  111. successToast('设置成功')
  112. setTimeout(() => {
  113. uni.navigateBack()
  114. }, 2000)
  115. } else {
  116. uni.hideLoading();
  117. errorToast('设置失败:' + msg)
  118. }
  119. }
  120. //取消并关闭
  121. const cancelPopup = () => {
  122. popupRef.value?.close()
  123. }
  124. </script>
  125. <style lang="scss" scoped>
  126. page {
  127. background: #EFEFF4;
  128. }
  129. </style>
  130. <style lang="scss">
  131. @import "@/style/my/project.scss";
  132. </style>