<template>
  <div class="container">
    <!-- 查询配置 -->
    <div style="padding: 0px 20px">
      <div ref="lxHeader">
        <LxHeader icon="md-apps" text="支部旧址详情" style="margin-bottom: 10px; border: 0px; margin-top: 15px">
          <div slot="content"></div>
        </LxHeader>
      </div>
      <div class="table-tree">
        <el-table :data="tableData" :height="tableHeight" style="width: 100%">
          <el-table-column type="index" width="50" align="center" label="序号"> </el-table-column>
          <el-table-column :prop="column.field" :align="column.align" v-for="(column,index) in columns"
            :label="column.title" :width="column.width">
            <template slot-scope="scope">
              <div v-if="column.type=='opt'">
                <Button ghost size="small" @click="edit(scope.row)" type="primary"
                  style="margin-left: 10px;">编辑</Button>
              </div>
              <div v-else>{{scope.row[column.field]}}</div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>

    <el-dialog title="详情编辑" :visible.sync="dialogFormVisible" fullscreen width="90%">
      <el-form :model="form" :rules="rules" ref="form" label-position="right" :label-width="formLabelWidth">
          <el-form-item label="名称" prop="name">
            <el-input v-model="form.name" placeholder="请填写任务名称" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="地址" prop="address">
            <el-input v-model="form.address" placeholder="请填写地址" autocomplete="off"></el-input>
          </el-form-item>
          <el-row>
            <el-col :span="10">
              <el-form-item label="成立日期" prop="set_date">
                <el-date-picker style="width: 100%;" type="date" value-format="yyyy-MM-dd" v-model="form.set_date" placeholder="成立日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- // 团队预约须知,个人预约须知,团队退票须知,个人退票须知,开馆时段,坐标 -->
          <el-form-item label="开馆时间" prop="sub_title">
            <el-input type="textarea" rows="3" v-model="form.sub_title" placeholder="请填写简介" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="团队预约须知" prop="team_notice">
            <el-input type="textarea" rows="3" v-model="form.team_notice" placeholder="请填写团队预约须知" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="个人预约须知" prop="person_notice">
            <el-input type="textarea" rows="3" v-model="form.person_notice" placeholder="请填写个人预约须知" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="团队退票须知" prop="groupticket">
            <el-input type="textarea" rows="3" v-model="form.team_refund" placeholder="请填写团队退票须知" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="个人退票须知" prop="singletips">
            <el-input type="textarea" rows="3" v-model="form.person_refund" placeholder="请填写个人退票须知" autocomplete="off"></el-input>
          </el-form-item>
          <el-row>
            <el-col :span="10">
              <el-form-item label="地址经度" prop="longitude">
                <el-input v-model="form.longitude" placeholder="请填写地址经度" autocomplete="off"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10" :offset="4">
              <el-form-item label="地址纬度" prop="latitude">
                <el-input v-model="form.latitude" placeholder="请填写地址纬度" autocomplete="off"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item label="详情内容" prop="content">
            <div style="width: 99.9%;">
              <tinymce ref="tiny" v-model="form.content" :height="300" />
            </div>
          </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="resetForm('form')">取 消</el-button>
        <el-button type="primary" @click="submitForm('form')">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>
<script>
  import LxHeader from "@/components/LxHeader/index.vue";
  import Tinymce from '@/components/Tinymce'
  // import maps from 'qqmap'
  import {
    show,
    save
  } from "../../api/resource/addressinfo.js";
  export default {
    components: {
      LxHeader,
      Tinymce,
    },
    data() {
      return {
        dialogFormVisible: false,
        formLabelWidth: "120px",
        tableHeight: 0,
        tableData: [],
        form: {
          name:"支部旧址详情",
          address:"",
          sub_title:"",
          set_date: "",
          team_notice:"",
          person_notice:"",
          team_refund:"",
          person_refund:"",
          longitude:"",
          latitude:"",
          content:""
        },
        columns: [{
            field: "name",
            title: "名称",
            type: "string"
          },
          {
            field: "address",
            title: "地址",
            type: "string"
          },
          {
            field: "set_date",
            title: "成立时间",
            type: "string",
            width: 300,
            align: "center"
          },
          {
            field: "操作",
            title: "操作",
            width: 220,
            type: "opt",
          }
        ],
        rules: {
          name: [{
            required: true,
            message: '请输入基地名称',
            trigger: 'blur'
          }]
        }
      }
    },
    created() {
      this.initLoad();
      this.load();

    },
    mounted() {
    },
    methods: {

      initLoad() {
        var that = this;
        var clientHeight = document.documentElement.clientHeight
        var lxHeader_height = 96.5; //查询 头部
        var paginationHeight = 37; //分页的高度
        var topHeight = 50; //页面 头部
        let tableHeight = clientHeight - lxHeader_height - topHeight - paginationHeight - 20;
        that.tableHeight = tableHeight;

      },
      load() {
        var that = this;
        show().then(res => {
          this.tableData.push(res);
        }).catch(error => {

        })

      },
      info(obj) {
        var that = this;
        show().then(res => {
          let result = Object.assign(that.form, res);
          that.form = result;
          this.$refs.tiny.setContent(result.content);
        }).catch(error => {

        })

      },
      edit(obj) {
        this.form = this.$options.data().form;
        this.clientHeight = document.documentElement.clientHeight - 84 - 110;
        if (obj) {
          var that = this;
          that.info(obj);
        } else {}
        this.dialogFormVisible = true;
      },
      submitForm(formName) {
        var that = this;
        this.$refs[formName].validate((valid) => {
          if (valid) {
            if (that.form) {
              save(that.form).then(response => {
                console.log(response)
                this.$Message.success('操作成功');
                that.dialogFormVisible = false;
                this.tableData=[];
                that.load();
              }).catch(error => {})
            } else {}

          } else {
            this.$Message.error('数据校验失败');
            return false;
          }
        });
      },
      resetForm(formName) {
        var that = this;
        this.$refs.tiny.setContent("");
        this.$refs[formName].resetFields();
        that.dialogFormVisible = false;
      },
    }
  };
</script>
