index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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="请输入弹窗名称" />
  7. </el-form-item>
  8. <el-form-item label="当前状态:">
  9. <el-select v-model="form.status" placeholder="请选择当前状态">
  10. <el-option v-for="item in disabledOptions" :key="item.value" :value="item.value" :label="item.label" />
  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="getDialog('新增')"
  17. v-hasPermi="['operation:dialog:add']">新增</el-button>
  18. </el-form-item>
  19. </el-form>
  20. <!-- 列表 -->
  21. <el-table :data="tableData" v-loading="loading">
  22. <el-table-column label="序号" type="index" align="center" />
  23. <el-table-column label="弹窗名称" prop="name" align="center" show-overflow-tooltip />
  24. <el-table-column label="弹窗图片" align="center" width="100px">
  25. <template slot-scope="scope">
  26. <el-image :src="scope.row.pic" />
  27. </template>
  28. </el-table-column>
  29. <el-table-column label="关联设备" align="center" :formatter="devFormatter" show-overflow-tooltip />
  30. <el-table-column label="创建时间" prop="createTime" align="center" />
  31. <el-table-column label="当前状态" prop="status" align="center" :formatter="statusFormatter" />
  32. <el-table-column label="操作" align="center">
  33. <template slot-scope="scope">
  34. <el-button type="text" @click="getDialog('查看', scope.row.id)">查看</el-button>
  35. <el-button v-if="scope.row.status === 0" type="text" @click="getChange(scope.row, 1, '下架')"
  36. v-hasPermi="['operation:dialog:down']">下架</el-button>
  37. <span v-else style="margin-left: 10px">
  38. <el-button type="text" @click="getDialog('编辑', scope.row.id)"
  39. v-hasPermi="['operation:dialog:edit']">编辑</el-button>
  40. <el-button type="text" @click="getChange(scope.row, 0, '上架')"
  41. v-hasPermi="['operation:dialog:up']">上架</el-button>
  42. <el-button type="delete" @click="getChange(scope.row, 2, '删除')"
  43. v-hasPermi="['operation:dialog:delete']">删除</el-button>
  44. </span>
  45. </template>
  46. </el-table-column>
  47. </el-table>
  48. <pagination v-show="total > 0" :total="total" :page.sync="form.pageNum" :limit.sync="form.pageSize"
  49. @pagination="getList" />
  50. <!-- 弹窗 -->
  51. <el-dialog :visible.sync="dialogVisible" :title="title" width="500px" :before-close="getClose">
  52. <el-form label-width="auto" :disabled="title === '查看' ? true : false">
  53. <el-form-item label="弹窗名称:">
  54. <el-input v-model="dialogForm.name" placeholder="请输入弹窗名称" />
  55. </el-form-item>
  56. <el-form-item label="关联设备:">
  57. <el-select v-model="dialogForm.deviceIds" multiple filterable placeholder="请选择关联设备">
  58. <el-option v-for="item in devOptions" :key="item.value" :value="item.value" :label="item.label" />
  59. </el-select>
  60. </el-form-item>
  61. <el-form-item label="弹窗图片:">
  62. <Upload listType="picture-card" :url="dialogForm.pic" @upload="upload"
  63. :disabled="title === '查看' ? true : false" />
  64. </el-form-item>
  65. </el-form>
  66. <div slot="footer">
  67. <el-button @click="getClose">取消</el-button>
  68. <el-button v-if="title !== '查看'" type="primary" @click="getSubmit">确定</el-button>
  69. </div>
  70. </el-dialog>
  71. </div>
  72. </template>
  73. <script>
  74. import { list, detail, change, devList, submit } from '@/api/operation/dialog'
  75. import { disabledMixin } from '@/mixin/index'
  76. export default {
  77. mixins: [disabledMixin],
  78. data() {
  79. return {
  80. // 遮罩层
  81. loading: false,
  82. // 表单
  83. form: {
  84. pageNum: 1,
  85. pageSize: 10
  86. },
  87. // 总数据
  88. total: 0,
  89. // 列表
  90. tableData: [],
  91. // 弹窗
  92. dialogVisible: false,
  93. // 弹窗名称
  94. title: '新增',
  95. // 弹窗表单
  96. dialogForm: {},
  97. // 设备列表
  98. devOptions: [],
  99. allDevs: []
  100. }
  101. },
  102. mounted() {
  103. this.getList()
  104. this.getDev(1)
  105. },
  106. methods: {
  107. // 列表
  108. getList() {
  109. this.loading = true
  110. list(this.form).then(res => {
  111. if (res.code === 0) {
  112. this.tableData = res.data.records
  113. this.total = res.data.total
  114. this.loading = false
  115. }
  116. })
  117. },
  118. // 搜索
  119. getSearch() {
  120. this.form.pageNum = 1
  121. this.getList()
  122. },
  123. // 重置
  124. getRefresh() {
  125. this.form = {
  126. pageNum: 1,
  127. pageSize: 10
  128. }
  129. this.getList()
  130. },
  131. // 上下架
  132. getChange(row, status, title) {
  133. this.$confirm(`是否${title}${row.name}?`, '提示', {
  134. type: 'warning'
  135. }).then(res => {
  136. change(row.id, status).then(res => {
  137. if (res.code === 0) {
  138. this.$message.success(`${title}成功!`)
  139. this.getList()
  140. }
  141. })
  142. }).catch(() => { })
  143. },
  144. // 弹窗
  145. getDialog(title, id) {
  146. this.dialogVisible = true
  147. this.title = title
  148. this.getDev(2)
  149. if (id) {
  150. detail(id).then(res => {
  151. if (res.code === 0) {
  152. this.dialogForm = res.data
  153. this.dialogForm.deviceIds = res.data.deviceIds.split(',')
  154. res.data.existDeviceList.map(i => {
  155. this.devOptions.unshift({
  156. value: i.clientTypeId,
  157. label: i.name
  158. })
  159. })
  160. }
  161. })
  162. }
  163. },
  164. // 设备列表
  165. getDev(type) {
  166. this.devOptions = []
  167. devList(type).then(res => {
  168. if (res.code === 0) {
  169. res.data.map(i => {
  170. let obj = {
  171. value: i.clientTypeId,
  172. label: i.name
  173. }
  174. type === 1 ? this.allDevs.push(obj) : this.devOptions.push(obj)
  175. })
  176. }
  177. })
  178. },
  179. // 上传
  180. upload(e) {
  181. this.dialogForm.pic = e.file
  182. },
  183. // 关闭
  184. getClose() {
  185. this.dialogVisible = false
  186. this.dialogForm = {}
  187. },
  188. // 确定
  189. getSubmit() {
  190. this.dialogForm.deviceIds = this.dialogForm.deviceIds.join(',')
  191. submit(this.dialogForm).then(res => {
  192. if (res.code === 0) {
  193. this.$message.success('提交成功!')
  194. this.getClose()
  195. this.getList()
  196. }
  197. })
  198. },
  199. // 字典翻译
  200. devFormatter(row) {
  201. return row.deviceIds ? row.deviceIds.split(',').map(i => this.selectDictLabel(this.allDevs, i)).join(',') : ''
  202. },
  203. statusFormatter(row) {
  204. return this.selectDictLabel(this.disabledOptions, row.status)
  205. }
  206. }
  207. }
  208. </script>
  209. <style lang="scss" scoped>
  210. </style>