<template>
  <div class="bgColor">
    <div slot="content" class="scroll-wrapper">
      <div class="demo">
        <!-- <div class="header">留言列表</div> -->
        <cube-select
          class="stateSearch"
          v-model="searchType"
          :options="searchsType"
          @change="stateChange()"
        ></cube-select>
        <div class="scroll-list-wrap">
          <cube-scroll
            ref="scroll"
            :data="items"
            :options="options"
            @pulling-down="onPullingDown"
            @pulling-up="onPullingUp"
          >
            <div class="conentBox">
              <div class="conent" v-for="item in items">
                <div class="top" @click="operation(item)">
                  <div class="head">
                    <p>
                      <i class="iconfont dsit-icon-test2 newPapir"></i>
                      来源：{{item.uud}}
                      <span :class="{'btn':true,'isValid':item.isValid==0,'noValid':item.isValid==1}">{{item.isValid==0?'有效':'无效'}}</span>
                    </p>
                  </div>
                  <div class="center">
                    <p class="desc">
                      <span class="fl">留言电话：</span>
                      <span class="grayFont">{{item.ano}}</span>
                    </p>
                  </div>
                  <div class="bottom">
                    <span class="fl">处理状态: {{item.isExcute==0?'未处理':'已处理'}}</span>
                    <span class="fr">留言时间：{{item.recTime}}</span>
                  </div>
                </div>
                <div class="oper" v-show="operShow&&operId==item.id">
                    <a class="operItem" href="javascript:;" v-if="item.isExcute==0" @click="toNewIncident(item.ano,item.id)">
                        <i class="iconfont dsit-bianji2"></i>
                        <span>新建事件</span>
                    </a>
                    <a class="operItem" href="javascript:;" v-if="item.isExcute==0" @click="changeValid(item)">
                        <i class="iconfont dsit-false-circle"></i>
                        <span>无效</span>
                    </a>
                    <a class="operItem" href="javascript:;" @click="showAudio(item.recFileName)">
                        <i class="iconfont dsit-huifang"></i>
                        <span>回放</span>
                    </a>
                    <a class="operItem" :href="'tel:'+item.ano">
                        <i class="iconfont dsit-huibo"></i>
                        <span>回拨</span>
                    </a>
                </div>
              </div>
              <div class="wushuju" v-show="wushuju">
                <img src="./../../static/images/quesheng.png" alt>
                <p>暂无留言</p>
              </div>
            </div>
            <template v-if="customPullDown" slot="pulldown" slot-scope="props">
              <div
                v-if="props.pullDownRefresh"
                class="cube-pulldown-wrapper"
                :style="props.pullDownStyle"
              >
                <div
                  v-show="props.beforePullDown"
                  class="before-trigger"
                  :style="{paddingTop: props.bubbleY + 'px'}"
                >
                  <span :class="{rotate: props.bubbleY > pullDownRefreshThreshold - 80}">↓</span>
                </div>
                <div class="after-trigger" v-show="!props.beforePullDown">
                  <div v-show="props.isPullingDown" class="loading">
                    <cube-loading></cube-loading>
                  </div>
                  <div v-show="!props.isPullingDown" class="text">
                    <span class="refresh-text">更新成功</span>
                  </div>
                </div>
              </div>
            </template>
          </cube-scroll>
        </div>
      </div>
    </div>
    <load-ing v-show="!items.length&&!wushuju"></load-ing>
    <div class="mask" v-if="audioMask" @click="hideAudio()">
      <audio controls autoplay="autoplay" id="bgMusic">
        <source :src="audioSrc" type="audio/mpeg">
      </audio>
    </div>
  </div>
</template>
<script>
import Vue from "vue";
import CubePage from "../components/cube-page.vue";
import SwitchOption from "../components/switch-option";
import InputOption from "../components/input-option";
import SelectOption from "../components/select-option";
import { formatDate } from "./../components/js/date.js";
import LoadIng from "./../views/loading.vue";
import http from "../request/http"
export default {
  data() {
    return {
      loginUser: JSON.parse(localStorage.getItem("loginUser")),
      items: [],
      pullDownRefresh: true,
      pullDownRefreshThreshold: 60,
      pullDownRefreshStop: 40,
      pullDownRefreshTxt: "Refresh success",
      pullUpLoad: true,
      pullUpLoadThreshold: 0,
      pullUpLoadMoreTxt: "加载更多",
      pullUpLoadNoMoreTxt: "没有更多数据",
      customPullDown: true,
      wushuju: false,
      audioSrc:'',//音频路径
      audioMask:false,//音频
      searchsType: [
        {
          text: "全部",
          value: "全部"
        },
        {
          text: "主校区",
          value: "主校区"
        },
        {
          text: "同济校区",
          value: "同济校区"
        },
        {
          text: "校园卡",
          value: "校园卡"
        }
      ],
      searchType: "全部",
      sum: 10,
      idx: 0,
      loadShow: true,
      operShow:false,//是否展示操作区域
      operId:'',//当前点击操作区域的id
    };
  },
  components: {
    CubePage,
    SwitchOption,
    InputOption,
    SelectOption,
    LoadIng
  },
  computed: {
    options() {
      return {
        pullDownRefresh: this.pullDownRefreshObj,
        pullUpLoad: this.pullUpLoadObj,
        scrollbar: true
      };
    },
    pullDownRefreshObj: function() {
      return this.pullDownRefresh
        ? {
            threshold: parseInt(this.pullDownRefreshThreshold),
            txt: this.pullDownRefreshTxt
          }
        : false;
    },
    pullUpLoadObj: function() {
      return this.pullUpLoad
        ? {
            threshold: parseInt(this.pullUpLoadThreshold),
            txt: {
              more: this.pullUpLoadMoreTxt,
              noMore: this.pullUpLoadNoMoreTxt
            }
          }
        : false;
    }
  },
  methods: {
    // 筛选
    stateChange() {
      var that = this;
      this.loadShow = true;
      that.items = [];
      that.idx = 0;
      that.sum = 10;
      that.getData();
    },
    // 获取列表数据
    getData() {
      var that = this;
      var postData=that.searchType=='全部'?{idx: that.idx,
          sum: that.sum,
          hjzxRecord:{}}:{idx: that.idx,
          sum: that.sum,
          hjzxRecord:{uud:that.searchType}};
      http.bpmFetchDataList('hjzxRecord',postData)
        .then(function(res) {
          if (res.data.list.length > 0) {
            that.wushuju = false;
            for (var i = 0; i < res.data.list.length; i++) {
              res.data.list[i].recTime = formatDate(
                new Date(res.data.list[i].recTime),
                "yyyy-MM-dd hh:mm"
              );
            }
            that.items = that.items.concat(res.data.list);
          } else if(res.data.list.length <= 0) {
            that.wushuju = true;
          }
          that.loadShow = false;
        });
    },
    // 展开操作区域
    operation(data) {
      if(data.id==this.operId){
        this.operShow=!this.operShow;
      }else{
        this.operShow=true;
      }
      this.operId=data.id;
    },
    // 新建事件
    toNewIncident(tel,id){
      this.$router.push({name:'NewIncident',params:{
        tel:tel,
        recordId:id
      }})
    },
    // 点击无效
    changeValid(data){
      var that=this;
      http.recordChangeValid({id:data.id,isValid:1,isExcute:1,field1:1})
      .then(function(res){
        if(res.data.status==200){
          that.dialog = that
            .$createDialog({
              type: "alert",
              title: "该信息状态更改为无效",
              content: "",
              onConfirm: (e, promptValue) => {
                that.$router.go(0)
              }
            }).show();
        }
      })
    },
    // 播放音频
    showAudio(src){
      this.audioMask=true;
      this.audioSrc=http.host+src;
    },
    // 隐藏音频组件
    hideAudio(){
      this.audioMask=false;
    },
    onPullingDown() {
      var that = this;
      that.idx = 0;
      that.sum = 10;
      that.items = [];
      setTimeout(() => {
        that.getData();
      }, 1000);
    },
    onPullingUp() {
      var that = this;
      that.idx = that.idx + 1;
      that.getData();
    },
    updatePullDownRefresh(val) {
      this.pullDownRefresh = val;
    },
    updatePullDownRefreshThreshold(val) {
      this.pullDownRefreshThreshold = val;
    },
    updatePullDownRefreshTxt(val) {
      this.pullDownRefreshTxt = val;
    },
    updatePullUpLoad(val) {
      this.pullUpLoad = val;
    },
    updatePullUpLoadThreshold(val) {
      this.pullUpLoadThreshold = val;
    },
    updatePullUpLoadMoreTxt(val) {
      this.pullUpLoadMoreTxt = val;
    },
    updatePullUpLoadNoMoreTxt(val) {
      this.pullUpLoadNoMoreTxt = val;
    },
    updateCustomPullDown(val) {
      this.customPullDown = val;
    },
    rebuildScroll() {
      Vue.nextTick(() => {
        this.$refs.scroll.destroy();
        this.$refs.scroll.initScroll();
      });
    }
  },
  created() {
    var that = this;
    // this.getParamsState();
    this.getData();
  }
};
</script>
<style lang="stylus" rel="stylesheet/stylus" scoped>
.scroll-list-wrap {
  /* height: 350px */
  height: 87vh;
  /* border: 1px solid rgba(0, 0, 0, 0.1) */
  border-radius: 5px;
  transform: rotate(0deg); // fix 子元素超出边框圆角部分不隐藏的问题
  overflow: hidden;
  padding-top: .88rem;
}

.foods-wrapper {
  .food-item {
    display: flex;

    /* padding: 18px */
    /* border-bottom: 1px solid rgba(7, 17, 27, 0.1) */
    /* border-top: 1px solid rgba(7, 17, 27, 0.1)!important */
    &:last-child {
      border-none();
      margin-bottom: 0;
    }

    .icon {
      flex: 0 0 57px;
      margin-right: 10px;
    }

    .food-content {
      flex: 1;

      .name {
        margin: 2px 0 8px 0;
        height: 14px;
        line-height: 14px;
        font-size: 14px;
        color: rgb(7, 17, 27);
      }

      .description, .extra {
        line-height: 10px;
        font-size: 10px;
        color: rgb(147, 153, 159);
      }

      .description {
        line-height: 12px;
        margin-bottom: 8px;
      }

      .extra {
        .count {
          margin-right: 12px;
        }
      }

      .price {
        font-weight: 700;
        line-height: 24px;

        .now {
          margin-right: 8px;
          font-size: 14px;
          color: rgb(240, 20, 20);
        }

        .old {
          text-decoration: line-through;
          font-size: 10px;
          color: rgb(147, 153, 159);
        }
      }

      .cartcontrol-wrapper {
        position: absolute;
        right: 0;
        bottom: 12px;

        .scroll-wrapper {
          .cube-pulldown-wrapper {
            .before-trigger {
              font-size: 30px;
              line-height: 30px;
              align-self: flex-end;

              span {
                display: inline-block;
                transition: all 0.3s;
                color: #666;

                &.rotate {
                  transform: rotate(180deg);
                }
              }
            }

            .after-trigger {
              .refresh-text {
                color: grey;
              }
            }
          }
        }
      }
    }
  }
}
</style>
<style lang='less' scoped>
.cont {
  margin-top: 1.86rem;
}
.scroll-list-wrap {
  // padding-top: .88rem;
}
// .header {
//   width: 100%;
//   height: 0.88rem;
//   line-height: 0.88rem;
//   text-align: center;
//   color: #fff;
//   font-size: 0.37rem;
//   background: linear-gradient(#2e2f32, #414246);
//   position: fixed;
//   top: 0;
//   z-index: 6;
// }

.mask{
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  background: rgba(0,0,0,.5);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stateSearch {
  width: 100%;
  position: fixed;
  // top: 0.88rem;
  z-index: 6;
}
.bgColor {
  background-color: white;
}
.food-item {
  border-top: 0.16rem rgb(238, 238, 238) solid;
}
.food-content {
  border-top: 0.01rem rgb(223, 222, 222) solid;
  border-bottom: 0.01rem rgb(223, 222, 222) solid;
}
.cube-select {
  height: 0.88rem;
  line-height: 0.88rem;
  padding: 0 0.24rem;
  font-size: 0.36rem;
  color: #333333;
  border-bottom: 0.08rem solid #e5e5e5;
}
.title {
  display: flex;
  justify-content: space-between;
  height: 0.7rem;
  line-height: 0.7rem;
  border-top: 0.01rem rgb(223, 222, 222) solid;
  padding: 0 0.24rem;
  border-bottom: 0.01rem rgb(223, 222, 222) solid;
}
.title i {
  font-size: 0.32rem;
  color: #005395;
}
.title div:nth-child(1) {
  font-size: 0.32rem;
}
.title div:nth-child(1) span {
  display: inline-block;
  margin-left: 0.08rem;
}
.title div:nth-child(2) {
  padding: 0.05rem 0.3rem;
  /* border: 0.01rem rgb(0,0,255) solid; */
  border-radius: 16px;
  /* color: rgb(0,0,255); */
  height: 0.25rem;
  line-height: 0.25rem;
  margin-top: 0.15rem;
  font-size: 0.24rem;
}
.weishouli {
  color: #991f00;
  border: 0.01rem #991f00 solid;
  background-color: #f4e8e5;
}
.bushouli {
  color: #666666;
  background-color: #eeeeee;
  border: 0.01rem #666666 solid;
}
.chulizhong {
  color: #003057;
  background-color: #e5eaee;
  border: 0.01rem #003057 solid;
}
.daipingjia {
  color: #825b00;
  background-color: #f2eee5;
  border: 0.01rem #825b00 solid;
}
.yijiejue {
  color: #40a19c;
  background-color: #ebf5f5;
  border: 0.01rem #40a19c solid;
}
.yichehui {
  color: #48a843;
  background-color: #ecf6ec;
  border: 0.01rem #48a843 solid;
}
// .conent {
//   font-size: 0.28rem;
//   line-height: 0.39rem;
//   overflow: hidden;
//   display: -webkit-box;
//   -webkit-line-clamp: 2;
//   -webkit-box-orient: vertical;
//   word-break: break-all;
//   padding: 0 0.64rem;
//   margin: 0.24rem 0;
// }
.timeBox {
  display: flex;
  justify-content: space-between;
  font-size: 0.24rem;
  color: #999999;
  border-top: 0.01rem rgb(223, 222, 222) solid;
  height: 0.7rem;
  line-height: 0.7rem;
  padding: 0 0.24rem 0 0.64rem;
}
.wushuju {
  margin-top: 2.4rem;
  text-align: center;
  color: #999;
}
.wushuju img {
  height: 1.68re;
}
.conentBox {
  width: 100%;
  height: 100%;
  .conent {
    font-size: 0.32rem;
    font-weight: 400;
    line-height: 0.45rem;
    border-bottom: 0.16rem solid #e5e5e5;
    .head {
      border-bottom: 0.01rem solid #e6e6e6;
      p {
        padding: 0.24rem 0.48rem;
        i {
          color: #00559d;
        }
        .btn {
          float: right;
        }
      }
    }
    .center {
      color: #333333;
      border-bottom: 0.01rem solid #e6e6e6;
      padding: 0.24rem 0.48rem;
      p {
        &.desc{
        overflow: hidden;
        max-height: .88rem;
        }
        .grayFont {
          overflow-x: scroll;
          color: #666;
        }
      }
    }
    .bottom {
      overflow: hidden;
      line-height: 0.86rem;
      border-bottom: 0.01rem solid #e6e6e6;
      font-size: 0.24rem;
      color: #999;
      padding: 0 0.24rem 0 0.48rem;
    }
    .oper{
        width: 100%;
        height: 1.56rem;
        display: flex;
        justify-content: space-around;
        align-items: center;
        .operItem{
            text-align: center;
            color: #01559d;
            .iconfont{
              font-size: .5rem;
            }
            span{
                display: block;
            }
        }
    }
  }
}
</style>