index.vue 6.11 KB
<template>
  <div class="app-container">
    <el-header height>
      <el-button type="primary" @click="openDialog">创建</el-button>
    </el-header>
    <el-main>
      <el-tabs v-model="queryForm.oneStepCode" @tab-click="initOneStepImage">
        <el-tab-pane v-for="item in oneStepList" :key="item.id" :label="item.oneStepName"
                     :name="item.oneStepCode"></el-tab-pane>
      </el-tabs>

      <el-table
        :data="oneStepImageList"
        style="width: 100%"
        stripe
        highlight-current-row
        v-loading="loading"
      >
        <el-table-column label="图片">
          <template slot-scope="scope">
            <a :href="scope.row.imageUrl" target="_blank">
              <div style="width: 100px;">
                <el-image :src="scope.row.imageUrl"></el-image>
              </div>
            </a>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-link type="primary" @click="deleteOneStepImage(scope.row.oneStepImageCode)">删除</el-link>
            <el-link type="primary" @click="editOneStepImage(scope.row)">编辑</el-link>
            <el-link type="primary" v-show="scope.$index!==0"
                     @click="changeImage(scope.row,oneStepImageList[scope.$index-1])"><i
              class="el-icon-sort"></i>上移 &nbsp
            </el-link>
            <el-link type="primary" v-show="scope.$index!==oneStepImageList.length-1"
                     @click="changeImage(scope.row,oneStepImageList[scope.$index+1])"><i class="el-icon-sort"></i>下移
              &nbsp
            </el-link>
          </template>
        </el-table-column>
      </el-table>

    </el-main>
    <el-footer>

    </el-footer>


    <el-dialog
      width="60%"
      :title="title"
      :visible.sync="dialogVisible">
      <el-form :model="oneStepImageForm" ref="oneStepImageForm" :rules="oneStepImageFormRules" label-width="180px">
        <el-form-item label="图片:" prop="imageUrl">
          <upload-item
            v-model="oneStepImageForm.imageUrl"
            v-on:before-upload="loading=true"
            v-on:after-upload="loading=false"
          ></upload-item>
        </el-form-item>
        <el-form-item label="一步操作系列:" prop="oneStepCode">
          <el-select v-model="oneStepImageForm.oneStepCode" placeholder="请选择">
            <el-option
              v-for="item in oneStepList"
              :key="item.oneStepCode"
              :label="item.oneStepName"
              :value="item.oneStepCode">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button type="primary" @click="submitForm('oneStepImageForm')">提交</el-button>
    <el-button @click="cancelCreate">取消</el-button>
    </span>
    </el-dialog>
  </div>
</template>

<script>
  import {request} from '@/api/fetch-api'
  import UploadItem from '@/components/UploadItem'

  let urls = {
    oneStepListUrl: '/tianbao_edu_api/admin/oneStep/list',
    oneStepImageListUrl: '/tianbao_edu_api/admin/oneStepImage/list',
    changeUrl: '/tianbao_edu_api/admin/oneStepImage/change',
    oneStepImageSaveUrl: '/tianbao_edu_api/admin/oneStepImage/save',
    oneStepImageDelUrl: '/tianbao_edu_api/admin/oneStepImage/delete'
  }
  export default {
    components: {UploadItem},
    data() {
      return {
        oneStepImageList: [],
        queryForm: {
          page: 1,
          size: 1000,
          oneStepCode: ''
        },
        oneStepList: [],
        dialogVisible: false,
        oneStepImageForm: {},
        oneStepImageFormRules: {
          imageUrl:[{required: true, message: '请上传图片', trigger: 'blur'}],
          oneStepCode:[{required: true, message: '请选择', trigger: 'blur'}]
        },
        title: "",
        loading: false
      }
    },
    methods: {
      handleClick(tab, event) {

      },
      initOneStep() {
        request.get(urls.oneStepListUrl, {page: 1, size: 10000}).then(data => {
          this.oneStepList = data.content.list
          this.queryForm.oneStepCode = this.oneStepList[0].oneStepCode
          this.initOneStepImage()
        }).catch(() => {

        })
      },
      initOneStepImage() {
        this.loading = true
        request.get(urls.oneStepImageListUrl, this.queryForm).then(data => {
          this.loading = false
          this.oneStepImageList = data.content.list
        }).catch(() => {

        })
      },
      openDialog() {
        this.dialogVisible = true
        this.oneStepImageForm = {}
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            request.post(urls.oneStepImageSaveUrl, this.oneStepImageForm).then(response => {
              this.dialogVisible = false
              this.$message.success("保存成功")
              this.initOneStep()
            }).catch(() => {

            })
          } else {
            console.log('error submit!!')
            return false
          }
        })
      },
      cancelCreate() {
        this.dialogVisible = false
        this.oneStepImageForm = {}
      },
      deleteOneStepImage(code) {
        this.$confirm('此操作将永久删除, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          request.post(urls.oneStepImageDelUrl, {oneStepImageCode: code}).then(response => {
            this.initOneStepImage()
            this.$message.success("删除成功")
          }).catch(() => {

          })
        }).catch(() => {
        })
      },
      editOneStepImage(row) {
        this.dialogVisible = true
        this.oneStepImageForm = JSON.parse(JSON.stringify(row))
      },
      changeImage(row, row2) {
        let form = {
          oneCode: row.oneStepImageCode,
          twoCode: row2.oneStepImageCode
        }
        request.post(urls.changeUrl, form).then(response => {
          this.initOneStep()
        }).catch(() => {

        })
      }
    },
    created() {
      this.initOneStep()
    },

  }
</script>

<style scoped>

</style>