myActivity.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <view v-if="appStore.amProfileStore.notDemo()">
  3. <SearchBar
  4. v-model:query-type="queryType"
  5. v-model:search-input-value="searchInputValue"
  6. v-model:search-type="searchType"
  7. v-model:search-dropdown-value="searchDropdownValue"
  8. search-btn-icon="add"
  9. search-btn-text="发布"
  10. :search-dropdown-list="dropList"
  11. :search-placeholder="searchPlaceholder"
  12. :search-tab-list="searchTabList"
  13. :query-type-data="queryTypeData"
  14. :height="topHeight"
  15. @search-btn="onCreateActivity"
  16. @search="onSearch"
  17. ></SearchBar>
  18. <vb-list
  19. custom-class="mx-15 pt-15"
  20. :query-fun="queryType == 0 ? apis.amActivity.activityApi.myCreateActivity : myJoinActivity"
  21. :query-params="queryParams"
  22. :height="listHeight"
  23. >
  24. <template #item="{ item }">
  25. <ListCard :item="item" :type="itemType" :map="{ id: 'activityId', date: 'activityDate' }"></ListCard>
  26. </template>
  27. </vb-list>
  28. </view>
  29. </template>
  30. <script lang="ts" setup>
  31. import dayjs from "dayjs"
  32. import apis from "@/api"
  33. import route from "@/route"
  34. import appStore from "@/stores"
  35. import ListCard from "@/components/listCard.vue"
  36. import SearchBar from "@/components/searchBar.vue"
  37. import "dayjs/locale/zh-cn" // 导入本地化语言
  38. dayjs.locale("zh-cn") // 使用本地化语言
  39. const params = route.getRouteParams("myActivity")
  40. const isMine = computed(() => {
  41. return params && params.userName ? false : true
  42. })
  43. const itemType = computed(() => {
  44. return queryType.value == 0 && isMine.value ? "activityEdit" : "activityDetail"
  45. })
  46. const userName = computed(() => {
  47. if (params && params.userName) {
  48. return params.userName
  49. }
  50. return appStore.authStore.getUser().userName
  51. })
  52. const amId = computed(() => {
  53. if (params && params.amId) {
  54. return params.amId
  55. }
  56. return appStore.authStore.getUser().amId
  57. })
  58. const wHeight = uni.getWindowInfo().windowHeight
  59. const topHeight = ref(130)
  60. const listHeight = computed(() => {
  61. return wHeight - topHeight.value - 15
  62. })
  63. const searchInputValue = ref("")
  64. const queryType = ref(0)
  65. const searchType = ref("")
  66. const searchDropdownValue = ref([])
  67. const queryParams = ref(
  68. isMine.value
  69. ? { title: "" }
  70. : queryType.value == 0
  71. ? {
  72. createBy: userName.value,
  73. auditStatus: 1,
  74. title: "",
  75. }
  76. : {
  77. amId: amId.value,
  78. title: "",
  79. }
  80. )
  81. const searchPlaceholder = ref("搜索校友活动标题")
  82. const queryTypeData = computed(() => {
  83. return [
  84. { value: 0, text: "创建的活动" },
  85. { value: 1, text: "参与的活动" },
  86. ]
  87. })
  88. const dropList = computed(() => {
  89. const arr = []
  90. arr.push({
  91. emptyTitle: "全部分类",
  92. data: categoryColumns.value,
  93. map: { text: "categoryName", value: "categoryId" },
  94. })
  95. return arr
  96. })
  97. const categoryColumns = ref<any>([])
  98. const searchTabList = computed(() => {
  99. const arr = []
  100. // arr.push({ text: "最新", value: "new" })
  101. // arr.push({ text: "最热", value: "hot" })
  102. arr.push({ text: "近一周", value: "week" })
  103. arr.push({ text: "近一月", value: "month" })
  104. arr.push({ text: "全部", value: "" })
  105. return arr
  106. })
  107. const myJoinActivity = (query: any) => {
  108. return apis.amActivity.activityApi.myJoinActivity(query, amId.value)
  109. }
  110. function onSearch() {
  111. search()
  112. }
  113. function search() {
  114. const params: any = {
  115. title: searchInputValue.value || "",
  116. category: searchDropdownValue.value[0] || "",
  117. }
  118. if (!isMine.value) {
  119. if (queryType.value == 0) {
  120. params.createBy = userName.value
  121. params.auditStatus = "1"
  122. } else if (queryType.value == 1) {
  123. params.amId = amId.value
  124. }
  125. }
  126. if (searchType.value) {
  127. switch (searchType.value) {
  128. case "new":
  129. params.orderByColumn = "createTime"
  130. params.isAsc = "desc"
  131. break
  132. case "hot":
  133. params.orderByColumn = "readCount"
  134. params.isAsc = "desc"
  135. break
  136. case "week":
  137. params.params = {}
  138. params.params["beginActivityDate"] = dayjs().startOf("day").add(-7, "day").format("YYYY-MM-DD HH:mm:ss")
  139. params.params["endActivityDate"] = dayjs().endOf("day").format("YYYY-MM-DD HH:mm:ss")
  140. break
  141. case "month":
  142. params.params = {}
  143. params.params["beginActivityDate"] = dayjs().startOf("day").add(-30, "day").format("YYYY-MM-DD HH:mm:ss")
  144. params.params["endActivityDate"] = dayjs().endOf("day").format("YYYY-MM-DD HH:mm:ss")
  145. break
  146. default:
  147. break
  148. }
  149. }
  150. queryParams.value = params
  151. }
  152. function onCreateActivity() {
  153. route.navigate("activityEdit")
  154. }
  155. function loadCategory() {
  156. apis.system.categoryApi.getActivityCategory().then((res) => {
  157. categoryColumns.value = [{ categoryName: "全部分类", categoryId: "" }, ...res]
  158. })
  159. }
  160. function init() {
  161. if (!isMine.value && params.name) {
  162. uni.setNavigationBarTitle({ title: params.name + "的活动" })
  163. }
  164. loadCategory()
  165. }
  166. onLoad(init)
  167. </script>
  168. <style scoped></style>