index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="商品名称" prop="name">
  5. <el-input v-model="queryParams.name" placeholder="请输入商品名称" clearable @keyup.enter.native="handleQuery"/>
  6. </el-form-item>
  7. <el-form-item label="商品编码" prop="code">
  8. <el-input v-model="queryParams.code" placeholder="请输入商品编码" clearable @keyup.enter.native="handleQuery"/>
  9. </el-form-item>
  10. <el-form-item label="商品分类" prop="categoryIds">
  11. <el-cascader v-model="queryParams.categoryIds" placeholder="请输入商品分类"
  12. :options="categoryList" :props="propName" clearable ref="category"/>
  13. </el-form-item>
  14. <el-form-item label="商品品牌" prop="brandId">
  15. <el-select v-model="queryParams.brandId" placeholder="请输入商品品牌" clearable @keyup.enter.native="handleQuery">
  16. <el-option v-for="item in brandList" :key="item.id" :label="item.name" :value="item.id"/>
  17. </el-select>
  18. </el-form-item>
  19. <!-- TODO 待实现:商品类型 -->
  20. <!-- TODO 待实现:商品标签 -->
  21. <!-- TODO 待实现:营销活动 -->
  22. <!-- TODO 前端优化:商品销量、商品价格,排的整齐一点 -->
  23. <el-form-item label="商品销量">
  24. <el-col :span="7" style="padding-left:0">
  25. <el-form-item prop="salesCountMin">
  26. <el-input v-model="queryParams.salesCountMin" placeholder="最低销量" clearable @keyup.enter.native="handleQuery"/>
  27. </el-form-item>
  28. </el-col>
  29. <el-col :span="1">-</el-col>
  30. <el-col :span="7" style="padding-left:0">
  31. <el-form-item prop="salesCountMax">
  32. <el-input v-model="queryParams.salesCountMax" placeholder="最高销量" clearable @keyup.enter.native="handleQuery"/>
  33. </el-form-item>
  34. </el-col>
  35. </el-form-item>
  36. <el-form-item label="商品价格" prop="code">
  37. <el-col :span="7" style="padding-left:0">
  38. <el-form-item prop="marketPriceMin">
  39. <el-input v-model="queryParams.marketPriceMin" placeholder="最低价格" clearable @keyup.enter.native="handleQuery"/>
  40. </el-form-item>
  41. </el-col>
  42. <el-col :span="1">-</el-col>
  43. <el-col :span="7" style="padding-left:0">
  44. <el-form-item prop="marketPriceMax">
  45. <el-input v-model="queryParams.marketPriceMax" placeholder="最高价格" clearable @keyup.enter.native="handleQuery"/>
  46. </el-form-item>
  47. </el-col>
  48. </el-form-item>
  49. <el-form-item>
  50. <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  51. <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  52. </el-form-item>
  53. </el-form>
  54. <!-- 操作工具栏 -->
  55. <el-row :gutter="10" class="mb8">
  56. <el-col :span="1.5">
  57. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  58. v-hasPermi="['product:spu:create']">添加商品</el-button>
  59. </el-col>
  60. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"/>
  61. </el-row>
  62. <el-tabs v-model="activeTabs" type="card" @tab-click="handleClick">
  63. <!-- 全部 -->
  64. <el-tab-pane label="全部" name="all">
  65. <!-- 列表 -->
  66. <el-table v-loading="loading" :data="list">
  67. <el-table-column label="商品信息" align="center" width="260">
  68. <template slot-scope="scope">
  69. <div class="product-info">
  70. <img v-if="scope.row.picUrls" :src="scope.row.picUrls[0]" alt="分类图片" class="img-height" />
  71. <div class="message">{{ scope.row.name }}</div>
  72. </div>
  73. </template>
  74. <!-- TODO 前端优化:可以有个 + 号,点击后,展示每个 sku -->
  75. </el-table-column>
  76. <el-table-column label="价格" align="center" prop="marketPrice" :formatter="formatPrice"/>
  77. <el-table-column label="库存" align="center" prop="totalStock"/>
  78. <el-table-column label="销量" align="center" prop="salesCount"/>
  79. <el-table-column label="排序" align="center" prop="sort"/>
  80. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  81. <template slot-scope="scope">
  82. <span>{{ parseTime(scope.row.createTime) }}</span>
  83. </template>
  84. </el-table-column>
  85. <el-table-column label="状态" align="center" prop="status">
  86. <template slot-scope="scope">
  87. <dict-tag :type="DICT_TYPE.PRODUCT_SPU_STATUS" :value="scope.row.status"/>
  88. </template>
  89. </el-table-column>
  90. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  91. <template slot-scope="scope">
  92. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  93. v-hasPermi="['product:spu:update']">修改</el-button>
  94. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  95. v-hasPermi="['product:spu:delete']">删除</el-button>
  96. </template>
  97. </el-table-column>
  98. </el-table>
  99. </el-tab-pane>
  100. <!-- 销售中 -->
  101. <el-tab-pane label="销售中" name="on">
  102. <!-- 列表 -->
  103. <el-table v-loading="loading" :data="list">
  104. <el-table-column label="商品信息" align="center" width="260">
  105. <template slot-scope="scope">
  106. <div class="product-info">
  107. <img v-if="scope.row.picUrls" :src="scope.row.picUrls[0]" alt="分类图片" class="img-height"/>
  108. <div class="message">{{ scope.row.name }}</div>
  109. </div>
  110. </template>
  111. </el-table-column>
  112. <el-table-column label="价格" align="center" prop="marketPrice" :formatter="formatPrice"/>
  113. <el-table-column label="库存" align="center" prop="totalStock"/>
  114. <el-table-column label="销量" align="center" prop="salesCount"/>
  115. <el-table-column label="排序" align="center" prop="sort"/>
  116. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  117. <template slot-scope="scope">
  118. <span>{{ parseTime(scope.row.createTime) }}</span>
  119. </template>
  120. </el-table-column>
  121. <el-table-column label="状态" align="center" prop="status">
  122. <template slot-scope="scope">
  123. <dict-tag :type="DICT_TYPE.PRODUCT_SPU_STATUS" :value="scope.row.status"/>
  124. </template>
  125. </el-table-column>
  126. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  127. <template slot-scope="scope">
  128. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  129. v-hasPermi="['product:spu:update']">修改</el-button>
  130. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  131. v-hasPermi="['product:spu:delete']">删除</el-button>
  132. </template>
  133. </el-table-column>
  134. </el-table>
  135. </el-tab-pane>
  136. <!-- 仓库中 -->
  137. <el-tab-pane label="仓库中" name="off">
  138. <!-- 列表 -->
  139. <el-table v-loading="loading" :data="list">
  140. <el-table-column label="商品信息" align="center" width="260">
  141. <template slot-scope="scope">
  142. <div class="product-info">
  143. <img v-if="scope.row.picUrls" :src="scope.row.picUrls[0]" alt="分类图片" class="img-height"/>
  144. <div class="message">{{ scope.row.name }}</div>
  145. </div>
  146. </template>
  147. </el-table-column>
  148. <el-table-column label="价格" align="center" prop="marketPrice" :formatter="formatPrice"/>
  149. <el-table-column label="库存" align="center" prop="totalStock"/>
  150. <el-table-column label="销量" align="center" prop="salesCount"/>
  151. <el-table-column label="排序" align="center" prop="sort"/>
  152. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  153. <template slot-scope="scope">
  154. <span>{{ parseTime(scope.row.createTime) }}</span>
  155. </template>
  156. </el-table-column>
  157. <el-table-column label="状态" align="center" prop="status">
  158. <template slot-scope="scope">
  159. <dict-tag :type="DICT_TYPE.PRODUCT_SPU_STATUS" :value="scope.row.status"/>
  160. </template>
  161. </el-table-column>
  162. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  163. <template slot-scope="scope">
  164. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  165. v-hasPermi="['product:spu:update']">修改</el-button>
  166. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  167. v-hasPermi="['product:spu:delete']">删除</el-button>
  168. </template>
  169. </el-table-column>
  170. </el-table>
  171. </el-tab-pane>
  172. <!-- 预警中 -->
  173. <el-tab-pane label="预警中" name="remind">
  174. <!-- 列表 -->
  175. <el-table v-loading="loading" :data="list">
  176. <el-table-column label="商品信息" align="center" width="260">
  177. <template slot-scope="scope">
  178. <div class="product-info">
  179. <img v-if="scope.row.picUrls" :src="scope.row.picUrls[0]" alt="分类图片" class="img-height"/>
  180. <div class="message">{{ scope.row.name }}</div>
  181. </div>
  182. </template>
  183. </el-table-column>
  184. <el-table-column label="价格" align="center" prop="marketPrice" :formatter="formatPrice"/>
  185. <el-table-column label="库存" align="center" prop="totalStock"/>
  186. <el-table-column label="销量" align="center" prop="salesCount"/>
  187. <el-table-column label="排序" align="center" prop="sort"/>
  188. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  189. <template slot-scope="scope">
  190. <span>{{ parseTime(scope.row.createTime) }}</span>
  191. </template>
  192. </el-table-column>
  193. <el-table-column label="状态" align="center" prop="status">
  194. <template slot-scope="scope">
  195. <dict-tag :type="DICT_TYPE.PRODUCT_SPU_STATUS" :value="scope.row.status"/>
  196. </template>
  197. </el-table-column>
  198. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  199. <template slot-scope="scope">
  200. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  201. v-hasPermi="['product:spu:update']">修改</el-button>
  202. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  203. v-hasPermi="['product:spu:delete']">删除</el-button>
  204. </template>
  205. </el-table-column>
  206. </el-table>
  207. </el-tab-pane>
  208. </el-tabs>
  209. <!-- 分页组件 -->
  210. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
  211. @pagination="getList"/>
  212. </div>
  213. </template>
  214. <script>
  215. import {deleteSpu, getSpuPage,} from "@/api/mall/product/spu";
  216. import {getProductCategoryList} from "@/api/mall/product/category";
  217. import {getBrandList} from "@/api/mall/product/brand";
  218. export default {
  219. name: "Spu",
  220. data() {
  221. return {
  222. activeTabs: "all",
  223. propName: {
  224. checkStrictly: true,
  225. label: "name",
  226. value: "id",
  227. },
  228. brandList: [],
  229. categoryList: [],
  230. // 遮罩层
  231. loading: true,
  232. // 导出遮罩层
  233. exportLoading: false,
  234. // 显示搜索条件
  235. showSearch: true,
  236. // 总条数
  237. total: 0,
  238. // 商品spu列表
  239. list: [],
  240. dateRangeCreateTime: [],
  241. // 查询参数
  242. queryParams: {
  243. pageNo: 1,
  244. pageSize: 10,
  245. name: null,
  246. code: null,
  247. categoryIds: [],
  248. categoryId: null,
  249. brandId: null,
  250. status: null,
  251. salesCountMin: null,
  252. salesCountMax: null,
  253. marketPriceMin: null,
  254. marketPriceMax: null,
  255. tabStatus: null,
  256. },
  257. };
  258. },
  259. created() {
  260. this.getList();
  261. this.getListCategory()
  262. this.getListBrand()
  263. },
  264. methods: {
  265. /** 查询分类列表 */
  266. getListCategory() {
  267. // 执行查询
  268. getProductCategoryList().then((response) => {
  269. this.categoryList = this.handleTree(response.data, "id", "parentId");
  270. });
  271. },
  272. /** 查询品牌列表 */
  273. getListBrand() {
  274. // 执行查询
  275. getBrandList().then((response) => {
  276. this.brandList = response.data;
  277. });
  278. },
  279. /** 查询列表 */
  280. getList() {
  281. this.loading = true;
  282. // 处理查询参数
  283. let params = {...this.queryParams};
  284. params.marketPriceMin = this.queryParams.marketPriceMin === null ? null : params.marketPriceMin * 100;
  285. params.marketPriceMax = this.queryParams.marketPriceMax === null ? null : params.marketPriceMax * 100;
  286. params.categoryId = this.queryParams.categoryIds[this.queryParams.categoryIds.length - 1];
  287. this.addBeginAndEndTime(params, this.dateRangeCreateTime, "createTime");
  288. // 执行查询
  289. getSpuPage(params).then((response) => {
  290. this.list = response.data.list;
  291. this.total = response.data.total;
  292. this.loading = false;
  293. });
  294. },
  295. /** 搜索按钮操作 */
  296. handleQuery() {
  297. this.queryParams.pageNo = 1;
  298. this.getList();
  299. },
  300. /** 重置按钮操作 */
  301. resetQuery() {
  302. this.dateRangeCreateTime = [];
  303. this.$refs.category.$refs.panel.checkedValue = [];//也可以是指定的值,默认返回值是数组,也可以返回单个值
  304. this.$refs.category.$refs.panel.activePath = [];
  305. this.$refs.category.$refs.panel.syncActivePath();
  306. this.resetForm("queryForm");
  307. this.handleQuery();
  308. },
  309. /** 新增按钮操作 */
  310. handleAdd() {
  311. this.$router.push({ name: 'SpuAdd'})
  312. },
  313. /** 修改按钮操作 */
  314. handleUpdate(row) {
  315. this.$router.push({ name: 'SpuEdit', params: { spuId: row.id }})
  316. },
  317. /** 删除按钮操作 */
  318. handleDelete(row) {
  319. const id = row.id;
  320. this.$modal
  321. .confirm('是否确认删除商品spu编号为"' + id + '"的数据项?')
  322. .then(function () {
  323. return deleteSpu(id);
  324. }).then(() => {
  325. this.getList();
  326. this.$modal.msgSuccess("删除成功");
  327. }).catch(() => {
  328. });
  329. },
  330. formatPrice(row, column, cellValue) {
  331. return '¥' + this.divide(cellValue, 100);
  332. },
  333. // 选中 tab
  334. handleClick(val) {
  335. if (val.name === "all") {
  336. this.queryParams.tabStatus = null;
  337. } else if (val.name === "on") {
  338. this.queryParams.tabStatus = 0;
  339. } else if (val.name === "off") {
  340. this.queryParams.tabStatus = 1;
  341. } else if (val.name === "remind") {
  342. this.queryParams.tabStatus = 2;
  343. } else {
  344. this.queryParams.tabStatus = null;
  345. }
  346. this.getList();
  347. }
  348. },
  349. };
  350. </script>
  351. <style lang="scss">
  352. .app-container {
  353. .el-tag + .el-tag {
  354. margin-left: 10px;
  355. }
  356. .product-info {
  357. display: flex;
  358. .img-height {
  359. height: 50px;
  360. width: 50px;
  361. }
  362. .message {
  363. margin-left: 10px;
  364. text-overflow: ellipsis;
  365. display: -webkit-box;
  366. -webkit-line-clamp: 2;
  367. word-break: break-all;
  368. -webkit-box-orient: vertical;
  369. white-space: normal;
  370. overflow: hidden;
  371. height: 50px;
  372. line-height: 25px;
  373. }
  374. }
  375. }
  376. </style>