<template>
  <div class="content">
    <div class="rollback">
      <Icon
        style="font-size: 20px; cursor: pointer"
        icon="ant-design:arrow-left-outlined"
        @click="emits('changeShowParent')"
      />
    </div>
    <div class="screen-div">
      <div class="screen-item">
        <div class="screen-item-label">年份</div>
        <a-select
          allowClear
          style="flex: 1"
          v-model:value="params.year"
          :options="props.yearOptions"
        />
      </div>
      <div class="screen-item">
        <div class="screen-item-label">标注类型</div>
        <a-select
          allowClear
          style="flex: 1"
          v-model:value="params.is_build_complete"
          :options="markTypeOptions"
        />
      </div>
      <div class="screen-item">
        <div class="screen-item-label">图斑号</div>
        <a-input v-model:value="params.geomid" style="flex: 1" />
      </div>
      <div class="screen-item">
        <div class="screen-item-label">
          <a-button type="primary" @click="query">查询</a-button>
        </div>
      </div>
      <!-- <div class="screen-button-div">
        <a-button type="primary" size="small">排序(图斑面积)</a-button>
        <a-button type="primary" size="small">排序(耕地面积)</a-button>
        <a-button type="primary" size="small">导出</a-button>
        <a-button type="primary" size="small">我的收藏</a-button>
        <a-button size="small">查询</a-button>
      </div> -->
    </div>
    <div class="data-list-div">
      <div
        v-for="(item, index) in dataList"
        :key="index"
        class="data-list-item"
        v-if="dataList.length > 0"
      >
        <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-address" :title="item.address">
                <a-tag color="processing" v-if="item.address">{{ item.address }}</a-tag>
              </div>
              <div class="item-info-batch">
                <a-tag color="success">{{ item.unitname }}</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">
          <Icon
            style="font-size: 20px; color: #0960bd; cursor: pointer"
            icon="ant-design:audit-outlined"
            @click="goAudit(item)"
          />
        </div>
      </div>
      <div v-else class="no-data">
        <a-empty :image="simpleImage" />
      </div>
    </div>
    <div class="pagination-div" v-if="dataList.length > 0">
      <a-pagination
        size="small"
        :total="total"
        show-size-changer
        show-quick-jumper
        @change="changePagination"
      />
    </div>
    <a-modal
      width="100%"
      wrap-class-name="full-modal"
      v-model:open="auditOpen"
      title="审核"
      footer=""
      :destroyOnClose="true"
    >
      <template #footer> </template>
      <Audit
        ref="posRef"
        :processId="processId"
        :taskId="taskId"
        :isRead="isRead"
        :type="type"
        @closeModel="closeMolder"
      />
    </a-modal>
  </div>
</template>

<script setup lang="ts">
  import { onMounted, ref, defineEmits } from 'vue';
  import { StarOutlined } from '@ant-design/icons-vue';
  import Icon from '@/components/Icon/Icon.vue';
  import { getLoadTaskDetailList } from '@/api/bootstraps/index';
  import { flowStore } from '@/store/modules/flow';
  import { getDetail } from '@/api/sys/WFSchemeInfo';
  import { Audit } from '@/views/demo/workflow/task/process/page';
  import { Empty } from 'ant-design-vue';

  const simpleImage = Empty.PRESENTED_IMAGE_SIMPLE;
  const emits = defineEmits(['changeTask', 'changeShowParent']);

  const flowWfDataStore = flowStore();

  const props = defineProps(['areaId', 'yearOptions', 'year']);
  const processId = ref('');
  const taskId = ref('');
  const isRead: any = ref(0);
  const type = ref('');
  const auditOpen = ref(false);
  const params = ref({
    page: 1,
    limit: 10,
    level: null,
    areaid: props.areaId,
    geomid: null,
    year: props.year,
    is_build_complete: null,
  });
  const markTypeOptions = ref([
    { label: '在建', value: 0 },
    { label: '已建成', value: 1 },
    { label: '持续变化', value: 2 },
  ]);

  const dataList = ref([]);
  const total = ref(0);
  function query() {
    params.value.page = 1;
    getTaskList();
  }
  async function getTaskList() {
    console.log(params.value);
    const data = await getLoadTaskDetailList(params.value);
    dataList.value = data.items;
    total.value = data.total;
  }
  function changePagination(page, pageSize) {
    console.log(page, pageSize);
    params.value.page = page;
    params.value.limit = pageSize;
    getTaskList();
  }
  async function goAudit(record) {
    let data = await getDetail({ code: record.processcode });
    let scheme = JSON.parse(data.scheme.content);
    let wfData = scheme.wfData;
    flowWfDataStore.setWfDataAll(wfData);
    auditOpen.value = true;
    processId.value = record.processid;
    taskId.value = record.taskeid;
    type.value = record.type;
  }
  async function locationFun(record) {
    emits('changeTask', record);
  }
  onMounted(() => {
    getTaskList();
  });
</script>
<style lang="less">
  .full-modal {
    .ant-modal {
      max-width: 100%;
      top: 0;
    }

    .ant-modal-content {
      height: calc(100vh);
    }

    .ant-modal-body {
      height: 85%;
    }
  }
</style>
<style lang="less" scoped>
  .content {
    height: 100%;
    display: flex;
    flex-direction: column;
  }
  .screen-div {
    padding: 10px;
    display: flex;
    width: 100%;
    margin-top: 10px;
    flex-wrap: wrap;
    background: @component-background;
    .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%;
    }
  }
  .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 {
        height: 30px;
        width: 30px;
        display: flex;
        justify-content: space-evenly;
        font-size: 20px;
        border: 1px solid #d9d9d9;
        border-radius: 50%;
        margin-left: 20px;
        .collect-button:hover {
          color: rgb(255, 205, 42);
        }
      }
    }
  }
  .pagination-div {
    background: @component-background;
    padding: 0 10px 10px;
  }
  .no-data {
    padding: 20px 0;
  }
  .rollback {
    background: @component-background;
    padding: 10px;
  }
</style>
