<template>
  <view class="commit-box">
    <u-empty text="没有找到未评价的课程信息" font-size="36" mode="list" v-if="g.length == 0 "></u-empty>
    <view
      v-if="g.length > 0"
      style="height: 100vh;width: 100vw;overflow: hidden;padding:0 0 10px 0;"
    >
      <scroll-view
        :scroll-y="true"
        @scrolltolower="lower"
        :enable-back-to-top="true"
        :enable-flex="true"
        :scroll-top="scrollTop"
        @scroll="scroll"
        style="height: 100%; padding-bottom: 0px;"
      >
	  
        <view class="good-list" v-if="g.length>0">
          <view class="good-item" v-for="(x, i) in g" :key="i">
            <image class="good-pic" :src="x.CoverImage" mode="aspectFit" />
            <view class="right-box">
              <view class="good-info">
                <view class="good-name">{{x.GoodsName}}</view>
              </view>
              <view class="op-box">
                <u-button
                  size="mini"
                  ripple
                  plain
                  shape="circle"
                  :custom-style="{color:mc,borderColor:mc}"
                  @click="goCommit(x)"
                >评价</u-button>
              </view>
            </view>
          </view>
        </view>
        <u-loadmore
          v-if="showLoading"
          :status="status"
          :load-text="loadText"
          :font-size="24"
          :margin-top="20"
          :margin-bottom="20"
          bg-color="#F5F5F5"
        />
      </scroll-view>
    </view>
    <!-- <view class="quick" v-if="!loading">
      <view class="item">
        <u-icon name="cart-o" size="48" color="#333" />
      </view>
      <view class="item" @click="goTop">
        <u-icon name="arrow-up" size="48" color="#333" />
      </view>
    </view>-->
	<auth v-if="showAuth" @changeuserinfo="reloadUserinfo" @gbAuth='gbAuth'></auth>
  </view>
</template>

<script>
	import auth from "@/components/auth/index.vue";
export default {
	components: {
		auth
	},
  data() {
    return {
      pageTitle: "课程评论",
      loading: false,
      g: [],
      showLoading: false,
      loadText: {
        loadmore: "轻轻上拉，加载更多",
        loading: "努力加载中",
        nomore: "没有更多评价课程了",
      },
	  showAuth:false,
      status: "loadmore",
      scrollTop: 0,
      old: {
        scrollTop: 0,
      },
      mc: "",
      secondary: "",
      msg: {
        pageIndex: 1,
        pageSize: 10,
        IsComment: 2,
        GoodsName: "",
        OrderNo: "",
		OrderClassify:2,
      },
      page_count: 0,
      isover: false,
    };
  },
  onShow() {
    this.msg.pageIndex = 1;
    this.g = [];
    console.log(this.g)
	this.u = uni.getStorageSync("mall_UserInfo");
	if (!this.u) {
		this.u = {
			nickName: "未登录",
			avatarUrl: ""
		};
		this.showAuth = true;
	} else {
		this.init();
	}
    
    
  },
  mounted() {
	  let currentPages = getCurrentPages();
	  let u = "/" + currentPages[currentPages.length - 1].route;
	  let pages = uni.getStorageSync("basedata")
	    ? uni.getStorageSync("basedata").bar_title
	    : [];
	  pages.forEach((x) => {
	    if (x.value == u) {
	      this.pageTitle = x.new_name ? x.new_name : x.name;
	    }
	  });
    uni.setNavigationBarTitle({
      title: this.pageTitle,
    });
    this.mc = this.$uiConfig.mainColor;
    this.secondary = this.$uiConfig.secondary;
  },
  methods: {
	  reloadUserinfo() {
	  	this.u = uni.getStorageSync("mall_UserInfo");
	  	// this.showAuth=false;
	  	this.init();
	  },
	  //关闭登录窗口
	  gbAuth() {
	  	uni.navigateBack()
	  },
    scroll(e) {
      this.old.scrollTop = e.detail.scrollTop;
    },
    goCommit(x) {
      let msg = {
        GoodsId: x.GoodsId,
        OrderDetailId: x.OrderDetailId,
        GoodsName: x.GoodsName,
        CoverImage: x.CoverImage,
      };
      uni.navigateTo({
        url:
          "/pages/school/personal/order-commit-details?param=" +
          encodeURIComponent(JSON.stringify(msg)),
        fail: function (e) {
          console.log(e);
        },
      });
    },
    goTop(e) {
      this.scrollTop = this.old.scrollTop;
      this.$nextTick(function () {
        this.scrollTop = 0;
      });
    },
    init() {
      this.isover = false;
      this.loading = true;
      this.showLoading = this.msg.pageIndex != 1;
      this.request2(
        {
          url: "/api/AppletOrder/GetAppletGoodsWaitCommentPageList",
          data: this.msg,
        },
        (res) => {
          this.isloading = false;
          if (res.resultCode == 1) {
            this.g = this.g.concat(res.data.pageData);
            this.page_count = res.data.pageCount;
            if (this.page_count == 1) {
              this.isover = true;
              this.status = "nomore";
            } else {
              this.status = "loadmore";
            }
			
          }
          uni.hideNavigationBarLoading();
        }
      );
    },
    lower(e) {
      if (this.msg.pageIndex < this.page_count) {
        this.status = "loading";
        this.msg.pageIndex++;
        this.init();
      } else {
        this.isover = true;
        this.status = "nomore";
      }
    },
  },
};
</script>

<style>
.commit-box {
  background: #faf8f9;
  height: 100vh;
  position: relative;
}
.commit-box .quick {
  right: 50rpx;
  bottom: 50rpx;
  position: absolute;
}

.commit-box .quick .item {
  background: #fff;
  border: 1px solid #aaa;
  height: 90rpx;
  width: 90rpx;
  color: #333;
  border-radius: 90rpx;
  margin-top: 40rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}
.commit-box .good-list {
}
.commit-box .good-list .good-item {
  margin-top: 10px;
  background: #fff;
  padding: 10px;
  border-radius: 10px;
  display: flex;
}
.commit-box .good-list .good-item .good-pic {
  width: 232rpx;
  height: 128rpx;
  margin-right: 15px;
  border-radius: 5px;
}
.commit-box .good-list .good-item .right-box {
  width: 1px;
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 128rpx;
}
.commit-box .good-list .good-item .right-box .good-info {
  flex: 1;
  width: 100%;
  height: 1px;
}
.commit-box .good-list .good-item .right-box .op-box {
  text-align: right;
  height: 25px;
}
.commit-box .good-list .good-item .right-box .good-info .good-name {
  font-size: 27rpx;
  color: #333;
  text-overflow: -o-ellipsis-lastline;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 5px;
}
.commit-box .good-list .good-item .right-box .good-info .good-attr {
  text-align: left;
}
</style>