Collection.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. <!-- -->
  2. <template>
  3. <div>
  4. <main-top :crumb="crumbData">
  5. <div slot="con">
  6. <el-button type="primary" @click="$router.push({name:'edit-collection',query:{type},params:{type:0,id:'none'}})">新增精品典藏</el-button>
  7. </div>
  8. </main-top>
  9. <div class="table-interface">
  10. <div class="con-left">
  11. <el-menu :default-active="`1-${type}`" @select="handleSelect" class="el-menu-vertical-demo" :collapse="isCollapse">
  12. <el-submenu index="1">
  13. <template slot="title">
  14. <i class="el-icon-menu"></i>
  15. <span slot="title">精品典藏</span>
  16. </template>
  17. <el-menu-item v-for="(item,i) in collectionType" :key="i" :index="'1-'+item.id">{{item.name}}</el-menu-item>
  18. </el-submenu>
  19. </el-menu>
  20. <div class="sousuo" @click="isCollapse=!isCollapse">
  21. <i :class="isCollapse?'el-icon-arrow-right':'el-icon-arrow-left'"></i>
  22. </div>
  23. </div>
  24. <div class="top-body">
  25. <ul class="tab">
  26. <li @click="status = 5" :class="{active:status !== 4}">待审核</li>
  27. <li @click="status = 4" :class="{active:status === 4}">审核通过</li>
  28. </ul>
  29. <div class="info-top">
  30. <div class="info-left">
  31. <span>发布时间:</span>
  32. <el-date-picker
  33. v-model="time"
  34. type="daterange"
  35. range-separator="-"
  36. value-format="yyyy-MM-dd HH:mm:ss"
  37. start-placeholder="开始日期"
  38. end-placeholder="结束日期">
  39. </el-date-picker>
  40. <span style="margin-left:1.25rem;">状态:</span>
  41. <el-select style="width:6.25rem;" v-model="status" placeholder="请选择">
  42. <el-option label="全部" :value="5"></el-option>
  43. <el-option v-for="(item,i) in statusArr" :key="i" :label="item.name" :value="item.id"></el-option>
  44. </el-select>
  45. <span style="margin-left:1.25rem;">标题关键字:</span>
  46. <el-input class="elInput" v-model="inputKey" placeholder="请输入标题关键字搜索"></el-input>
  47. <el-button type="primary" @click="getInformation">查找</el-button>
  48. <el-button @click="reset">重置</el-button>
  49. </div>
  50. <div class="info-right">
  51. </div>
  52. </div>
  53. <el-table :data="tableData" height="55vh" class="collection-con" style="width: 100%">
  54. <el-table-column
  55. v-for="(item, idx) in data"
  56. :key="idx"
  57. :sortable="item.prop==='viewCount'"
  58. :prop="item.prop"
  59. :width="item.prop === 'thumb'?250:'auto'"
  60. :label="item.label"
  61. >
  62. <template slot-scope="scope" >
  63. <el-switch
  64. v-model="scope.row[item.prop]"
  65. v-if="item.prop === 'display'"
  66. v-show="status === 4"
  67. @change="changeState(scope.row)"
  68. inactive-color="#ccc">
  69. </el-switch>
  70. <el-image
  71. v-else-if="item.prop === 'thumb'"
  72. style="width:auto;height:125px;"
  73. :src="scope.row[item.prop]"
  74. :preview-src-list="[scope.row[item.prop]]">
  75. <div slot="error" class="image-slot">
  76. <i class="el-icon-picture-outline"></i>
  77. </div>
  78. </el-image>
  79. <el-input type="number" class="icenter" v-else-if="(item.prop === 'sort')" @blur="handleSort(scope.row)" v-model="scope.row[item.prop]"></el-input>
  80. <span v-else v-html="scope.row[item.prop]||'-'"></span>
  81. </template>
  82. </el-table-column>
  83. <el-table-column label="操作">
  84. <template slot-scope="scope" >
  85. <template v-if="status !== 4">
  86. <template v-if="scope.row.statusStr === '待审核'">
  87. <span class="o-span" @click="goto(scope.row)" v-if="scope.row.statusStr === '待审核'">
  88. '审核'
  89. </span>
  90. </template>
  91. <template v-else>
  92. <span class="o-span" @click="goto(scope.row)">编辑</span>
  93. <span class="o-span" @click="del(scope.row)">删除</span>
  94. </template>
  95. </template>
  96. <template v-else>
  97. <span class="o-span" @click="goto(scope.row)">查看</span>
  98. <span class="o-span" v-if="(!scope.row.display)" @click="del(scope.row)">删除</span>
  99. </template>
  100. </template>
  101. </el-table-column>
  102. </el-table>
  103. <div class="e-pagination">
  104. <el-pagination
  105. @current-change="handleCurrentChange"
  106. :current-page.sync="currentPage"
  107. @size-change="handleSizeChange"
  108. :page-size="size"
  109. :page-sizes="PAGESIZES"
  110. layout="total, sizes, prev, pager, next, jumper"
  111. :total="total"
  112. ></el-pagination>
  113. </div>
  114. </div>
  115. </div>
  116. </div>
  117. </template>
  118. <script>
  119. // 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  120. // 例如:import 《组件名称》 from '《组件路径》';
  121. import MainTop from '@/components/main-top'
  122. import {changeState} from '@/util/commonfn.js'
  123. const crumbData = [
  124. {
  125. name: '精品典藏管理',
  126. id: 4
  127. }
  128. ]
  129. let collectionType = [
  130. {
  131. id:3,
  132. name:'实物模型'
  133. },
  134. {
  135. id:1,
  136. name:'专题图库'
  137. },
  138. {
  139. id:2,
  140. name:'视频档案'
  141. }
  142. ]
  143. let data = [
  144. {
  145. prop: "idx",
  146. label: "编号"
  147. },
  148. {
  149. prop: "title",
  150. label: "标题"
  151. },
  152. {
  153. prop: "thumb",
  154. label: "封面图片"
  155. },
  156. {
  157. prop: "sort",
  158. label: "排序"
  159. },
  160. {
  161. prop: "viewCount",
  162. label: "阅读"
  163. },
  164. {
  165. prop: "submitName",
  166. label: "发布人"
  167. },
  168. {
  169. prop: "createTime",
  170. label: "发布时间"
  171. },
  172. {
  173. prop: "statusStr",
  174. label: "所属状态"
  175. }
  176. ];
  177. export default {
  178. // import引入的组件需要注入到对象中才能使用
  179. components: {
  180. MainTop,
  181. },
  182. data () {
  183. return {
  184. isCollapse:false,
  185. crumbData,
  186. time:'',
  187. tableData: [],
  188. inputKey: '',
  189. currentPage: 1,
  190. size: 25,
  191. total: 0,
  192. collectionType,
  193. loading: false,
  194. status:5,
  195. type:this.$route.params.type
  196. }
  197. },
  198. computed:{
  199. data(){
  200. data.pop()
  201. let item = this.status === 4?{
  202. prop: "display",
  203. label: "是否显示"
  204. }:{
  205. prop: "statusStr",
  206. label: "所属状态"
  207. }
  208. data.push(item)
  209. return data
  210. }
  211. },
  212. watch: {
  213. currentPage () {
  214. this.refresh()
  215. },
  216. size () {
  217. this.refresh()
  218. },
  219. status () {
  220. this.refresh()
  221. },
  222. type(){
  223. this.refresh()
  224. }
  225. },
  226. mounted () {
  227. this.refresh()
  228. },
  229. methods: {
  230. handleSort(item=""){
  231. if(!item||!item.sort)return
  232. this.$http.get(`/manage/goods/sort/${item.id}/${item.sort}`, {
  233. headers: {
  234. token: window.localStorage.getItem("token"),
  235. },
  236. })
  237. .then((res) => {
  238. if (res.code === 0) {
  239. // this.refresh();
  240. } else {
  241. this.$notify.error({
  242. title: "错误",
  243. message: res.msg
  244. });
  245. }
  246. });
  247. },
  248. changeState(item) {
  249. changeState(item,'goods',()=>{
  250. this.refresh();
  251. })
  252. },
  253. handleSelect(index){
  254. this.type = Number(index.substr(-1))
  255. this.$router.push({
  256. name:'collection',
  257. params:{
  258. type:this.type
  259. }
  260. })
  261. // this.refresh()
  262. },
  263. reset(){
  264. this.inputKey=''
  265. this.status=5
  266. },
  267. del (item) {
  268. let ids = item.id
  269. this.$confirm('删除后,信息将无法恢复,是否继续?', '提示', {
  270. confirmButtonText: '确定',
  271. cancelButtonText: '取消',
  272. type: 'warning'
  273. }).then(() => {
  274. this.$http.get(`/manage/goods/remove/${ids}`,{headers: {
  275. token: window.localStorage.getItem('token')
  276. }}).then(res => {
  277. if (res.code === 0) {
  278. this.$alert('删除成功', '提示', {
  279. confirmButtonText: '确定',
  280. callback: () => {
  281. this.refresh()
  282. }
  283. })
  284. } else {
  285. this.$notify.error({
  286. title: '错误',
  287. message: res.msg
  288. })
  289. }
  290. })
  291. }).catch(() => {
  292. this.$message({
  293. type: 'info',
  294. message: '已取消删除'
  295. })
  296. })
  297. },
  298. gotoShow (item) {
  299. this.$router.push({ name: 'show-collection', params: { id: item.id } })
  300. },
  301. goto (item) {
  302. this.$router.push({ name: 'edit-collection', params: { type: 1,id:item.id } })
  303. },
  304. refresh () {
  305. this.loading = true
  306. this.getInformation()
  307. this.loading = false
  308. },
  309. handleCurrentChange (val) {
  310. this.currentPage = val
  311. },
  312. handleSizeChange(val){
  313. this.size = val
  314. },
  315. async getInformation () {
  316. let params = {
  317. pageNum:this.currentPage,
  318. pageSize: this.size,
  319. searchKey: this.inputKey,
  320. startTime: this.time? (this.time[0].split(' ')[0] + ' 00:00:00') : '',
  321. endTime: this.time? (this.time[1].split(' ')[0] + ' 23:59:59') : '',
  322. status: this.status,
  323. type:this.type
  324. }
  325. let result = await this.$http({
  326. method: 'post',
  327. data: params,
  328. headers: {
  329. token: window.localStorage.getItem('token')
  330. },
  331. url: '/manage/goods/list'
  332. })
  333. if (result.code !== 0) {
  334. return
  335. }
  336. this.tableData = result.data.list
  337. this.total = result.data.total
  338. this.tableData.forEach((item, i) => {
  339. item["idx"] = i + 1;
  340. item["typeStr"] = this.typeStr[item.type];
  341. item["statusStr"] = this.statusStr[item.status];
  342. item["createTime"] = item["createTime"].split(' ')[0] + '<br/>' +item["createTime"].split(' ')[1]
  343. item["display"] = Boolean(item["display"]);
  344. });
  345. }
  346. }
  347. }
  348. </script>
  349. <style lang="less" scoped>
  350. .top-body{
  351. border-top: .0625rem solid #e6e6e6;
  352. line-height: 1.5;
  353. padding: 0 1.25rem 1.25rem;
  354. align-items: center;
  355. box-sizing: border-box;
  356. background: #fff;
  357. margin: 1rem 0;
  358. width: 90%;
  359. }
  360. .top-body .top-con{
  361. font-weight: bold;
  362. }
  363. .table-title{
  364. padding: 1rem 1rem 1rem 0 ;
  365. font-size: 1rem;
  366. color: #2d2d2d;
  367. border-bottom: .0625rem solid #ccc;
  368. display: flex;
  369. justify-content: space-between;
  370. }
  371. .more{
  372. color: #ec652d;
  373. cursor: pointer;
  374. }
  375. .top-right{
  376. background-color: #ec652d;
  377. height: 3.5625rem;
  378. line-height: 3.5625rem;
  379. color: #fff;
  380. padding: 0 1.875rem;
  381. border-radius: .3125rem;
  382. font-size: 1.125rem;
  383. font-weight: bold;
  384. }
  385. .search-body{
  386. background-color: #fff;
  387. margin: 1.25rem 0;
  388. }
  389. .interface-table{
  390. height: calc(100% - 17.1875rem);
  391. overflow-x: hidden;
  392. background-color: #fff;
  393. padding: 0 1.125rem 2.375rem;
  394. box-sizing: border-box;
  395. }
  396. .zan-con{
  397. display: flex;
  398. width: 100%;
  399. justify-content: space-around;
  400. margin-top: 1.5rem;
  401. text-align: center;
  402. font-size: 1.125rem;
  403. }
  404. .zan-con .line{
  405. height: 8rem;
  406. width: .0625rem;
  407. background: #ccc;
  408. }
  409. .zan-con .zan-contain{
  410. display: flex;
  411. justify-content: space-between;
  412. flex-direction: column;
  413. }
  414. .zan-con .zan-contain p{
  415. font-size: 2.25rem;
  416. }
  417. .zan-con .zan-contain p:first-child{
  418. font-size: .875rem;
  419. line-height: 1.5;
  420. }
  421. .zan-sub{
  422. text-align: right;
  423. margin-top: 1.25rem;
  424. color: #a5a5a5;
  425. font-size: .875rem;
  426. }
  427. .table-interface{
  428. height: calc(100% - 3rem);
  429. display: flex;
  430. justify-content: space-between;
  431. background-color: #fff;
  432. .con-left{
  433. border-right: solid 1px #e5e5e5;
  434. position: relative;
  435. margin-right: 30px;
  436. .sousuo{
  437. position: absolute;
  438. top: 50%;
  439. transform: translateY(-50%);
  440. right: -30px;
  441. cursor: pointer;
  442. }
  443. }
  444. }
  445. .info-top{
  446. padding: 1.25rem 0;
  447. display: flex;
  448. justify-content: space-between;
  449. border-bottom: .0625rem #a5a5a5 solid;
  450. }
  451. .o-span{
  452. cursor: pointer;
  453. color: rgb(7, 152, 244);
  454. }
  455. .collection-con{
  456. width: 100%;
  457. overflow-x: hidden;
  458. overflow-y: auto;
  459. height: 55vh;
  460. }
  461. .collection-con ul{
  462. display: flex;
  463. flex-wrap: wrap;
  464. margin-top: 1.25rem;
  465. }
  466. .collection-con ul li {
  467. width: 24%;
  468. margin-right: 1%;
  469. cursor: pointer;
  470. font-size: .8rem;
  471. color: #2d2d2d;
  472. margin-bottom: 1.25rem;
  473. }
  474. .collection-con ul .li-img {
  475. position: relative;
  476. }
  477. .collection-con ul .li-img div{
  478. position: absolute;
  479. left: .625rem;
  480. bottom: .625rem;
  481. color: #fff;
  482. }
  483. .collection-con ul .li-img div span{
  484. margin-right: .625rem;
  485. }
  486. .collection-con ul img {
  487. width: 100%;
  488. }
  489. .collection-con{
  490. .li-txt,.li-name{
  491. display: flex;
  492. justify-content: space-between;
  493. align-items: center;
  494. }
  495. .li-name{
  496. margin-top: .5rem;
  497. div{
  498. font-size: 1rem;
  499. font-weight: bold;
  500. color: #532F1C;
  501. &:last-of-type{
  502. color: #707070;
  503. font-size: .875rem;
  504. font-weight: normal;
  505. span{
  506. margin-left: .30rem;
  507. &:last-of-type{
  508. &:hover{
  509. color: #409EFF;
  510. }
  511. }
  512. &:hover{
  513. color: #c56351;
  514. }
  515. }
  516. }
  517. }
  518. }
  519. }
  520. .el-menu-vertical-demo:not(.el-menu--collapse) {
  521. width: 200px;
  522. min-height: 400px;
  523. }
  524. .el-menu{
  525. border-right: none!important;
  526. }
  527. </style>