<template>
  <page-head title="getCurrentPages"></page-head>
  <view class="uni-padding-wrap">
    <button class="btn btn-get-page-style" type="default" @click="getPageStyle">getPageStyle</button>
    <button class="btn btn-set-page-style-1" type="default" @click="setPageStyle(true)">setPageStyle(true)</button>
    <button class="btn btn-set-page-style-0" type="default" @click="setPageStyle(false)">setPageStyle(false)</button>
    <text class="page-style">当前 PageStyle</text>
    <text class="page-style-value">{{pageStyleText}}</text>
    <text class="status">状态：</text>
    <view class="status-list">
      <text>enablePullDownRefresh: {{enablePullDownRefreshStatus}}</text>
    </view>
    <text class="tips">当前版本仅支持设置属性 enablePullDownRefresh</text>
  </view>
</template>

<script>
  class Page {
    constructor(public route : string) {
    }
  }

  export default {
    data() {
      return {
        checked: false,
        pages: [] as Page[],
        currentPageStyle: {} as UTSJSONObject,
        // TODO
        enablePullDownRefreshStatus: true
      }
    },
    computed: {
      pageStyleText() : string {
        return JSON.stringify(this.currentPageStyle)
      }
    },
    onLoad() {
      const pages = getCurrentPages();
      const currentPage = pages[pages.length - 1];
      this.currentPageStyle = currentPage.getPageStyle();
      this.enablePullDownRefreshStatus = this.currentPageStyle["enablePullDownRefresh"] as boolean
    },
    onPullDownRefresh() {
      setTimeout(() => {
        uni.stopPullDownRefresh()
      }, 3000)
    },
    methods: {
      getPageStyle() {
        const pages = getCurrentPages();
        const currentPage = pages[pages.length - 1];
        this.currentPageStyle = currentPage.getPageStyle();
      },
      setPageStyle(enable : boolean) {
        // 目前仅支持 enablePullDownRefresh
        const pages = getCurrentPages();
        const currentPage = pages[pages.length - 1];
        currentPage.setPageStyle({
          enablePullDownRefresh: enable
        });
        this.enablePullDownRefreshStatus = enable
      },
      startPullDownRefresh() {
        uni.startPullDownRefresh()
      }
    },
  }
</script>


<style>
  .btn {
    margin-top: 10px;
  }

  .page-style {
    margin-top: 15px;
  }

  .page-style-value {
    margin-top: 5px;
    padding: 5px;
    background-color: #fff;
    width: 100%;
    /* #ifdef WEB */
    overflow-wrap: break-word;
    /* #endif */
  }

  .status {
    margin-top: 20px;
  }

  .status-list {
    margin-top: 5px;
  }

  .tips {
    font-size: 12px;
    margin-top: 15px;
    opacity: .8;
  }
</style>
