index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <!-- -->
  2. <template>
  3. <div>
  4. <main-top :crumb="crumbData"></main-top>
  5. <div class="table-interface">
  6. <div class="top-body">
  7. <div class="info-top">
  8. <div class="info-left">
  9. <span>按文物类别查看:</span>
  10. <el-select style="width:100px;" v-model="typeId" placeholder="请选择">
  11. <el-option label="全部" value=""></el-option>
  12. <el-option v-for="(item,i) in plist" :key="i" :label="item.name" :value="item.id"></el-option>
  13. </el-select>
  14. <span style="margin-left:20px;">按文物年代查看:</span>
  15. <el-select style="width:180px; text-align:center;" v-model="timeId" placeholder="请选择">
  16. <el-option label="全部" value=""></el-option>
  17. <el-option v-for="(item,i) in tlist" :key="i" :label="item.name" :value="item.id"></el-option>
  18. </el-select>
  19. <el-input style="width:220px;margin:0 20px;" v-model="inputKey" placeholder="请输入文物名称搜索"></el-input>
  20. <el-button type="primary" @click="getInformation">查找</el-button>
  21. <el-button @click="inputKey=''">重置</el-button>
  22. <el-select style="margin-left:20px;" @change="piliang" :value="'批量导入 '" placeholder="请选择">
  23. <el-option
  24. label="模板下载"
  25. value="模板下载">
  26. </el-option>
  27. <el-option
  28. label="批量导入"
  29. value="批量导入">
  30. </el-option>
  31. </el-select>
  32. <input @change="uploadChange" class="upload-btn" ref="upload" type="file">
  33. </div>
  34. <div class="info-right">
  35. <el-button type="primary" @click="$router.push({name:'edit-cultural-relic',params:{type:0}})">新增文物</el-button>
  36. </div>
  37. </div>
  38. <div class="collection-con">
  39. <ul>
  40. <li class="theme-color" @click="gotoShow(item)" v-for="(item,i) in tableData" :key="i">
  41. <div class="li-img">
  42. <el-image :fit="'cover'" style="width:100%;height:100%;" :src="item.unityPic"></el-image>
  43. <!-- <div class="liulan"><span>浏览量: {{Math.round(Math.random()*100000)}}</span> 点赞数: {{Math.round(Math.random()*1000)}}</div> -->
  44. </div>
  45. <div>{{item.timeName}} {{item.typeName}} <span @click.stop="del(item)" class="del">删除</span></div>
  46. <p>{{item.name}}</p>
  47. </li>
  48. </ul>
  49. </div>
  50. <div class="e-pagination">
  51. <el-pagination
  52. @current-change="handleCurrentChange"
  53. :current-page.sync="currentPage"
  54. :page-size="size"
  55. layout="prev, pager, next, jumper"
  56. :total="total"
  57. ></el-pagination>
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. </template>
  63. <script>
  64. // 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  65. // 例如:import 《组件名称》 from '《组件路径》';
  66. import MainTop from '@/components/main-top'
  67. import SearchBar from '@/components/search-bar'
  68. const crumbData = [
  69. {
  70. name: '文物库',
  71. id: 4
  72. }
  73. ]
  74. export default {
  75. // import引入的组件需要注入到对象中才能使用
  76. components: {
  77. MainTop,
  78. SearchBar
  79. },
  80. data () {
  81. return {
  82. crumbData,
  83. tableData: [],
  84. inputKey: '',
  85. currentPage: 1,
  86. size: 20,
  87. total: 0,
  88. loading: false,
  89. plist: [],
  90. tlist: [],
  91. typeId: '',
  92. timeId: ''
  93. }
  94. },
  95. watch: {
  96. currentPage () {
  97. this.refresh()
  98. },
  99. size () {
  100. this.refresh()
  101. },
  102. inputKey () {
  103. this.refresh()
  104. }
  105. },
  106. mounted () {
  107. this.getPositionList()
  108. this.getTypeList()
  109. this.refresh()
  110. },
  111. methods: {
  112. del (item) {
  113. let data = {
  114. id: item.id
  115. }
  116. this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
  117. confirmButtonText: '确定',
  118. cancelButtonText: '取消',
  119. type: 'warning'
  120. }).then(() => {
  121. this.$http.post('/collection/deleteCollection', data).then(res => {
  122. if (res.code === 0) {
  123. this.$notify.success({
  124. title: '提示',
  125. message: '删除成功',
  126. duration: 2000
  127. })
  128. this.refresh()
  129. } else {
  130. this.$notify.error({
  131. title: '错误',
  132. message: res.msg,
  133. duration: 2000
  134. })
  135. }
  136. })
  137. }).catch(() => {
  138. this.$message({
  139. type: 'info',
  140. message: '已取消删除'
  141. })
  142. })
  143. },
  144. async uploadChange (e) {
  145. let file = e.target.files[0]
  146. let formData = new FormData()
  147. formData.append('file', file)
  148. const res = await this.$http.post(
  149. '/collection/importCollection',
  150. formData,
  151. {'Content-Type': 'multipart/form-data'})
  152. if (res.code === 0) {
  153. this.$alert(`上传成功`, '提示', {
  154. confirmButtonText: '确定',
  155. callback: action => {
  156. this.refresh()
  157. }
  158. })
  159. } else {
  160. this.$alert(`上传失败,${res.msg}`, '提示', {
  161. confirmButtonText: '确定',
  162. callback: action => {
  163. this.refresh()
  164. }
  165. })
  166. }
  167. },
  168. piliang (data) {
  169. if (data === '模板下载') {
  170. window.open('/collection/importData.xlsx', '_blank')
  171. } else {
  172. this.$refs.upload.click()
  173. }
  174. },
  175. async getPositionList () {
  176. let result = await this.$http({
  177. method: 'post',
  178. data: {
  179. state: 0
  180. },
  181. url: '/collection/typeList'
  182. })
  183. this.plist = result.data
  184. },
  185. async getTypeList () {
  186. let result = await this.$http({
  187. method: 'post',
  188. url: '/collection/timeList'
  189. })
  190. this.tlist = result.data
  191. },
  192. gotoShow (item) {
  193. this.$router.push({ name: 'show-cultural-relic', params: { id: item.id } })
  194. },
  195. goto (item) {
  196. window.localStorage.setItem('editCollection', JSON.stringify(item))
  197. this.$router.push({ name: 'edit-collection', params: { type: 1 } })
  198. },
  199. refresh () {
  200. this.loading = true
  201. this.getInformation()
  202. this.loading = false
  203. },
  204. handleCurrentChange (val) {
  205. this.currentPage = val
  206. },
  207. async getInformation () {
  208. let params = {
  209. name: this.inputKey,
  210. typeId: this.typeId,
  211. timeId: this.timeId,
  212. pageNum: this.currentPage,
  213. pageSize: this.size
  214. }
  215. let result = await this.$http({
  216. method: 'post',
  217. data: params,
  218. url: '/collection/list'
  219. })
  220. if (result.code !== 0) {
  221. return
  222. }
  223. this.tableData = result.data.list
  224. this.total = result.data.total
  225. }
  226. }
  227. }
  228. </script>
  229. <style scoped>
  230. /* 引入公共css类 */
  231. @import url(./style);
  232. </style>