index.vue 5.9 KB

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