<template>
  <div class="wrapper padding">
    <div class="card">
      <header>{{ detail.title }}</header>
      <div class="date">{{ detail.createTime }}</div>
      <div class="detail-content">{{ detail.content }}
      </div>
      <div class="photo-title">图片</div>
      <div class="photo-wrap">
        <img :src="item.url" alt=""
             v-for="(item,index) in detail.files" :key="index" @click="preview(index)">
      </div>
    </div>
    <AiGroup>
      <AiItem v-if="detail.contactPerson" label="联系人" :value="detail.contactPerson"/>
      <AiItem label="联系方式">
        <u-icon name="phone-fill" size="32" label-size="32" color="#4181FF" labelColor="#4181FF" :label="detail.phone" @click="phone"/>
      </AiItem>
      <AiItem v-if="detail.address" label="地址" :value="detail.address"/>
    </AiGroup>
    <div class="btn-wrapper" v-if="detail.openId == user.openId">
      <div class="btn" @click="unDo" hover-class="text-hover">撤销发布</div>
    </div>
    <!-- <div class="btn" @click="unDo" v-if="type==1">撤销发布</div> -->
  </div>
</template>

<script>
import {mapState} from 'vuex'

export default {
  name: "agDetail",
  appName: "农产品详情",
  data() {
    return {
      id: null,
      type: null,
      detail: {},
    }
  },
  onLoad(opt) {
    this.id = opt.id;
    this.type = opt.type;
    this.getDetail();
  },
  computed: {
    ...mapState(['user'])
  },
  methods: {
    preview(index) {
      this.$previewImage(this.detail.files, index, "url");
    },
    phone() {
      uni.makePhoneCall({
        phoneNumber: this.detail.phone
      })
    },
    unDo() {
      uni.showModal({
        title: "提示",
        content: "是否确定要撤销？",
        success: res => {
          if (res.confirm) {
            this.$instance.post("/app/appshowagriculturalproduce/delete", null, {
              params: {ids: this.id}
            }).then(ret => {
              if (ret.code == 0) {
                this.$u.toast("撤销成功");
                setTimeout(_ => {
                  uni.navigateBack();
                }, 500)
              }
            })
          }
        }
      })
    },
    getDetail() {
      this.$instance.post("/app/appshowagriculturalproduce/queryDetailById", null, {
        params: {id: this.id}
      }).then(res => {
        if (res?.data) {
          this.detail = res.data;
        }
      })
    }
  },
}
</script>

<style lang="scss" scoped>
.padding {
  padding-bottom: 156px;

  .card {
    background-color: #FFFFFF;
    margin-bottom: 24px;
    box-sizing: border-box;
    padding: 40px 32px;

    header {
      font-size: 48px;
      font-weight: 600;
      color: #333333;
      line-height: 66px;
    }

    .date {
      font-size: 30px;
      font-weight: 400;
      color: #999999;
      margin-top: 16px;
    }

    .detail-content {
      font-size: 36px;
      font-weight: 400;
      color: #333333;
      line-height: 64px;
      margin-top: 64px;
      padding-bottom: 48px;
    }

    .photo-title {
      height: 112px;
      display: flex;
      align-items: center;
      font-size: 32px;
      font-weight: 400;
      color: #999999;
    }

    .photo-wrap {
      display: flex;
      align-items: center;
      gap: 4px;
      flex-wrap: wrap;

      & > img {
        width: 225px;
        height: 225px;
      }
    }

    .item {
      display: flex;
      justify-content: space-between;
      margin-bottom: 32px;

      &:last-child {
        margin-bottom: 0;
      }

      .label {
        font-size: 32px;
        font-weight: 400;
        color: #999999;
      }

      .value {
        font-size: 32px;
        font-weight: 400;
        color: #4181FF;
      }

      .address {
        width: 480px;
        font-size: 32px;
        font-weight: 400;
        color: #333333;
        line-height: 44px;
        text-align: right;
      }
    }
  }

  .btn-wrapper {
    height: 100px;
    line-height: 100px;
  }

  .btn {
    width: 686px;
    height: 88px;
    background: #FFFFFF;
    border-radius: 16px;
    border: 1px solid #FF4466;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 34px;
    font-weight: 600;
    position: fixed;
    left: 50%;
    bottom: 32px;
    transform: translateX(-50%);
    color: #FF4466;
  }
}
</style>
