index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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="searchgo"
  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('/coupon/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('/coupon/delete')"
  25. type="primary"
  26. :disabled="multiple"
  27. size="small"
  28. icon="el-icon-delete"
  29. @click="del(ids)"
  30. >删除
  31. </el-button>
  32. </div>
  33. </div>
  34. </el-col>
  35. </el-row>
  36. <div>
  37. <el-table
  38. ref="multipleTable"
  39. v-loading="loading"
  40. :row-class-name="rowClass"
  41. row-key="id"
  42. :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
  43. :border="false"
  44. :stripe="true"
  45. class="eltable"
  46. :data="list"
  47. style="width: 100%"
  48. @selection-change="selection"
  49. >
  50. <el-table-column align="center" type="selection" width="42" />
  51. <el-table-column align="center" property="id" label="编号" show-overflow-tooltip width="70" />
  52. <el-table-column align="left" property="name" label="名称" show-overflow-tooltip width="160" />
  53. <el-table-column align="left" property="ptype" label="发放方式" show-overflow-tooltip width="" />
  54. <el-table-column align="left" property="buy_price" label="购买价格" show-overflow-tooltip width="" />
  55. <el-table-column align="left" property="coupon_type" label="类型" show-overflow-tooltip width="" />
  56. <el-table-column align="left" property="couponway" label="优惠方案" show-overflow-tooltip width="300" />
  57. <el-table-column align="left" property="expire_type" label="使用期限" show-overflow-tooltip width="300" />
  58. <el-table-column align="left" property="color" label="优惠券颜色" show-overflow-tooltip width="" />
  59. <el-table-column align="center" property="status" label="状态" show-overflow-tooltip width="">
  60. <template slot-scope="scope">
  61. <el-switch
  62. v-model="scope.row.status"
  63. :active-value="1"
  64. :inactive-value="0"
  65. @change="listUpdate(scope.row,'status')"
  66. />
  67. </template>
  68. </el-table-column>
  69. <el-table-column align="center" property="sort" label="排序" show-overflow-tooltip width="80">
  70. <template slot-scope="scope" class="sort">
  71. <el-input v-model="scope.row.sort" size="mini" placeholder="排序" @blur.stop="listUpdate(scope.row,'sort')" />
  72. </template>
  73. </el-table-column>
  74. <el-table-column
  75. :fixed="$store.getters.device !== 'mobile'?'right':false"
  76. label="操作"
  77. align="center"
  78. width="100"
  79. >
  80. <template slot-scope="scope">
  81. <div v-if="scope.row.id">
  82. <el-button v-if="checkPermission('/coupon/update')" size="mini" type="primary" @click="update(scope.row)"><i
  83. class="el-icon-edit"
  84. />修改</el-button>
  85. </div>
  86. </template>
  87. </el-table-column>
  88. </el-table>
  89. <Pagination
  90. :total="page_data.total"
  91. :page.sync="page_data.page"
  92. :limit.sync="page_data.limit"
  93. @pagination="index"
  94. />
  95. </div>
  96. <!--添加/修改-->
  97. <Update :info="updateInfo" :opentype="opentype" :show.sync="dialog.updateDialogStatus" size="small" @refesh_list="index" />
  98. </div>
  99. </template>
  100. <script>
  101. import Search from '@/components/common/Search'
  102. import Pagination from '@/components/Pagination'
  103. import Update from '@/views/coupon/update.vue'
  104. import {
  105. confirm,
  106. param2Obj
  107. } from '@/utils/common'
  108. export default {
  109. name: 'Coupon',
  110. components: {
  111. Search,
  112. Pagination,
  113. Update
  114. },
  115. data() {
  116. return {
  117. dialog: {
  118. updateDialogStatus: false
  119. },
  120. ids: [],
  121. single: true,
  122. multiple: true,
  123. list: [],
  124. opentype: 'add',
  125. updateInfo: {},
  126. loading: false,
  127. ws: {},
  128. filename: '',
  129. page_data: {
  130. limit: 20,
  131. page: 1,
  132. total: 20
  133. },
  134. searchVisible: true,
  135. searchForm: [],
  136. searchData: {}
  137. }
  138. },
  139. mounted() {
  140. this.index()
  141. },
  142. methods: {
  143. searchgo() {
  144. this.page_data.page = 1
  145. this.index()
  146. },
  147. index() {
  148. const param = {
  149. limit: this.page_data.limit,
  150. page: this.page_data.page
  151. }
  152. Object.assign(param, this.searchData)
  153. Object.assign(param, param2Obj(this.$route.fullPath))
  154. this.loading = true
  155. this.$api.post('/coupon/index', param).then(res => {
  156. this.list = res.data.data
  157. this.page_data.total = res.data.total
  158. this.loading = false
  159. // console.log(this.page_data);
  160. if (this.page_data.page == 1) {
  161. this.searchForm = [
  162. {
  163. type: 'Select',
  164. label: '推荐状态',
  165. prop: 'is_recommended',
  166. data: [{
  167. 'key': '推荐',
  168. 'val': '1'
  169. }, {
  170. 'key': '不荐',
  171. 'val': '0'
  172. }],
  173. width: '150px'
  174. },
  175. {
  176. type: 'Input',
  177. label: '关键词',
  178. prop: 'keyword',
  179. width: '230px'
  180. }
  181. ]
  182. }
  183. })
  184. },
  185. listUpdate(row, field) {
  186. if (row.id) {
  187. this.$api.post('/coupon/listUpdate', {
  188. id: row.id,
  189. [field]: row[field]
  190. }).then(res => {
  191. this.$message({
  192. message: '操作成功',
  193. type: 'success'
  194. })
  195. })
  196. }
  197. },
  198. add() {
  199. this.opentype = 'add'
  200. this.dialog.updateDialogStatus = true
  201. },
  202. update(row) {
  203. this.opentype = 'update'
  204. const id = row.id ? row.id : this.ids.join(',')
  205. this.$api.post('/coupon/getInfo', {
  206. id: id
  207. }).then(res => {
  208. this.dialog.updateDialogStatus = true
  209. this.updateInfo = res.data
  210. })
  211. },
  212. del(row) {
  213. confirm({
  214. content: '确定要操作吗'
  215. }).then(() => {
  216. const ids = row.id ? row.id : this.ids.join(',')
  217. this.$api.post('/coupon/delete', {
  218. id: ids
  219. }).then(res => {
  220. this.$message({
  221. message: res.msg,
  222. type: 'success'
  223. })
  224. this.index()
  225. })
  226. }).catch(() => {})
  227. },
  228. selection(selection) {
  229. this.ids = selection.map(item => item.id)
  230. this.single = selection.length != 1
  231. this.multiple = !selection.length
  232. },
  233. rowClass({
  234. row,
  235. rowIndex
  236. }) {
  237. for (let i = 0; i < this.ids.length; i++) {
  238. if (row.id === this.ids[i]) {
  239. return 'rowLight'
  240. }
  241. }
  242. }
  243. }
  244. }
  245. </script>
  246. <style scoped>
  247. .table_list_pic {
  248. width: 80px;
  249. height: 80px;
  250. vertical-align: middle;
  251. }
  252. </style>