<template>
  <div class="div_page_bg">
    <div class="div_content">
      <!--      <van-pull-refresh v-model="refreshing" @refresh="onRefresh">-->
      <van-list v-model="loading"
                :finished="finished"
                finished-text="没有更多了"
                @load="onLoad">
        <break-rules-item v-for="data in breakRulesList"
                          :key="data.id"
                          :data="data"></break-rules-item>
      </van-list>
      <!--      </van-pull-refresh>-->
    </div>
    <!--    <van-button type="primary" size="small" style="position: absolute;top: 0" @click="submit">提交</van-button>-->
  </div>
</template>

<script>
import BreakRulesItem from "../../../components/crm/breakRulesItem";
import { getDecorateApplyList, selectDecorationBreakRule } from "../../../service/getData";
export default {
  name: "breakRulesList",
  components: { BreakRulesItem },
  data () {
    return {
      activeName: '',
      decorationId: '',
      refreshing: false,
      loading: false,
      finished: true,
      searchForm: {
        userId: localStorage.getItem("memberId"),
      },
      breakRulesList: [],
    }
  },
  beforeRouteLeave (to, from, next) {
    try {
      EbeiPlugins.cleanNavigationRightButton();
      EbeiPlugins.setBackButtonAction('');
    } catch (e) {

    }
    next()
  },
  created () {

    this.decorationId = this.$route.query.decorationId;
    this.$toast.loading({
      message: '加载中...',
      duration: 0,
      forbidClick: true
    });
    this.selectDecorationBreakRuleJS();
    try {
      EbeiPlugins.setNavigationRightButtons([{ 'name': '新增', 'script': 'add()' }]);
    } catch (e) {

    }
    let that = this;
    window['add'] = () => {
      that.submit();
    };
  },

  methods: {
    selectDecorationBreakRuleJS () {
      let that = this;
      let path = [this.decorationId];
      selectDecorationBreakRule(path, this.searchForm).then(res => {
        that.$toast.clear();
        that.refreshing = false;
        that.loading = false;
        if (res.status == 200) {
          that.breakRulesList = res.data
          // if (that.decorateLists.length == res.data.total) {
          //   that.finished = true;
          // } else {
          //   that.finished = false;
          // }

        } else {
          // that.finished = true;
        }
      }).catch(error => {

      })
    },

    onRefresh () {
      this.currentIndex = 1;
      this.decorateLists = [];
      this.selectDecorationBreakRuleJS();
    },
    onLoad () {
      this.currentIndex++;
      this.selectDecorationBreakRuleJS();
    },
    submit () {
      this.$router.push({
        path: 'decorateOperate',
        query: {
          type: 2,
          decorationId: this.decorationId
        }
      })
    }

  }
}
</script>

<style scoped>
.div_page_bg {
  width: 100%;
  height: 100vh;
  background-color: rgba(252, 252, 252, 1);
}

.div_content {
  height: calc(100vh);
  overflow-y: auto;
  /*background-color: white;*/
  /*border-radius: 7px;*/
}
.div_content_title {
  display: flex;
  flex-direction: row;
  margin: 20px 20px 20px 20px;
  background-color: white;
}
</style>
