project.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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, nextTick} from "vue";
  52. import {onLoad} from '@dcloudio/uni-app'
  53. import {useAppStore} from "@/store";
  54. import mainApi from "~api/user/project";
  55. import {errorToast, successToast} from "@/utils/tools";
  56. import {deepClone, getArrValue} from "js-fast-way";
  57. import {getProjectContract} from "@/store/user";
  58. //初始变量
  59. const store = useAppStore()
  60. const userInfo = ref(store.userInfo);
  61. const projectInfo = ref({pid: '', cid: ''});
  62. const projectId = ref('');
  63. const contractId = ref('');
  64. //渲染完成
  65. onLoad(() => {
  66. projectInfo.value = deepClone({
  67. pid: store.projectId,
  68. cid: store.contractId
  69. })
  70. getProjectAndContract()
  71. })
  72. //获取项目以及合同段数据
  73. const dataLists = ref([])
  74. const getProjectAndContract = async () => {
  75. const {pid, cid } = projectInfo.value
  76. uni.showLoading({title: '获取数据中...', mask: true});
  77. const { data } = await mainApi.getProjectAndContract()
  78. dataLists.value = getArrValue(data)
  79. uni.hideLoading();
  80. await nextTick(() => {
  81. projectId.value = pid
  82. contractId.value = cid
  83. })
  84. }
  85. //合同段点击
  86. const contractClick = ({id: pid}, {id: cid}) => {
  87. projectId.value = pid
  88. contractId.value = cid
  89. }
  90. //设置项目
  91. const popupRef = ref(null)
  92. const setDataClick = () => {
  93. popupRef.value?.open()
  94. }
  95. //设置默认项目
  96. const setProjectClick = async () => {
  97. const pid = projectId.value, cid = contractId.value
  98. if (!pid || !cid) {
  99. cancelPopup()
  100. errorToast('请先选择项目和合同段')
  101. return
  102. }
  103. uni.showLoading({title: '设置中...', mask: true});
  104. cancelPopup()
  105. const { error, code, msg } = await mainApi.setDefaultProject({
  106. projectId: projectId.value,
  107. contractId: contractId.value,
  108. })
  109. if (!error && code === 200) {
  110. await getProjectContract()
  111. uni.hideLoading();
  112. successToast('设置成功')
  113. setTimeout(() => {
  114. uni.navigateBack()
  115. }, 2000)
  116. } else {
  117. uni.hideLoading();
  118. errorToast('设置失败:' + msg)
  119. }
  120. }
  121. //取消并关闭
  122. const cancelPopup = () => {
  123. popupRef.value?.close()
  124. }
  125. </script>
  126. <style lang="scss" scoped>
  127. page {
  128. background: #EFEFF4;
  129. }
  130. </style>
  131. <style lang="scss">
  132. @import "@/style/my/project.scss";
  133. </style>