view.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <hc-sys id="app-sys" class="hc-images-page" :isNavBar="false">
  3. <view id="hc-images-nav-bar" class="hc-images-nav-bar" un-border-b="1 solid gray-2">
  4. <hc-nav-back-bar title="声像文件">
  5. <view class="more-bar" v-if="dataList.length > 0" @click="deleteTap">
  6. <text class="text-26" :class="isDelete?'':'text-red-4'">{{isDelete? '取消' : '删除'}}</text>
  7. </view>
  8. </hc-nav-back-bar>
  9. <view class="cu-bar bg-white search py-2" un-border-t="1 solid gray-2" v-if="pageNode.type === 1">
  10. <view class="search-form radius">
  11. <text class="cuIcon-search"/>
  12. <input v-model="searchForm.queryStr" :adjust-position="false" type="text" placeholder="根据题名,名称或拍摄者搜索" confirm-type="search"/>
  13. </view>
  14. <view class="action">
  15. <button class="cu-btn bg-blue-5 text-white" hover-class="none" @click="searchClick">搜索</button>
  16. </view>
  17. </view>
  18. <view class="cu-bar bg-white search py-2" un-border-t="1 solid gray-2" v-if="pageNode.type === 2">
  19. <view class="search-form radius">
  20. <uni-datetime-picker type="date" v-model="searchForm.queryDate"/>
  21. </view>
  22. <view class="action">
  23. <button class="cu-btn bg-blue-5 text-white" hover-class="none" @click="searchClick">搜索</button>
  24. </view>
  25. </view>
  26. </view>
  27. <!-- 数据列表 -->
  28. <z-paging ref="pageRef" :style="pagingStyle" v-model="dataList" @query="getDataList">
  29. <template v-for="(item, index) in imageList" :key="index">
  30. <view class="cu-bar bg-white py-2 mt-1" un-border-b="1 solid gray-1">
  31. <view class="px-3">{{item.name}}</view>
  32. </view>
  33. <template v-for="(items, indexs) in item.child" :key="indexs">
  34. <view class="bg-white hc-p hc-flex" un-border-b="1 solid gray-1" @click="itemClick(items, index, indexs)">
  35. <view class="hc-flex mr-2" v-if="isDelete" @click.stop="checkClick(items, index, indexs)">
  36. <uni-icons type="checkbox-filled" size="26" color="#ee5b20" v-if="items.check"/>
  37. <uni-icons type="checkbox" size="26" color="#9a9a9a" v-else/>
  38. </view>
  39. <view class="hc-flex">
  40. <view class="hc-flex-center h-100 w-100 b-rounded" un-border="1 solid gray-3" v-if="items.type === 1">
  41. <text class="i-ri-vidicon-line text-50 text-gray-4"/>
  42. </view>
  43. <hc-img class="b-rounded" :src="items.imageUrl?.toString()?.split(',')[0]" width="50" height="50" v-if="items.type === 2"/>
  44. </view>
  45. <view class="relative flex-1 ml-3">
  46. <view class="text-30 text-black clip-2">{{items.title}}</view>
  47. <view class="text-24 mt-1 text-cut">{{items.textContent}}</view>
  48. </view>
  49. </view>
  50. </template>
  51. </template>
  52. </z-paging>
  53. <!--底部操作区域 -->
  54. <view id="hc-bottom-bar" class="hc-bottom-bar"/>
  55. <view id="hc-bottom-btn-bar" class="hc-bottom-btn-bar">
  56. <view class="hc-flex" v-if="isDelete">
  57. <view class="hc-flex" @click="allCheckClick">
  58. <uni-icons type="checkbox-filled" size="24" color="#ee5b20" v-if="checkList.length === dataList.length"/>
  59. <uni-icons type="checkbox" size="24" color="#9a9a9a" v-else/>
  60. <text class="ml-1">全选</text>
  61. </view>
  62. <view class="flex-1 ml-4 text-gray-5 text-24">
  63. <text class="mr-1">已勾选</text>
  64. <text class="text-red-5">{{checkList.length}}</text>
  65. <text class="ml-1">条数据</text>
  66. </view>
  67. <button hover-class="none" class="cu-btn bg-red-5 text-white" @click="delCheckList">删除选中</button>
  68. </view>
  69. <view class="relative" v-else>
  70. <button hover-class="none" class="cu-btn block bg-purple-8 text-white" @click="addFileData">新增声像文件</button>
  71. </view>
  72. </view>
  73. </hc-sys>
  74. </template>
  75. <script setup>
  76. import {getCurrentInstance, ref} from "vue";
  77. import {onLoad, onShow, onReady} from '@dcloudio/uni-app'
  78. import {useAppStore} from "@/store";
  79. import mainApi from '~api/image/index';
  80. import {arrIndex, deepClone, getArrValue} from "js-fast-way";
  81. import {errorToast, querySelect, showModal, successToast} from "@/utils/tools";
  82. //初始变量
  83. const store = useAppStore()
  84. const instance = getCurrentInstance().proxy
  85. const contractInfo = ref(store.contractInfo);
  86. const projectId = ref(store.projectId);
  87. const contractId = ref(store.contractId);
  88. //基础变量
  89. const pageRef = ref(null)
  90. const pageNode = ref({});
  91. const dataList = ref([])
  92. const isNodes = ref(false)
  93. //页面启动
  94. onLoad(({node}) => {
  95. pageNode.value = node ? JSON.parse(decodeURIComponent(node)) : {};
  96. })
  97. onReady(() => {
  98. setPagingStyle()
  99. })
  100. onShow(() => {
  101. if (isNodes.value) {
  102. searchClick()
  103. }
  104. })
  105. //内容区域
  106. const pagingStyle = ref({
  107. position: 'relative',
  108. width: '100%',
  109. bottom: 0,
  110. })
  111. const setPagingStyle = async () => {
  112. const {height: appHeight} = await querySelect(instance, 'app-sys')
  113. const {height: navHeight} = await querySelect(instance, 'hc-images-nav-bar')
  114. const {height: bottomHeight} = await querySelect(instance, 'hc-bottom-bar')
  115. const {height: bottomBtnHeight} = await querySelect(instance, 'hc-bottom-btn-bar')
  116. // #ifdef H5
  117. let content = navHeight + bottomHeight + bottomBtnHeight
  118. pagingStyle.value.height = (appHeight - content) + 'px'
  119. // #endif
  120. // #ifdef APP-PLUS
  121. const {screenHeight, safeArea} = uni.getWindowInfo()
  122. content = navHeight + (screenHeight - safeArea.bottom) + bottomBtnHeight
  123. pagingStyle.value.height = (screenHeight - content) + 'px'
  124. // #endif
  125. }
  126. //条件搜索
  127. const searchClick = () => {
  128. imageList.value = []
  129. pageRef.value?.reload()
  130. }
  131. //获取数据
  132. const searchForm = ref({queryStr: ''})
  133. const getDataList = async (pageNo, pageSize) => {
  134. if (pageNo === 1) {
  135. imageList.value = []
  136. }
  137. const {id, fileType, type, treeId} = pageNode.value
  138. if (!type || !id || !type || !fileType) {
  139. errorToast('参数异常,请退出重试')
  140. pageRef.value?.complete([]);
  141. return false;
  142. }
  143. //树类型
  144. const form = searchForm.value
  145. if (type === 1 && treeId) {
  146. delete form.queryDate
  147. form.wbsIdsStr = treeId
  148. }
  149. if (type === 2) {
  150. delete form.wbsIdsStr
  151. delete form.queryStr
  152. }
  153. //获取数据
  154. uni.showLoading({title: '获取数据中...', mask: true});
  155. const { data } = await mainApi.getPageList({
  156. ...form,
  157. projectId: projectId.value,
  158. contractId: contractId.value,
  159. classifyId: id,
  160. current: pageNo,
  161. size: pageSize,
  162. isApp: 1,
  163. })
  164. //处理数据
  165. let res = getArrValue(data), newArr = [];
  166. if (res.length > 0) {
  167. for (let i = 0; i < res.length; i++) {
  168. const item = res[i].child;
  169. for (let j = 0; j < item.length; j++) {
  170. newArr.push(item[j])
  171. }
  172. }
  173. setImageList(deepClone(res)) //处理数据
  174. pageRef.value?.complete(newArr);
  175. } else {
  176. pageRef.value?.complete([]);
  177. }
  178. isNodes.value = true
  179. uni.hideLoading();
  180. }
  181. //处理列表显示数据
  182. const imageList = ref([])
  183. const setImageList = (data) => {
  184. const arr = imageList.value
  185. if (arr.length > 0 && data.length > 0) {
  186. const item = arr[arr.length - 1]
  187. const items = data[0]
  188. if (item.name === items.name) {
  189. const child = item.child
  190. item.child = child.concat(items.child)
  191. data.splice(0, 1)
  192. }
  193. imageList.value = arr.concat(data)
  194. } else {
  195. imageList.value = data
  196. }
  197. }
  198. //批量删除
  199. const isDelete = ref(false)
  200. const deleteTap = () => {
  201. isDelete.value = !isDelete.value
  202. }
  203. //点击选中
  204. const checkList = ref([])
  205. const checkClick = (item) => {
  206. const list = checkList.value
  207. const index = arrIndex(list, 'id', item.id)
  208. if (item.check) {
  209. list.splice(index, 1)
  210. item.check = false
  211. } else {
  212. item.check = true
  213. list.push(item)
  214. }
  215. checkList.value = list
  216. }
  217. //全选
  218. const allCheckClick = () => {
  219. const check = checkList.value, list = dataList.value
  220. const arr = imageList.value
  221. if (check.length === list.length) {
  222. arr.forEach(item => {
  223. item.child.forEach(items => {
  224. items.check = false
  225. })
  226. })
  227. checkList.value = []
  228. } else {
  229. let newArr = []
  230. arr.forEach(item => {
  231. item.child.forEach(items => {
  232. items.check = true
  233. newArr.push(items)
  234. })
  235. })
  236. checkList.value = newArr
  237. }
  238. }
  239. //列表项被点击
  240. const itemClick = (item, index, indexs) => {
  241. if(isDelete.value) {
  242. checkClick(item, index, indexs)
  243. } else {
  244. uni.navigateTo({
  245. url: `/pages/image/info?id=${item.id}`
  246. })
  247. }
  248. }
  249. //删除选中数据
  250. const delCheckList = async () => {
  251. if (checkList.value.length <= 0) {
  252. errorToast('请选择要删除的数据')
  253. return false
  254. }
  255. const res = await showModal({
  256. title: '批量删除提醒',
  257. content: '确定要删除选中的数据吗?',
  258. })
  259. if (!res) return false;
  260. uni.showLoading({title: '批量删除中...', mask: true});
  261. const ids = checkList.value.map(item => item.id)
  262. const { error, code, msg } = await mainApi.removeImageclassifyFile({
  263. ids: ids.join(',')
  264. })
  265. uni.hideLoading();
  266. if (!error && code === 200) {
  267. successToast('删除成功')
  268. searchClick()
  269. } else {
  270. errorToast('删除失败: ' + msg)
  271. }
  272. }
  273. //新增文件数据
  274. const addFileData = () => {
  275. //准备跳转路由
  276. const node = encodeURIComponent(JSON.stringify({
  277. ...pageNode.value
  278. }));
  279. uni.navigateTo({
  280. url: `/pages/image/form?node=${node}`
  281. })
  282. }
  283. </script>
  284. <style lang="scss">
  285. @import "@/style/image/view.scss";
  286. </style>