<!-- 外部链接 -->
<template>
  <div class="app-container externalLink">
    <div class="page-container externalLinkPage" v-if="pageType === 1">
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm"
                 :inline="true" style="width:100%;">
          <el-form-item label="" prop="searchValue">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="请输入名称"
              style="width: 200px"
            />
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
          <p class="page-add-common-style-button"
             style="float: right;"
             @click="tableButton(1)"
             v-hasPermiRouter="['system:link:add']"
          >新增</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="dataList">
          <el-table-column label="名称" prop="linkName"  show-overflow-tooltip/>
          <el-table-column label="链接地址" prop="linkUrl" width="500" show-overflow-tooltip/>
          <el-table-column label="跳转方式" prop="skipType" width="120" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{scope.row.skipType?'新窗口':'当前窗口'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="登录验证" prop="isAuth" width="120" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{scope.row.isAuth?'是':'否'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="认证方式" prop="authMode" width="120" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{scope.row.authMode==0?'无':(scope.row.authMode==1?'携参':(scope.row.authMode==2?'cookie':''))}}</span>
            </template>
          </el-table-column>
          <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="160" show-overflow-tooltip v-if="tableButtonType">
            <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)"
                   v-hasPermiRouter="['system:link:edit']"
                >编辑</p>
                <p class="table-button-p"
                   @click="tableButton(3,scope.row)"
                   v-hasPermiRouter="['system:link:del']"
                >删除</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>
    <addPage v-if="pageType == 2" :propsData="propsData"></addPage>
  </div>
</template>
<script>
  import { systemLinkList,systemLinkDelete, } from "@/api/serviceCenter/index";
  import addPage from "./addPage.vue";
  export default {
    name: 'index',
    components: {
      addPage
    },
    data () {
      return {
        tableButtonType:this.hasPermiDom(['system:link:edit','system:link:del']),
        //页面状态
        pageType:1,
        //页面遮罩
        loading:false,
        //下拉列表数据
        optionList:[{value:true,label:'启用'},{value:false,label:'停用'}],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          searchValue:"",
        },
        //时间数据
        dateRange:[],
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //组件传参
        propsData:{},
      }
    },
    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,
          searchValue:"",
        });
        this.getList();
      },
      //获取数据列表
      getList(){
        this.$set(this,'loading',true);
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        systemLinkList(obj).then(response => {
          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
          this.$set(this,'loading',false);
        });
      },
      //操作按钮
      tableButton(type,row){
        let self = this;
        if(type == 1){
          //新增
          this.$set(this,'propsData',{
            linkName:'',
            linkUrl:'',
            skipType:false,
            isAuth:false,
            reqApi:'',
            reqMethod:'post',
            paramType:'JSON',
            authMode:0,
            requestArgument:[],
            carryArgument:[],
          });
          this.$set(this,'pageType',2);
        }else if(type == 2){
          //编辑
          let params = JSON.parse(row.params)
          let obj = {
            linkId:row.linkId,
            linkName:row.linkName,
            linkUrl:row.linkUrl,
            skipType:row.skipType,
            isAuth:row.isAuth,
            authMode:row.authMode,
            paramType:row.reqMethod == 'post'?row.paramType:'',
            reqApi:row.isAuth?row.reqApi:'',
            reqMethod:row.isAuth?row.reqMethod:'',
            requestArgument:params.requestArgument,
            carryArgument:params.carryArgument,
          };
          this.$set(this,'propsData',JSON.parse(JSON.stringify(obj)));
          this.$set(this,'pageType',2);
        }else if(type == 3){
          //删除
          this.$confirm('是否确认删除?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
          }).then(() => {
            systemLinkDelete({linkId:row.linkId}).then(response => {
              self.msgSuccess(response.message)
              self.getList();
            });
          }).catch(() => {});
        }else if(type == 4){
          this.$set(this,'pageType',1);
          self.getList();
        }
      },
    },
  }
</script>
<style scoped lang="scss">
  .externalLink{
    .externalLinkPage{
    }
  }
</style>
<style lang="scss">
  .externalLink-dialog{
    .externalLink-dialog-max-big-box{
      .externalLink-dialog-big-box{
        display: flex;
        height:520px;
        .externalLink-dialog-left-box{
          width:400px;
        }
        .externalLink-dialog-center-box{
          padding-left:20px;
          width:400px;
          border-left:1px dashed #dedede;
        }
        .externalLink-dialog-right-box{
          padding-left:20px;
          width:400px;
          border-left:1px dashed #dedede;
        }
        .for-custom-parameter-max-big-box{
          display: flex;
          width:260px;
          margin-bottom:20px;
          .input-box{
            flex:1;
            border: 1px solid #999;
            border-right:none;
            border-top-left-radius:4px;
            border-bottom-left-radius:4px;
            .top-border{
              border-top:1px solid #999;
            }
            .el-input--suffix{
              border:none;
            }
            .el-input__inner{
              border:none;
            }
          }
          .del-button-box{
            display: flex;
            flex-direction: column;
            width:30px;
            background-color: #FF6666;
            border:1px solid #FF6666;
            border-top-right-radius:4px;
            border-bottom-right-radius:4px;
            cursor: pointer;
            .del-button-null{
              flex:1;
            }
            .del-button{
              line-height:83px;
              text-align: center;
              font-size:20px;
              color:#fff;
            }
          }
        }
        .add-button{
          width:260px;
          height:40px;
          line-height:40px;
          text-align: center;
          font-size:20px;
          color:#fff;
          background-color: #0183FA;
          border:1px solid #0183FA;
          border-radius:4px;
          cursor: pointer;
        }
      }
    }
  }
</style>
