index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <div class="app-container">
  3. <!-- 搜索表单 -->
  4. <el-form inline label-width="100px" size="mini" @submit.native.prevent>
  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-input v-model="form.clientType" placeholder="请输入设备型号" clearable />
  10. </el-form-item>
  11. <el-form-item>
  12. <el-button type="primary" icon="el-icon-search" @click="getSearch">搜索</el-button>
  13. <el-button icon="el-icon-refresh" @click="getRefresh">重置</el-button>
  14. <el-button type="primary" icon="el-icon-plus" plain @click="getChange()"
  15. v-hasPermi="['device:list:add']">
  16. 新增
  17. </el-button>
  18. <el-button type="primary" icon="el-icon-top" @click="getShelves(1)" :disabled="isDisabled()"
  19. v-hasPermi="['device:list:up']">
  20. 批量上架
  21. </el-button>
  22. <el-button type="primary" icon="el-icon-bottom" @click="getShelves(2)" :disabled="isDisabled()"
  23. v-hasPermi="['device:list:down']">
  24. 批量下架
  25. </el-button>
  26. </el-form-item>
  27. </el-form>
  28. <!-- 表格 -->
  29. <el-table :data="tableData" v-loading="loading" @selection-change="handleSelectionChange">
  30. <el-table-column type="selection" align="center" />
  31. <el-table-column label="设备ID" prop="id" align="center" />
  32. <el-table-column label="设备型号" prop="clientType" align="center" />
  33. <el-table-column label="设备名称" prop="name" align="center" />
  34. <el-table-column label="设备图片" prop="img" align="center" width="100">
  35. <template slot-scope="scope">
  36. <el-image :src="scope.row.img" />
  37. </template>
  38. </el-table-column>
  39. <el-table-column label="设备类型" prop="categoryName" align="center" />
  40. <el-table-column label="是否热门" prop="isHot" align="center" :formatter="hotFormatter" />
  41. <el-table-column label="升级方式" prop="upgradeType" align="center" :formatter="upgradeTypeFormatter" />
  42. <el-table-column label="创建时间" prop="createTimeText" align="center" />
  43. <el-table-column label="操作" align="center">
  44. <template slot-scope="scope">
  45. <el-button type="text" @click="getChange(scope.row.id, '查看')">查看</el-button>
  46. <el-button v-if="scope.row.status === 2" type="text" @click="getShelves(1, scope.row.id)" v-hasPermi="['device:list:up']">
  47. 上架
  48. </el-button>
  49. <el-button v-else type="text" @click="getShelves(2, scope.row.id)" v-hasPermi="['device:list:down']">
  50. 下架
  51. </el-button>
  52. <el-button type="text" @click="getChange(scope.row.id)" v-hasPermi="['device:list:edit']">
  53. 编辑
  54. </el-button>
  55. <el-button v-if="scope.row.status === 2" type="delete" @click="getDelete(scope.row.id)" v-hasPermi="['device:list:delete']">
  56. 删除
  57. </el-button>
  58. </template>
  59. </el-table-column>
  60. </el-table>
  61. <pagination v-show="total>0" :total="total" :page.sync="form.pageNum" :limit.sync="form.pageSize"
  62. @pagination="getList" />
  63. </div>
  64. </template>
  65. <script>
  66. import { listPage, deviceDelete, batchChange } from '@/api/device/list'
  67. export default {
  68. dicts: ['hot_yes_no', 'dev_list_version'],
  69. data() {
  70. return {
  71. // 遮罩层
  72. loading: true,
  73. // 表格
  74. tableData: [],
  75. // 总数据
  76. total: 0,
  77. // 搜索表单
  78. form: {
  79. pageNum: 1,
  80. pageSize: 10
  81. },
  82. // 批量上下架
  83. changeForm: {
  84. ids: '',
  85. type: null
  86. }
  87. }
  88. },
  89. mounted() {
  90. this.getList()
  91. },
  92. methods: {
  93. // 列表
  94. getList() {
  95. this.loading = true
  96. listPage(this.form).then(res => {
  97. this.tableData = res.data.records
  98. this.total = res.data.total
  99. this.loading = false
  100. })
  101. },
  102. // 搜索
  103. getSearch() {
  104. this.form.pageNum = 1
  105. this.form.pageSize = 10
  106. this.getList()
  107. },
  108. // 重置
  109. getRefresh() {
  110. this.form = {
  111. name: '',
  112. pageNum: 1,
  113. pageSize: 10
  114. }
  115. this.getList()
  116. },
  117. // 禁用上下架功能
  118. isDisabled() {
  119. return this.changeForm.ids === '' ? true : false
  120. },
  121. // 上下架
  122. getShelves(key, e) {
  123. if (e) {
  124. this.changeForm.ids = e
  125. }
  126. let title = key === 1 ? '上架' : '下架'
  127. this.changeForm.type = key
  128. batchChange(this.changeForm).then(res => {
  129. if (res.code === 0) {
  130. this.$message.success(`${title}成功!`)
  131. this.getList()
  132. }
  133. })
  134. },
  135. // 新增 / 编辑 / 查看
  136. getChange(id, key) {
  137. this.$router.push({
  138. path: `/device/list/detail`,
  139. query: {
  140. id: id,
  141. key: key
  142. }
  143. })
  144. },
  145. // 多选
  146. handleSelectionChange(e) {
  147. if (e.length > 0) {
  148. let arr = []
  149. e.filter(i => {
  150. arr.push(i.id)
  151. this.changeForm.ids = arr.join(',')
  152. })
  153. } else {
  154. this.changeForm.ids = ''
  155. }
  156. },
  157. // 删除
  158. getDelete(id) {
  159. this.$confirm('确定要删除?', {
  160. type: 'warning'
  161. }).then(() => {
  162. deviceDelete(id).then(res => {
  163. if (res.code === 0) {
  164. this.getList()
  165. this.$message.success('删除成功!')
  166. }
  167. })
  168. }).catch(() => { })
  169. },
  170. // 字典翻译
  171. hotFormatter(row) {
  172. return this.selectDictLabel(this.dict.type.hot_yes_no, row.isHot)
  173. },
  174. upgradeTypeFormatter(row) {
  175. return this.selectDictLabel(this.dict.type.dev_list_version, row.upgradeType)
  176. }
  177. }
  178. }
  179. </script>
  180. <style lang="scss" scoped>
  181. </style>