<template>
  <div class="flex flex-col justify-center k-app-protection-list__item van-clearfix">
    <van-cell-group clickable @click="itemClick">
      <van-cell :title="data.name">
        <template #right-icon>
          <van-button
          size="mini"
          color="#008cd6"
          type="info"
          @click.stop="updateStatus(data, '1');return false;"
          v-if="data.status != '1' && data.orgId == orgId"
          >布防时间登记</van-button
        >
        <van-button
          size="mini"
          color="#008cd6"
          type="info"
          @click.stop="updateStatus(data, '0');return false;"
          v-if="data.status != '0' && data.orgId == orgId"
          >撤防时间登记</van-button
        >
        </template>
      </van-cell>
      <van-cell title="布撤防状态" >
        <template #right-icon>
            <!-- <span v-if="data.status==1" style="color:rgb(0,164,46)">布防</span>
            <span v-else-if="data.status==0" style="color:rgb(215,0,15)">撤防</span> -->
            <span >{{getDictLabel(data.status, 'protection_status', '未上报')}}</span>
        </template>
      </van-cell>
      <van-cell
        v-if="data.status == '0' || data.status == '1'"
        :title="data.status == '0' ? '撤防时间' : '布防时间'"
        :value="data.statusUpdateTime"
      />
    </van-cell-group>
  </div>
</template>
<script>
import { mapGetters } from 'vuex'
import * as api from '@/api/protection.js'
import { Dialog } from 'vant'
import dayjs from 'dayjs'
export default {
  components: {},
  data() {
    return {}
  },
  computed: {
    ...mapGetters(['orgName', 'orgId','dictionary'])
  },
  watch: {},
  props: {
    data: {},
    statusOptions: {}
  },
  methods: {
    formatDate(dateStr) {
      return toFormatStr(dateStr)
    },
    updateStatus(data, status) {
      Dialog.confirm({
        message: `是否更新${this.getDictLabel(status, 'protection_status', '未上报')}时间？`
      })
        .then(() => {
          api.updateStatus(data.id, status).then(r => {
            if (r.data) {
              data.status = status
              data.statusUpdateTime = dayjs(r.data).format('YYYY-MM-DD HH:MM:ss')
            }
          })
        })
        .catch(() => {
          // on cancel
        })
    },
    itemClick() {
      this.$router.push('/protection/detail?id=' + this.data.id)
    }
  },
  async created() {},
  async mounted() {
    
  }
}
</script>
<style lang="scss" scoped>
.k-app-protection-list__item {
  //   height: 11.85rem;
  background: #ffffff;
  margin: 0.3rem 0.325rem 0;
  font-size: 3.733333vw;
  .top {
    // min-height: 3rem;
    padding: 0.05rem 0.05rem;
    display: flex;
    flex-direction: row;
    align-items: center;
    border-bottom: 1px solid #f3f4f5;
    > label {
      //   height: 1.38rem;
      // font-size: 1rem;
      //   line-height: 1.25rem;
      color: #323233;
      opacity: 1;
    }
  }
  .bottom {
    min-height: 7.75rem;
    padding: 0 1rem;
    span {
      height: 1.25rem;
      font-size: 0.88rem;
      line-height: 1.25rem;
      color: #000000;
      opacity: 0.61;
    }
  }
}
.wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}
</style>
