<template>
  <div class="wrap">
    <div class="title" v-if="activeInfo.id">
      <i class="el-icon-setting"></i>
      <div class="text">{{ activeInfo.name }}-配置项</div>
    </div>
    <div class="content" v-if="activeInfo.id">
      <template>
        <div class="chunk">
          <div class="chunkTitle">宽度设置: （{{ activeInfo.width }}%）</div>
          <div class="btn">
            <el-slider
              v-model="activeInfo.width"
              :max="100"
              :min="10"
            ></el-slider>
          </div>
        </div>
        <div class="chunk">
          <div class="chunkTitle">
            是否居中:
            <el-checkbox v-model="activeInfo.alignCenter"></el-checkbox>
          </div>
        </div>
        <div class="chunk">
          <div class="btn resize">
            <el-button
              type="primary"
              icon="el-icon-refresh-left"
              @click="resizeActiveWidth"
              size="mini"
              >还原默认</el-button
            >
          </div>
        </div>
      </template>
    </div>
    <!-- <div class="chunk">
          {{ elementList }}
        </div> -->
    <div class="lookView" v-if="elementList.length">
      <div class="btnChunk">
        <el-button
          type="primary"
          icon="el-icon-view"
          @click="viewHanlde"
          size="mini"
          >预览</el-button
        >
      </div>
      <div class="btnChunk">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          @click="cleanHanlde"
          >清空</el-button
        >
      </div>
      <div class="btnChunk">
        <el-button
          :loading="submitLoading"
          type="success"
          icon="el-icon-plus"
          size="mini"
          @click="submitHanlde"
          >提交</el-button
        >
      </div>
    </div>
  </div>
</template>

<script>
import { mapActions, mapGetters, mapMutations } from "vuex";
import _ from "lodash";
// import { SaveMyWidgetAPI } from "@/api/apis/layOutAuth.js";
export default {
  data() {
    return {
      submitLoading: false,
    };
  },
  computed: {
    ...mapGetters(["elementList", "activeInfo", "mouseenterInfo"]),
  },
  methods: {
    // 提交
    async submitHanlde() {
      this.submitLoading = true;
      let tempArr = _.cloneDeep(this.elementList).map((item) => {
        this.$delete(item, "component");
        return item;
      });
      const res = await SaveMyWidgetAPI(JSON.stringify(tempArr));
      this.submitLoading = false;
      if (res.code == 1) {
        this.$message({
          type: "success",
          message: "保存成功！",
        });
        this.$router.push({ name: "Index" });
      }
    },
    //清空组件
    cleanHanlde() {
      this.$confirm("确定清空组件？")
        .then((_) => {
          this.CLEAN_ELEMENT_LIST();
        })
        .catch((_) => {});
    },
    //还原选中模块宽度
    resizeActiveWidth() {
      this.RESIZE_ACTIVE_WIDTH();
    },
    ...mapMutations("dropIndex", ["RESIZE_ACTIVE_WIDTH", "CLEAN_ELEMENT_LIST"]),
    //点击预览
    viewHanlde() {
      this.$emit("viewHanlde");
    },
  },
};
</script>

<style scoped lang='scss'>
.wrap {
  background-color: #fff;
  padding: 10px;
  width: 100%;
  height: 100%;
  position: relative;
  > .title {
    display: flex;
    align-items: center;
    .text {
      font-size: 14px;
      margin-left: 10px;
    }
  }
  > .content {
    margin-top: 20px;
    > .chunk {
      margin: 10px 0;
      width: 100%;
      > .chunkTitle {
        font-size: 14px;
      }
      > .btn {
        width: 90%;
        margin: 0 auto;
      }
      > .resize {
        display: flex;
        justify-content: flex-end;
      }
    }
  }
  > .lookView {
    position: absolute;
    bottom: 10px;
    display: flex;
    .btnChunk {
      flex: 1;
      margin-right: 2px;
    }
  }
}
</style>
