copyTime.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <hc-sys class="hc-ledger-copy-time" :isNavBar="false">
  3. <hc-breadcrumb :data="breadcrumbData" @change="breadcrumbChange" v-if="breadcrumbData.length > 0"/>
  4. <!--所有记录-->
  5. <CopyUserList v-if="viewType==='all'" v-model="selectedLogTime" :data="allLogTime"/>
  6. <!--按日期选择 年份-->
  7. <CopyLogCollapse v-if="viewType === 'date'" v-model="logYear" :data="yearDateList" @action="yearDateAction">
  8. <template #default="{item, index}">
  9. <CopyUserList v-if="item.logs.length > 0" v-model="selectedLogTime" :data="item.logs"/>
  10. </template>
  11. </CopyLogCollapse>
  12. <!--按日期选择 月份-->
  13. <CopyLogCollapse v-if="viewType === 'month'" text="日期" v-model="logMonth" :data="monthDateList" @action="monthDateAction">
  14. <template #default="{item, index}">
  15. <CopyUserList v-if="item.logs.length > 0" v-model="selectedLogTime" :data="item.logs"/>
  16. </template>
  17. </CopyLogCollapse>
  18. <!--按日期选择 日期-->
  19. <CopyLogCollapse v-if="viewType === 'day'" :action="false" v-model="logDay" :data="dayDateList">
  20. <template #default="{item, index}">
  21. <CopyUserList v-if="item.logs.length > 0" v-model="selectedLogTime" :data="item.logs"/>
  22. </template>
  23. </CopyLogCollapse>
  24. <!--底部操作栏-->
  25. <HcTabbarBlock :height="70"/>
  26. <hc-tabbars class="hc-operation-bar">
  27. <view class="selected-bar" @click="selectedShow" v-if="selectedLogTime.length > 0">
  28. <text class="label">已选择:{{selectedLogTime.length}}条记录</text>
  29. <text class="icon i-ri-arrow-up-s-line"/>
  30. </view>
  31. <view class="selected-bar" v-else>
  32. <text class="text">请先在上方勾选要复制的记录</text>
  33. </view>
  34. <view class="btn-bar">
  35. <button class="cu-btn blue" @click="confirmClick">确认复制</button>
  36. </view>
  37. </hc-tabbars>
  38. <!-- 普通弹窗 -->
  39. <hc-popup bg="#E9EAEC" title="已选择" ref="popupRef" @confirm="popupConfirm">
  40. <view class="popup-selected-log-time" v-for="(item, index) in selectedLogTime" :key="index">
  41. <view class="content-bar">
  42. <view class="avatar">{{ getUserName(getSelectedVal(item, 'createUserName')) }}</view>
  43. <view class="content">
  44. <view class="name">{{ getSelectedVal(item, 'createUserName') }}</view>
  45. <view class="text">{{ getSelectedVal(item, 'recordTime') }}</view>
  46. </view>
  47. </view>
  48. <button class="cu-btn" @click="removeSelected(index)">移除</button>
  49. </view>
  50. </hc-popup>
  51. </hc-sys>
  52. </template>
  53. <script setup>
  54. import {ref, nextTick, getCurrentInstance} from "vue";
  55. import {onLoad} from '@dcloudio/uni-app'
  56. import {arrKeyValue, getArrValue} from "js-fast-way";
  57. import CopyUserList from "./components/user-list.vue";
  58. import CopyLogCollapse from "./components/log-collapse.vue";
  59. import mainApi from '~api/ledger/index';
  60. import {getUserName} from "@/utils/utils";
  61. import {errorToast, showModal, successToast} from "@/utils/tools";
  62. //初始变量
  63. const pageNode = ref({})
  64. const instance = getCurrentInstance().proxy
  65. //页面传参数据
  66. let eventChannel = null;
  67. const getEventChannel = async () => {
  68. await nextTick();
  69. eventChannel = instance.getOpenerEventChannel();
  70. }
  71. //视图类型
  72. const viewType = ref('all')
  73. onLoad((option) => {
  74. breadcrumbData.value = [
  75. {name: '按日期选择', key: 'date'},
  76. {name: '全部记录'},
  77. ]
  78. viewType.value = 'all'
  79. if (option.node) {
  80. getEventChannel()
  81. const res = JSON.parse(decodeURIComponent(option.node));
  82. uni.setNavigationBarTitle({title: '复制任意时间表格及内容'})
  83. console.log(res)
  84. pageNode.value = res
  85. queryReportLogTimeTree()
  86. }
  87. })
  88. //面包屑
  89. const breadcrumbData = ref([])
  90. const breadcrumbChange = ({key}) => {
  91. if (key === 'date') {
  92. setLogYear()
  93. viewType.value = 'date'
  94. } else if (key === 'year') {
  95. breadcrumbData.value = []
  96. viewType.value = 'date'
  97. } else if (key === 'month') {
  98. const year = breadcrumbData.value[0]
  99. breadcrumbData.value = [
  100. {name: year.name, key: 'year', value: year.value},
  101. {name: '月份记录'},
  102. ]
  103. viewType.value = 'month'
  104. }
  105. }
  106. //获取当前合同段下本日志节点的填报资料日期树
  107. const logTimeTree = ref([])
  108. const queryReportLogTimeTree = async () => {
  109. uni.showLoading({title: '获取数据中...', mask: true});
  110. const { contractId, pkeyId } = pageNode.value
  111. const { data } = await mainApi.queryReportLogTimeTree({
  112. contractId: contractId,
  113. nodePrimaryKeyId: pkeyId,
  114. })
  115. let res = getArrValue(data), newArr = [];
  116. for (let i = 0; i < res.length; i++) {
  117. const logs = await queryLogTimeTreeList(res[i].hierarchy);
  118. for (let j = 0; j < logs.length; j++) {
  119. newArr.push(logs[j])
  120. }
  121. }
  122. logTimeTree.value = res
  123. allLogTime.value = newArr
  124. uni.hideLoading();
  125. }
  126. //获取填报记录
  127. const allLogTime = ref([])
  128. const queryLogTimeTreeList = async (time) => {
  129. const { contractId, pkeyId } = pageNode.value
  130. const { data } = await mainApi.queryLogTimeTreeList({
  131. contractId: contractId,
  132. nodePrimaryKeyId: pkeyId,
  133. time: time,
  134. })
  135. const res = getArrValue(data)
  136. for (let i = 0; i < res.length; i++) {
  137. const {createUserName} = res[i]
  138. res[i].avatarName = getUserName(createUserName ?? '')
  139. }
  140. return res
  141. }
  142. const getLogTimeList = async (item) => {
  143. const logs = getArrValue(item.logs)
  144. if (logs.length <= 0) {
  145. return await queryLogTimeTreeList(item.hierarchy)
  146. } else {
  147. return logs
  148. }
  149. }
  150. //年份折叠面板
  151. const logYear = ref('')
  152. const yearDateList = ref([])
  153. const setLogYear = async () => {
  154. uni.showLoading({title: '获取数据中...', mask: true});
  155. breadcrumbData.value = []
  156. const arr = logTimeTree.value
  157. for (let i = 0; i < arr.length; i++) {
  158. arr[i].logs = await getLogTimeList(arr[i])
  159. }
  160. yearDateList.value = arr
  161. uni.hideLoading();
  162. }
  163. const yearDateAction = async ({ name, hierarchy, treeList}) => {
  164. uni.showLoading({title: '获取数据中...', mask: true});
  165. const arr = getArrValue(treeList)
  166. for (let i = 0; i < arr.length; i++) {
  167. arr[i].logs = await getLogTimeList(arr[i])
  168. }
  169. breadcrumbData.value = [
  170. {name: name, key: 'year', value: hierarchy},
  171. {name: '月份记录'},
  172. ]
  173. logMonth.value = ''
  174. monthDateList.value = arr
  175. viewType.value = 'month'
  176. uni.hideLoading();
  177. }
  178. //月份折叠面板
  179. const logMonth = ref('')
  180. const monthDateList = ref([])
  181. const monthDateAction = async ({ name, hierarchy, treeList}) => {
  182. uni.showLoading({title: '获取数据中...', mask: true});
  183. const year = breadcrumbData.value[0]
  184. const arr = getArrValue(treeList)
  185. for (let i = 0; i < arr.length; i++) {
  186. arr[i].logs = await getLogTimeList(arr[i])
  187. }
  188. breadcrumbData.value = [
  189. {name: year.name, key: 'year', value: year.value},
  190. {name: name, key: 'month', value: hierarchy},
  191. {name: '日期记录'},
  192. ]
  193. logDay.value = ''
  194. dayDateList.value = arr
  195. viewType.value = 'day'
  196. uni.hideLoading();
  197. }
  198. //日期折叠面板
  199. const logDay = ref('')
  200. const dayDateList = ref([])
  201. //底部弹窗
  202. const popupRef = ref(null)
  203. const selectedShow = () => {
  204. popupRef.value?.setTitle(`已选择(${selectedLogTime.value.length})`)
  205. popupRef.value?.open()
  206. }
  207. const getSelectedVal = (val, name) => {
  208. return arrKeyValue(allLogTime.value,'id', name, val)
  209. }
  210. const removeSelected = (index) => {
  211. selectedLogTime.value.splice(index, 1)
  212. const leng = selectedLogTime.value.length;
  213. popupRef.value?.setTitle(`已选择(${leng})`)
  214. if (leng <= 0 ) popupRef.value?.close()
  215. }
  216. const popupConfirm = () => {
  217. popupRef.value?.close()
  218. }
  219. //确认复制
  220. const selectedLogTime = ref([])
  221. const confirmClick = async () => {
  222. const arr = selectedLogTime.value;
  223. if (arr.length <= 0) {
  224. errorToast('请先选择要复制的记录');
  225. return
  226. }
  227. //确认提示框
  228. const res = await showModal({
  229. title: '复制提醒',
  230. content: '复制后将覆盖原有记录,是否继续?',
  231. })
  232. if (!res) return
  233. //发起复制请求
  234. uni.showLoading({title: '复制数据中...', mask: true});
  235. const { contractId, pkeyId, date } = pageNode.value
  236. const { error, code } = await mainApi.copyTheLogBusinessData({
  237. contractId: contractId,
  238. nodePrimaryKeyId: pkeyId,
  239. currentTime: date,
  240. theLogId: arr.join(','),
  241. })
  242. //处理数据
  243. uni.hideLoading();
  244. if (!error && code === 200) {
  245. successToast('复制成功');
  246. eventChannel.emit('finish');
  247. setTimeout(() => {
  248. uni.navigateBack()
  249. }, 2000)
  250. } else {
  251. errorToast('复制失败,请稍后再试');
  252. }
  253. }
  254. </script>
  255. <style lang="scss" scoped>
  256. page {
  257. height: 100%;
  258. background: #E9EAEC;
  259. }
  260. </style>
  261. <style lang="scss">
  262. @import "@/style/ledger/copyTime.scss";
  263. </style>