index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <div
  3. class="classification_list"
  4. v-loading.fullscreen.lock="fullscreenLoading"
  5. >
  6. <div class="classification_list_headerSelect">
  7. <div class="classification-list-btn">
  8. <el-form ref="form" :model="form" inline label-width="90px">
  9. <el-form-item class="header_top_form" label="分类名称:" prop="name">
  10. <el-input
  11. v-model.trim="form.name"
  12. size="small"
  13. placeholder="请输入"
  14. clearable
  15. ></el-input>
  16. </el-form-item>
  17. <el-form-item class="header_top_form" label="状态:" prop="status">
  18. <el-select
  19. v-model="form.status"
  20. clearable
  21. size="small"
  22. placeholder="请选择"
  23. >
  24. <el-option
  25. v-for="item in options"
  26. :key="item.value"
  27. :label="item.label"
  28. :value="item.value"
  29. >
  30. </el-option>
  31. </el-select>
  32. </el-form-item>
  33. </el-form>
  34. <div style="margin-right: 23px">
  35. <el-button
  36. size="small"
  37. style="width: 88px"
  38. type="primary"
  39. @click="search"
  40. >查询</el-button
  41. >
  42. <el-button size="small" style="width: 88px" @click="resetForm('form')"
  43. >重置</el-button
  44. >
  45. </div>
  46. </div>
  47. <div style="text-align: right">
  48. <el-button
  49. size="small"
  50. style="width: 104px; margin-right: 23px"
  51. @click="addList"
  52. icon="iconfont icon-a-zu13"
  53. >新增</el-button
  54. >
  55. </div>
  56. </div>
  57. <div>
  58. <el-table
  59. ref="editTable"
  60. :data="tableData"
  61. stripe
  62. :header-cell-style="{ background: '#F7F7F7' }"
  63. :height="screenHeight"
  64. >
  65. <el-table-column
  66. label="分类名称"
  67. prop="name"
  68. align="center"
  69. show-overflow-tooltip
  70. ></el-table-column>
  71. <el-table-column
  72. label="链接地址"
  73. prop="linkUrl"
  74. align="center"
  75. min-width="180"
  76. ></el-table-column>
  77. <el-table-column
  78. label="禁用/启用"
  79. prop="status"
  80. align="center"
  81. >
  82. <template slot-scope="scope">
  83. <div>
  84. <el-switch
  85. v-model="scope.row.status"
  86. active-color="#17A8FF"
  87. inactive-color="#AFAFAF"
  88. @change="switchChange($event, scope.row)"
  89. >
  90. </el-switch>
  91. </div> </template
  92. ></el-table-column>
  93. <el-table-column
  94. label="创建人"
  95. prop="createUserName"
  96. align="center"
  97. show-overflow-tooltip
  98. ></el-table-column>
  99. <el-table-column
  100. label="创建时间"
  101. prop="createTime"
  102. align="center"
  103. show-overflow-tooltip
  104. ></el-table-column>
  105. <el-table-column label="操作" width="140px" align="center">
  106. <template slot-scope="scope">
  107. <div>
  108. <el-button type="text" @click="edit(scope.row)">编辑</el-button>
  109. </div>
  110. </template>
  111. </el-table-column>
  112. </el-table>
  113. </div>
  114. <el-pagination
  115. @size-change="handleSizeChange"
  116. @current-change="handleCurrentChange"
  117. :current-page="form.pageNum"
  118. :page-sizes="[100, 200, 300, 400]"
  119. :page-size="form.pageSize"
  120. background
  121. layout="total,prev, pager, next,jumper"
  122. :total="form.total"
  123. >
  124. </el-pagination>
  125. <edit-dialog ref="editDialogRefs" />
  126. </div>
  127. </template>
  128. <script>
  129. import editDialog from './edit'
  130. import * as api from '@/api/api'
  131. export default {
  132. name: 'classification',
  133. components: {
  134. editDialog
  135. },
  136. data() {
  137. return {
  138. fullscreenLoading: false,
  139. form: {
  140. name: '',
  141. status: '',
  142. pageNum: 1,
  143. pageSize: 10,
  144. start: '',
  145. total: 0
  146. },
  147. tableData: [],
  148. options: [
  149. { label: '启用', value: 1 },
  150. { label: '禁用', value: 0 }
  151. ],
  152. screenHeight: document.body.clientHeight - 320,
  153. tableDataheight: 0
  154. }
  155. },
  156. mounted() {
  157. this.screenHeight = document.body.clientHeight - 320
  158. window.onresize = () => {
  159. return (() => {
  160. this.screenHeight = document.body.clientHeight - 320
  161. })()
  162. }
  163. this.tableDataList()
  164. },
  165. methods: {
  166. /**
  167. * @method 重置
  168. * **/
  169. resetForm(formName) {
  170. this.$refs[formName].resetFields()
  171. this.search()
  172. },
  173. /**
  174. * @method 搜索
  175. * **/
  176. search() {
  177. if (sessionStorage.getItem('classifica')) {
  178. this.form.pageNum = Number(sessionStorage.getItem('classifica'))
  179. sessionStorage.removeItem('classifica')
  180. } else {
  181. this.form.pageNum = 1
  182. }
  183. this.tableDataList()
  184. },
  185. /**
  186. * @method 列表数据
  187. * **/
  188. tableDataList() {
  189. this.tableData = []
  190. this.fullscreenLoading = true
  191. let code = {
  192. name: this.form.name,
  193. page: this.form.pageNum,
  194. pageSize: this.form.pageSize,
  195. start: this.form.start,
  196. status: this.form.status
  197. }
  198. api
  199. .GET('/doc/type/list', code)
  200. .then(res => {
  201. if (res.code == 0) {
  202. this.tableData = res.data.list
  203. this.tableData.forEach(item => {
  204. item.status == 1 ? (item.status = true) : (item.status = false)
  205. })
  206. this.form.pageNum = res.data.currPage
  207. this.form.pageSize = res.data.pageSize
  208. this.form.total = res.data.totalCount
  209. this.fullscreenLoading = false
  210. this.$nextTick(() => {
  211. this.$refs.editTable.bodyWrapper.scrollTop = this.tableDataheight
  212. this.tableDataheight = 0
  213. })
  214. }
  215. })
  216. .catch(() => {
  217. this.fullscreenLoading = false
  218. })
  219. },
  220. /**
  221. * @method 分页条数
  222. * **/
  223. handleSizeChange(val) {
  224. this.form.pageNum = 1
  225. this.form.pageSize = val
  226. this.tableDataList()
  227. },
  228. /**
  229. * @method 分页
  230. * **/
  231. handleCurrentChange(val) {
  232. this.form.pageNum = val
  233. this.tableDataList()
  234. },
  235. // 编辑
  236. edit(val) {
  237. this.tableDataheight = this.$refs.editTable.bodyWrapper.scrollTop
  238. sessionStorage.setItem('classifica', this.form.pageNum)
  239. let code = {
  240. title: '分类编辑',
  241. show: false,
  242. typeId: val.typeId
  243. }
  244. this.$refs.editDialogRefs.openClose(code)
  245. },
  246. /**
  247. * @method 新增
  248. * **/
  249. addList() {
  250. let code = {
  251. title: '分类新增',
  252. show: true
  253. }
  254. this.$refs.editDialogRefs.openClose(code)
  255. },
  256. /**
  257. * @method 切换状态
  258. * **/
  259. switchChange(val, item) {
  260. this.tableDataheight = this.$refs.editTable.bodyWrapper.scrollTop
  261. sessionStorage.setItem('classifica', this.form.pageNum)
  262. val ? (val = 1) : (val = 0)
  263. let code = {
  264. id: item.typeId,
  265. status: val
  266. }
  267. api
  268. .PUT('/doc/type/updateSwitch', code)
  269. .then(data => {
  270. if (data.code == 0) {
  271. this.search()
  272. this.$message.success(data.message)
  273. }
  274. })
  275. .catch(() => {
  276. this.search()
  277. })
  278. }
  279. }
  280. }
  281. </script>
  282. <style lang="less">
  283. .classification_list {
  284. .classification_list_headerSelect {
  285. .classification-list-btn {
  286. display: flex;
  287. justify-content: space-between;
  288. align-items: center;
  289. margin-bottom: 10px;
  290. }
  291. margin-bottom: 20px;
  292. .el-form-item {
  293. margin-bottom: 10px;
  294. margin-right: 60px;
  295. .el-input__inner {
  296. background: #f5f5f5;
  297. opacity: 1;
  298. border-radius: 17px;
  299. }
  300. }
  301. .icon-a-zu13 {
  302. font-size: 11px;
  303. margin-right: 5px;
  304. }
  305. }
  306. }
  307. </style>