<template>
  <div>
    <Modal title="历史沿革" footer-hide :width="64" v-model="isShow">
      <Button
        type="primary"
        style="margin-bottom: 10px"
        @click="
          $refs['addHistory'].setRow(row),
            $refs['addHistory'].setType('add'),
            $refs['addHistory'].show()
        "
        >新增记录</Button
      >
      <xy-table
        :btn-width="120"
        style="width: 100%"
        :auths="['delete', 'edit']"
        :height="360"
        :is-page="false"
        ref="xyTable"
        :list="list"
        :table-item="table"
        @delete="destroy"
        @editor="
          (row1) => {
            $refs['addHistory'].setId(row1.id),
             $refs['addHistory'].setType('editor');
            $refs['addHistory'].setRow(row);
            $refs['addHistory'].show();
          }
        "
      ></xy-table>
    </Modal>

    <addHistory ref="addHistory" @refresh="getList"></addHistory>
  </div>
</template>

<script>
import { index, destroy } from "@/api/system/baseForm";

import addHistory from "@/views/assets/component/addHistory.vue";
export default {
  components: {
    addHistory,
  },
  data() {
    return {
      id: "",
      isShow: false,
      row: {},

      list: [],
      table: [
        {
          prop: "fashengshijian",
          label: "发生时间",
          width: 200
        },
        {
          prop: "mianjitiaozheng",
          label: "面积调整",
          width: 200,
          align: "left",
        },
        {
          prop: "qitashuoming",
          label: "其他说明",
          width: 220,
          align: "left",
        },
        {
          prop: "zichanlaiyuan",
          label: "资产来源",
          width: 220,
          align: "left",
        },
      ],
    };
  },
  methods: {
    setRow(row) {
      this.row = row;
    },
    show() {
      this.isShow = true;
    },
    hide() {
      this.isShow = false;
    },
    setId(id) {
      if (typeof id === "number") {
        this.id = id;
        this.select.filter[0].value = id;
      }
    },
    async destroy (row) {
      await destroy({
        id: row.id,
        table_name: 'his_evolutions'
      })
      await this.getList()
    },

    async getList () {
      const res = await index({
        table_name: 'his_evolutions',
        page: 1,
        page_size: 9999,
        filter: [
          {
            key: /\/land/g.test(this.$route.path) ? 'land_id' : 'house_id',
            op: 'eq',
            value: this.row.id
          }
        ]
      })
      this.list = res.data;
    },
  },
  computed: {},
  watch: {
    isShow(newVal) {
      if (newVal) {
        this.getList();
      }
    },
  },
};
</script>

<style scoped lang="scss"></style>
