<template>
    <div>
        <el-card class="crumbs-card">
            <div class="crumbs">
                <el-breadcrumb separator="\/">
                    <el-breadcrumb-item :to="{ path: '\/main\/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item :to="{ path: '\/main\/first' }">白名单列表</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
        </el-card>
        <el-card class="container">
            <el-form :inline="true" class="demo-form-inline">
                <el-form-item label="景点名">
                    <el-input v-model="name" placeholder=""></el-input>
                </el-form-item>
                <el-form-item label="地点">
                    <el-input v-model="site" placeholder=""></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="getV">查询</el-button>
                    <el-button type="primary" @click="toAddSpot">添加景点</el-button>
                    <el-button type="danger" v-if="ids.length &gt; 0" @click="removes">删除选中</el-button>
<pre><code>            &lt;/el-form-item&gt;
        &lt;/el-form&gt;
        &lt;el-table
                @selection-change=&quot;selectChange&quot;
                :data=&quot;spots&quot;
                style=&quot;width: 100%&quot;&gt;
            &lt;el-table-column
                    type=&quot;selection&quot;
                    width=&quot;55&quot;&gt;
            &lt;/el-table-column&gt;
            &lt;el-table-column
                    prop=&quot;name&quot;
                    label=&quot;景点名称&quot;&gt;
            &lt;/el-table-column&gt;
            &lt;el-table-column
                    prop=&quot;site&quot;
                    label=&quot;地点&quot;&gt;
            &lt;/el-table-column&gt;
            &lt;el-table-column
                    prop=&quot;introduce&quot;
                    label=&quot;介绍&quot;&gt;
            &lt;/el-table-column&gt;
            &lt;el-table-column
                    label=&quot;图片&quot;&gt;
                &lt;template slot-scope=&quot;scope&quot;&gt;
                    &lt;img :src=&quot;picUrl() + scope.row.path&quot; width=&quot;100px&quot;&gt;
                &lt;/template&gt;
            &lt;/el-table-column&gt;
            &lt;el-table-column
                    prop=&quot;recommend&quot;
                    label=&quot;是否推荐&quot;&gt;
                &lt;template slot-scope=&quot;scope&quot;&gt;
                    &lt;el-switch
                            :value=&quot;scope.row.recommend == 1&quot;
                            active-color=&quot;#13ce66&quot;
                            inactive-color=&quot;#ff4949&quot;&gt;
                    &lt;/el-switch&gt;
                &lt;/template&gt;
            &lt;/el-table-column&gt;
            &lt;el-table-column
                    label=&quot;操作&quot;&gt;
                &lt;template slot-scope=&quot;scope&quot;&gt;
                    &lt;!--&lt;el-button type=&quot;text&quot; @click=&quot;&quot;&gt;设置为推荐&lt;/el-button&gt;--&gt;
                    &lt;el-button type=&quot;text&quot; @click=&quot;openEdit(scope.row)&quot;&gt;编辑&lt;/el-button&gt;
                    &lt;el-button type=&quot;text&quot; @click=&quot;remove(scope.row)&quot;&gt;删除&lt;/el-button&gt;
                &lt;/template&gt;
            &lt;/el-table-column&gt;
        &lt;/el-table&gt;
        &lt;el-pagination
                background
                @size-change=&quot;pageSizeChange&quot;
                @current-change=&quot;pageNoChange&quot;
                :current-page=&quot;pageNo&quot;
                :page-sizes=&quot;[10, 20, 30, 40, 100]&quot;
                :page-size=&quot;pageSize&quot;
                layout=&quot;total, sizes, prev, pager, next, jumper&quot;
                :total=&quot;total&quot;&gt;
        &lt;/el-pagination&gt;
    &lt;/el-card&gt;
    &lt;!--编辑弹框--&gt;
    &lt;el-dialog title=&quot;景点信息&quot; width=&quot;40%&quot; :visible.sync=&quot;dialogFormVisible&quot;&gt;
        &lt;el-form ref=&quot;form&quot; label-width=&quot;80px&quot;&gt;
            &lt;el-form-item label=&quot;景点名&quot;&gt;
                &lt;el-input v-model=&quot;editSpot.name&quot;&gt;&lt;/el-input&gt;
            &lt;/el-form-item&gt;
            &lt;el-form-item label=&quot;地点&quot;&gt;
                &lt;el-input v-model=&quot;editSpot.site&quot;&gt;&lt;/el-input&gt;
            &lt;/el-form-item&gt;
            &lt;el-form-item label=&quot;简介&quot;&gt;
                &lt;el-input type=&quot;textarea&quot; v-model=&quot;editSpot.introduce&quot;&gt;&lt;/el-input&gt;
            &lt;/el-form-item&gt;
            &lt;el-form-item label=&quot;原始图片&quot;&gt;
                 &lt;img :src=&quot;picUrl() + editSpot.path&quot; width=&quot;100px&quot;&gt;
            &lt;/el-form-item&gt;
            &lt;el-form-item label=&quot;图片&quot; prop=&quot;path&quot;&gt;
                &lt;el-input type=&quot;text&quot; v-model=&quot;editSpot.path&quot; hidden&gt;&lt;/el-input&gt;
                &lt;el-upload
                        action=&quot;\/api\/file\/upload&quot;
                        list-type=&quot;picture-card&quot;
                        :on-preview=&quot;handlePictureCardPreview&quot;
                        :on-success=&quot;uploadSuccess&quot;
                        :limit=&quot;number&quot;
                        :on-change=&quot;UploadImage&quot;
                        :on-remove=&quot;handleRemove&quot;&gt;
                    &lt;i class=&quot;el-icon-plus&quot;&gt;&lt;/i&gt;
                &lt;/el-upload&gt;
                &lt;el-dialog :visible.sync=&quot;dialogVisible&quot;&gt;
                    &lt;img width=&quot;100%&quot; :src=&quot;picUrl() + editSpot.path&quot; alt=&quot;&quot;&gt;
                &lt;/el-dialog&gt;
            &lt;/el-form-item&gt;
            &lt;el-form-item label=&quot;联系电话&quot;&gt;
                &lt;el-input v-model=&quot;editSpot.phone&quot;&gt;&lt;/el-input&gt;
            &lt;/el-form-item&gt;
            &lt;el-form-item label=&quot;路径推荐&quot;&gt;
                &lt;el-input type=&quot;textarea&quot; v-model=&quot;editSpot.strategy&quot;&gt;&lt;/el-input&gt;
            &lt;/el-form-item&gt;
            &lt;el-form-item label=&quot;是否推荐&quot;&gt;
                &lt;!--&lt;el-input v-model=&quot;editSpot.recommend&quot;&gt;&lt;/el-input&gt;--&gt;
                &lt;el-switch v-model=&quot;editSpot.recommend&quot;&gt;&lt;/el-switch&gt;
            &lt;/el-form-item&gt;
        &lt;/el-form&gt;
        &lt;div slot=&quot;footer&quot; class=&quot;dialog-footer&quot;&gt;
            &lt;el-button @click=&quot;dialogFormVisible = false&quot;&gt;取 消&lt;/el-button&gt;
            &lt;el-button type=&quot;primary&quot; @click=&quot;saveSpot&quot;&gt;确 定&lt;/el-button&gt;
        &lt;/div&gt;
    &lt;/el-dialog&gt;
&lt;/div&gt;
</code></pre>
</template>
<script>
import {getSpotList, removeByIds, removeById, updateSpot} from '@api/spot'
 export default {
  name: 'spotList',
  data: function () {
    return {
      pr: '',
      dialogImageUrl: '',
      dialogVisible: false,
      dialogFormVisible: false,
      editSpot: {},
      spots: [],
      pageNo: 1,
      pageSize: 10,
      total: 0,
      name: '',
      site: '',
      ids: []
    }
  },
  methods: {
    getV () {
      let obj = {
        pageNo: this.pageNo,
        pageSize: this.pageSize,
        name: this.name,
        site: this.site
      }
      getSpotList(obj).then(res => {
        // 这里的res就是后端直接返回的json
        this.spots = res.data.records
        this.total = res.data.total
      })
    },

    handleRemove (file, fileList) {
      console.log(file, fileList)
    },
    handlePictureCardPreview (file) {
      this.dialogImageUrl = file.url
      this.dialogVisible = true
    },
    uploadSuccess (res) {
      this.dialogImageUrl = res.url
      this.editSpot.path = res.url
    },

    picUrl () {
      return this.pr
    },

    toAddSpot () {
      this.$router.push({path: '\/main\/spot\/add'})
    },

    // 表格选择项发生变化
    selectChange (value) {
      this.ids = value.map(spot => spot.id)
    },
    // 保存
    saveSpot () {
      console.info(this.editSpot)
      this.editSpot.recommend = this.editSpot.recommend ? 1 : 0
      updateSpot(this.editSpot).then(res => {
        this.$message({
          message: '修改成功',
          type: 'success'
        })
        this.dialogFormVisible = false
        this.getV()
      })
    },
    // 打开编辑
    openEdit (obj) {
      // 克隆对象 克隆了再用
      let newObjj = JSON.parse(JSON.stringify(obj))
      this.editSpot = newObjj
      this.editSpot.recommend = this.editSpot.recommend === 1
      this.dialogFormVisible = true
    },
    // 批量删除
    removes () {
      this.$confirm('此操作将永久删除选中数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let obj = {ids: this.ids}
        removeByIds(obj).then(res => {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          this.getV()
        })
      }).catch(() => {

      })
    },
    // 点击删除
    remove (spot) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let obj = {id: spot.id}
        removeById(obj).then(res => {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          this.getV()
        })
      }).catch(() => {

      })
    },
    //    页码改变
    pageNoChange (value) {
      this.pageNo = value
      this.getV()
    },
    // 页面大小改变
    pageSizeChange (value) {
      this.pageSize = value
      this.getV()
    }
  },
  // 生命周期
  // 页面刚创建时
  created: function () {
    this.pr = 'http://localhost:8081/'
    this.getV()
  }
}
</script>
<style scoped>

</style>

原文地址: https://www.cveoy.top/t/topic/p0Bn 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录