<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.pic_path ? shareUrl + field.pic_path : '/static/nodata.svg'" mode="aspectFill" />
        </view>
        <view class="info">
          <view class="title">
            {{ field.name }}
          </view>
          <view class="time">
			  <view style="margin-bottom: 10rpx;">
				  <view>开放时间</view>
				  <view style="margin-top: 6rpx;">{{field.open_days}}：{{field.open_hours}}</view>
			  </view>
			 <view class="field-btn-box">
				 <button  :class="{
					close: field.order_status == '今日未开放',
					free: field.order_status == '空闲',
					full: field.order_status == '今日已满',
					can: field.order_status == '今日可约',}">
					{{field.order_status}}</button>
				 <!-- <button style="background: #00a8ea;" :disabled="field.order_status == '今日已满' || field.order_status == '未开放'">前往预约</button> -->
				 <button style="background: #00a8ea;font-weight: bolder;color:#ffffff">前往预约</button>
			 </view>
		  </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import md5 from "@/common/md5.js";
export default {
  data() {
    return {
      fieldList: [],
	  shareUrl:getApp().globalData.shareUrl,
    };
  },
  onLoad() {
    this.getMyList();
  },
  methods: {
    toDetail(index) {
      uni.navigateTo({
        url: "/pages/makeField/viewDetail?id=" + index,
      });
    },
    getMyList() {
      let md5Sign = md5(
        "method=" +
          "area" +
          "&timestamp=" +
          getApp().globalData.globalTimestamp +
          "&secret=" +
          getApp().globalData.secret
      );
      let url =
        getApp().globalData.shareUrl +
        "api/api.php" +
        "?method=area&source=area&action=list&timestamp=" +
        getApp().globalData.globalTimestamp +
        "&sign=" +
        md5Sign;
      uni.request({
        url: url,
        method: "POST",
        header: {
          "content-type": "application/x-www-form-urlencoded",
        },
        data: {
			// method:'area',
			page:'',
			page_size :''
		},
        success: (res) => {
          if (res.data.code === 200) {
            let list = res.data.data.list;
			// list.forEach((item,index)=>{
			// 	item.statusName = '空闲'
			// })
			// list[1].statusName = '今日已满';
			// list[2].statusName = '今日可约';
			this.fieldList = 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: 300;
			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;
			  };
			  .close {
			  	 background: #7f7f7f; 
				 font-weight: bolder;
			  };
			  .free {
				 background: #75e2a8; 
				 font-weight: bolder;
			  };
			  .full {
				 background: #f59a23; 
				 font-weight: bolder;
			  }
			  .can {
			  	background: #94a8ff; 
				font-weight: bolder;
			  }
		  }
        }
      }
    }
  }
}
</style>
