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

    <el-dialog :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xml"
        :headers="upload.headers"
        :action="
          upload.url + '?sysCode=' + upload.sysCode 
        "
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          <em>点击上传</em>
        </div>
      </el-upload>

      <a
        class="download"
        style="float: right"
        href="/数据统计格式-(补填数据时请不要修改格式，可删除样例).xlsx"
        download
        title="下载"
        >模板下载</a>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

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

export default {
  methods: {
    handleAttsSuccess(response, file, fileList) {
      let code = response.code;
      if (code === 1) {
        this.attform.attachUrl = response.url;
        this.attform.attachName = file.name;
      } else {
        this.$message.error("上传文件失败");
      }
      console.log(this.attform);
    },
    submitAttsForm(row) {
      this.upload.sysCode = row.sysCode;
      this.upload.open = open;
    },
    // 提交上传文件
    submitFileForm(row) {
      this.$refs.upload.submit();
      this.upload.open = false;
    },
  },

  mixins: [table],
  data() {
    return {
      exportData: {},
      upload: {
        // 是否显示弹出层（xml导入）
        open: false,
        // 弹出层标题（xml导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        sysCode: "",
        // 设置上传的请求头部
        // headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: "/m/supplement/importOfficeInformation",
      },

      dialogVisible: false,
      config: {
        search: [ {
            name: "sysCode",
            type: "text",
            label: "系统编码",
          },],
        exportData: {},
        columns: [
          { type: "selection", width: 60 },
          { label: "入驻系统名称", prop: "eventName" },
          { label: "入驻系统编码", prop: "sysCode" },
          { label: "申请并受理接口地址", prop: "acceptAdress" },
          { label: "审查接口地址", prop: "reviewAdress" },
          { label: "决定接口地址", prop: "decideAdress" },
          { label: "区划", prop: "compartment" },
          { label: "街道", prop: "address" },
          {
            label: "操作",
            width: 180,
            formatter: (row) => {
              return (
                <div>
                  <el-button
                    type="primary"
                    icon="el-icon-edit"
                    round
                    size="mini"
                    onClick={() => {
                      this.toEdit(row);
                    }}
                  >
                    编辑
                  </el-button>

                  <el-button
                    type="primary"
                    round
                    size="mini"
                    onClick={() => {
                      this.submitAttsForm(row);
                    }}
                  >
                    上传
                  </el-button>
                </div>
              );
            },
          },
        ],
      },
    };
  },
};
</script>