project.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 c2" @click="onlyEffectivelick">仅本次生效</button>
  45. </view>
  46. <view class="popup-btn-bar">
  47. <button type="primary" class="popup-btn c3" @click="cancelPopup">关闭</button>
  48. </view>
  49. </view>
  50. </uni-popup>
  51. </hc-sys>
  52. </template>
  53. <script setup>
  54. import {ref, nextTick} from "vue";
  55. import {onLoad} from '@dcloudio/uni-app'
  56. import {useAppStore} from "@/store";
  57. import mainApi from "~api/user/project";
  58. import {errorToast, successToast} from "@/utils/tools";
  59. import {deepClone, getArrValue} from "js-fast-way";
  60. //初始变量
  61. const store = useAppStore()
  62. const userInfo = ref(store.userInfo);
  63. const projectInfo = ref({pid: '', cid: ''});
  64. const projectId = ref('');
  65. const contractId = ref('');
  66. const app = getApp()
  67. //渲染完成
  68. onLoad(() => {
  69. projectInfo.value = deepClone({
  70. pid: store.projectId,
  71. cid: store.contractId
  72. })
  73. getProjectAndContract()
  74. })
  75. //获取项目以及合同段数据
  76. const dataLists = ref([])
  77. const getProjectAndContract = async () => {
  78. const {pid, cid } = projectInfo.value
  79. uni.showLoading({title: '获取数据中...', mask: true});
  80. const { data } = await mainApi.getProjectAndContract()
  81. dataLists.value = getArrValue(data)
  82. uni.hideLoading();
  83. await nextTick(() => {
  84. projectId.value = pid
  85. contractId.value = cid
  86. })
  87. }
  88. //合同段点击
  89. const projectData = ref({})
  90. const contractData = ref({})
  91. const contractClick = (project, contract) => {
  92. //设置数据
  93. projectData.value = project
  94. contractData.value = contract
  95. //设置ID
  96. projectId.value = project.id
  97. contractId.value = contract.id
  98. }
  99. //设置项目
  100. const popupRef = ref(null)
  101. const setDataClick = () => {
  102. popupRef.value?.open()
  103. }
  104. //设置默认项目
  105. const setProjectClick = async () => {
  106. const pid = projectId.value, cid = contractId.value
  107. if (!pid || !cid) {
  108. cancelPopup()
  109. errorToast('请先选择项目和合同段')
  110. return
  111. }
  112. uni.showLoading({title: '设置中...', mask: true});
  113. cancelPopup()
  114. const { error, code, msg } = await mainApi.setDefaultProject({
  115. projectId: projectId.value,
  116. contractId: contractId.value,
  117. })
  118. if (!error && code === 200) {
  119. await setProjectContractData()
  120. uni.hideLoading();
  121. successToast('设置成功')
  122. setTimeout(() => {
  123. uni.navigateBack()
  124. }, 2000)
  125. } else {
  126. uni.hideLoading();
  127. errorToast('设置失败:' + msg)
  128. }
  129. }
  130. //仅本次生效
  131. const onlyEffectivelick = async () => {
  132. const pid = projectId.value, cid = contractId.value
  133. if (!pid || !cid) {
  134. cancelPopup()
  135. errorToast('请先选择项目和合同段')
  136. return
  137. }
  138. uni.showLoading({title: '设置中...', mask: true});
  139. await setProjectContractData()
  140. uni.hideLoading();
  141. successToast('设置成功')
  142. setTimeout(() => {
  143. uni.navigateBack()
  144. }, 1200)
  145. }
  146. //设置项目合同信息
  147. const setProjectContractData = async () => {
  148. const pid = store.projectId, cid = store.contractId
  149. const pids = projectId.value, cids = contractId.value
  150. if (pid !== pids || cid !== cids) {
  151. store.setProjectId(pids)
  152. store.setContractId(cids)
  153. store.setProjectInfo(projectData.value)
  154. store.setContractInfo(contractData.value)
  155. app.socketSendMsg(`${pids},${cids}`)
  156. }
  157. return true
  158. }
  159. //取消并关闭
  160. const cancelPopup = () => {
  161. popupRef.value?.close()
  162. }
  163. </script>
  164. <style lang="scss" scoped>
  165. page {
  166. background: #EFEFF4;
  167. }
  168. </style>
  169. <style lang="scss">
  170. @import "@/style/my/project.scss";
  171. </style>