index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <template>
  2. <div class="app-container">
  3. <template v-if="!isShowDetail">
  4. <div class="tab-container clearfix">
  5. <div class="tab-list fl">
  6. <div class="item" :class="screenForm.status === '' ? 'current':''" @click="changeType('')">
  7. 全部({{ (downCount + upCount) || 0 }})</div>
  8. <div class="item" :class="screenForm.status ? 'current':''" @click="changeType(true)">
  9. 租凭中({{ upCount || 0 }})</div>
  10. <div class="item" :class="screenForm.status === false ? 'current':''" @click="changeType(false)">
  11. 已下架({{ downCount || 0 }})</div>
  12. </div>
  13. <el-button type="primary" size="small" @click="addOrEdit('add')">添加商品</el-button>
  14. </div>
  15. <div class="screen2-container">
  16. <el-row :gutter="20">
  17. <el-col :xs="24" :sm="2" :lg="3" style="opacity: 0;">.</el-col>
  18. <el-col :xs="24" :sm="20" :lg="18">
  19. <el-form ref="form" :model="screenForm" label-width="80px">
  20. <div class="search">
  21. <el-input v-model="screenForm.keyword" placeholder="想快速搜索什么商品呢?输入商品名称,商品id,商品分类都可快速找到"
  22. class="input-with-select" clearable @change="getListByScreen">
  23. <el-button slot="append" icon="el-icon-search" @click="getListByScreen"></el-button>
  24. </el-input>
  25. </div>
  26. <div class="screen clearfix">
  27. <el-row :gutter="20">
  28. <el-col :xs="12" :sm="12" :lg="4">
  29. <el-form-item label="商品分类:" label-width="90px">
  30. <el-cascader v-model="screenForm.classify" :options="classifyList"
  31. :props="{ label: 'name', value: 'categoryId' }" size="small"
  32. @change="getListByScreen">
  33. </el-cascader>
  34. </el-form-item>
  35. </el-col>
  36. <el-col :xs="12" :sm="12" :lg="8">
  37. <el-form-item label="租凭定金:" label-width="90px">
  38. <el-input v-model="screenForm.price1" size="small" @change="getListByScreen"
  39. clearable></el-input>
  40. <span>至</span>
  41. <el-input v-model="screenForm.price2" size="small" @change="getListByScreen"
  42. clearable></el-input>
  43. </el-form-item>
  44. </el-col>
  45. <el-col :xs="12" :sm="12" :lg="8">
  46. <el-form-item label="租凭价格:" label-width="90px">
  47. <el-input v-model="screenForm.amount1" size="small" @change="getListByScreen"
  48. clearable></el-input>
  49. <span>至</span>
  50. <el-input v-model="screenForm.amount2" size="small" @change="getListByScreen"
  51. clearable></el-input>
  52. </el-form-item>
  53. </el-col>
  54. </el-row>
  55. </div>
  56. </el-form>
  57. </el-col>
  58. <el-col :xs="24" :sm="2" :lg="3" style="opacity: 0;">.</el-col>
  59. </el-row>
  60. </div>
  61. <div class="mymain-container">
  62. <div class="table">
  63. <el-table v-loading="listLoading" :data="dataList" element-loading-text="Loading" border fit
  64. highlight-current-row stripe @selection-change="handleTableSelection">
  65. <el-table-column align="center" type="selection" width="55" fixed></el-table-column>
  66. <el-table-column align="center" label="一级分类图片" prop="imgUrl" width="85">
  67. <template slot-scope="scope">
  68. <el-image style="width: 60px; height: 60px; display: block;" :src="scope.row.imgUrl"
  69. :preview-src-list="[scope.row.imgUrl]" fit="cover"></el-image>
  70. </template>
  71. </el-table-column>
  72. <el-table-column align="center" label="商品ID" prop="id" min-width="200"></el-table-column>
  73. <el-table-column align="center" label="商品名称" prop="name" min-width="200"></el-table-column>
  74. <el-table-column align="center" label="租凭价格" prop="leasePrice" min-width="200"></el-table-column>
  75. <el-table-column align="center" label="租凭定金" prop="depositPrice" min-width="200"></el-table-column>
  76. <el-table-column align="center" label="排序" prop="sort" min-width="110" sortable>
  77. <template slot-scope="scope">
  78. <!-- {{ scope.row.sortNum }} -->
  79. <span style="margin-right: 10px">{{ scope.row.sort }}</span>
  80. <i class="el-icon-edit pointer" @click="editData('sort', scope.row)"></i>
  81. </template>
  82. </el-table-column>
  83. <el-table-column align="center" label="状态" class-name="status-col">
  84. <template slot-scope="scope">
  85. <div style="display: flex; flex-wrap: wrap; align-items: center; justify-content: center;">
  86. <el-tag size="small"
  87. :type="scope.row.status ? 'success':'danger'">{{ scope.row.status ? '上架':'下架' }}</el-tag>
  88. </div>
  89. </template>
  90. </el-table-column>
  91. <el-table-column align="center" label="操作" width="280" fixed="right">
  92. <template slot-scope="scope">
  93. <el-button v-if="$restrict('edit')" type="primary" size="mini"
  94. @click="addOrEdit('edit', scope.row.id)">编辑</el-button>
  95. <el-button v-if="$restrict('copyLink')" type="primary" size="mini" class="tag-read"
  96. @click="copy(scope.row.id)"
  97. :data-clipboard-text="scope.row.id">复制链接</el-button>
  98. <el-popconfirm v-if="$restrict('del')" style="margin-left: 10px;" title="确定删除吗?"
  99. @confirm="delItem(scope.row.id)">
  100. <el-button slot="reference" size="mini">删除</el-button>
  101. </el-popconfirm>
  102. </template>
  103. </el-table-column>
  104. </el-table>
  105. </div>
  106. <div class="pagination clearfix">
  107. <div class="fr">
  108. <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
  109. :current-page="currentPage" :page-sizes="[10, 20, 50, 100]" :page-size="10"
  110. layout="total, sizes, prev, pager, next, jumper" :total="listTotal">
  111. </el-pagination>
  112. </div>
  113. </div>
  114. </div>
  115. </template>
  116. <template v-else>
  117. <detail @back="backList" :title="'租凭产品' + formTypeItems[formType]" :id="id" :formType="formType"></detail>
  118. </template>
  119. </div>
  120. </template>
  121. <script>
  122. import { getList, del, getClassifyList, getGoodsStateCount, getDetail, save } from '@/api/tenancyProduct'
  123. import Clipboard from 'clipboard'
  124. import detail from './detail'
  125. import { EventBus } from '@/utils/eventBus'
  126. export default {
  127. components: {detail},
  128. data() {
  129. return {
  130. dataList: null, // 列表数据
  131. isShowDetail: false,
  132. listLoading: true, // 列表加载loading
  133. currentPage: 1, // 当前页码
  134. pageSize: 10, // 每页数量
  135. listTotal: 0, // 列表总数
  136. screenForm: {
  137. status: '',
  138. keyword: '',
  139. classify: '',
  140. status: '',
  141. price1: '',
  142. price2: '',
  143. amount1: '',
  144. amount2: '',
  145. },
  146. select_status: [ // 筛选字段 - 状态
  147. {
  148. label: '上架',
  149. value: true
  150. },
  151. {
  152. label: '下架',
  153. value: false
  154. }
  155. ],
  156. classifyList: [],
  157. upCount: 0,
  158. downCount: 0,
  159. id: '',
  160. formType: 0,
  161. formTypeItems: ['新增','编辑'],
  162. tableSelection: [],
  163. }
  164. },
  165. created() {
  166. this.getClassifyList();
  167. this.getList();
  168. EventBus.$on("updateGoodsListPage", () => {
  169. this.getList();
  170. })
  171. },
  172. methods: {
  173. getClassifyList() {
  174. let params = {
  175. name: '',
  176. status: true
  177. };
  178. getClassifyList(params).then(res => {
  179. res.data.unshift({
  180. name: '全部',
  181. categoryId: '',
  182. children: null,
  183. });
  184. this.classifyList = res.data;
  185. })
  186. },
  187. backList() {
  188. this.id = ''
  189. this.isShowDetail = false;
  190. this.getListByScreen()
  191. },
  192. getList() {
  193. this.listLoading = true;
  194. let categoryId = '';
  195. if (this.screenForm.classify) {
  196. categoryId = this.screenForm.classify[1];
  197. }
  198. let params = {
  199. status: this.screenForm.status,
  200. keyword: this.screenForm.keyword,
  201. categoryId: categoryId,
  202. status: this.screenForm.status,
  203. startDeposit: this.screenForm.price1,
  204. endDeposit: this.screenForm.price2,
  205. startPrice: this.screenForm.amount1,
  206. endPrice: this.screenForm.amount2,
  207. pageNum: this.currentPage,
  208. pageSize: this.pageSize
  209. };
  210. getList(params).then(res => {
  211. this.dataList = res.data.records;
  212. this.listTotal = res.data.total;
  213. this.listLoading = false;
  214. })
  215. getGoodsStateCount({}).then(res => {
  216. this.downCount = res.data.downCount;
  217. this.upCount = res.data.upCount;
  218. })
  219. },
  220. async editData(type, item){
  221. let params = {}
  222. await getDetail({id: item.id}).then(res => {
  223. params = res.data;
  224. })
  225. this.$prompt('请输入排序', '编辑', {
  226. confirmButtonText: '确定',
  227. cancelButtonText: '取消',
  228. inputValue: item.sort,
  229. promptObj: {
  230. inputType: 'number',
  231. inputValidator: function(value) {
  232. if(!value && value !== 0) return '请输入排序'
  233. if(value*1 < 0) return '排序不能小于0'
  234. }
  235. }
  236. }).then(({ value }) => {
  237. params[type] = value;
  238. save(params).then(res => {
  239. this.$successMsg('编辑成功');
  240. this.getList();
  241. })
  242. }).catch(() => {});
  243. },
  244. // 更改每页数量
  245. handleSizeChange(val) {
  246. this.pageSize = val;
  247. this.currentPage = 1;
  248. this.getList();
  249. },
  250. // 更改当前页
  251. handleCurrentChange(val) {
  252. this.currentPage = val;
  253. this.getList();
  254. },
  255. // 筛选后重新获取列表
  256. getListByScreen() {
  257. this.currentPage = 1;
  258. this.getList();
  259. },
  260. // 切换类型
  261. changeType(status) {
  262. this.screenForm.status = status;
  263. this.getListByScreen();
  264. },
  265. // 删除商品
  266. delItem(id) {
  267. del([id]).then(res => {
  268. this.getList();
  269. this.$successMsg();
  270. })
  271. },
  272. // 添加商品
  273. addOrEdit(type, id) {
  274. if(id){
  275. this.id = id
  276. }
  277. this.formType = id?1:0
  278. this.isShowDetail = true
  279. },
  280. copy() {
  281. const clipboard = new Clipboard('.tag-read');
  282. // clipboard.on('success', e => {
  283. // this.$successMsg('复制成功');
  284. // })
  285. clipboard.on('error', e => {
  286. console.log('该浏览器不支持复制');
  287. return false;
  288. })
  289. this.$successMsg('复制成功');
  290. },
  291. // 表格选择列
  292. handleTableSelection(val) {
  293. this.tableSelection = val;
  294. },
  295. }
  296. }
  297. </script>
  298. <style scoped lang="scss">
  299. .tab-container {
  300. .tab-list {
  301. .item {
  302. float: left;
  303. font-size: 14px;
  304. margin-right: 20px;
  305. cursor: pointer;
  306. line-height: 32px;
  307. &.current {
  308. color: #409EFF;
  309. }
  310. }
  311. }
  312. }
  313. .screen2-container {
  314. .search {
  315. margin-top: 30px;
  316. }
  317. .screen {
  318. margin-top: 20px;
  319. .el-input {
  320. width: 40%;
  321. }
  322. span {
  323. width: 20%;
  324. display: inline-block;
  325. text-align: center;
  326. color: #666666;
  327. }
  328. }
  329. }
  330. .pointer {
  331. cursor: pointer;
  332. color: #409EFF;
  333. }
  334. </style>
  335. <style lang="scss">
  336. .screen2-container {
  337. .el-form-item__label {
  338. line-height: 32px;
  339. }
  340. .el-form-item__content {
  341. line-height: 32px;
  342. }
  343. }
  344. .el-image-viewer__wrapper .el-icon-circle-close {
  345. color: #ffffff !important;
  346. font-size: 60px;
  347. }
  348. </style>