<template>
  <div class="dashboard-editor-container">

    <panel-group @handleSetLineChartData="handleSetLineChartData" />


        <el-form ref="form" :model="form" :rules="rules" label-width="180px">
          <h3>基本情報</h3>
          <el-form-item :label="$t('table.deptName')" prop="deptName">
            <el-input :disabled='isDetails' v-model="form.deptName" :placeholder="$t('placeholder.deptName')" />
          </el-form-item>
          <el-form-item :label="$t('table.leader')" prop="leader">
            <el-input :disabled='isDetails' v-model="form.leader" :placeholder="$t('placeholder.leader')" />
          </el-form-item>
          <el-form-item :label="$t('table.username1')" prop="phone">
            <el-input :disabled='isDetails' v-model="form.phone" :placeholder="$t('placeholder.phone')" />
          </el-form-item>
          <el-form-item :label="$t('table.address')" prop="address">
            <el-input :disabled='isDetails' v-model="form.address" :placeholder="$t('placeholder.address')" />
          </el-form-item>
          <h3>ルール説明</h3>
          <el-collapse v-model="activeNames" accordion>
            <el-collapse-item :title="$t('table.pointDesc')" name="1">
              <el-form-item  prop="pointDesc">
                <editor v-model="form.pointDesc" :min-height="150" :height="384"/>
               </el-form-item>
            </el-collapse-item>
            <el-collapse-item :title="$t('table.couponDesc')" name="2">
              <el-form-item  prop="couponDesc">
                 <editor v-model="form.couponDesc" :min-height="192" :height="384"/>
              </el-form-item>
            </el-collapse-item>
          </el-collapse>
          <h3>ツアー関連設定共通情報</h3>
          <el-collapse accordion>
            <el-collapse-item :title="$t('table.safety')" name="1">
              <el-form-item  prop="safety">
                  <editor v-model="form.safety" :min-height="150" :height="384"/>
              </el-form-item>
            </el-collapse-item>
            <el-collapse-item :title="$t('table.process')" name="2">
              <el-form-item  prop="process">
                  <editor v-model="form.process" :min-height="192" :height="384"/>
              </el-form-item>
              </el-collapse-item>
            <el-collapse-item :title="$t('table.cancel')" name="3">
              <el-form-item  prop="cancel">
                  <editor v-model="form.cancel" :min-height="192" :height="384"/>
              </el-form-item>
              </el-collapse-item>
            <el-collapse-item :title="$t('table.about')" name="4">
              <el-form-item  prop="about">
                  <editor v-model="form.about" :min-height="192" :height="384"/>
              </el-form-item>
              </el-collapse-item>
            <el-collapse-item :title="$t('table.mark')" name="5">
              <el-form-item  prop="mark">
                  <editor v-model="form.mark" :min-height="192" :height="384"/>
              </el-form-item>
              </el-collapse-item>
            <el-collapse-item :title="$t('table.privacy')" name="6">
              <el-form-item  prop="privacy">
                  <editor v-model="form.privacy" :min-height="192" :height="384"/>
              </el-form-item>
              </el-collapse-item>
            <el-collapse-item :title="$t('table.agreement')" name="7">
              <el-form-item  prop="agreement">
                  <editor v-model="form.agreement" :min-height="192" :height="384"/>
              </el-form-item>
              </el-form-item>
            </el-collapse-item>
          </el-collapse>
        </el-form>


        <div slot="footer" class="dialog-footer">
          <el-button v-if="!isDetails" type="primary" @click="submitForm">{{$t('btn.submit')}}</el-button>
          <el-button @click="cancel">{{$t('btn.cancel')}}</el-button>
        </div>
                
  </div>
</template>

<script>
import PanelGroup from './dashboard/PanelGroup'
import {getBusCompany, updateBusCompany, getBusCompanyMe } from "@/api/busCompany/busCompany";
const lineChartData = {
  newVisitis: {
    expectedData: [100, 120, 161, 134, 105, 160, 165],
    actualData: [120, 82, 91, 154, 162, 140, 145]
  },
  messages: {
    expectedData: [200, 192, 120, 144, 160, 130, 140],
    actualData: [180, 160, 151, 106, 145, 150, 130]
  },
  purchases: {
    expectedData: [80, 100, 121, 104, 105, 90, 100],
    actualData: [120, 90, 100, 138, 142, 130, 130]
  },
  shoppings: {
    expectedData: [130, 140, 141, 142, 145, 150, 160],
    actualData: [120, 82, 91, 154, 162, 140, 130]
  }
}

export default {
  name: 'Index',
  components: {
    PanelGroup,
  },
  data() {
    return {
      lineChartData: lineChartData.newVisitis,
      // 表单参数
      form: {},
      // 遮罩层
      loading: true,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      isDetails: false,
      deptId:100,
    }
  },
  created() {
    this.getBusCompanyInfo();
  },
  methods: {
    handleSetLineChartData(type) {
      this.lineChartData = lineChartData[type]
    },
    /** 初期情报取得 */
    getBusCompanyInfo() {
  	  this.isDetails = false
      getBusCompanyMe().then(response => {
        this.form = response.data;
        this.deptId= response.data.deptId;
        this.open = true;
        this.title = this.$t('dialog.busTitel2')
      });
    },
        /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          updateBusCompany(this.form).then(response => {
            this.$modal.msgSuccess(this.$t('message.success1'));
            this.open = false;
            this.getBusCompanyInfo();
          });
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.getBusCompanyInfo(101);
    },
    scrollTop() {

    },
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  // position: relative;
  // position: absolute;
  // top: 0;
  // bottom: 0;
  // left: 0;
  // right: 0;
  overflow-x: hidden;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
