index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <div>
  3. <el-row class="app-toptool" type="flex">
  4. <el-col :span="16">
  5. <Search
  6. size="small"
  7. :search-visible="searchVisible"
  8. :search-data.sync="searchData"
  9. :search-form="searchForm"
  10. @refesh_list="index"
  11. />
  12. </el-col>
  13. <el-col :span="8">
  14. <div class="btn-group" style="margin-bottom:11px;float: right;">
  15. <div>
  16. <el-button
  17. v-if="checkPermission('/kefu/commonly/add')"
  18. type="primary"
  19. size="small"
  20. icon="el-icon-plus"
  21. @click="add()"
  22. >添加</el-button>
  23. <el-button
  24. v-if="checkPermission('/kefu/commonly/delete')"
  25. type="primary"
  26. :disabled="multiple"
  27. size="small"
  28. icon="el-icon-delete"
  29. @click="del(ids)"
  30. >删除</el-button>
  31. </div>
  32. </div>
  33. </el-col>
  34. </el-row>
  35. <div id="charts_one" style="width:100%;min-height:80vh">
  36. <el-table
  37. v-loading="loading"
  38. ref="multipleTable"
  39. :row-class-name="rowClass"
  40. row-key="id"
  41. :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
  42. :border="false"
  43. :stripe="true"
  44. class="eltable"
  45. @selection-change="selection"
  46. :data="list"
  47. style="width: 100%"
  48. >
  49. <el-table-column align="center" type="selection" width="42" />
  50. <el-table-column align="center" type="" property="id" label="编号" show-overflow-tooltip width="70" />
  51. <el-table-column align="center" property="content" label="内容" show-overflow-tooltip width="" />
  52. <el-table-column align="center" property="px" label="排序" show-overflow-tooltip width="" />
  53. <el-table-column align="center" property="status" label="状态" show-overflow-tooltip width="">
  54. <template slot-scope="scope">
  55. <el-switch
  56. v-model="scope.row.status"
  57. :active-value="1"
  58. :inactive-value="0"
  59. @change="listUpdate(scope.row,'status')"
  60. />
  61. </template>
  62. </el-table-column>
  63. <el-table-column
  64. :fixed="$store.getters.device !== 'mobile'?'right':false"
  65. label="操作"
  66. align="center"
  67. width="130"
  68. >
  69. <template slot-scope="scope">
  70. <div v-if="scope.row.id">
  71. <el-button v-if="checkPermission('/kefu/commonly/update')" size="mini" type="primary" @click="update(scope.row)"><i
  72. class="el-icon-edit"
  73. />修改</el-button>
  74. </div>
  75. </template>
  76. </el-table-column>
  77. </el-table>
  78. <Pagination
  79. :total="page_data.total"
  80. :page.sync="page_data.page"
  81. :limit.sync="page_data.limit"
  82. @pagination="index"
  83. />
  84. </div>
  85. <!--添加/修改-->
  86. <Update :info="updateInfo" :opentype="opentype" :show.sync="dialog.updateDialogStatus" size="small" @refesh_list="index" />
  87. </div>
  88. </template>
  89. <script>
  90. import Search from '@/components/common/Search.vue'
  91. import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
  92. import Update from '@/views/kefu/commonly/update.vue'
  93. import {
  94. confirm,
  95. param2Obj
  96. } from '@/utils/common'
  97. export default {
  98. name: 'Commonly',
  99. components: {
  100. Search,
  101. Pagination,
  102. Update
  103. },
  104. data() {
  105. return {
  106. dialog: {
  107. updateDialogStatus: false
  108. },
  109. ids: [],
  110. single: true,
  111. multiple: true,
  112. list: [],
  113. opentype: 'add',
  114. updateInfo: {},
  115. loading: false,
  116. page_data: {
  117. limit: 20,
  118. page: 1,
  119. total: 20
  120. },
  121. searchVisible: true,
  122. searchForm: [],
  123. searchData: {}
  124. }
  125. },
  126. mounted() {
  127. this.index()
  128. },
  129. methods: {
  130. index() {
  131. const param = {
  132. limit: this.page_data.limit,
  133. page: this.page_data.page
  134. }
  135. Object.assign(param, this.searchData)
  136. Object.assign(param, param2Obj(this.$route.fullPath))
  137. this.loading = true
  138. this.$api.post('/kefu.commonly/index', param).then(res => {
  139. this.list = res.data.data
  140. this.page_data.total = res.data.total
  141. this.loading = false
  142. if (this.page_data.page == 1) {
  143. this.searchForm = [{
  144. type: 'Input',
  145. label: '关键词',
  146. prop: 'keyword',
  147. width: '150px'
  148. },
  149. {
  150. type: 'Select',
  151. label: '状态',
  152. prop: 'status',
  153. data: [{
  154. 'key': '正常',
  155. 'val': '1'
  156. }, {
  157. 'key': '禁用',
  158. 'val': '0'
  159. }],
  160. width: '150px'
  161. }
  162. ]
  163. }
  164. })
  165. },
  166. listUpdate(row, field) {
  167. if (row.id) {
  168. this.$api.post('/kefu.commonly/listUpdate', {
  169. id: row.id,
  170. [field]: row[field]
  171. }).then(res => {
  172. this.$message({
  173. message: '操作成功',
  174. type: 'success'
  175. })
  176. })
  177. }
  178. },
  179. add() {
  180. this.opentype = 'add'
  181. this.dialog.updateDialogStatus = true
  182. },
  183. update(row) {
  184. this.opentype = 'update'
  185. const id = row.id ? row.id : this.ids.join(',')
  186. this.$api.post('/kefu.commonly/getInfo', {
  187. id: id
  188. }).then(res => {
  189. this.dialog.updateDialogStatus = true
  190. this.updateInfo = res.data
  191. })
  192. },
  193. del(row) {
  194. confirm({
  195. content: '确定要操作吗'
  196. }).then(() => {
  197. const ids = row.id ? row.id : this.ids.join(',')
  198. this.$api.post('/kefu.commonly/delete', {
  199. id: ids
  200. }).then(res => {
  201. this.$message({
  202. message: res.msg,
  203. type: 'success'
  204. })
  205. this.index()
  206. })
  207. }).catch(() => {})
  208. },
  209. selection(selection) {
  210. this.ids = selection.map(item => item.id)
  211. this.single = selection.length != 1
  212. this.multiple = !selection.length
  213. },
  214. rowClass({
  215. row,
  216. rowIndex
  217. }) {
  218. for (let i = 0; i < this.ids.length; i++) {
  219. if (row.id === this.ids[i]) {
  220. return 'rowLight'
  221. }
  222. }
  223. }
  224. }
  225. }
  226. </script>