index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <div class="app-container">
  3. <!-- 搜索工作栏 -->
  4. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  5. <el-form-item label="商品分类" prop="goodsTypeId">
  6. <el-input v-model="queryParams.goodsTypeId" placeholder="请输入商品分类" clearable @keyup.enter.native="handleQuery"/>
  7. </el-form-item>
  8. <el-form-item label="商品名称" prop="goodsName">
  9. <el-input v-model="queryParams.goodsName" placeholder="请输入商品名称" clearable @keyup.enter.native="handleQuery"/>
  10. </el-form-item>
  11. <el-form-item label="商品价格" prop="goodsPrice">
  12. <el-input v-model="queryParams.goodsPrice" placeholder="请输入商品价格" clearable @keyup.enter.native="handleQuery"/>
  13. </el-form-item>
  14. <el-form-item label="创建时间" prop="createTime">
  15. <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
  16. range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" />
  17. </el-form-item>
  18. <el-form-item>
  19. <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  20. <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  21. </el-form-item>
  22. </el-form>
  23. <!-- 操作工具栏 -->
  24. <el-row :gutter="10" class="mb8">
  25. <el-col :span="1.5">
  26. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)"
  27. v-hasPermi="['restaurant:restaurant:create']">新增</el-button>
  28. </el-col>
  29. <el-col :span="1.5">
  30. <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
  31. v-hasPermi="['restaurant:restaurant:export']">导出</el-button>
  32. </el-col>
  33. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  34. </el-row>
  35. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  36. <el-table-column label="商品编号" align="center" prop="id" />
  37. <el-table-column label="商品分类" align="center" prop="goodsTypeId" />
  38. <el-table-column label="商品名称" align="center" prop="goodsName" />
  39. <el-table-column label="商品价格" align="center" prop="goodsPrice" />
  40. <el-table-column label="商品图标" align="center" prop="goodsIcon" />
  41. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  42. <template v-slot="scope">
  43. <span>{{ parseTime(scope.row.createTime) }}</span>
  44. </template>
  45. </el-table-column>
  46. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  47. <template v-slot="scope">
  48. <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)"
  49. v-hasPermi="['restaurant:restaurant:update']">修改</el-button>
  50. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  51. v-hasPermi="['restaurant:restaurant:delete']">删除</el-button>
  52. </template>
  53. </el-table-column>
  54. </el-table>
  55. <!-- 分页组件 -->
  56. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
  57. @pagination="getList"/>
  58. <!-- 对话框(添加 / 修改) -->
  59. <GoodsForm ref="formRef" @success="getList" />
  60. </div>
  61. </template>
  62. <script>
  63. import * as GoodsApi from '@/api/restaurant/restaurant';
  64. import GoodsForm from './GoodsForm.vue';
  65. export default {
  66. name: "Goods",
  67. components: {
  68. GoodsForm,
  69. },
  70. data() {
  71. return {
  72. // 遮罩层
  73. loading: true,
  74. // 导出遮罩层
  75. exportLoading: false,
  76. // 显示搜索条件
  77. showSearch: true,
  78. // 总条数
  79. total: 0,
  80. // 商品列表
  81. list: [],
  82. // 是否展开,默认全部展开
  83. isExpandAll: true,
  84. // 重新渲染表格状态
  85. refreshTable: true,
  86. // 选中行
  87. currentRow: {},
  88. // 查询参数
  89. queryParams: {
  90. pageNo: 1,
  91. pageSize: 10,
  92. goodsTypeId: null,
  93. goodsName: null,
  94. goodsPrice: null,
  95. goodsIcon: null,
  96. createTime: [],
  97. },
  98. };
  99. },
  100. created() {
  101. this.getList();
  102. },
  103. methods: {
  104. /** 查询列表 */
  105. async getList() {
  106. try {
  107. this.loading = true;
  108. const res = await GoodsApi.getGoodsPage(this.queryParams);
  109. this.list = res.data.list;
  110. this.total = res.data.total;
  111. } finally {
  112. this.loading = false;
  113. }
  114. },
  115. /** 搜索按钮操作 */
  116. handleQuery() {
  117. this.queryParams.pageNo = 1;
  118. this.getList();
  119. },
  120. /** 重置按钮操作 */
  121. resetQuery() {
  122. this.resetForm("queryForm");
  123. this.handleQuery();
  124. },
  125. /** 添加/修改操作 */
  126. openForm(id) {
  127. this.$refs["formRef"].open(id);
  128. },
  129. /** 删除按钮操作 */
  130. async handleDelete(row) {
  131. const id = row.id;
  132. await this.$modal.confirm('是否确认删除商品编号为"' + id + '"的数据项?')
  133. try {
  134. await GoodsApi.deleteGoods(id);
  135. await this.getList();
  136. this.$modal.msgSuccess("删除成功");
  137. } catch {}
  138. },
  139. /** 导出按钮操作 */
  140. async handleExport() {
  141. await this.$modal.confirm('是否确认导出所有商品数据项?');
  142. try {
  143. this.exportLoading = true;
  144. const data = await GoodsApi.exportGoodsExcel(this.queryParams);
  145. this.$download.excel(data, '商品.xls');
  146. } catch {
  147. } finally {
  148. this.exportLoading = false;
  149. }
  150. },
  151. }
  152. };
  153. </script>