index.vue 5.05 KB
<template>
  <div class="app-container">
    <el-header height>
      <el-button type="primary" @click="openDialog">创建</el-button>
    </el-header>
    <el-main>
      <el-table
        :data="oneStepList"
        style="width: 100%"
        stripe
        highlight-current-row
        v-loading="loading"
      >
        <el-table-column label="名称" prop="oneStepName"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-link type="primary" @click="deleteOneStep(scope.row.oneStepCode)">删除</el-link>
            <el-link type="primary" @click="editOneStep(scope.row)">编辑</el-link>
            <el-link type="primary" v-show="scope.$index!==0" @click="change(scope.row,oneStepList[scope.$index-1])"><i
              class="el-icon-sort"></i>上移 &nbsp
            </el-link>
            <el-link type="primary" v-show="scope.$index!==oneStepList.length-1"
                     @click="change(scope.row,oneStepList[scope.$index+1])"><i class="el-icon-sort"></i>下移 &nbsp
            </el-link>
          </template>
        </el-table-column>
      </el-table>

      <el-footer>
        <div style="text-align:right;">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="queryForm.page"
            :page-size="queryForm.size"
            layout="total, prev, pager, next"
            :total="total">
          </el-pagination>
        </div>
      </el-footer>
    </el-main>

    <el-dialog
      width="60%"
      :title="title"
      :visible.sync="dialogVisible">
      <el-form :model="oneStepForm" ref="oneStepForm" :rules="oneStepFormRules" label-width="180px">
        <el-form-item label="名称:" prop="oneStepName">
          <el-input v-model="oneStepForm.oneStepName" maxlength="100" show-word-limit></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm('oneStepForm')">提交</el-button>
        <el-button @click="cancelCreate">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

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

  let urls = {
    oneStepListUrl: '/tianbao_edu_api/admin/oneStep/list',
    oneStepSaveUrl: '/tianbao_edu_api/admin/oneStep/save',
    oneStepDelUrl: '/tianbao_edu_api/admin/oneStep/delete',
    changeUrl: '/tianbao_edu_api/admin/oneStep/change'
  }

  export default {
    data() {
      return {
        oneStepList: [],
        total: 0,
        loading: false,
        queryForm: {
          page: 1,
          size: 10
        },
        dialogVisible: false,
        oneStepForm: {},
        oneStepFormRules: {
          oneStepName: [{required: true, message: '请输入名称', trigger: 'blur'}],
        },
        title: ''
      }
    },
    methods: {
      initOneStep() {
        this.loading = true
        request.get(urls.oneStepListUrl, this.queryForm).then(data => {
          this.loading = false
          this.oneStepList = data.content.list
          this.total = data.content.total
        }).catch(() => {

        })
      },
      change(row, row2) {
        let form = {
          oneCode: row.oneStepCode,
          twoCode: row2.oneStepCode
        }
        request.post(urls.changeUrl, form).then(response => {
          this.initOneStep()
        }).catch(() => {

        })
      },
      deleteOneStep(code) {
        this.$confirm('此操作将永久删除, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          request.post(urls.oneStepDelUrl, {oneStepCode: code}).then(response => {
            this.initOneStep()
            this.$message.success("删除成功")
          }).catch(() => {

          })
        }).catch(() => {
        })

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

            })
          } else {
            console.log('error submit!!')
            return false
          }
        })
      },
      cancelCreate() {
        this.dialogVisible = false
        this.oneStepForm = {}
      },
      /*分页*/
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`)
        this.queryForm.size = val
        this.queryForm.page = 1
        this.initOneStep()
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`)
        this.queryForm.page = val
        this.initOneStep()
      },
    },
    created() {
      this.initOneStep()
    }
  }
</script>

<style scoped>

</style>