<!--
 * @Description: 修改
 * @Author: wsd
 * @Date: 2022-10-26 14:20:38
 * @LastEditTime: 2022-11-04 00:24:54
 * @LastEditors: wsd
-->
<template>
  <el-dialog
    title="历史版本"
    :visible.sync="dialogVisible"
    width="80%"
    :close-on-click-modal="false"
    :before-close="handleClose"
  >
    <div class="container">
      <el-table :data="rowData">
        <el-table-column type="index" label="序号" width="50" align="center">
        </el-table-column>
        <el-table-column
          prop="versionNo"
          label="版本号"
          align="center"
          show-overflow-tooltip
        >
          <!-- <template #default="{row}">
            <p>{{row.version ? row.version : '无'}}</p>
          </template> -->
        </el-table-column>
        <el-table-column
          prop="updateon"
          label="发布时间"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="createby"
          label="发布人"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="versionDesc"
          label="修订内容"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="description"
          label="操作"
          align="center"
          show-overflow-tooltip
        >
          <template #default="{ row }">
            <el-button type="text" @click="recovery(row, 'recovery')"
              >恢复</el-button
            >
            <el-button type="text" @click="recoverys(row, 'active')"
              >恢复并激活</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
  </el-dialog>
</template>
<script>
import { versionSave, versionBackup, versionQuery } from '@/api/system_manage'
import {
  publishProxyService
} from '@/api/esb_service'
export default {
  name: '',
  components: {},
  props: {
    rowData: {
      type: Array,
      default: () => []
    },
    visibles: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      page: {
        pageSize: 10,
        pageNum: 1,
        total: 0
      },
      indRow: '',
      dialogVisible: false,
      tableData: []
    }
  },
  watch: {
    rowData(row) {
      this.tableData = row
      this.indRow = this.tableData.length > 0 ? this.tableData[0].versionNo : ''
      console.log(this.tableData)
    },
    visibles(val) {
      this.dialogVisible = val
    }
  },
  created() {},
  mounted() {
    // this.getData()
  },
  methods: {
    handleClose() {
      this.dialogVisible = false
      this.$emit('confirm')
    },
    recovery(row, type) {
      if (row.versionNo === 'v1') {
        this.$message.warning('无法回退，已经是最初版本')
        return
      }
      this.$confirm('确定恢复当前版本的代理服务吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          console.log(row, 'this.rowData')
          versionBackup({
            id: row.id,
            versionNo: row.versionNo
          }).then((res) => {
            this.handleClose()
            // versionSave({
            //   proxyServiceId: row.proxyServiceId,
            //   versionDesc: this.indRow + '版本回退',
            //   versionNo: 'v' + (parseInt(this.indRow.split('v')[1]) + 1)
            // }).then((res) => {
            //   this.handleClose()
            // })
          })
        })
        .catch(() => {
          // this.$message({
          //   type: 'info',
          //   message: '已取消删除'
          // })
        })
    },
    recoverys(row, type) {
      if (row.versionNo === 'v1') {
        this.$message.warning('无法回退，已经是最初版本')
        return
      }
      this.$confirm('确定恢复并激活当前版本的代理服务？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        versionBackup({
          id: row.id,
          versionNo: row.versionNo
        }).then((res) => {
          this.handleClose()
          // versionSave({
          //   proxyServiceId: row.proxyServiceId,
          //   versionDesc: this.indRow + '版本回退',
          //   versionNo: 'v' + (parseInt(this.indRow.split('v')[1]) + 1)
          // }).then((res) => {
          //   publishProxyService(row.proxyServiceId).then((rt) => {
          //     if (rt.status === '200') {
          //       let ind = true
          //       let inds = ''
          //       rt.data.forEach(item => {
          //         if (!item.success) {
          //           ind = false
          //           inds += item.message
          //         }
          //       })
          //       if (ind) {
          //         this.$message({
          //           message: '发布成功',
          //           type: 'success'
          //         })
          //         this.handleClose()
          //       } else {
          //         this.$message({
          //           message: inds,
          //           type: 'error'
          //         })
          //       }
          //     }
          //   }).catch(() => {
          //   })
          // })
        })
      })
    }
  }
}
</script>
<style lang='scss' scoped>
</style>
