tab2.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <div>
  3. <a-row>
  4. <a-col :span="24">
  5. <div class="container search-container">
  6. <a-form
  7. layout="inline"
  8. :model="formState"
  9. @finish="handleFinish"
  10. @finishFailed="handleFinishFailed"
  11. >
  12. <a-form-item
  13. :label="t('room.roomTitle')"
  14. name="roomTitle"
  15. style="width: 250px"
  16. >
  17. <a-input
  18. v-model:value="formState.roomTitle"
  19. :placeholder="t('room.roomTitle')"
  20. >
  21. </a-input>
  22. </a-form-item>
  23. <a-form-item
  24. :label="t('room.usingTime2')"
  25. name="username"
  26. style="width: 350px"
  27. >
  28. <a-range-picker
  29. :show-time="{ format: 'HH:mm' }"
  30. format="YYYY-MM-DD HH:mm"
  31. style="width: 80%"
  32. allowClear
  33. v-model:value="formState.userTime"
  34. />
  35. </a-form-item>
  36. <a-form-item>
  37. <a-button type="primary" html-type="submit">
  38. {{ t('base.confirm') }}
  39. </a-button>
  40. </a-form-item>
  41. <a-form-item>
  42. <a-button type="primary" @click="exportList">
  43. {{ t('base.export') }}
  44. </a-button>
  45. </a-form-item>
  46. </a-form>
  47. </div>
  48. </a-col>
  49. </a-row>
  50. <a-row>
  51. <div class="container">
  52. <a-table
  53. :columns="columns"
  54. :data-source="roomList"
  55. :pagination="pagination"
  56. bordered
  57. >
  58. <template #bodyCell="{ column, text }">
  59. <!-- <template v-if="column.dataIndex === 'sceneNameList'">
  60. {{ text[0] }}
  61. </template> -->
  62. <template v-if="column.dataIndex === 'roomStatus'">
  63. <span v-if="text == 0">未开始</span>
  64. <span v-if="text == 1">带看中</span>
  65. <span v-if="text == 2">已结束</span>
  66. </template>
  67. </template>
  68. </a-table>
  69. </div>
  70. </a-row>
  71. </div>
  72. </template>
  73. <script lang="ts" setup>
  74. import { computed, onMounted, UnwrapRef, watch, reactive, unref } from 'vue'
  75. import { TableColumnProps, TablePaginationConfig } from 'ant-design-vue'
  76. import { useStatisticStore } from '@/store/modules/statistic'
  77. import { useI18n } from '@/hook/useI18n'
  78. const { t } = useI18n()
  79. const props = defineProps<{
  80. current: string
  81. }>()
  82. const statisticStore = useStatisticStore()
  83. // const total = computed(() => statisticStore.allRoom.total)
  84. const pagination = computed<TablePaginationConfig>(() => {
  85. return {
  86. current: statisticStore.allRoom.pageNum,
  87. total: statisticStore.allRoom.total,
  88. pageSize: statisticStore.allRoom.pageSize,
  89. showSizeChanger: true,
  90. onChange: (current: number, page: any) => {
  91. console.log('page', current, page)
  92. pagination.value.current = current
  93. pagination.value.pageSize = page
  94. fetchList()
  95. },
  96. pageSizeOptions: ['10', '20', '50', '100'],
  97. showTotal: (total: string) => t('statistic.pageCount').replace('%N%', total) //分页中显示总的数据
  98. } as unknown as TablePaginationConfig
  99. })
  100. const roomList = computed(() => statisticStore.allRoom.list)
  101. interface FormState {
  102. roomTitle: string
  103. userTime: [string, string]
  104. }
  105. const formState: UnwrapRef<FormState> = reactive({
  106. roomTitle: '',
  107. userTime: ['', '']
  108. })
  109. const columns: TableColumnProps[] = [
  110. // {
  111. // title: '房间id',
  112. // dataIndex: 'roomId'
  113. // },
  114. {
  115. title: t('room.roomTitle'),
  116. dataIndex: 'roomTitle',
  117. width: 130
  118. },
  119. {
  120. title: t('statistic.relatedScenes'),
  121. dataIndex: 'sceneNameListStr'
  122. },
  123. {
  124. title: t('statistic.duration'),
  125. dataIndex: 'lookTime',
  126. width: 100
  127. },
  128. {
  129. title: t('statistic.createTime'),
  130. dataIndex: 'createTime',
  131. width: 130
  132. },
  133. {
  134. title: t('statistic.status'),
  135. dataIndex: 'roomStatus',
  136. width: 80
  137. },
  138. {
  139. title: t('statistic.watch'),
  140. dataIndex: 'lookManCount',
  141. width: 70
  142. },
  143. {
  144. title: t('statistic.share'),
  145. dataIndex: 'shareCount',
  146. width: 70
  147. }
  148. ]
  149. const fetchList = () => {
  150. statisticStore.fetchAllRoomList({
  151. pageNum: pagination.value.current,
  152. pageSize: pagination.value.pageSize,
  153. timeList: formState.userTime
  154. ? formState.userTime.filter(i => i).map(item => item.toString())
  155. : [],
  156. roomTitle: formState.roomTitle?.length ? formState.roomTitle : ''
  157. })
  158. }
  159. const exportList = () => {
  160. statisticStore.exportAllRoomList({
  161. pageNum: pagination.value.current,
  162. pageSize: pagination.value.pageSize,
  163. timeList: formState.userTime
  164. ? formState.userTime.filter(i => i).map(item => item.toString())
  165. : [],
  166. roomTitle: formState.roomTitle?.length ? formState.roomTitle : ''
  167. })
  168. }
  169. watch(
  170. () => props.current,
  171. val => {
  172. console.log('current,', unref(val))
  173. if (Number(unref(val)) === 2) {
  174. statisticStore.setAllRoomListPage()
  175. fetchList()
  176. } else {
  177. formState.roomTitle = ''
  178. formState.userTime = ['', '']
  179. }
  180. },
  181. {
  182. immediate: true
  183. }
  184. )
  185. const handleFinish = () => {
  186. statisticStore.setAllRoomListPage()
  187. fetchList()
  188. }
  189. const handleFinishFailed = () => {}
  190. </script>
  191. <style lang="less">
  192. .container {
  193. background-color: #fff;
  194. padding: 25px;
  195. width: 100%;
  196. margin-bottom: 25px;
  197. min-width: 875px;
  198. }
  199. </style>