<template>
  <div class="right_con">
    <Tabs type="card">
      <TabPane label="系统更新" name="list">
        <div class="page_summary">
          自动更新步骤：
          <br>① 下载更新包
          <br>② 备份数据库、备份需要更新的文件
          <br>③ 执行数据库更新脚本、替换跟新文件
          <br>注意：步骤③执行过程中若没有出现错误则为更新成功，若出现错误则需要回滚操作（还原更新前的状态：用备份文件替换新文件，备份数据库替换新数据库）
        </div>
        <Table :columns="updateSystemList" :data="updateSystemData" border class="tables"></Table>
        <p class="system_tip fl">尊敬的用户，您的系统当前版本为{{this.nowVeison}} <span v-if="showTipVerSion">，最新版本为{{this.newVeison}}，建议您进行更新升级。</span></p>
        <Button class="system_btn" type="primary" @click="detectionSystem" style="margin-left:10px">检测更新</Button>
      </TabPane>
    </Tabs>
    <updateSystemModal :isUpdateSystem.sync="isUpdateSystem" :notCanUpdate.sync="notCanUpdate" :updateSystemDataDetail='updateSystemDataDetail'></updateSystemModal>
  </div>
</template>
<script>
import updateSystemModal from '@@/set/update_system_modal'
export default {
  name: "update_system",
  components:{ updateSystemModal },
  data() {
    return {
      isUpdateSystem:false,
      notCanUpdate:false,
      updateSystemDataDetail:{},
      nowVeison:'',
      newVeison:'',
      showTipVerSion:true,
      updateSystemList: [
        {
          title: "版本",
          key:'version_name'
        },
        {
          title: "更新时间",
          key:'update_time'
        },
        {
          title: "更新内容",
          render:(h,params)=>{
            return h('div',params.row.content.map(item=>{
              return h('div',[
                h('p',{
                  style:{
                    lineHeight:'30px'
                  }
                },item)
              ])
            }))
          }
        }
      ],
      updateSystemData: []
    };
  },
  methods:{
    getUpdateSystemList(){
      this.$api.getUpdateSystemList().then(data=>{
        if(data.code==200){
          this.updateSystemData=data.data
        }else{
          this.$Message.info(data.msg)
        }
      })
    },
    detectionSystem(){
      this.$api.detectionSystem().then(data=>{
        if(data.code==200){
          this.isUpdateSystem=true
          this.updateSystemDataDetail=data.data
        }else if(data.code==8003){
          this.notCanUpdate=true
        }else{
          this.$Message.info(data.msg)
        }
      })
    },
    currentVersion() {
      this.$api.getcurrentVersion().then(response =>{
        if(response.code ==200) {
          this.nowVeison = response.data.version_name
        }else {
          this.$Message.info(data.msg)
        }
      })
    },
    newVersionData() {
       this.$api.getNewVersion().then(response =>{
        if(response.code ==200) {
          this.showTipVerSion = true
          this.newVeison = response.data.version_name
        }else {
          this.showTipVerSion = false
          return false
        }
      })
    }
  },
  created(){
    this.getUpdateSystemList()
    this.currentVersion()
    this.newVersionData()
  }
};
</script>
<style>
.right_con {
  padding-top: 20px;
}
.system_tip {
  font-size: 14px;
  margin-top: 20px
}
.system_btn.ivu-btn{
    height: 26px;
    font-size: 12px;
    padding: 0 15px;
    margin-top: 17px
}
</style>

