index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <div class='app-container'>
  3. <!-- 搜索 -->
  4. <el-form inline size="mini">
  5. <el-form-item label="大类名称:">
  6. <el-input v-model="form.name" placeholder="请输入大类名称" clearable />
  7. </el-form-item>
  8. <el-form-item label="设备分类:">
  9. <el-select v-model="form.categoryId" placeholder="请选择设备分类" clearable>
  10. <el-option v-for="item in categoryOptions" :key="item.value" :value="item.value" :label="item.label" />
  11. </el-select>
  12. </el-form-item>
  13. <el-form-item label="当前状态:">
  14. <el-select v-model="form.status" placeholder="请选择当前状态" clearable>
  15. <el-option v-for="item in onOrOffOptions" :key="item.value" :value="item.value" :label="item.label" />
  16. </el-select>
  17. </el-form-item>
  18. <el-form-item label="是否热门:">
  19. <el-select v-model="form.isHot" placeholder="请选择是否热门" clearable>
  20. <el-option v-for="item in yesOrNoOptions" :key="item.value" :value="item.value" :label="item.label" />
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item>
  24. <el-button type="primary" icon="el-icon-search" @click="getSearch">搜索</el-button>
  25. <el-button icon="el-icon-refresh" @click="getRefresh">重置</el-button>
  26. <el-button type="primary" icon="el-icon-plus" plain @click="getDetail()" v-hasPermi="['device:class:add']">新增</el-button>
  27. <el-button type="primary" :disabled="ids === ''" @click="getChange(ids, 2, '批量上架')" v-hasPermi="['device:class:up']">批量上架</el-button>
  28. <el-button type="primary" :disabled="ids === ''" @click="getChange(ids, 2, '批量下架')" v-hasPermi="['device:class:down']">批量下架</el-button>
  29. </el-form-item>
  30. </el-form>
  31. <!-- 列表 -->
  32. <el-table :data="tableData" v-loading="loading" @selection-change="handleSelection">
  33. <el-table-column type="selection" align="center" />
  34. <el-table-column label="大类Id" prop="id" align="center" show-overflow-tooltip />
  35. <el-table-column label="大类名称" prop="name" align="center" />
  36. <el-table-column label="设备图片" align="center" width="100px">
  37. <template slot-scope="scope"><el-image :src="scope.row.img" /></template>
  38. </el-table-column>
  39. <el-table-column label="设备分类" prop="categoryId" align="center" :formatter="categoryIdFormatter" />
  40. <el-table-column label="设备类型" prop="type" align="center" :formatter="typeFormatter" />
  41. <el-table-column label="是否热门" prop="isHot" align="center" :formatter="isHotFormatter" />
  42. <el-table-column label="关联设备" prop="deviceIds" align="center" :formatter="deviceFormatter" show-overflow-tooltip />
  43. <el-table-column label="当前状态" prop="status" align="center" :formatter="statusFormatter" />
  44. <el-table-column label="更新时间" prop="updateTime" align="center" />
  45. <el-table-column label="创建时间" prop="createTime" align="center" />
  46. <el-table-column label="操作" align="center">
  47. <template slot-scope="scope">
  48. <el-button type="text" @click="getDetail(scope.row.id, true)">查看</el-button>
  49. <el-button v-if="scope.row.status === 1" type="text" @click="getChange(scope.row.id, 2, '下架')" v-hasPermi="['device:class:down']">下架</el-button>
  50. <span v-else style="margin-left: 10px;">
  51. <el-button type="text" @click="getDetail(scope.row.id)" v-hasPermi="['device:class:edit']">编辑</el-button>
  52. <el-button type="text" @click="getChange(scope.row.id, 1, '上架')" v-hasPermi="['device:class:up']">上架</el-button>
  53. <el-button type="delete" @click="getDelete(scope.row)" v-hasPermi="['device:class:delete']">删除</el-button>
  54. </span>
  55. </template>
  56. </el-table-column>
  57. </el-table>
  58. </div>
  59. </template>
  60. <script>
  61. import { list, change } from '@/api/device/class'
  62. import { devCategoryMixin, devMixin, onOrOffMixin, devTypeMixin, yesOrNoMixin } from '@/mixin/index'
  63. export default {
  64. mixins: [devCategoryMixin, devMixin, onOrOffMixin, devTypeMixin, yesOrNoMixin],
  65. data() {
  66. return {
  67. // 遮罩层
  68. loading: false,
  69. // 表单
  70. form: {
  71. pageNum: 1,
  72. pageSize: 10
  73. },
  74. // 列表
  75. tableData: [],
  76. // 批量上下架
  77. ids: ''
  78. }
  79. },
  80. mounted() {
  81. this.getList()
  82. },
  83. methods: {
  84. // 列表
  85. getList() {
  86. this.loading = true
  87. list(this.form).then(res => {
  88. if (res.code === 0) {
  89. this.tableData = res.data.records
  90. this.total = res.data.total
  91. this.loading = false
  92. }
  93. })
  94. },
  95. // 搜索
  96. getSearch() {
  97. this.form.pageNum = 1
  98. this.getList()
  99. },
  100. // 重置
  101. getRefresh() {
  102. this.form = {
  103. pageNum: 1,
  104. pageSize: 10
  105. }
  106. this.getList()
  107. },
  108. // 新增
  109. getDetail(id, boolean) {
  110. this.$router.push({
  111. path: '/device/class/detail',
  112. query: {
  113. id: id,
  114. boolean: boolean
  115. }
  116. })
  117. },
  118. // 多选
  119. handleSelection(e) {
  120. if (e.length > 0) {
  121. let arr = []
  122. e.filter(i => {
  123. arr.push(i.id)
  124. this.ids = arr.join(',')
  125. })
  126. } else {
  127. this.ids = ''
  128. }
  129. },
  130. // 上架 下架 删除
  131. getChange(ids, status, title) {
  132. change(ids, status).then(res => {
  133. if (res.code === 0) {
  134. this.$message.success(`${title}成功!`)
  135. this.getList()
  136. }
  137. })
  138. },
  139. // 删除
  140. getDelete(e) {
  141. this.$confirm(`是否删除${e.name}?`, '提示', {
  142. type: 'warning'
  143. }).then(() => {
  144. this.getChange(e.id, 0, '删除')
  145. })
  146. },
  147. // 字典翻译
  148. categoryIdFormatter(row) {
  149. return this.selectDictLabel(this.categoryOptions, row.categoryId)
  150. },
  151. typeFormatter(row) {
  152. return this.selectDictLabel(this.devTypeOptions, row.type)
  153. },
  154. isHotFormatter(row) {
  155. return this.selectDictLabel(this.yesOrNoOptions, row.isHot)
  156. },
  157. deviceFormatter(row) {
  158. return row.deviceIds.split(',').map(i => this.selectDictLabel(this.devOptions, i))
  159. },
  160. statusFormatter(row) {
  161. return this.selectDictLabel(this.onOrOffOptions, row.status)
  162. }
  163. }
  164. }
  165. </script>