index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="88px">
  4. <el-form-item label="商品分类" prop="typeId">
  5. <el-select v-model="queryParams.typeId" placeholder="请选择商品分类" clearable>
  6. <el-option v-for="dict in typeIdOptions" :key="dict.id" :label="dict.name" :value="dict.id"></el-option>
  7. </el-select>
  8. </el-form-item>
  9. <el-form-item label="商品标题" prop="title"><el-input v-model="queryParams.title" placeholder="请输入商品标题" clearable @keyup.enter.native="handleQuery" /></el-form-item>
  10. <el-form-item label="创建时间" prop="createTime">
  11. <el-date-picker
  12. clearable
  13. v-model="dateRange"
  14. value-format="yyyy-MM-dd HH:mm:ss"
  15. type="daterange"
  16. range-separator="至"
  17. start-placeholder="开始日期"
  18. end-placeholder="结束日期"
  19. ></el-date-picker>
  20. </el-form-item>
  21. <el-form-item>
  22. <el-button type="cyan" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  23. <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  24. </el-form-item>
  25. </el-form>
  26. <el-row :gutter="10" class="mb8">
  27. <el-button type="primary" icon="el-icon-plus" :disabled="ids.length > 0" @click="handleOp" v-hasPermi="['system/shop:goods:add']">新增</el-button>
  28. <el-button type="success" icon="el-icon-edit" :disabled="ids.length != 1" @click="handleOp" v-hasPermi="['system/shop:goods:edit']">修改</el-button>
  29. <el-button type="danger" icon="el-icon-delete" :disabled="ids.length == 0" @click="handleDelete" v-hasPermi="['system/shop:goods:remove']">批量删除</el-button>
  30. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  31. </el-row>
  32. <el-table v-loading="loading" border :data="goodsList" @selection-change="handleSelectionChange">
  33. <el-table-column type="selection" width="55" align="center" />
  34. <el-table-column label="商品标题" align="center" prop="title" />
  35. <el-table-column label="商品类型" align="center" prop="tbGoodsType.name" />
  36. <el-table-column label="商品图片" align="center">
  37. <template slot-scope="scope">
  38. <el-image class="lsw_square" :fit="'contain'" style="max-width:80px;" :src="baseUrl+scope.row.pic" :preview-src-list="[baseUrl+scope.row.pic]"></el-image>
  39. </template>
  40. </el-table-column>
  41. <el-table-column label="商品价格" align="center" prop="price" />
  42. <el-table-column label="状态" align="center" prop="state" sortable width="120">
  43. <template slot-scope="scope">
  44. <el-tag type="danger" v-if="scope.row.state == 1">下架</el-tag>
  45. <el-tag type="success" v-if="scope.row.state == 0">上架</el-tag>
  46. </template>
  47. </el-table-column>
  48. <el-table-column label="创建时间" align="center" prop="createTime" />
  49. <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width">
  50. <template slot-scope="scope">
  51. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleOp(scope.row)" v-hasPermi="['system/shop:goods:edit']">修改</el-button>
  52. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['system/shop:goods:remove']">删除</el-button>
  53. </template>
  54. </el-table-column>
  55. </el-table>
  56. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  57. <!-- 添加或修改对话框 -->
  58. <edit v-if="dialogVisible" ref="dialog" @refresh="getList"></edit>
  59. </div>
  60. </template>
  61. <script>
  62. import { typeList, listGoods, getGoods, delGoods, addGoods, updateGoods, exportGoods } from '@/api/system/shop/goods';
  63. import edit from './edit';
  64. export default {
  65. components: {
  66. edit
  67. },
  68. data() {
  69. return {
  70. baseUrl: process.env.VUE_APP_BASE_API,
  71. //新增,修改弹出框
  72. dialogVisible: false,
  73. // 遮罩层
  74. loading: true,
  75. // 选中数组
  76. // 日期范围
  77. dateRange: [],
  78. ids: [],
  79. // 显示搜索条件
  80. showSearch: true,
  81. // 总条数
  82. total: 0,
  83. typeIdOptions: [],
  84. // 商品表格数据
  85. goodsList: [],
  86. // 查询参数
  87. queryParams: {
  88. pageNum: 1,
  89. pageSize: 10,
  90. typeId: null,
  91. title: null,
  92. createTime: null,
  93. orderByColumn: 'id', //排序字段
  94. isAsc: 'desc' //排序方式
  95. }
  96. };
  97. },
  98. created() {
  99. typeList().then(response => {
  100. this.typeIdOptions = response.data;
  101. });
  102. this.getList();
  103. },
  104. methods: {
  105. /** 查询商品列表 */
  106. getList() {
  107. this.loading = true;
  108. listGoods(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
  109. this.goodsList = response.rows;
  110. this.total = response.total;
  111. this.loading = false;
  112. });
  113. },
  114. /** 搜索按钮操作 */
  115. handleQuery() {
  116. this.queryParams.pageNum = 1;
  117. this.getList();
  118. },
  119. /** 重置按钮操作 */
  120. resetQuery() {
  121. this.dateRange = [];
  122. this.resetForm('queryForm');
  123. this.handleQuery();
  124. },
  125. // 多选框选中数据
  126. handleSelectionChange(selection) {
  127. this.ids = selection.map(item => item.id);
  128. },
  129. /** 新增,修改按钮操作 */
  130. handleOp(row) {
  131. this.dialogVisible = true;
  132. const ids = row.id || this.ids;
  133. this.$nextTick(() => {
  134. this.$refs.dialog.init(ids);
  135. });
  136. },
  137. /** 删除按钮操作 */
  138. handleDelete(row) {
  139. const ids = row.id || this.ids;
  140. this.$confirm('是否确认删除商品编号为"' + ids + '"的数据项?', '警告', { type: 'warning' })
  141. .then(() => {
  142. return delGoods(ids);
  143. })
  144. .then(() => {
  145. this.getList();
  146. this.msgSuccess('删除成功');
  147. });
  148. }
  149. }
  150. };
  151. </script>