index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="直播ID" prop="liveId">
  5. <el-input
  6. v-model="queryParams.liveId"
  7. placeholder="请输入直播ID"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="商品名称" prop="goodsName">
  14. <el-input
  15. v-model="queryParams.goodsName"
  16. placeholder="请输入商品名称"
  17. clearable
  18. size="small"
  19. @keyup.enter.native="handleQuery"
  20. />
  21. </el-form-item>
  22. <el-form-item label="描述" prop="goodsDesc">
  23. <el-input
  24. v-model="queryParams.goodsDesc"
  25. placeholder="请输入描述"
  26. clearable
  27. size="small"
  28. @keyup.enter.native="handleQuery"
  29. />
  30. </el-form-item>
  31. <el-form-item label="封图" prop="imgUrl">
  32. <el-input
  33. v-model="queryParams.imgUrl"
  34. placeholder="请输入封图"
  35. clearable
  36. size="small"
  37. @keyup.enter.native="handleQuery"
  38. />
  39. </el-form-item>
  40. <el-form-item label="单价" prop="price">
  41. <el-input
  42. v-model="queryParams.price"
  43. placeholder="请输入单价"
  44. clearable
  45. size="small"
  46. @keyup.enter.native="handleQuery"
  47. />
  48. </el-form-item>
  49. <el-form-item label="原价" prop="opPrice">
  50. <el-input
  51. v-model="queryParams.opPrice"
  52. placeholder="请输入原价"
  53. clearable
  54. size="small"
  55. @keyup.enter.native="handleQuery"
  56. />
  57. </el-form-item>
  58. <el-form-item label="状态" prop="status">
  59. <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
  60. <!-- <el-option label="请选择字典生成" value="" />-->
  61. <el-option v-for="(item,index) in goodsStatusOptions" :key="item.dictValue+index" :label="item.dictLabel" :value="item.dictValue" />
  62. </el-select>
  63. </el-form-item>
  64. <el-form-item label="库存表" prop="stock">
  65. <el-input
  66. v-model="queryParams.stock"
  67. placeholder="请输入库存表"
  68. clearable
  69. size="small"
  70. @keyup.enter.native="handleQuery"
  71. />
  72. </el-form-item>
  73. <el-form-item label="排序号" prop="sort">
  74. <el-input
  75. v-model="queryParams.sort"
  76. placeholder="请输入排序号"
  77. clearable
  78. size="small"
  79. @keyup.enter.native="handleQuery"
  80. />
  81. </el-form-item>
  82. <el-form-item>
  83. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  84. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  85. </el-form-item>
  86. </el-form>
  87. <el-row :gutter="10" class="mb8">
  88. <el-col :span="1.5">
  89. <el-button
  90. type="primary"
  91. plain
  92. icon="el-icon-plus"
  93. size="mini"
  94. @click="handleAdd"
  95. v-hasPermi="['live:liveGoods:add']"
  96. >新增</el-button>
  97. </el-col>
  98. <el-col :span="1.5">
  99. <el-button
  100. type="success"
  101. plain
  102. icon="el-icon-edit"
  103. size="mini"
  104. :disabled="single"
  105. @click="handleUpdate"
  106. v-hasPermi="['live:liveGoods:edit']"
  107. >修改</el-button>
  108. </el-col>
  109. <el-col :span="1.5">
  110. <el-button
  111. type="danger"
  112. plain
  113. icon="el-icon-delete"
  114. size="mini"
  115. :disabled="multiple"
  116. @click="handleDelete"
  117. v-hasPermi="['live:liveGoods:remove']"
  118. >删除</el-button>
  119. </el-col>
  120. <el-col :span="1.5">
  121. <el-button
  122. type="warning"
  123. plain
  124. icon="el-icon-download"
  125. size="mini"
  126. :loading="exportLoading"
  127. @click="handleExport"
  128. v-hasPermi="['live:liveGoods:export']"
  129. >导出</el-button>
  130. </el-col>
  131. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  132. </el-row>
  133. <el-table border v-loading="loading" :data="liveGoodsList" @selection-change="handleSelectionChange">
  134. <el-table-column type="selection" width="55" align="center" />
  135. <el-table-column label="ID" align="center" prop="goodsId" />
  136. <el-table-column label="直播ID" align="center" prop="liveId" />
  137. <el-table-column label="商品名称" align="center" prop="goodsName" />
  138. <el-table-column label="描述" align="center" prop="goodsDesc" />
  139. <el-table-column label="封图" align="center" prop="imgUrl" />
  140. <el-table-column label="组图" align="center" prop="images" />
  141. <el-table-column label="单价" align="center" prop="price" />
  142. <el-table-column label="原价" align="center" prop="opPrice" />
  143. <el-table-column label="状态" align="center" prop="status" :formatter="goodsStatusFormatter"/>
  144. <el-table-column label="库存表" align="center" prop="stock" />
  145. <el-table-column label="排序号" align="center" prop="sort" />
  146. <el-table-column label="备注" align="center" prop="remark" />
  147. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  148. <template slot-scope="scope">
  149. <el-button
  150. size="mini"
  151. type="text"
  152. icon="el-icon-edit"
  153. @click="handleUpdate(scope.row)"
  154. v-hasPermi="['live:liveGoods:edit']"
  155. >修改</el-button>
  156. <el-button
  157. size="mini"
  158. type="text"
  159. icon="el-icon-delete"
  160. @click="handleDelete(scope.row)"
  161. v-hasPermi="['live:liveGoods:remove']"
  162. >删除</el-button>
  163. </template>
  164. </el-table-column>
  165. </el-table>
  166. <pagination
  167. v-show="total>0"
  168. :total="total"
  169. :page.sync="queryParams.pageNum"
  170. :limit.sync="queryParams.pageSize"
  171. @pagination="getList"
  172. />
  173. <!-- 添加或修改直播商品对话框 -->
  174. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  175. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  176. <el-form-item label="直播ID" prop="liveId">
  177. <el-input v-model="form.liveId" placeholder="请输入直播ID" />
  178. </el-form-item>
  179. <el-form-item label="商品名称" prop="goodsName">
  180. <el-input v-model="form.goodsName" placeholder="请输入商品名称" />
  181. </el-form-item>
  182. <el-form-item label="描述" prop="goodsDesc">
  183. <el-input v-model="form.goodsDesc" placeholder="请输入描述" />
  184. </el-form-item>
  185. <el-form-item label="封图" prop="imgUrl">
  186. <ImageUpload v-model="form.imgUrl" type="image" :limit=1 :width="150"
  187. :height="150"/>
  188. </el-form-item>
  189. <el-form-item label="组图" prop="images">
  190. <ImageUpload v-model="form.images" type="image" :limit=10 :width="150"
  191. :height="150"/>
  192. </el-form-item>
  193. <el-form-item label="单价" prop="price">
  194. <el-input v-model="form.price" placeholder="请输入单价" />
  195. </el-form-item>
  196. <el-form-item label="原价" prop="opPrice">
  197. <el-input v-model="form.opPrice" placeholder="请输入原价" />
  198. </el-form-item>
  199. <el-form-item label="状态">
  200. <el-radio-group v-model="form.status">
  201. <el-radio :label="item.dictValue" v-for="item in goodsStatusOptions" >{{item.dictLabel}}</el-radio>
  202. </el-radio-group>
  203. </el-form-item>
  204. <el-form-item label="库存表" prop="stock">
  205. <el-input v-model="form.stock" placeholder="请输入库存表" />
  206. </el-form-item>
  207. <el-form-item label="排序号" prop="sort">
  208. <el-input v-model="form.sort" placeholder="请输入排序号" />
  209. </el-form-item>
  210. <el-form-item label="备注" prop="remark">
  211. <el-input v-model="form.remark" placeholder="请输入备注" />
  212. </el-form-item>
  213. </el-form>
  214. <div slot="footer" class="dialog-footer">
  215. <el-button type="primary" @click="submitForm">确 定</el-button>
  216. <el-button @click="cancel">取 消</el-button>
  217. </div>
  218. </el-dialog>
  219. </div>
  220. </template>
  221. <script>
  222. import { listLiveGoods, getLiveGoods, delLiveGoods, addLiveGoods, updateLiveGoods, exportLiveGoods } from "@/api/live/liveGoods";
  223. export default {
  224. name: "LiveGoods",
  225. data() {
  226. return {
  227. //字典
  228. goodsStatusOptions: [],
  229. // 遮罩层
  230. loading: true,
  231. // 导出遮罩层
  232. exportLoading: false,
  233. // 选中数组
  234. ids: [],
  235. // 非单个禁用
  236. single: true,
  237. // 非多个禁用
  238. multiple: true,
  239. // 显示搜索条件
  240. showSearch: true,
  241. // 总条数
  242. total: 0,
  243. // 直播商品表格数据
  244. liveGoodsList: [],
  245. // 弹出层标题
  246. title: "",
  247. // 是否显示弹出层
  248. open: false,
  249. // 查询参数
  250. queryParams: {
  251. pageNum: 1,
  252. pageSize: 10,
  253. liveId: null,
  254. goodsName: null,
  255. goodsDesc: null,
  256. imgUrl: null,
  257. images: null,
  258. price: null,
  259. opPrice: null,
  260. status: null,
  261. stock: null,
  262. sort: null,
  263. },
  264. // 表单参数
  265. form: {},
  266. // 表单校验
  267. rules: {
  268. }
  269. };
  270. },
  271. created() {
  272. this.getList();
  273. this.getDicts("sys_live_goods_show").then(response => {
  274. this.goodsStatusOptions = response.data;
  275. });
  276. },
  277. methods: {
  278. /** 查询直播商品列表 */
  279. getList() {
  280. this.loading = true;
  281. listLiveGoods(this.queryParams).then(response => {
  282. this.liveGoodsList = response.rows;
  283. this.total = response.total;
  284. this.loading = false;
  285. });
  286. },
  287. goodsStatusFormatter(row, column) {
  288. return this.selectDictLabel(this.statusOptions, row.status);
  289. },
  290. // 取消按钮
  291. cancel() {
  292. this.open = false;
  293. this.reset();
  294. },
  295. // 表单重置
  296. reset() {
  297. this.form = {
  298. goodsId: null,
  299. liveId: null,
  300. goodsName: null,
  301. goodsDesc: null,
  302. imgUrl: null,
  303. images: null,
  304. price: null,
  305. opPrice: null,
  306. status: 0,
  307. stock: null,
  308. sort: null,
  309. createTime: null,
  310. createBy: null,
  311. updateBy: null,
  312. updateTime: null,
  313. remark: null
  314. };
  315. this.resetForm("form");
  316. },
  317. /** 搜索按钮操作 */
  318. handleQuery() {
  319. this.queryParams.pageNum = 1;
  320. this.getList();
  321. },
  322. /** 重置按钮操作 */
  323. resetQuery() {
  324. this.resetForm("queryForm");
  325. this.handleQuery();
  326. },
  327. // 多选框选中数据
  328. handleSelectionChange(selection) {
  329. this.ids = selection.map(item => item.goodsId)
  330. this.single = selection.length!==1
  331. this.multiple = !selection.length
  332. },
  333. /** 新增按钮操作 */
  334. handleAdd() {
  335. this.reset();
  336. this.open = true;
  337. this.title = "添加直播商品";
  338. },
  339. /** 修改按钮操作 */
  340. handleUpdate(row) {
  341. this.reset();
  342. const goodsId = row.goodsId || this.ids
  343. getLiveGoods(goodsId).then(response => {
  344. this.form = response.data;
  345. this.open = true;
  346. this.title = "修改直播商品";
  347. });
  348. },
  349. /** 提交按钮 */
  350. submitForm() {
  351. this.$refs["form"].validate(valid => {
  352. if (valid) {
  353. if (this.form.goodsId != null) {
  354. updateLiveGoods(this.form).then(response => {
  355. this.msgSuccess("修改成功");
  356. this.open = false;
  357. this.getList();
  358. });
  359. } else {
  360. addLiveGoods(this.form).then(response => {
  361. this.msgSuccess("新增成功");
  362. this.open = false;
  363. this.getList();
  364. });
  365. }
  366. }
  367. });
  368. },
  369. /** 删除按钮操作 */
  370. handleDelete(row) {
  371. const goodsIds = row.goodsId || this.ids;
  372. this.$confirm('是否确认删除直播商品编号为"' + goodsIds + '"的数据项?', "警告", {
  373. confirmButtonText: "确定",
  374. cancelButtonText: "取消",
  375. type: "warning"
  376. }).then(function() {
  377. return delLiveGoods(goodsIds);
  378. }).then(() => {
  379. this.getList();
  380. this.msgSuccess("删除成功");
  381. }).catch(() => {});
  382. },
  383. /** 导出按钮操作 */
  384. handleExport() {
  385. const queryParams = this.queryParams;
  386. this.$confirm('是否确认导出所有直播商品数据项?', "警告", {
  387. confirmButtonText: "确定",
  388. cancelButtonText: "取消",
  389. type: "warning"
  390. }).then(() => {
  391. this.exportLoading = true;
  392. return exportLiveGoods(queryParams);
  393. }).then(response => {
  394. this.download(response.msg);
  395. this.exportLoading = false;
  396. }).catch(() => {});
  397. }
  398. }
  399. };
  400. </script>