<template>
  <div>
    <!--    <el-form-item :label="i18nt('designer.setting.dsEnabled')"><el-switch v-model="optionModel.dsEnabled"></el-switch></el-form-item>
        <el-form-item v-if="optionModel.dsEnabled" :label="i18nt('请求访问')">
          <el-input
            class="search-input"
            max="200"
            v-model="optionModel.accessName"
            @clear="
              optionModel.accessCode = '';
              $forceUpdate();
            "
            v-el-readonly
            clearable
          >
            <i slot="suffix" class="el-input__icon el-icon-search" @click="showRequestaccessDialog = true"></i>
          </el-input>
        </el-form-item>-->
    <el-form-item :label="i18nt('背景颜色')">
      <el-color-picker v-model="optionModel.echarPieOption.backgroundColor"></el-color-picker>
    </el-form-item>
    <el-form-item :label="i18nt('饼图样式')">
      <el-select v-model="optionModel.echarPieOption.series[0].radius">
        <el-option label="实心饼图" :value="'70%'"></el-option>
        <el-option label="空心饼图" :value="['40%', '70%']"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="自定义图表配置" label-width="150px">
      <a href="javascript:void(0);" class="a-link link-oneLind"
         @click="editEventHandler('echartConfig', ['dataId', 'formCode'])">
        <span>{{ optionModel.echartConfig }}</span>
        <i class="el-icon-edit"></i>
      </a>
    </el-form-item>
    <el-form-item label-width="0">
      <el-divider class="custom-divider-margin-top">标题设置</el-divider>
    </el-form-item>
    <el-form-item :label="i18nt('显示标题')">
      <el-switch v-model="optionModel.echarPieOption.title.show"></el-switch>
    </el-form-item>
    <el-form-item :label="i18nt('标题')">
      <el-input v-model="optionModel.echarPieOption.title.text"></el-input>
    </el-form-item>
    <!-- <el-form-item :label="i18nt('字体颜色')"><el-color-picker v-model="optionModel.echarPieOption.title.textStyle.color"></el-color-picker></el-form-item> -->
    <!-- <el-form-item :label="i18nt('字体粗细')">
      <el-select v-model="optionModel.echarPieOption.title.textStyle.fontWeight">
        <el-option label="正常" value="normal"></el-option>
        <el-option label="粗体" value="bold"></el-option>
        <el-option label="特粗体" value="bolder"></el-option>
        <el-option label="细体" value="lighter"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item :label="i18nt('字体大小')"><base-input-number :scale="0" v-model="optionModel.echarPieOption.title.textStyle.fontSize"></base-input-number></el-form-item> -->
    <el-form-item :label="i18nt('背景颜色')">
      <el-color-picker v-model="optionModel.echarPieOption.title.backgroundColor"></el-color-picker>
    </el-form-item>
    <el-form-item :label="i18nt('字体位置')">
      <el-select v-model="optionModel.echarPieOption.title.left">
        <el-option label="居中" value="center"></el-option>
        <el-option label="左对齐" value="left"></el-option>
        <el-option label="右对齐" value="right"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item :label="i18nt('副标题')">
      <el-input v-model="optionModel.echarPieOption.title.subtext"></el-input>
    </el-form-item>
    <!-- <el-form-item :label="i18nt('字体颜色')"><el-color-picker v-model="optionModel.echarPieOption.title.subtextStyle.color"></el-color-picker></el-form-item>
    <el-form-item :label="i18nt('字体粗细')">
      <el-select v-model="optionModel.echarPieOption.title.subtextStyle.fontWeight">
        <el-option label="正常" value="normal"></el-option>
        <el-option label="粗体" value="bold"></el-option>
        <el-option label="特粗体" value="bolder"></el-option>
        <el-option label="细体" value="lighter"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item :label="i18nt('字体大小')"><base-input-number :scale="0" v-model="optionModel.echarPieOption.title.subtextStyle.fontSize"></base-input-number></el-form-item> -->

    <el-form-item label-width="0">
      <el-divider class="custom-divider-margin-top">数值设定</el-divider>
    </el-form-item>
    <el-form-item :label="i18nt('显示数值')">
      <el-switch v-model="showSeriesLabel"></el-switch>
    </el-form-item>
    <el-form-item :label="i18nt('字体大小')">
      <base-input-number :scale="0" v-model="optionModel.echarPieOption.series[0].label.fontSize"></base-input-number>
    </el-form-item>
    <el-form-item :label="i18nt('颜色')">
      <el-color-picker v-model="optionModel.echarPieOption.series[0].label.color"></el-color-picker>
    </el-form-item>
    <el-form-item :label="i18nt('字体粗细')">
      <el-select v-model="optionModel.echarPieOption.series[0].label.fontWeight">
        <el-option label="正常" value="normal"></el-option>
        <el-option label="粗体" value="bold"></el-option>
        <el-option label="特粗体" value="bolder"></el-option>
        <el-option label="细体" value="lighter"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item :label="i18nt('数值位置')">
      <el-select v-model="optionModel.echarPieOption.series[0].label.position">
        <el-option label="外侧" value="outside"></el-option>
        <el-option label="内侧" value="inside"></el-option>
        <el-option label="中心" value="center"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item :label="i18nt('数值格式')">
      <el-input v-model="optionModel.echarPieOption.series[0].label.formatter"></el-input>
    </el-form-item>
    注：{b}：数据名。{c}：数据值。{d}：百分比。

    <el-form-item label-width="0">
      <el-divider class="custom-divider-margin-top">提示语设置</el-divider>
    </el-form-item>
    <!-- <el-form-item :label="i18nt('字体大小')"><base-input-number :scale="0" v-model="optionModel.echarPieOption.tooltip.textStyle.fontSize"></base-input-number></el-form-item> -->
    <el-form-item :label="i18nt('网格线颜色')">
      <el-color-picker v-model="optionModel.echarPieOption.tooltip.borderColor"></el-color-picker>
    </el-form-item>

    <el-form-item label-width="0">
      <el-divider class="custom-divider-margin-top">图例操作</el-divider>
    </el-form-item>
    <el-form-item :label="i18nt('显示图例')">
      <el-switch v-model="optionModel.echarPieOption.legend.show"></el-switch>
    </el-form-item>
    <!-- <el-form-item :label="i18nt('字体颜色')"><el-color-picker v-model="optionModel.echarPieOption.legend.textStyle.color"></el-color-picker></el-form-item>
    <el-form-item :label="i18nt('字体大小')"><base-input-number :scale="0" v-model="optionModel.echarPieOption.legend.textStyle.fontSize"></base-input-number></el-form-item> -->
    <el-form-item :label="i18nt('图例宽度')">
      <base-input-number :scale="0" v-model="optionModel.echarPieOption.legend.itemWidth"></base-input-number>
    </el-form-item>
    <el-form-item :label="i18nt('横向位置')">
      <el-select v-model="optionModel.echarPieOption.legend.left">
        <el-option label="左对齐" value="left"></el-option>
        <el-option label="右对齐" value="right"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item :label="i18nt('纵向位置')">
      <el-select v-model="optionModel.echarPieOption.legend.top">
        <el-option label="顶部" value="top"></el-option>
        <el-option label="底部" value="bottom"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item :label="i18nt('布局前置')">
      <el-select v-model="optionModel.echarPieOption.legend.orient">
        <el-option label="竖排" value="horizontal"></el-option>
        <el-option label="横排" value="vertical"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label-width="0">
      <el-divider class="custom-divider-margin-top">自定义配色</el-divider>
    </el-form-item>
    <draggable tag="ul" class="draggable-box" :list="optionModel.echarPieOption.color"
               v-bind="{ group: 'optionsGroup', ghostClass: 'ghost', handle: '.el-icon-s-operation' }">
      <li v-for="(colorItem, index) in optionModel.echarPieOption.color" :key="index">
        <i class="el-icon-s-operation"></i>
        <el-color-picker v-model="optionModel.echarPieOption.color[index]"></el-color-picker>
        <!-- {{colorItem}} -->
        <el-button circle plain size="mini" type="danger" @click="deleteColor(index)" icon="el-icon-minus"
                   class="col-delete-button"></el-button>
      </li>
    </draggable>
    <el-button type="text" @click="addColor" icon="el-icon-circle-plus-outline" class="add-option">
      {{ i18nt('designer.setting.addOption') }}
    </el-button>
    <requestaccessDialog
      v-if="showRequestaccessDialog"
      :visiable.sync="showRequestaccessDialog"
      @confirm="confirmInsertRequestaccess"
      multi="false"
      :param="{ reportCode: reportTemplate.reportCode }"
    />
  </div>
</template>

<script>
import i18n from '../../../../../../components/xform/utils/i18n';
import Draggable from 'vuedraggable';
import requestaccessDialog from '../../../../../../views/user/form/report_requestaccess/dialog.vue';
import eventMixin from "@base/components/xform/form-designer/setting-panel/property-editor/event-handler/eventMixin";

export default {
  name: 'echart-pie-editor',
  mixins: [eventMixin, i18n],
  props: {
    designer: Object,
    selectedWidget: Object,
    optionModel: Object
  },
  inject: ['getReportTemplate'],
  components: {
    Draggable,
    requestaccessDialog
  },
  computed: {
    reportTemplate: function () {
      return this.getReportTemplate();
    },
    showSeriesLabel: {
      get() {
        return this.optionModel.echarPieOption.series[0].label.show;
      },
      set(val) {
        this.optionModel.echarPieOption.series.forEach(item => {
          item.label.show = val || false;
        });
      }
    }
  },
  data() {
    return {
      showRequestaccessDialog: false
    };
  },
  created() {
    let optionModel = this.optionModel;
  },
  methods: {
    addColor() {
      this.optionModel.echarPieOption.color.push('');
    },
    deleteColor(index) {
      this.optionModel.echarPieOption.color.splice(index, 1);
    },
    confirmInsertRequestaccess(rows) {
      if (rows.length) {
        let row = rows[0];
        this.optionModel.accessName = row.accessName;
        this.optionModel.accessCode = row.accessCode;
      }
    }
  }
};
</script>

<style scoped></style>
