<template>
  <div class="content">
    <div class="rollback">
      <Icon
        style="font-size: 20px; cursor: pointer"
        icon="ant-design:arrow-left-outlined"
        @click="emits('closeShowInfo', false)"
      />
    </div>
    <div class="screen-div">
      <div class="screen-item">
        <div class="screen-item-label">年份</div>
        <a-select
          allowClear
          style="flex: 1"
          v-model:value="props.infoScreenData.year"
          :options="yearOptions"
          @change="(value) => emits('mapListScreenChange', value, 'year')"
        />
      </div>
      <div class="screen-item">
        <div class="screen-item-label">批次</div>
        <a-select
          allowClear
          style="flex: 1"
          v-model:value="props.infoScreenData.batch"
          :options="batchOptions"
          @change="(value) => emits('mapListScreenChange', value, 'batch')"
        />
      </div>
      <div class="screen-item">
        <div class="screen-item-label">图斑号</div>
        <a-input
          allowClear
          v-model:value="props.infoScreenData.mapNo"
          style="flex: 1"
          @change="(value) => emits('mapListScreenChange', value.target.value, 'mapNo')"
        />
      </div>
      <div class="screen-item" v-if="cityType.level === 0">
        <div class="screen-item-label">市级区划</div>
        <a-select
          disabled
          allowClear
          style="flex: 1"
          v-model:value="props.infoScreenData.countyId"
          :options="props.municipalAreaOptions"
          @change="(value) => emits('mapListScreenChange', value, 'countyId')"
        />
      </div>
      <div class="screen-item" v-if="cityType.level === 0">
        <div class="screen-item-label">县级区划</div>
        <a-select
          allowClear
          style="flex: 1"
          v-model:value="props.infoScreenData.streetId"
          :options="props.countiesAreaOptions"
          @change="(value) => emits('mapListScreenChange', value, 'streetId')"
        />
      </div>
      <div class="screen-item" v-if="cityType.level !== 0">
        <div class="screen-item-label">县级区划</div>
        <a-select
          disabled
          allowClear
          style="flex: 1"
          v-model:value="props.infoScreenData.countyId"
          :options="props.municipalAreaOptions"
          @change="(value) => emits('mapListScreenChange', value, 'countyId')"
        />
      </div>
      <div class="screen-item" v-if="cityType.level !== 0">
        <div class="screen-item-label">镇级区划</div>
        <a-select
          allowClear
          style="flex: 1"
          v-model:value="props.infoScreenData.streetId"
          :options="props.countiesAreaOptions"
          @change="(value) => emits('mapListScreenChange', value, 'streetId')"
        />
      </div>
      <div class="screen-item">
        <div class="screen-item-label">图斑类型</div>
        <a-select
          allowClear
          style="flex: 1"
          v-model:value="props.infoScreenData.mapType"
          :options="mapTypeOptions"
          @change="(value) => emits('mapListScreenChange', value, 'mapType')"
        />
      </div>
      <div class="screen-item" v-if="props.infoScreenData.mapType === 1">
        <div class="screen-item-label">违法类型</div>
        <a-select
          allowClear
          style="flex: 1"
          v-model:value="props.infoScreenData.illegalType"
          :options="illegalTypeOptions"
          @change="(value) => emits('mapListScreenChange', value, 'illegalType')"
        />
      </div>
      <div class="screen-item" v-if="props.infoScreenData.illegalType === 0">
        <div class="screen-item-label">整改措施</div>
        <a-select
          allowClear
          style="flex: 1"
          v-model:value="props.infoScreenData.measure"
          :options="measureOptions"
          @change="(value) => emits('mapListScreenChange', value, 'measure')"
        />
      </div>
      <div class="screen-item">
        <div class="screen-item-label">图斑状态</div>
        <a-select
          allowClear
          style="flex: 1"
          v-model:value="props.infoScreenData.mapStatus"
          :options="mapStatusOptions"
          @change="(value) => emits('mapListScreenChange', value, 'mapStatus')"
        />
      </div>
      <div class="screen-item">
        <div class="screen-item-label">标注类型</div>
        <a-select
          allowClear
          style="flex: 1"
          v-model:value="props.infoScreenData.markType"
          :options="markTypeOptions"
          @change="(value) => emits('mapListScreenChange', value, 'markType')"
        />
      </div>
      <div class="screen-button-div">
        <a-button type="primary" @click="dataListSort('area')">
          {{ `排序(图斑面积) ${props.infoScreenData.sort === 'area' ? orderMark() : '-'}` }}
        </a-button>
        <a-button type="primary" @click="dataListSort('gengdi_area')">
          {{ `排序(耕地面积) ${props.infoScreenData.sort === 'gengdi_area' ? orderMark() : '-'}` }}
        </a-button>
        <a-button type="primary">导出</a-button>
        <!-- <a-button
          type="primary"
          :style="openCollect && 'background: #bf0000;'"
          @click="getCollectList"
          >我的收藏</a-button
        > -->
        <a-button @click="emits('getInfoList', 1)">查询</a-button>
      </div>
    </div>
    <div class="data-list-div">
      <div
        v-if="props.infoDataList.length > 0"
        v-for="(item, index) in props.infoDataList"
        :key="index"
        class="data-list-item"
      >
        <div class="select-mark"></div>
        <Icon
          style="font-size: 30px; color: #0a6dea; cursor: pointer"
          icon="gis:poi-alt"
          @click="locationFun(item)"
        />
        <div class="data-list-item-content">
          <div class="item-info-div">
            <div class="item-info-id">{{ item.case_no }}</div>
            <div class="item-info-layout">
              <div class="item-info-batch">
                <a-tag color="processing" v-if="item.address">{{ item.address }}</a-tag>
              </div>
              <div class="item-info-batch">
                <a-tag color="success" v-if="item.case_name">{{ item.case_name }}</a-tag>
              </div>
            </div>
          </div>
          <div class="item-data-div">
            <div class="item-data-item" v-if="item.area">
              <div class="item-mark-div sum-mark">总</div>
              <div class="area-data">{{ item.area }}</div>
            </div>
            <div class="item-data-item" v-if="item.gengdi_area">
              <div class="item-mark-div plowland-mark">耕</div>
              <div class="area-data">{{ item.gengdi_area }}</div>
            </div>
            <div class="item-data-item" v-if="item.yongjiujibennongtian_area">
              <div class="item-mark-div farmland-mark">农</div>
              <div class="area-data">{{ item.yongjiujibennongtian_area }}</div>
            </div>
            <div class="item-data-item" v-if="item.zhongdianquyu_area">
              <div class="item-mark-div focus-area">重</div>
              <div class="area-data">{{ item.zhongdianquyu_area }}</div>
            </div>
            <div class="item-data-item" v-if="item.guotukongjianguihua_area">
              <div class="item-mark-div padding-mark">规</div>
              <div class="area-data">{{ item.guotukongjianguihua_area }}</div>
            </div>
            <div class="item-data-item" v-if="item.shengtaibaohuhongxian_area">
              <div class="item-mark-div adjust-mark">生</div>
              <div class="area-data">{{ item.shengtaibaohuhongxian_area }}</div>
            </div>
          </div>
        </div>
        <div class="button-div">
          <!-- <StarOutlined class="collect-button" /> -->
          <Icon
            title="飞地调整"
            style="font-size: 20px; cursor: pointer"
            icon="ant-design:send-outlined"
            @click="changeArea(item)"
          />
          <Icon
            title="详情"
            style="font-size: 20px; color: #0960bd; cursor: pointer"
            icon="bx:detail"
            @click="showInfo(item)"
          />
        </div>
      </div>
      <div v-else class="no-data">
        <a-empty :image="simpleImage" />
      </div>
    </div>
    <div class="pagination-div">
      <a-pagination
        size="small"
        v-model:pageSize="props.pageSize"
        v-model:current="props.pageNo"
        :total="props.total"
        show-size-changer
        show-quick-jumper
        @change="changePage"
      />
    </div>
    <Amend @register="registerModal" @success="handleSuccess" />
    <a-modal
      width="80%"
      v-model:open="showInfoOpen"
      title="详情"
      :footer="null"
      :maskClosable="true"
      :destroyOnClose="true"
      @cancel="showInfoOpen = false"
    >
      <div class="modal-content">
        <ShowInfoModal :showInfoData="showInfoData" />
      </div>
    </a-modal>
  </div>
</template>

<script setup lang="ts">
  import { ref, onMounted, defineEmits, defineProps, computed } from 'vue';
  import { StarOutlined } from '@ant-design/icons-vue';
  import Icon from '@/components/Icon/Icon.vue';
  import {
    addCaseFavorite,
    getFavoriteCaseList,
    deleteFavoriteCase,
  } from '@/api/bootstraps/index.ts';
  import { getLoadDroneCaseInfoDetail } from '@/api/bootstraps/index.ts';
  import {
    batchOptions,
    yearOptions,
    mapTypeOptions,
    illegalTypeOptions,
    measureOptions,
    mapStatusOptions,
    markTypeOptions,
  } from '@/views/demo/bootstraps/curbspotcity/util.ts';
  import Amend from './amend.vue';
  import { useModal } from '@/components/Modal';
  import { Empty } from 'ant-design-vue';
  import ShowInfoModal from '@/views/demo/bootstraps/curbspotcity/MapList/ShowInfoModal/index.vue';

  const [registerModal, { openModal }] = useModal();
  const simpleImage = Empty.PRESENTED_IMAGE_SIMPLE;

  const emits = defineEmits([
    'closeShowInfo',
    'mapListScreenChange',
    'changeInfoPage',
    'getInfoList',
    'changeTask',
    'infoDataListSort',
    'collectChange',
  ]);
  const props = defineProps([
    'infoScreenData',
    'cityType',
    'municipalAreaOptions',
    'countiesAreaOptions',
    'pageNo',
    'pageSize',
    'total',
    'infoDataList',
  ]);
  const order = ref(0); // 0: 不排序 1: 升序 2: 降序
  const orderMark = () => {
    switch (order.value) {
      case 0:
        return '-';
      case 1:
        return '↑';
      case 2:
        return '↓';
    }
  };
  const showInfoOpen = ref(false);
  const openCollect = computed(() => {
    if (props.infoScreenData.type === '') return false;
    return true;
  });
  const showInfoData = ref();
  onMounted(() => {
    console.log('onMounted');
  });

  async function locationFun(record) {
    console.log(record);
    emits('changeTask', record.geomid);
  }

  const changePage = (page, pageSize) => {
    console.log(page, pageSize);
    emits('changeInfoPage', page, pageSize);
  };
  const collectItem = (item) => {
    console.log(item);
    let userInfo = userStore.getUserInfo;
    let params = {
      id: item.id,
      caseNo: item.case_no,
      favoriteUserId: userInfo.id,
    };
    addCaseFavorite(params).then((res) => {
      console.log(res);
      message.success('收藏成功');
      emits('getInfoList');
    });
  };
  const cancelCollectItem = (item) => {
    deleteFavoriteCase(item.Fid).then((res) => {
      message.success('取消收藏成功');
      emits('getInfoList');
    });
  };
  const getCollectList = () => {
    let collect = props.infoScreenData.type;
    let value: number | string = '';
    if (collect === '') {
      value = 1;
    } else if (collect === 1) {
      value = '';
    }
    emits('collectChange', value);
  };
  const dataListSort = (type) => {
    order.value = (order.value + 1) % 3;
    emits('infoDataListSort', type, order.value);
  };
  const showInfo = (item) => {
    console.log(item);
    showInfoData.value = item;
    showInfoOpen.value = true;
  };
  function changeArea(record) {
    console.log(record);
    openModal(true, {
      record: record,
    });
  }
  function handleSuccess() {}
</script>

<style lang="less" scoped>
  .content {
    height: 100%;
    display: flex;
    flex-direction: column;
  }
  .screen-div {
    padding: 10px;
    background: @component-background;
    display: flex;
    width: 100%;
    flex-wrap: wrap;
    margin-top: 10px;
    .screen-item {
      width: 50%;
      display: flex;
      margin-bottom: 3px;
      .screen-item-label {
        width: 75px;
        padding-left: 10px;
        display: flex;
        align-items: center;
        font-size: 15px;
      }
    }
    .screen-button-div {
      // display: flex;
      // justify-content: space-between;
      width: 100%;
      button {
        margin: 10px 10px 0 0;
      }
    }
  }
  .data-list-div {
    flex: 1;
    overflow: auto;
    padding: 10px;
    background: @component-background;
    margin-top: 10px;
    height: 60vh;
    .data-list-item {
      display: flex;
      height: 90px;
      align-items: center;
      border-bottom: 1px solid #cdcccc;
      .select-mark {
        width: 3px;
        height: 100%;
      }
      .data-list-item-content {
        padding-left: 5px;
        width: 80%;
        .item-info-div {
          display: flex;
          align-items: center;
          margin-bottom: 5px;
          .item-info-id {
            width: 185px;
            border-radius: 11px;
            display: flex;
            align-items: center;
            // justify-content: center;
            height: 22px;
            font-weight: 500;
            font-size: 15px;
          }
          .item-info-layout {
            padding-left: 15px;
            display: flex;
            flex: 1;
            justify-content: space-between;
          }
          .item-info-address {
            // width: 120px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
          .item-info-batch {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }
        .item-data-div {
          display: flex;
          justify-content: space-between;
          .item-data-item {
            display: flex;
            align-items: center;
            border-radius: 6px 6px 0px 6px;
            border: 1px solid #dddddd;
            margin-right: 10px;
            .item-mark-div {
              width: 20px;
              height: 20px;
              color: #fff;
              border-radius: 4px 4px 0px 4px;
              display: flex;
              align-items: center;
              justify-content: center;
              margin-right: 7px;
            }
            .sum-mark {
              background: rgb(46 90 173);
            }
            .plowland-mark {
              background: #01692a;
            }
            .adjust-mark {
              background: #c06b1a;
            }
            .farmland-mark {
              background: #7d2bb1;
            }
            .focus-area {
              background: rgb(225 91 91);
            }
            .padding-mark {
              background: #36afa4;
            }
            .area-data {
              width: 55px;
            }
          }
        }
      }
      .button-div {
        flex: 1;
        width: 100%;
        height: 100%;
        display: flex;
        justify-content: space-evenly;
        font-size: 20px;
        .collect-button:hover {
          color: rgb(255, 205, 42);
        }
      }
    }
  }
  .pagination-div {
    display: flex;
    align-items: center;
    background: @component-background;
    justify-content: center;
  }
  .no-data {
    padding: 20px 0;
  }
  .rollback {
    background: @component-background;
    padding: 10px;
  }
</style>
