index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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="getList"
  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('/agentcode/delete')"
  18. type="primary"
  19. :disabled="multiple"
  20. size="small"
  21. icon="el-icon-delete"
  22. @click="del(ids)"
  23. >删除
  24. </el-button>
  25. </div>
  26. </div>
  27. </el-col>
  28. </el-row>
  29. <el-table
  30. ref="multipleTable"
  31. v-loading="loading"
  32. :row-class-name="rowClass"
  33. :tree-props="{children: 'children'}"
  34. :default-expand-all="expand"
  35. row-key="id"
  36. :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
  37. :border="false"
  38. :stripe="true"
  39. class="eltable"
  40. :data="list"
  41. style="width: 100%"
  42. @selection-change="selection"
  43. >
  44. <el-table-column align="center" type="selection" width="42" />
  45. <el-table-column
  46. align="center"
  47. type=""
  48. property="id"
  49. label="编号"
  50. show-overflow-tooltip
  51. width="70"
  52. />
  53. <el-table-column
  54. align="left"
  55. property="uid"
  56. label="会员"
  57. show-overflow-tooltip
  58. width=""
  59. />
  60. <el-table-column
  61. align="left"
  62. property="agent_code"
  63. label="邀请码"
  64. show-overflow-tooltip
  65. width=""
  66. />
  67. <el-table-column
  68. align="left"
  69. property="create_time"
  70. label="生成时间"
  71. show-overflow-tooltip
  72. width=""
  73. />
  74. <el-table-column
  75. align="center"
  76. property="status"
  77. label="状态"
  78. show-overflow-tooltip
  79. width=""
  80. >
  81. <template slot-scope="scope">
  82. <el-switch
  83. v-model="scope.row.status"
  84. :active-value="1"
  85. :inactive-value="0"
  86. @change="listUpdate(scope.row,'status')"
  87. />
  88. </template>
  89. </el-table-column>
  90. <el-table-column
  91. label="操作"
  92. align="center"
  93. width="100"
  94. >
  95. <template slot-scope="scope">
  96. <div v-if="scope.row.id">
  97. <el-button
  98. v-if="checkPermission('/agentcode/update')"
  99. size="mini"
  100. type="primary"
  101. @click="update(scope.row)"
  102. ><i
  103. class="el-icon-edit"
  104. />修改</el-button>
  105. </div>
  106. </template>
  107. </el-table-column>
  108. </el-table>
  109. <div style="height: 60px;" />
  110. <!--添加/修改-->
  111. <Update :info="updateInfo" :opentype="opentype" :show.sync="dialog.updateDialogStatus" size="small" @refesh_list="getList" />
  112. </div>
  113. </template>
  114. <script>
  115. import Search from '@/components/common/Search'
  116. import Update from '@/views/agentcode/update.vue'
  117. import waves from '@/directive/waves' // waves directive
  118. import {
  119. confirm,
  120. param2Obj
  121. } from '@/utils/common'
  122. export default {
  123. name: 'agentcode',
  124. directives: { waves },
  125. components: {
  126. Search,
  127. Update
  128. },
  129. data() {
  130. return {
  131. dialog: {
  132. updateDialogStatus: false
  133. },
  134. ids: [],
  135. single: true,
  136. multiple: true,
  137. list: [],
  138. opentype: 'add',
  139. updateInfo: {},
  140. loading: false,
  141. searchVisible: true,
  142. searchForm: [],
  143. searchData: {},
  144. expand: true
  145. }
  146. },
  147. mounted() {
  148. this.getList()
  149. },
  150. methods: {
  151. getList() {
  152. const param = {}
  153. Object.assign(param, this.searchData)
  154. Object.assign(param, param2Obj(this.$route.fullPath))
  155. this.loading = true
  156. this.$api.post('/agentcode/index', param).then(res => {
  157. this.list = res.data
  158. this.loading = false
  159. this.searchForm = [{
  160. type: 'Input',
  161. label: '关键词',
  162. prop: 'keyword',
  163. width: '230px'
  164. }
  165. ]
  166. })
  167. },
  168. listUpdate(row, field) {
  169. if (row.id) {
  170. this.$api.post('/agentcode/listUpdate', {
  171. id: row.id,
  172. [field]: row[field]
  173. }).then(res => {
  174. this.$message({
  175. message: '操作成功',
  176. type: 'success'
  177. })
  178. })
  179. }
  180. },
  181. add() {
  182. this.opentype = 'add'
  183. this.dialog.updateDialogStatus = true
  184. },
  185. update(row) {
  186. this.opentype = 'update'
  187. const id = row.id ? row.id : this.ids.join(',')
  188. this.$api.post('/agentcode/getInfo', {
  189. id: id
  190. }).then(res => {
  191. this.dialog.updateDialogStatus = true
  192. this.updateInfo = res.data
  193. })
  194. },
  195. del(row) {
  196. confirm({
  197. content: '确定要操作吗'
  198. }).then(() => {
  199. const ids = row.id ? row.id : this.ids.join(',')
  200. this.$api.post('/agentcode/delete', {
  201. id: ids
  202. }).then(res => {
  203. this.$message({
  204. message: res.msg,
  205. type: 'success'
  206. })
  207. this.getList()
  208. })
  209. }).catch(() => {})
  210. },
  211. selection(selection) {
  212. this.ids = selection.map(item => item.id)
  213. this.single = selection.length != 1
  214. this.multiple = !selection.length
  215. },
  216. rowClass({
  217. row,
  218. rowIndex
  219. }) {
  220. for (let i = 0; i < this.ids.length; i++) {
  221. if (row.id === this.ids[i]) {
  222. return 'rowLight'
  223. }
  224. }
  225. },
  226. toggleRowExpansion() {
  227. this.expand = !this.expand
  228. this.list.forEach(item => {
  229. this.$refs.multipleTable.toggleRowExpansion(item, this.expand)
  230. })
  231. }
  232. }
  233. }
  234. </script>
  235. <style scoped>
  236. .edit-input {
  237. padding-right: 100px;
  238. }
  239. .cancel-btn {
  240. position: absolute;
  241. right: 15px;
  242. top: 10px;
  243. }
  244. </style>