<template>
  <div class="fruit7">
    <div class="content">
      <div
        :class="['card', item.useState == 0 ? 'select' : 'unselect']"
        @click="change(item)"
        v-for="(item, index) in list"
        :key="index"
      >
        <div
          class="left"
          style="display: flex; align-items: center; height: 125px"
        >
          <div class="selectimg" style="margin: 0 10px">
            <img v-if="item.useState == 0" src="./images/4-5.png" alt="" />
            <img v-else src="./images/4-4.png" alt="" />
          </div>
          <div class="fruitimg" style="margin: 0 10px">
            <img
              style="width: 100px; height: 100px"
              :src="item.fruitsPicture"
              alt=""
            />
          </div>
          <div class="title">
            <div class="name">{{ item.fruitsName }}</div>
            <div
              class="amount"
              style="
                width: 130px;
                display: flex;
                align-items: center;
                justify-content: space-between;
              "
            >
              <div class="num" style="color: #eb4e3f">{{ item.weight }}kg</div>
              <div class="count" style="color: #999999; font-size: 16px">
                数量：1
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="card disable" v-for="(item, index) in list1" :key="index">
        <div
          class="left"
          style="display: flex; align-items: center; height: 125px"
        >
          <div class="selectimg" style="margin: 0 10px">
            <img src="./images/4-4.png" alt="" />
          </div>
          <div class="fruitimg" style="margin: 0 10px">
            <img
              style="width: 100px; height: 100px"
              :src="item.fruitsPicture"
              alt=""
            />
          </div>
          <div class="title">
            <div class="name">{{ item.fruitsName }}</div>
            <div
              class="amount"
              style="
                width: 130px;
                display: flex;
                align-items: center;
                justify-content: space-between;
              "
            >
              <div class="num" style="color: #eb4e3f">{{ item.weight }}kg</div>
              <div class="count" style="color: #999999; font-size: 16px">
                数量：1
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="bottom">
      <div class="operation" @click="ensure">确认提货</div>
      <div class="safe-area"></div>
    </div>
  </div>
</template>

<script>
import { offlineConfirmPickUpGoods } from "@/api/fruit.js";
import Vue from "vue";
import { Toast } from "vant";

Vue.use(Toast);

export default {
  name: "fruit7",
  data() {
    return {
      list: [],
      list1: [],
    };
  },
  created() {
    this.list = this.$route.query.convertibleInfoList.filter((item) => {
      if (item.useState == 0 || item.useState == 2) {
        return item;
      } else if (item.useState == 1) {
        this.list1.push(item);
      }
    });
  },
  methods: {
    change(val) {
      this.list.map((item) => {
        if (item.id == val.id) {
          if (item.useState == 0) {
            item.useState = 2;
          } else {
            item.useState = 0;
          }
        }
      });
    },
    ensure() {
      let fruitsList = this.list
        .filter((item) => {
          if (item.useState == 0) {
            return item;
          }
        })
        .map((ele) => {
          return {
            fruitsCode: ele.fruitsCode,
            id: ele.id,
            weight: ele.weight,
            extractOrder: ele.sort,
          };
        });
      if (fruitsList.length > 0 && fruitsList) {
        let params = {
          fruitsList,
          qrCode: this.$route.params.qrCode,
          supplyCode: this.$route.params.code,
          uid: "",
          userMobile: "",
          userName: "",
        };
        offlineConfirmPickUpGoods(params).then(() => {
          this.$router.replace({
            name: "Fruit6",
            query: this.$route.params.qrCode,
          });
        });
      } else {
        Toast.fail("至少选择一项！");
      }
    },
  },
};
</script>

<style lang="stylus" scoped>
.fruit7 {
  height: 100vh;
  display: flex;
  flex-direction: column;

  .content {
    box-sizing: border-box;
    padding-bottom: constant(safe-area-inset-bottom);
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(100vh - 100px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .card {
    display: flex;
    width: 90%;
    justify-content: space-between;
    align-items: center;
    background: #fff;
    margin: 10px 0;

    .left {
      display: flex;
      align-items: center;
      font-size: 50px;

      .title {
        height: 180px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
      }
    }
  }

  .unselect {
    font-size: 50px;
  }

  .disable {
    background: url('./images/4-1.png');
    font-size: 50px;
  }

  .bottom {
    display: flex;
    flex-direction: column;
    position: fixed;
    bottom: 0;
    width: 100%;
    left: 0px;
    box-sizing: border-box;
    padding-bottom: constant(safe-area-inset-bottom);
    padding-bottom: env(safe-area-inset-bottom);

    .operation {
      width: 100%;
      background: #EB4E3F;
      font-size: 40px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #fff;
      line-height: 100px;
      text-align: center;
      margin-top: 20px;
    }
  }
}
</style>