<template>
  <div class="new-tab-option">
    <div class="setting-title" @click="show = !show">
      <div>按钮设置</div>
      <e class="el-icon-arrow-right" v-show="!show"></e>
      <e class="el-icon-arrow-down" v-show="show"></e>
    </div>
    <el-form size="mini" label-width="80px" v-show="show">
      <el-form-item label="按钮文字">
        <el-input v-model="option.text"></el-input>
      </el-form-item>
      <el-form-item label="文字颜色">
        <el-color-picker v-model="option.color"></el-color-picker>
      </el-form-item>
      <el-form-item label="文字大小">
        <el-input type="number" v-model="option.fontSize"></el-input>
      </el-form-item>
      <el-form-item label="按钮背景">
        <el-color-picker v-model="option.bgTop"></el-color-picker>
        <el-color-picker v-model="option.bgBottom"></el-color-picker>
      </el-form-item>
      <el-form-item label="按钮高度">
        <el-input type="number" v-model="option.btnHeight"></el-input>
      </el-form-item>
      <el-form-item label="按钮宽度">
        <el-input type="number" v-model="option.btnWidth"></el-input>
      </el-form-item>
      <el-form-item label="按钮圆角">
        <el-input type="number" v-model="option.btnRadius"></el-input>
      </el-form-item>
    </el-form>
    <div class="setting-title" @click="listShow = !listShow">
      <div>组件设置</div>
      <e class="el-icon-arrow-right" v-show="!listShow"></e>
      <e class="el-icon-arrow-down" v-show="listShow"></e>
    </div>

    <el-form label-width="100px" v-show="listShow">
      <el-form-item label="分割线宽度">
        <el-input type="number" v-model="option.lineWidth"></el-input>
      </el-form-item>
      <el-form-item label="分割线长度">
        <el-input type="number" v-model="option.lineHeight"></el-input>
      </el-form-item>
      <el-form-item label="分割线颜色">
        <el-color-picker v-model="option.lineColor"></el-color-picker>
      </el-form-item>
      <el-form-item label="文字颜色">
        <el-color-picker v-model="option.listColor"></el-color-picker>
      </el-form-item>
      <el-form-item label="文字大小">
        <el-input type="number" v-model="option.listFontSize"></el-input>
      </el-form-item>
      <el-form-item label="按钮背景">
        <el-color-picker v-model="option.listBgtop"></el-color-picker>
        <el-color-picker v-model="option.listBgbottom"></el-color-picker>
      </el-form-item>
      <el-form-item label="按钮高度">
        <el-input type="number" v-model="option.listBtnHeight"></el-input>
      </el-form-item>
      <el-form-item label="按钮宽度">
        <el-input type="number" v-model="option.listBtnWidth"></el-input>
      </el-form-item>
      <el-form-item label="按钮圆角">
        <el-input type="number" v-model="option.listBtnRudius"></el-input>
      </el-form-item>
    </el-form>

    <div class="setting-title">
      <div>组件配置</div>
      <e class="el-icon-plus" @click="add"></e>
    </div>
    <div v-for="(item, index) in option.listArr" :key="index">
      <div
        style="
          font-size: 12px;
          padding-left: 20px;
          padding-bottom: 10px;
          margin-bottom: 10px;
          border-bottom: 2px solid #ccc;
          font-weight: bold;
        "
      >
        配置项{{ index + 1 }}
        <e
          style="float: right"
          @click="remove(index)"
          class="el-icon-close"
        ></e>
      </div>
      <el-form label-width="80px">
        <el-form-item label="图片">
          <!-- <el-input type="number" v-model="item.img"></el-input> -->
          <el-upload
            action=""
            class="avatar-uploader"
            ref="upload"
            :headers="{ 'Blade-Auth': Authorization }"
            :http-request="(value) => uploadExcel(index, value)"
            :limit="1"
            :show-file-list="false"
            :disabled="item.img !== ''"
          >
            <img v-if="item.img !== ''" style="width: 50%" :src="item.img" />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="配置名称">
          <el-input type="text" v-model="item.name"></el-input>
        </el-form-item>
        <el-form-item label="配置路径">
          <el-input type="text" v-model="item.src"></el-input>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { getToken } from "@/util/auth";
import website from "@/config/website";
// import { uploadFile } from "../../views/infoAdmin/customerAdmin/index";
export default {
  name: "new-tab-option",
  props: ["option"],
  data() {
    return {
      show: true,
      listShow: true,
      Authorization: "bearer " + getToken(),
      fileList: [],
    };
  },
  methods: {
    add() {
      let obj = {
        img: "",
        name: "",
        src: "",
      };
      this.option.listArr.push(obj);
    },
    remove(index) {
      this.option.listArr.splice(index, 1);
    },
    uploadExcel(index, value) {
      const formData = new FormData();
      formData.append("file", value.file);
      uploadFile(formData).then((res) => {
        if (res.data.code == 200) {
          // this.$refs.upload.clearFiles();
          let url = website.url.replace("/dev", "");
          this.option.listArr[index].img = url + res.data.msg;
        }
      });
    },
  },
};
</script>
<style lang="scss">
</style>
