<template>
  <div>
    <el-dialog title="获取账单生成历史记录（含错误信息）" v-model="dialogVisible">
      <div>
        <el-table :data="list" style="width: 100%">
          <el-table-column prop="startTime" label="账单周期">
            <template #default="{ row }">
              <div class="flex">
                <div>{{ row.startTime?.split(" ")[0] }}</div>
                <div class="mx-2">至</div>
                <div>{{ row.endTime?.split(" ")[0] }}</div>
              </div>
            </template>
          </el-table-column>

          <el-table-column prop="errMsgList" label="错误信息">
            <template #default="{ row }">
              <div v-if="row.errMsgList.length === 0">-</div>
              <div v-else v-for="(err, index) in row.errMsgList" :key="index">
                <div class="text-red-500">{{ err }}</div>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-dialog>
  </div>
</template>
<script lang="ts" setup>
import request from "@/api";
import { ref, computed, defineProps, defineEmits, watch, reactive } from "vue";
const props = defineProps({
  show: {
    type: Boolean,
    default: false
  },
  rowData: {
    type: Object,
    default: () => {}
  }
});
const emits = defineEmits(["update:show", "success"]);
const dialogVisible = computed({
  get() {
    return props.show;
  },
  set(n) {
    emits("update:show", n);
  }
});
const query = {
  page: 1,
  pageSize: 10
};
const total = ref(0);
const list = ref([]);
watch(
  () => dialogVisible.value,
  n => {
    if (n) {
      query.page = 1;
      getList();
    }
  }
);
const getList = () => {
  request
    .get("/archivesService/agency/orderBill/generateLog/paginate", {
      params: query.value
    })
    .then(resp => {
      list.value = resp.data.list.map(v => {
        return {
          ...v,
          errMsgList: JSON.parse(v.errMsg)
        };
      });
      total.value = resp.data.total;
    });
};
</script>
