<!-- app日志 -->
<template>
  <div class="app-container appLogs">
    <div class="page-container appLogsPage">
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm"
                 :inline="true" style="width:100%;">
          <el-form-item label="" v-if="linkType">
            <p class="title-p">{{linkData.ip?'当前地址：'+linkData.ip:''}}</p>
          </el-form-item>
          <el-form-item label="" prop="queryParamsData1" v-if="linkType">
            <el-input
              maxLength="30"
              v-model="queryParams.queryParamsData1"
              placeholder="请输入"
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="" prop="queryParamsData2" v-if="linkType">
            <el-select v-model="queryParams.queryParamsData2" placeholder="请选择" style="width: 200px">
              <el-option
                v-for="dict in optionList"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="state" v-if="linkType">
            <el-date-picker
              :clearable="false"
              v-model="dateRange"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery" v-if="linkType">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery" v-if="linkType">重置</p>
          <p class="page-submit-common-style-button"
             style="float: right;"
             v-if="!linkType"
             @click="dialogOpen"
          >新建连接</p>
          <p class="page-out-common-style-button"
             style="float: right;"
             v-if="linkType"
             @click="breakConnection"
          >断开连接</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" border :data="dataList">
          <el-table-column label="名称" prop="name"  show-overflow-tooltip/>
          <el-table-column label="内容" prop="content" width="200" show-overflow-tooltip/>
          <el-table-column label="创建时间" prop="createTime" width="200" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime,"{y}-{m}-{d} {h}:{i}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="200" show-overflow-tooltip>
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p"
                   @click="tableButton(2,scope.row)"
                >详情</p>
                <p class="table-button-p"
                   @click="tableButton(3,scope.row)"
                >编辑</p>
                <p class="table-button-p"
                   @click="tableButton(4,scope.row)"
                >删除</p>
                <p class="table-button-null"></p>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-show="total>0"
                    :total="total"
                    :page.sync="queryParams.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
    <!--新增弹窗-->
    <el-dialog class="appLogs-dialog" title='设备地址' width="540px" append-to-body
               :visible.sync="dialogType" v-if="dialogType" @close="dialogOff()"
               :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form :model="dialogForm" ref="dialogForm" :inline="true" :rules="dialogRules" class="appLogs-min" label-width="80px">
        <el-form-item label="ip" prop="ip">
          <el-input v-model="dialogForm.ip" placeholder="请输入ip地址" style="width:350px;"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer dialog-footer-box">
        <p class="dialog-footer-button-null"></p>
        <p class="dialog-footer-button-info" @click="dialogOff()">取消</p>
        <p class="dialog-footer-button-primary" @click="dialogSubmit">提交</p>
        <p class="dialog-footer-button-null"></p>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  //import { getDicts } from "@/api/commonality/noPermission";
  //import { systemUserSelect } from "@/api/commonality/permission";
  //import { getInfo } from "@/api/basicsModules/index";
  //import addPage from "./addPage.vue";
  export default {
    name: 'index',
    //components: {
    //  addPage
    //},
    data () {
      return {
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          queryParamsData1:"",
          queryParamsData2 :null,
        },
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //组件传参
        propsData:{},
        //弹窗相关
        dialogType:false,
        dialogForm:{
          ip:'',
        },
        dialogRules:{
          ip: [
            { required: true, message: "请输入ip", trigger: "blur" },
            { required: true, message: "请输入ip", validator: this.spaceJudgment, trigger: "blur" },
            { required: true, message: "请输入ip", trigger: "blur", pattern:/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/, },
          ],
        },
        linkType:false,
        linkData:{
          ip:'',
        },
      }
    },
    created () {

    },
    mounted () {
      //this.getList();
    },
    methods: {
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'dateRange',[])
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          queryParamsData1:"",
          queryParamsData2 :null,
        });
        this.getList();
      },
      //获取数据列表
      getList(){
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        if(this.dateRange[0]){
          obj.startTime = this.dateRange[0]+'T00:00:00'
          obj.endTime = this.dateRange[1]+'T23:59:59'
        }else{
          obj.startTime = "";
          obj.endTime = "";
        }
        getListFunction(obj).then(response => {
          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      //操作按钮
      tableButton(type,row){
        let self = this;
        if(type == 1){
          //新增
          this.$set(this,'pageType',2);
          this.$set(this,'propsData',{});
        }else if(type == 2){
          //详情
          this.$set(this,'pageType',2);
          let obj = JSON.parse(JSON.stringify(row))
          obj.showType = true;
          this.$set(this,'propsData',obj);
        }else if(type == 3){
          //编辑
          this.$set(this,'pageType',2);
          let obj = JSON.parse(JSON.stringify(row))
          obj.showType = false;
          this.$set(this,'propsData',obj);
        }else if(type == 4){
          //删除
          this.$confirm('是否确认删除?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
          }).then(() => {
            deleteFunction({id:row.id}).then(response => {
              self.msgSuccess(response.message)
              self.getList();
            });
          }).catch(() => {});
        }else if(type == 5){
          //启用&停用
          let text = row.state  ? "停用" : "启用";
          this.$confirm('是否确认' + text + '?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
          }).then(() => {
            stateFunction({id:row.id,state:!row.state,}).then(response => {
              self.msgSuccess(response.message)
              self.getList();
            });
          }).catch(() => {});
        }else if(type == 6){
          //返回并刷新
          this.$set(this,'pageType',1);
          this.getList();
        }
      },
      //弹层关闭
      dialogOff(){
        this.$set(this,'dialogType',false);
      },
      //弹层开启
      dialogOpen(){
        this.$set(this,'dialogForm',{
          ip:'',
        });
        this.$set(this,'dialogType',true);
      },
      //弹层确定
      dialogSubmit(){
        this.$refs["dialogForm"].validate(valid => {
          if (valid) {
            this.$set(this,'linkData',JSON.parse(JSON.stringify(this.dialogForm)));
            this.$set(this,'dialogType',false);
            this.$set(this,'linkType',true);
            // this.getList();
          }
        })
      },
      breakConnection(){
        this.$confirm('是否确认中断连接?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
        }).then(() => {
          this.$set(this.linkData,'ip','');
          this.$set(this,'linkType',false);
          this.$set(this,'dataList',[]);
          this.$set(this,'total',0);
        }).catch(() => {});
      },
    },
  }
</script>
<style scoped lang="scss">
  .appLogs{
    .appLogsPage{
      .title-p{
        background: #0183FA;
        border-radius: 4px;
        padding: 0 20px;
        color: #fff;
        line-height: 40px;
      }
    }
  }
</style>
