<template>
  <div class="FuneralList">
    <div class="top">
      <AiCard>
        <template #custom>
          <div class="left">
            <span class="nums"> {{ allNums }} </span>
            <span class="hint">全部丧礼</span>
          </div>

          <div class="right">
            <span class="nums">{{ addNums }}</span>
            <span class="hint">本月新增</span>
          </div>
        </template>
      </AiCard>
    </div>

    <template v-if="datas.length > 0">
      <AiCard v-for="(item, i) in datas" :key="i">
        <template #custom>
          <div class="names">
            <span>事主姓名</span>
            <span class="right">{{ item.name }}</span>
          </div>

          <div class="phones">
            <span>联系方式</span>
            <span class="right">{{ item.phone }}</span>
          </div>

          <div class="times">
            <span>上报时间</span>
            <span class="right" v-if="item.createTime">{{ item.createTime.substring(0, item.createTime.length - 3) }}</span>
          </div>

          <div class="areaNames" v-if="item.address">
            <span>上报地点</span>
            <span class="right">{{ item.address }}</span>
          </div>

          <div class="contents" v-if="item.content">
            <span>上报内容</span>
            <span class="right">{{ item.content }}</span>
          </div>

          <div class="imgs">
            <img :src="e.url" alt="" v-for="(e, i) in item.files" :key="i" @click.stop="previewImage(item.files, e.url)" />
          </div>

          <span class="types" :style="{ background: item.type == 0 ? '#FF65B8' : item.type == 1 ? '#FF883C' : '#1AAAFF' }">
            {{ $dict.getLabel('marriageType', item.type) }}
          </span>

          <span class="types" v-if="item.modeType" :style="{ background: item.modeType == 0 ? '#42D784' : '#1AAAFF' }" style="margin-left: 16px">
            {{ $dict.getLabel('modeType', item.modeType) }}
          </span>
        </template>

        <template #menu>
          <div class="menu" @tap.stop="toDetele(item)">删除</div>
        </template>
      </AiCard>
    </template>

    <AiEmpty description="暂无数据" v-else></AiEmpty>

    <u-modal v-model="deletShow" content="您确认要删除该条信息吗？" :show-cancel-button="true" :mask-close-able="true" :show-title="false" @confirm="delet"></u-modal>
  </div>
</template>

<script>
export default {
  name: 'FuneralList',
  components: {},
  props: {},
  data() {
    return {
      data: [],
      datas: [],
      current: 1,
      deletShow: false,
      deletId: '',
      current: 1,
      total: '',
      allNums: '',
      addNums: '',
    }
  },
  computed: {},
  watch: {},
  onLoad() {
    this.$dict.load('marriageType', 'modeType').then(() => {
      this.getCount()
      this.getList()
    })
  },
  onShow() {
    document.title = '婚丧嫁娶'
  },
  methods: {
    getCount() {
      uni.showLoading({
        title: '加载数据中',
      })
      this.$http.post('/app/appmarriagefuneralinfo/queryDataStatistics').then((res) => {
        if (res.code == 0) {
          this.data = res.data
          this.allNums = res.data[3].v1
          this.addNums = res.data[7].v1
          uni.hideLoading()
        }
      })
    },

    getList() {
      uni.showLoading({
        title: '加载数据中',
      })
      this.$http
        .post('/app/appmarriagefuneralinfo/list', null, {
          params: {
            size: 6,
            current: this.current,
            type: 1,
            personType: 0,
          },
        })
        .then((res) => {
          if (res.code == 0) {
            this.datas = this.current > 1 ? [...this.datas, ...res.data.records] : res.data.records
            this.total = res.data.total
            uni.hideLoading()
          }
        })
    },

    toDetele(item) {
      this.deletShow = true
      this.deletId = item.id
    },

    delet() {
      this.$http.post(`//app/appmarriagefuneralinfo/delete?ids=${this.deletId}`).then((res) => {
        if (res.code == 0) {
          this.$u.toast('删除成功！')
          this.getList()
        }
      })
    },

    previewImage(images, img) {
      uni.previewImage({
        urls: images.map((v) => v.url),
        current: img,
      })
    },
  },
  onReachBottom() {
    this.current = this.current + 1
    this.getList()
  },
}
</script>

<style scoped lang="scss">
.FuneralList {
  height: 100%;
  .top {
    .AiCard {
      background: #f3f6f9;
      ::v-deep .start {
        background: #fff;
        .fill {
          display: flex;
          align-items: center;
          padding: 38px 0;
          .left,
          .right {
            width: 50%;
            display: flex;
            flex-direction: column;
            align-items: center;
            .nums {
              font-size: 64px;
              font-weight: bold;
              color: #3192f4;
            }
            .hint {
              font-size: 28px;
              font-weight: 500;
            }
          }
        }
      }
    }
  }

  ::v-deep .AiCard {
    background: #f3f6f9;
    .start {
      display: flex;
      align-items: center;
      background: #fff;
      padding: 32px 32px 36px 32px;
      border-radius: 16px;
      .names,
      .phones,
      .times,
      .areaNames,
      .contents {
        display: flex;
        margin-top: 8px;
        .right {
          width: 76%;
          margin-left: 32px;
          font-size: 26px;
          color: #333333;
          word-break: break-all;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
        }
      }
      .contents {
        .right {
          -webkit-line-clamp: 3;
        }
      }

      .imgs {
        margin-top: 8px;

        img {
          width: 32%;
          height: 204px;
          margin-right: 8px;
        }

        img:nth-child(3n) {
          margin-right: 0;
        }
      }
      .types {
        display: inline-block;
        margin-top: 32px;
        border-radius: 8px;
        padding: 4px 8px;
        color: #fff;
      }
    }
    .mask {
      .moreMenu {
        transform: translate(-175px, 20px);
        .menu {
          text-align: center;
          line-height: 80px;
          width: 192px;
          height: 80px;
          font-size: 28px;
          font-weight: 400;
          color: #333333;
        }
      }
    }
  }
}
</style>
