<template>
  <div>
    <div class="search-wrapper">
      <el-form
        :inline="true"
        :model="searchForm"
        class="search_form"
        style="text-align: left"
      >
        <el-form-item label="地点名称">
          <el-input
            v-model="searchForm.name"
            placeholder="请输入地点名称"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-upload
            action="#"
            :http-request="uploadSubmit"
            :limit="1"
            ref="upload"
            :show-file-list="false"
          >
            <el-button type="primary">批量导入 </el-button>
          </el-upload>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="addAddress">新增地点</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="medium">
      <div class="table-wrapper leftTree">
        <el-tree
          :data="treeData"
          :props="defaultProps"
          @node-click="handleNodeClick"
        ></el-tree>
      </div>
      <div class="table-wrapper rightTable">
        <table-template
          :tableData="tableData"
          :tableColumns="tableColumns"
          :loading="loading"
          :pagination="pagination"
          @Jump="jumpPage"
          :indexShow="true"
        >
          <el-table-column slot="icon" label="服务图标" align="center">
            <template slot-scope="scope">
              <el-image
                style="width: 30px; height: 30px"
                :src="scope.row.icon"
                :preview-src-list="[scope.row.icon]"
              >
              </el-image>
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            label="操作"
            width="350"
            align="center"
          >
            <template slot-scope="scope">
              <el-button
                type="success"
                size="mini"
                class="btn"
                round
                @click="view(scope.row)"
                >编辑</el-button
              >
              <el-popconfirm
                title="确定删除此数据吗？"
                @confirm="del(scope.row)"
              >
                <el-button type="warning" size="mini" round slot="reference"
                  >删除</el-button
                >
              </el-popconfirm>
            </template>
          </el-table-column>
        </table-template>
      </div>
    </div>
    <el-dialog title="编辑" :visible.sync="dialogVisible" width="30%">
      <el-form
        :model="dataForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="服务名称" prop="name">
          <el-input v-model="dataForm.name"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import TableTemplate from "@/components/Table";

export default {
  components: { TableTemplate },

  data() {
    return {
      searchForm: {},
      TypeList: [],
      loading: false,
      tableData: [
        {
          name: "便利店",
          sort: "1",
        },
      ],
      tableColumns: [
        {
          key: "name",
          label: "地点名称",
        },

        {
          key: "type",
          label: "地点类型",
        },
        {
          key: "lng",
          label: "经度",
        },
        {
          key: "lat",
          label: "纬度",
        },
        {
          key: "address",
          label: "详细地址",
        },
        {
          key: "icon",
          label: "照片",
          type: "slot",
        },
        {
          key: "phone",
          label: "联系电话",
        },
        {
          key: "openTime",
          label: "开店时间",
        },
        {
          key: "closeTime",
          label: "闭店时间",
        },
      ],
      pagination: {
        total: 0,
        pageSize: 10,
        currentPage: 1,
      },
      rules: {
        name: [{ required: true, message: "请输入活动名称", trigger: "blur" }],
      },
      dataForm: {},
      dialogVisible: false,
      defaultProps: {
        children: "children",
        label: "label",
      },
      treeData: [
        {
          label: "一级 1",
          children: [
            {
              label: "二级 1-1",
              children: [
                {
                  label: "三级 1-1-1",
                },
              ],
            },
          ],
        },
        {
          label: "一级 2",
          children: [
            {
              label: "二级 2-1",
              children: [
                {
                  label: "三级 2-1-1",
                },
              ],
            },
            {
              label: "二级 2-2",
              children: [
                {
                  label: "三级 2-2-1",
                },
              ],
            },
          ],
        },
        {
          label: "一级 3",
          children: [
            {
              label: "二级 3-1",
              children: [
                {
                  label: "三级 3-1-1",
                },
              ],
            },
            {
              label: "二级 3-2",
              children: [
                {
                  label: "三级 3-2-1",
                },
              ],
            },
          ],
        },
      ],
    };
  },
  watch: {
    dialogVisible(val) {
      if (!val) {
        this.$refs.ruleForm.resetFields();
      }
    },
  },
  created() {
    this.init();
  },
  methods: {
    init() {},
    onSubmit() {},
    jumpPage() {
      this.init();
    },
    view() {
      this.dialogVisible = true;
    },
    del() {},
    // 新增地点
    addAddress() {},
    uploadSubmit(file) {
      let formData = new FormData();
      formData.append("file", file.file);
      // importAlgorithm(formData)
      //   .then((res) => {
      //     if (res.success) {
      //       this.$message.success("导入成功");
      //       this.$refs.upload.clearFiles();
      //     } else {
      //       this.$message.warning(res.errMsg || "导入失败");
      //       this.$refs.upload.clearFiles();
      //     }
      //   })
      //   .catch(() => {
      //     this.$message.warning("导入失败");
      //     this.$refs.upload.clearFiles();
      //   })
      //   .finally(() => {
      //     this.init();
      //   });
    },
    handleNodeClick(data) {
      console.log(data);
    },
  },
};
</script>

<style lang="stylus" scoped>
@import '~@/stylus/common';
.btn{
    margin-right 10px
}
.medium{
  display flex
  .leftTree{
    background #fff !important
    width 280px

    margin-right 15px
  }
  .rightTable{
    flex-grow 1
  }
}
</style>
