<template>
  <view class="content">
    <view class="supplyList">
      <view
        class="supplyCard"
        v-for="(field, i) in fieldList"
        :key="i"
		 @tap="toDetail(field.id)"
      >
        <view class="image_content">
          <image :src="field.image" mode="aspectFill" />
        </view>
        <view class="info">
          <view class="title">
            {{ field.title }}
          </view>
          <view class="time">
			  <view>
				  <view>开放时间</view>
				  <view style="margin-top: 6rpx;">周一至周五：08:00~17:00</view>
			  </view>
			 <view class="field-btn-box">
				 <button>今日已满</button>
				 <button style="background: #00a8ea;">前往预约</button>
			 </view>
		  </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import md5 from "@/common/md5.js";
export default {
  data() {
    return {
      fieldList: [],
	  statusObj:{
		  '1':'空闲',
		  '2':'今日已满',
		  '3':'今日可约'
	  }
    };
  },
  onLoad() {
    this.getMyList();
  },
  methods: {
    toDetail(index) {
      uni.navigateTo({
        url: "/pages/makeField/viewDetail?id=" + '13',
      });
    },
    getMyList() {
      let md5Sign = md5(
        "method=" +
          "need" +
          "&timestamp=" +
          getApp().globalData.globalTimestamp +
          "&secret=" +
          getApp().globalData.secret
      );
      let url =
        getApp().globalData.shareUrl +
        "api/api.php" +
        "?method=need&source=need&action=list&timestamp=" +
        getApp().globalData.globalTimestamp +
        "&sign=" +
        md5Sign;
      let postData = {
        s_type: this.index == 2 ? 1 : 2,
      };
      uni.request({
        url: url,
        method: "POST",
        header: {
          "content-type": "application/x-www-form-urlencoded",
        },
        data: this.index == -1 || this.index == 0 ? {} : postData,
        success: (res) => {
          if (res.data.code === 200) {
            let list = res.data.data.list;
            /* 
                supplyList: new Array(5).fill({
                image: "/static/supply/u1779.png",
                title: "移动式空气消毒机",
                time: "2021-08-30 14:50:00",
                state: 1,
                }),
                
       */
            this.fieldList = list.map((item) => {
              let ob = {
                image: "",
                title: "",
                time: "",
                state: "",
                id: "",
              };
              ob.id = item.id;
              ob.title = item.title;
              let time = this.$options.filters["globalTime"](item.addtime);
              let timeSecond = this.$options.filters["globalTimeSecond"](
                item.addtime
              );
              ob.time = time + " " + timeSecond;
              ob.state = item.type;
           //   ob.image = "/static/nodata.svg";
              ob.image = item.attach_list[0]
                ? getApp().globalData.shareUrl + item.attach_list[0]
                : "/static/nodata.svg";
              return ob;
            });
            // console.log(res.data.data.list);
          }
        },
        fail: () => {
          console.log("连接失败");
        },
      });
    },
  },
};
</script>

<style lang="scss" scope>
.active {
  color: $uni-color-primary;
}
.content {
  font-size: 32rpx;
  margin: 0 5%;
  .supplyList {
    .supplyCard {
      display: flex;
      width: 92%;
      margin: 3% 0;
      padding: 2% 4%;
      height: 5%;
      border-radius: 30rpx;
      box-shadow: rgba(100, 100, 111, 0.2) 0rpx 14rpx 50rpx 0rpx;
      .image_content {
        margin-right: 5%;
		display: flex;
		align-items: center;
        image {
			width: 300rpx;
			height: 265rpx;
			object-fit: cover;
			border-radius: 6rpx;
			background-color: #e4e4e4;
        }
      }
      .info {
		width: 100%;
        display: flex;
        flex-flow: column;
		justify-content: space-between;
        // justify-content: space-around;
		.title {
			width: 100%;
			text-overflow: -o-ellipsis-lastline;
			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-line-clamp: 2;
			line-clamp: 2;
			-webkit-box-orient: vertical;
			font-size: 32rpx;
		}
        .time {
			font-weight: 100;
			font-size: 24rpx;
			color: #7f7f7f;
			height: 60%;
			display: flex;
			flex-direction: column;
			justify-content: space-around;
			margin-top: 20rpx;
		  .field-btn-box {
			  display: flex;
			  justify-content: space-between;
			  align-items: center;
			  button{
				background: #95f204;
				color: #fff;
				font-size: 18rpx;
				margin: 0;
			  };
		  }
        }
      }
    }
  }
}
</style>
