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

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


        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
          <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-form-item :label="$t('table.safety')" prop="safety">
              <editor v-model="form.safety" :min-height="150" :height="384"/>
          </el-form-item>
          <el-form-item :label="$t('table.process')" prop="process">
              <editor v-model="form.process" :min-height="192" :height="384"/>
          </el-form-item>
          <el-form-item :label="$t('table.cancel')" prop="cancel">
              <editor v-model="form.cancel" :min-height="192" :height="384"/>
          </el-form-item>
          <el-form-item :label="$t('table.about')" prop="about">
              <editor v-model="form.about" :min-height="192" :height="384"/>
          </el-form-item>
          <el-form-item :label="$t('table.mark')" prop="mark">
              <editor v-model="form.mark" :min-height="192" :height="384"/>
          </el-form-item>
          <el-form-item :label="$t('table.privacy')" prop="privacy">
              <editor v-model="form.privacy" :min-height="192" :height="384"/>
          </el-form-item>
          <el-form-item :label="$t('table.agreement')" prop="agreement">
              <editor v-model="form.agreement" :min-height="192" :height="384"/>
          </el-form-item>

        </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);
    },
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

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

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