index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <!-- 数据量 -->
  2. <template>
  3. <div class="pricemoitorrecord">
  4. <a-card :bordered="false">
  5. <a-space class="search">
  6. <div class="silt-title">
  7. <span style="width: 70px; margin-right: 8px; text-align: right; display: block; line-height: 30px">{{
  8. '标题'
  9. }}</span>
  10. <a-input style="width: 220px" v-model:value="SearchFormDel.newsTitle" placeholder="请输入" />
  11. </div>
  12. <div class="silt-title">
  13. <span style="width: 70px; margin-right: 8px; text-align: right; display: block; line-height: 30px">{{
  14. '状态'
  15. }}</span>
  16. <a-select style="width: 220px" v-model:value="SearchFormDel.status">
  17. <a-select-option :value="3">禁用</a-select-option>
  18. <a-select-option :value="2">启用</a-select-option>
  19. <a-select-option :value="1">保存</a-select-option>
  20. </a-select>
  21. </div>
  22. <div class="btnBox">
  23. <a-button type="primary" class="primarySele" @click="Search"> 查询 </a-button>
  24. <a-button class="primarySele snowy-buttom-left" @click="onReset"> 重置 </a-button>
  25. <a-button type="primary" class="primarySele" @click="onView('add', {})"> 新增 </a-button>
  26. <a-button
  27. class="btnl colro primarySele"
  28. type="primary"
  29. :disabled="!hasSelected"
  30. :loading="state.loading"
  31. @click="start"
  32. >
  33. 批量操作(启用/禁用)
  34. </a-button>
  35. </div>
  36. </a-space>
  37. </a-card>
  38. <div class="list" style="margin-top: 10px">
  39. <a-table
  40. :data-source="tableData"
  41. :pagination="pagination"
  42. :columns="tableColumns"
  43. :row-key="(record) => record"
  44. :row-selection="{ selectedRowKeys: state.selectedRowKeys, onChange: onSelectChange }"
  45. >
  46. <template #bodyCell="{ column, record }">
  47. <template v-if="column.dataIndex === 'status'">
  48. <div class="switch_del">
  49. <a-switch
  50. v-if="record.status !== 1"
  51. :checked="record.status == 2 ? true : false"
  52. :checked-children="'启用'"
  53. :un-checked-children="'禁用'"
  54. @change="handleSwitchChange(record)"
  55. size="default"
  56. />
  57. <a-switch
  58. v-if="record.status == 1"
  59. :checked="record.status == 1 ? false : true"
  60. :checked-children="'启用'"
  61. :un-checked-children="'保存'"
  62. @change="handleSwitchChange(record)"
  63. size="default"
  64. />
  65. </div>
  66. </template>
  67. <template v-if="column.dataIndex === 'createUser'">
  68. {{ cocDLMXS(record.createUser) }}
  69. </template>
  70. <template v-if="column.key === '操作'">
  71. <a-button type="link" @click="onView('view', record)">查看</a-button>
  72. <a-button type="link" @click="onView('edit', record)">编辑</a-button>
  73. <a-popconfirm title="确定要删除吗?" @confirm="onView('del', record)">
  74. <a-button type="link">删除</a-button>
  75. </a-popconfirm>
  76. </template>
  77. </template>
  78. </a-table>
  79. </div>
  80. </div>
  81. <Form ref="formRef" @successful="tableRef.refresh()" @change="change" />
  82. </template>
  83. <script setup name="sharing">
  84. import business from '@/api/home/home.js'
  85. import { listPagination } from '@/hook/listlistPagination.js'
  86. import { reactive, ref } from 'vue'
  87. import { useRouter } from 'vue-router'
  88. import { defineComponent } from 'vue'
  89. import { message } from 'ant-design-vue'
  90. import Form from './form.vue'
  91. import { enumMap } from '@/hook/enumMap.js'
  92. const { cocDLMXS } = enumMap()
  93. const formRef = ref(null)
  94. const router = useRouter()
  95. const tableColumns = [
  96. {
  97. title: '序号',
  98. dataIndex: 'INDEX',
  99. align: 'center',
  100. customRender: ({ text, record, index }) => {
  101. return `${index + 1}`
  102. }
  103. },
  104. { title: '标题', align: 'center', dataIndex: 'newsTitle' },
  105. { title: '来源', align: 'center', dataIndex: 'newsSource' },
  106. { title: '状态', align: 'center', dataIndex: 'status' },
  107. { title: '发布人', align: 'center', dataIndex: 'createUser' },
  108. { title: '发布时间', align: 'center', dataIndex: 'publishTime' },
  109. { title: '操作', align: 'center', key: '操作' }
  110. ]
  111. //共享
  112. const handleSwitchChange = async (v) => {
  113. if (v.status == 1) {
  114. const res = await business.IMGXWbatchUpdateStatus([{ id: v.id, status: 2 }])
  115. } else if (v.status == 2) {
  116. const res = await business.IMGXWbatchUpdateStatus([{ id: v.id, status: 3 }])
  117. } else if (v.status == 3) {
  118. const res = await business.IMGXWbatchUpdateStatus([{ id: v.id, status: 2 }])
  119. }
  120. message.success('操作成功')
  121. await onSearch()
  122. }
  123. const state = reactive({
  124. selectedRowKeys: [],
  125. loading: false
  126. })
  127. const hasSelected = computed(() => state.selectedRowKeys.length > 0)
  128. const start = async () => {
  129. state.loading = true
  130. state.selectedRowKeys = []
  131. const res = await business.IMGXWbatchUpdateStatus(del.value)
  132. setTimeout(() => {
  133. state.loading = false
  134. message.success('操作成功')
  135. onSearch()
  136. }, 300)
  137. }
  138. const del = ref([])
  139. const onSelectChange = (selectedRowKeys) => {
  140. state.selectedRowKeys = []
  141. del.value = []
  142. state.selectedRowKeys = selectedRowKeys
  143. del.value = state.selectedRowKeys.map((item) => {
  144. return {
  145. id: item.id,
  146. status: item.status === 1 ? 2 : item.status === 2 ? 3 : 2
  147. }
  148. })
  149. console.log(del.value)
  150. }
  151. const { DEl, change, tableData, onSearch, handlePageChange, pagination, Search, onReset, SearchFormDel } =
  152. listPagination({ newsTitle: '', status: '' }, business.IMGXWlist, business.IMGXWdelete, {
  153. sortOrder: 'ASCEND'
  154. })
  155. const onView = (record, row) => {
  156. switch (record) {
  157. case 'add':
  158. formRef.value.onOpen(record, true, false)
  159. break
  160. case 'del':
  161. DEl(row)
  162. break
  163. case 'view':
  164. formRef.value.onOpen(record, true, true, row)
  165. break
  166. case 'edit':
  167. formRef.value.onOpen(record, true, false, row)
  168. break
  169. default:
  170. break
  171. }
  172. }
  173. </script>
  174. <style lang="less" scoped>
  175. .search {
  176. padding-top: 20px;
  177. // padding-left: 50px;
  178. margin-bottom: 32px;
  179. .btnBox {
  180. width: 100%;
  181. display: inline-block;
  182. display: flex;
  183. justify-content: space-around;
  184. align-items: center;
  185. .primarySele {
  186. margin-left: 20px;
  187. margin-right: 20px;
  188. }
  189. }
  190. }
  191. .silt-title {
  192. display: flex;
  193. }
  194. .switch_del {
  195. height: 40px;
  196. display: flex;
  197. justify-content: center;
  198. align-items: center;
  199. }
  200. </style>