commodityList.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="20">
  4. <!--用户数据-->
  5. <el-col :span="24" :xs="24">
  6. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
  7. <el-form-item label="商品名称:" prop="goodsName">
  8. <el-input
  9. v-model="queryParams.goodsName"
  10. placeholder="请输入商品名称"
  11. clearable
  12. style="width: 240px"
  13. @keyup.enter.native="handleQuery"
  14. />
  15. </el-form-item>
  16. <el-form-item label="商品分类:" prop="classifyId">
  17. <div style="width: 200px;">
  18. <treeselect
  19. v-model="queryParams.classifyId"
  20. :options="listTreeCopy"
  21. :show-count="true"
  22. placeholder="请选择商品分类"
  23. />
  24. </div>
  25. </el-form-item>
  26. <el-form-item label="上架状态:" prop="status">
  27. <el-select v-model="queryParams.status" clearable placeholder="请选择上架状态">
  28. <el-option :key="1" label="下架" :value="1"></el-option>
  29. <el-option :key="0" label="上架" :value="0"></el-option>
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item>
  33. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  34. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  35. </el-form-item>
  36. </el-form>
  37. <el-row :gutter="10" class="mb8">
  38. <el-col :span="1.5">
  39. <el-button
  40. type="primary"
  41. plain
  42. icon="el-icon-plus"
  43. size="mini"
  44. @click="handleAdd"
  45. v-hasPermi="configPermi.add"
  46. >添加商品</el-button>
  47. </el-col>
  48. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
  49. </el-row>
  50. <el-table v-loading="loading" :data="tableList" @selection-change="handleSelectionChange">
  51. <el-table-column type="index" label="序号" align="center" />
  52. <el-table-column label="商品图片" align="center" key="goodsImage" prop="goodsImage" v-if="columns[0].visible" :show-overflow-tooltip="true">
  53. <template slot-scope="scope">
  54. <el-image
  55. style="width: 60px; height: 40px"
  56. :src="scope.row.goodsImage"
  57. :preview-src-list="[scope.row.goodsImage]"
  58. fit="fill"></el-image>
  59. </template>
  60. </el-table-column>
  61. <el-table-column label="商品名称" align="center" key="goodsName" prop="goodsName" v-if="columns[1].visible" :show-overflow-tooltip="true" />
  62. <el-table-column label="分类" align="center" key="classifyName" prop="classifyName" v-if="columns[2].visible" :show-overflow-tooltip="true" />
  63. <el-table-column label="销售价格(元)" align="center" key="salePrice" prop="salePrice" v-if="columns[3].visible" :show-overflow-tooltip="true" />
  64. <el-table-column label="规格" align="center" key="specName" prop="specName" v-if="columns[4].visible" :show-overflow-tooltip="true" />
  65. <el-table-column label="库存" align="center" key="quantity" prop="quantity" v-if="columns[5].visible" :show-overflow-tooltip="true" />
  66. <el-table-column label="总销量" align="center" key="saleNum" prop="saleNum" v-if="columns[6].visible" :show-overflow-tooltip="true" />
  67. <el-table-column label="单位" align="center" key="unitName" prop="unitName" v-if="columns[7].visible" :show-overflow-tooltip="true" />
  68. <el-table-column label="限购" align="center" width="190px" key="name8" prop="name8" v-if="columns[8].visible" :show-overflow-tooltip="true">
  69. <template slot-scope="scope">
  70. <span>{{
  71. scope.row.daySale <=0 && scope.row.buyAstrict <=0? '不限' :
  72. scope.row.daySale <=0 && scope.row.buyAstrict > 0? ('每人限购数量'+scope.row.buyAstrict): ('每人每日限购数量'+scope.row.daySale)
  73. }}</span>
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="上架/下架" align="center" key="status" v-if="columns[9].visible">
  77. <template slot-scope="scope">
  78. <switchBox
  79. :defaultChecked="true"
  80. v-model="scope.row.status"
  81. @changeFun="openAttraction(scope.row)"
  82. :disabled="false"
  83. :active-value="0"
  84. :inactive-value="1"
  85. />
  86. </template>
  87. </el-table-column>
  88. <el-table-column label="创建时间" align="center" key="createTime" prop="createTime" v-if="columns[10].visible" :show-overflow-tooltip="true" />
  89. <el-table-column
  90. label="操作"
  91. align="center"
  92. class-name="small-padding fixed-width"
  93. width="180px"
  94. >
  95. <template slot-scope="scope" >
  96. <el-button
  97. size="mini"
  98. type="text"
  99. icon="el-icon-edit"
  100. @click="handleDetails(scope.row)"
  101. v-hasPermi="configPermi.editBase"
  102. >详情</el-button>
  103. <el-button
  104. size="mini"
  105. type="text"
  106. icon="el-icon-edit"
  107. @click="handleUpdate(scope.row)"
  108. v-hasPermi="configPermi.editBase"
  109. >修改</el-button>
  110. <el-button
  111. size="mini"
  112. type="text"
  113. icon="el-icon-delete"
  114. @click="handleDelete(scope.row)"
  115. v-hasPermi="configPermi.delect"
  116. >删除</el-button>
  117. </template>
  118. </el-table-column>
  119. </el-table>
  120. <pagination
  121. v-show="total>0"
  122. :total="total"
  123. :page.sync="queryParams.pageNum"
  124. :limit.sync="queryParams.pageSize"
  125. @pagination="getList"
  126. />
  127. </el-col>
  128. </el-row>
  129. <!-- 新增或修改 -->
  130. <addAndEdit ref="addAndEdit" :listTreeCopy="listTreeCopy" @refresh="getList" />
  131. <!-- 详情 -->
  132. <detailsBox ref="detailsBox" @refresh="getList"></detailsBox>
  133. </div>
  134. </template>
  135. <script>
  136. import {
  137. listTableApi,
  138. delTableParamsApi,
  139. publicByPutApi as releaseApi,
  140. addTableApi
  141. } from "@/api/CURD";
  142. import addAndEdit from "./formBox/commodityListForm.vue"
  143. import detailsBox from "./detailsBox/commodityListDetails.vue"
  144. import Treeselect from "@riophae/vue-treeselect";
  145. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  146. export default {
  147. name: "User",
  148. dicts: [],
  149. components: {addAndEdit,Treeselect,detailsBox},
  150. data() {
  151. return {
  152. title: "商品管理",// 通用标题
  153. configPermi: {
  154. add: ['productManagement:scenicAreaTickets:add'], // 新增权限
  155. details: [''], // 详情权限
  156. delect: ['productManagement:scenicAreaTickets:delect'], // 删除权限
  157. editBase: ['productManagement:scenicAreaTickets:editBase'], // 编辑基本信息权限
  158. editGuige: ['productManagement:scenicAreaTickets:editGuige'], // 编辑规格信息权限
  159. upload: [''],// 导入权限
  160. export: [''],// 导出权限
  161. release: ['']
  162. },
  163. configUrl: {
  164. list: '/merchant/merchantPerformAuditorium/shopGoodsList', // 列表地址
  165. delect: '/merchant/merchantPerformAuditorium/deleteMerchantGoods', // 删除地址
  166. upload: '',// 导入地址
  167. download:'', // 下载模板地址
  168. export: '',// 导出地址
  169. updateStatusById: '/merchant/merchantPerformAuditorium/updateStatus',
  170. classifyList: '/goods/goodsClassify/treeList', // 商品分类
  171. shopList: '/merchant/merchantShop/pageList', // 店铺
  172. },
  173. // 遮罩层
  174. loading: true,
  175. // 选中数组
  176. ids: [],
  177. // 非单个禁用
  178. single: true,
  179. // 非多个禁用
  180. multiple: true,
  181. // 显示搜索条件
  182. showSearch: true,
  183. // 总条数
  184. total: 0,
  185. // 用户表格数据
  186. tableList: null,
  187. // 查询参数
  188. queryParams: {
  189. pageNum: 1,
  190. pageSize: 10,
  191. },
  192. dateRange: [],
  193. // 控制列表是否显示
  194. columns: [
  195. { key: 0, label: `商品图片`, visible: true },
  196. { key: 2, label: `商品名称`, visible: true },
  197. { key: 3, label: `分类`, visible: true },
  198. { key: 4, label: `销售价格`, visible: true },
  199. { key: 5, label: `规格`, visible: true },
  200. { key: 6, label: `库存`, visible: true },
  201. { key: 7, label: `总销量`, visible: true },
  202. { key: 8, label: `单位`, visible: true },
  203. { key: 9, label: `限购`, visible: true },
  204. { key: 10, label: `上架/下架`, visible: true },
  205. { key: 11, label: `创建时间`, visible: true },
  206. ],
  207. listTreeCopy: [],
  208. shopList: [],
  209. shopListTime: null,
  210. shopListLoading: false,
  211. };
  212. },
  213. created() {
  214. this.getList();
  215. this.remoteClassifyId()
  216. this.remoteShop('')
  217. },
  218. methods: {
  219. /** 查询用户列表 */
  220. getList() {
  221. this.loading = true;
  222. listTableApi(
  223. this.configUrl.list,
  224. this.addDateRange(
  225. this.queryParams,
  226. this.dateRange)).then(response => {
  227. this.tableList = response.data.rows;
  228. this.total = response.data.total;
  229. this.loading = false;
  230. }
  231. ).catch (error=>{
  232. console.error('获取列表失败!!!!',error)
  233. this.tableList = [];
  234. this.total = 0;
  235. this.loading = false
  236. })
  237. },
  238. /** 搜索按钮操作 */
  239. handleQuery() {
  240. this.queryParams.pageNum = 1;
  241. this.getList();
  242. },
  243. /** 重置按钮操作 */
  244. resetQuery() {
  245. this.dateRange = [];
  246. this.queryParams = {
  247. pageNum: 1,
  248. pageSize: 10,
  249. }
  250. this.handleQuery();
  251. },
  252. // 多选框选中数据
  253. handleSelectionChange(selection) {
  254. this.ids = selection.map(item => item.id);
  255. this.single = selection.length != 1;
  256. this.multiple = !selection.length;
  257. },
  258. /** 新增按钮操作 */
  259. handleAdd() {
  260. if(this.$refs.addAndEdit) {
  261. this.$refs.addAndEdit.initData(this.title + '新增', "ADD",{})
  262. }
  263. },
  264. /** 修改按钮操作 */
  265. handleUpdate(row) {
  266. if(this.$refs.addAndEdit) {
  267. this.$refs.addAndEdit.initData(this.title + '编辑', "EDITInit",{...row})
  268. }
  269. },
  270. handleDetails(row){
  271. if(this.$refs.detailsBox) {
  272. this.$refs.detailsBox.initData(this.title + '详情',"DEATILSInit", {...row})
  273. }
  274. },
  275. /** 删除按钮操作 */
  276. handleDelete(row) {
  277. const goodsId = row.goodsId || this.ids;
  278. this.$modal.confirm('是否确认删除数据项?').then( () => {
  279. return delTableParamsApi(this.configUrl.delect,{
  280. goodsId: goodsId
  281. });
  282. }).then(() => {
  283. this.getList();
  284. this.$modal.msgSuccess("删除成功");
  285. }).catch((e) => {
  286. console.error("删除失败====",e)
  287. });
  288. },
  289. /** 导出按钮操作 */
  290. handleExport() {
  291. this.download(this.configUrl.export, {
  292. ...this.queryParams
  293. }, `${this.title }_${new Date().getTime()}.xlsx`)
  294. },
  295. /** 导入按钮操作 */
  296. handleImport() {
  297. if(this.$refs.upload) {
  298. this.$refs.upload.initData({
  299. width: '400px',
  300. // 弹出层标题(用户导入)
  301. title: this.title + "导入",
  302. // 下载模板地址
  303. importTemplate: this.configUrl.download,
  304. // 上传的地址
  305. url: this.configUrl.upload
  306. })
  307. }
  308. },
  309. /**
  310. * 修改状态
  311. * @date 2023-11-22
  312. * @returns {any}
  313. */
  314. openAttraction(row) {
  315. this.$modal.confirm(`是否确认${row.status == 0 ? '下架' : '上架'}吗?`).then( () => {
  316. return addTableApi(this.configUrl.updateStatusById,{
  317. goodsId: row.goodsId,
  318. status: row.status == 1 ? 0 : 1
  319. });
  320. }).then(() => {
  321. this.getList()
  322. this.$modal.msgSuccess(`${row.status == 0 ? '下架' : '上架'}成功`);
  323. }).catch((e) => {
  324. console.error("失败====",e)
  325. });
  326. },
  327. /** 远程搜索商品分类 */
  328. remoteClassifyId() {
  329. listTableApi(this.configUrl.classifyList).then(response => {
  330. let list = response.data
  331. this.listTreeCopy = list
  332. }
  333. ).catch (error=>{
  334. console.error('获取列表失败!!!!',error)
  335. this.listTreeCopy = [];
  336. })
  337. },
  338. /** 远程归属店铺 */
  339. remoteShop(value) {
  340. try {
  341. if(this.shopListTime) {
  342. clearTimeout(this.shopListTime)
  343. }
  344. this.shopListLoading = true
  345. this.shopListTime = setTimeout(async ()=>{
  346. let res = await listTableApi(this.configUrl.shopList,{name: value})
  347. this.shopList = res.data.rows
  348. this.shopListLoading = false
  349. },1000)
  350. } catch (error) {
  351. this.shopListLoading = false
  352. }
  353. },
  354. }
  355. };
  356. </script>