index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template> 
  2. <div class="app-container">
  3. <el-card class="filter-container" shadow="never">
  4. <div>
  5. <i class="el-icon-search"></i>
  6. <span>筛选搜索</span>
  7. <el-button
  8. style="float:right"
  9. type="primary"
  10. @click="handleSearchList()"
  11. size="small">
  12. 查询搜索
  13. </el-button>
  14. <el-button
  15. style="float:right;margin-right: 15px"
  16. @click="handleResetSearch()"
  17. size="small">
  18. 重置
  19. </el-button>
  20. </div>
  21. <div style="margin-top: 15px">
  22. <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
  23. <el-form-item label="优惠券名称:">
  24. <el-input v-model="listQuery.name" class="input-width" placeholder="优惠券名称"></el-input>
  25. </el-form-item>
  26. <el-form-item label="优惠券类型:">
  27. <el-select v-model="listQuery.type" placeholder="全部" clearable class="input-width">
  28. <el-option v-for="item in typeOptions"
  29. :key="item.value"
  30. :label="item.label"
  31. :value="item.value">
  32. </el-option>
  33. </el-select>
  34. </el-form-item>
  35. </el-form>
  36. </div>
  37. </el-card>
  38. <el-card class="operate-container" shadow="never">
  39. <i class="el-icon-tickets"></i>
  40. <span>数据列表</span>
  41. <el-button size="mini" class="btn-add" @click="handleAdd()">添加</el-button>
  42. </el-card>
  43. <div class="table-container">
  44. <el-table ref="couponTable"
  45. :data="list"
  46. style="width: 100%;"
  47. @selection-change="handleSelectionChange"
  48. v-loading="listLoading" border>
  49. <el-table-column type="selection" width="60" align="center"></el-table-column>
  50. <el-table-column label="编号" width="100" align="center">
  51. <template slot-scope="scope">{{scope.row.id}}</template>
  52. </el-table-column>
  53. <el-table-column label="优惠劵名称" align="center">
  54. <template slot-scope="scope">{{scope.row.name}}</template>
  55. </el-table-column>
  56. <el-table-column label="优惠券类型" width="100" align="center">
  57. <template slot-scope="scope">{{scope.row.type | formatType}}</template>
  58. </el-table-column>
  59. <el-table-column label="可使用商品" width="100" align="center">
  60. <template slot-scope="scope">{{scope.row.useType | formatUseType}}</template>
  61. </el-table-column>
  62. <el-table-column label="使用门槛" width="140" align="center">
  63. <template slot-scope="scope">满{{scope.row.minPoint}}元可用</template>
  64. </el-table-column>
  65. <el-table-column label="面值" width="100" align="center">
  66. <template slot-scope="scope">{{scope.row.amount}}元</template>
  67. </el-table-column>
  68. <el-table-column label="适用平台" width="100" align="center">
  69. <template slot-scope="scope">{{scope.row.platform | formatPlatform}}</template>
  70. </el-table-column>
  71. <el-table-column label="有效期" width="180" align="center">
  72. <template slot-scope="scope">{{scope.row.startTime|formatDate}}至{{scope.row.endTime|formatDate}}</template>
  73. </el-table-column>
  74. <el-table-column label="状态" width="100" align="center">
  75. <template slot-scope="scope">{{scope.row.endTime | formatStatus}}</template>
  76. </el-table-column>
  77. <el-table-column label="操作" width="180" align="center">
  78. <template slot-scope="scope">
  79. <el-button size="mini"
  80. type="text"
  81. @click="handleView(scope.$index, scope.row)">查看</el-button>
  82. <el-button size="mini"
  83. type="text"
  84. @click="handleUpdate(scope.$index, scope.row)">
  85. 编辑</el-button>
  86. <el-button size="mini"
  87. type="text"
  88. @click="handleDelete(scope.$index, scope.row)">删除</el-button>
  89. </template>
  90. </el-table-column>
  91. </el-table>
  92. </div>
  93. <div class="pagination-container">
  94. <el-pagination
  95. background
  96. @size-change="handleSizeChange"
  97. @current-change="handleCurrentChange"
  98. layout="total, sizes,prev, pager, next,jumper"
  99. :current-page.sync="listQuery.pageNum"
  100. :page-size="listQuery.pageSize"
  101. :page-sizes="[5,10,15]"
  102. :total="total">
  103. </el-pagination>
  104. </div>
  105. </div>
  106. </template>
  107. <script>
  108. import {fetchList,deleteCoupon} from '@/api/coupon';
  109. import {formatDate} from '@/utils/date';
  110. const defaultListQuery = {
  111. pageNum: 1,
  112. pageSize: 10,
  113. name: null,
  114. type: null
  115. };
  116. const defaultTypeOptions=[
  117. {
  118. label: '全场赠券',
  119. value: 0
  120. },
  121. {
  122. label: '会员赠券',
  123. value: 1
  124. },
  125. {
  126. label: '购物赠券',
  127. value: 2
  128. },
  129. {
  130. label: '注册赠券',
  131. value: 3
  132. }
  133. ];
  134. export default {
  135. name:'couponList',
  136. data() {
  137. return {
  138. listQuery:Object.assign({},defaultListQuery),
  139. typeOptions:Object.assign({},defaultTypeOptions),
  140. list:null,
  141. total:null,
  142. listLoading:false,
  143. multipleSelection:[]
  144. }
  145. },
  146. created(){
  147. this.getList();
  148. },
  149. filters:{
  150. formatType(type){
  151. for(let i=0;i<defaultTypeOptions.length;i++){
  152. if(type===defaultTypeOptions[i].value){
  153. return defaultTypeOptions[i].label;
  154. }
  155. }
  156. return '';
  157. },
  158. formatUseType(useType){
  159. if(useType===0){
  160. return '全场通用';
  161. }else if(useType===1){
  162. return '指定分类';
  163. }else{
  164. return '指定商品';
  165. }
  166. },
  167. formatPlatform(platform){
  168. if(platform===1){
  169. return '移动平台';
  170. }else if(platform===2){
  171. return 'PC平台';
  172. }else{
  173. return '全平台';
  174. }
  175. },
  176. formatDate(time){
  177. if(time==null||time===''){
  178. return 'N/A';
  179. }
  180. let date = new Date(time);
  181. return formatDate(date, 'yyyy-MM-dd')
  182. },
  183. formatStatus(endTime){
  184. let now = new Date().getTime();
  185. if(endTime>now){
  186. return '未过期'
  187. }else{
  188. return '已过期';
  189. }
  190. }
  191. },
  192. methods:{
  193. handleResetSearch() {
  194. this.listQuery = Object.assign({}, defaultListQuery);
  195. },
  196. handleSearchList() {
  197. this.listQuery.pageNum = 1;
  198. this.getList();
  199. },
  200. handleSelectionChange(val){
  201. this.multipleSelection = val;
  202. },
  203. handleSizeChange(val) {
  204. this.listQuery.pageNum = 1;
  205. this.listQuery.pageSize = val;
  206. this.getList();
  207. },
  208. handleCurrentChange(val) {
  209. this.listQuery.pageNum = val;
  210. this.getList();
  211. },
  212. handleAdd(){
  213. this.$router.push({path: '/sms/addCoupon'})
  214. },
  215. handleView(index, row) {
  216. this.$router.push({path: '/sms/couponHistory', query: {id: row.id}})
  217. },
  218. handleUpdate(index, row) {
  219. this.$router.push({path: '/sms/updateCoupon', query: {id: row.id}})
  220. },
  221. handleDelete(index, row) {
  222. this.$confirm('是否进行删除操作?', '提示', {
  223. confirmButtonText: '确定',
  224. cancelButtonText: '取消',
  225. type: 'warning'
  226. }).then(() => {
  227. deleteCoupon(row.id).then(response=>{
  228. this.$message({
  229. type: 'success',
  230. message: '删除成功!'
  231. });
  232. this.getList();
  233. });
  234. })
  235. },
  236. getList(){
  237. fetchList(this.listQuery).then(response=>{
  238. this.listLoading = false;
  239. this.list = response.data.list;
  240. this.total = response.data.total;
  241. });
  242. }
  243. }
  244. }
  245. </script>
  246. <style scoped>
  247. .input-width {
  248. width: 203px;
  249. }
  250. </style>