index.vue 6.5 KB

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