<template>
  <div class="page">
    <LayoutTable :data="tableData" :config="tableConfig" notSearch />
  </div>
</template>

<script>
import table from "@/assets/mixins/table";

export default {
  mixins: [table],
  created() {
    const { basicsId } = this.$route.query;
    this.config.addQuery = { basicsId: basicsId };
  },
  methods: {
    beforeRender(data) {
      return data;
    },

    formterApplyStr(arrs) {
      let temp = [];
      for (let i = 0; i < arrs.length; i++) {
        let str = "";
        str += i + 1 + ": " + arrs[i].content + "\n";
        temp.push(str);
      }

      return temp.join("");
    },
  },
  data() {
    return {
      config: {
        search: [],
        columns: [
          { type: "selection", width: 60 },
          { label: "模板标题", prop: "title", width: 200 },
          {
            label: "申请条件",
            prop: "content",
            formatter: (row) => {
              let content = this.formterApplyStr(JSON.parse(row.content));

              return <span style="white-space: pre-wrap">{content}</span>;
            },
          },

          {
            label: "操作",
            width: 180,
            formatter: (row) => {
              return (
                <div>
                  <el-button
                    type="primary"
                    icon="el-icon-edit"
                    round
                    size="mini"
                    onClick={() => {
                      this.toEdit(row);
                    }}
                  >
                    编辑
                  </el-button>
                </div>
              );
            },
          },
        ],
      },
    };
  },
};
</script>