<template>
  <div class="fruit3">
    <div class="content">
      <div
        class="card"
        @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>
    <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 { Dialog, Toast } from "vant";
Vue.use(Dialog).use(Toast);

export default {
  name: "fruit3",
  data() {
    return {
      list: [],
    };
  },
  created() {
    this.list = this.$route.query.convertibleInfoList;
  },
  methods: {
    change(val) {
      this.list.map((item) => {
        if (item.id == val.id) {
          if (item.useState == 0) {
            item.useState = 2;
          } else {
            item.useState = 0;
          }
        }
      });
    },
    ensure() {
      Dialog.confirm({
        message: "确定提货吗？",
      }).then(() => {
        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 && fruitsList.length > 0) {
          let data = {
            fruitsList: fruitsList,
            qrCode: this.$route.params.qrCode,
            supplyCode: this.$route.params.code,
            uid: "",
            userMobile: "",
            userName: "",
          };
          offlineConfirmPickUpGoods(data).then(() => {
            this.$router.replace({
              name: "Fruit6",
              query: this.$route.params.qrCode,
            });
          });
        } else {
          Toast.fail("至少选择一项！");
        }
      });
    },
  },
};
</script>

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

  .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;
  }

  .card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff;
    margin: 10px;
    border-radius: 10px;

    .left {
      display: flex;
      align-items: center;
    }

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

      .name {
        font-size: 50px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
      }

      .num {
        font-size: 50px;
        color: #EB4E3F;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
      }
    }
  }

  .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;
    }
  }
}
</style>