<template>
  <div v-loading="loading" class="addGuide">
    <div class="head-title">
      <span @click="CommonJump('directorGuideList')" class="blue point">{{$t('objFill.v101.daoyouguanl')}}</span> / {{$t('objFill.v101.bianjidygl')}}
    </div>
    <div class="content">
      <el-form :model="addMsg" :rules="rules" ref="addMsg" label-width="150px" style="width:50%">

        <el-form-item :label="$t('ground.dymc')" prop="Name" class="is-required">
          <el-input v-model="addMsg.Name" size="small" :placeholder="$t('objFill.v101.qingsrzdminc')" />
        </el-form-item>

        <el-form-item :label="$t('objFill.v101.yonghutoux')" size="small">
          <el-upload class="avatar-uploader" action="" accept="image/jpeg,image/gif,image/png,image/bmp"
                     :show-file-list="false" :http-request="UploadAttachment">
            <el-tooltip class="item" effect="dark" :content="$t('objFill.v101.jianyiccybsyb')" placement="top">
              <el-button >{{$t('objFill.xuanzhewj')}}</el-button>
            </el-tooltip>
          </el-upload>

            <div class="app-gallery-item" style="position: relative;width: 100px;margin-top: 10px;">
              <img v-if="!addMsg.GuidePhoto || addMsg.GuidePhoto==''"
                   src="../../../assets/img/default.png" style="width:80px;height:80px" alt="">
              <img v-else style="width:80px;height:80px" :src="addMsg.GuidePhoto"
                   alt="">
            </div>
        </el-form-item>

        <el-form-item :label="$t('objFill.v101.gongzuonx')" prop="WorkYears" class="is-required" size="small">
          <el-input v-model="addMsg.WorkYears" @keyup.native="checkPrice(addMsg,'WorkYears')" :placeholder="$t('objFill.v101.qingsrgznxi')">
            <template slot="append">{{$t('pub.year')}}</template>
          </el-input>
        </el-form-item>
        <el-form-item :label="$t('objFill.v101.zhandian')" prop="SiteId" class="is-required">
          <el-select class="w120"  v-model="addMsg.SiteId" size="small"
                     :placeholder="$t('pub.pleaseSel')">
            <el-option v-for="item in CarSiteList" :key="item.ID" :label="item.SiteName" :value="item.ID">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('scen.sc_tel')" prop="Telephone" class="is-required" size="small">
          <el-input v-model="addMsg.Telephone" :placeholder="$t('rule.EnterPNum')" type="number"/>
        </el-form-item>
        <el-form-item :label="$t('objFill.jingjilxdh')" prop="EmergencyPhone" class="is-required" size="small">
          <el-input v-model="addMsg.EmergencyPhone" :placeholder="$t('objFill.v101.qingsrjjlxdhua')" type="number"/>
        </el-form-item>
        <el-form-item :label="$t('objFill.v101.jianjie')">
<!--          <UE style="width:750px;" :defaultMsg="defaultMsg" :config="config" :IsMultiple="true" ref="ue"></UE>-->
              <my-edit  v-on:edit-value="addMsg.Introduction  = arguments[0]" v-bind:editValue="addMsg.Introduction"
              v-bind:toolbarShow="toolbar"  v-bind:referenceList="DefaultList" v-bind:placeholder="placeholder"></my-edit>
          <!-- <quill-editor  :options="editorOption"  v-model="addMsg.Introduction"></quill-editor> -->
        </el-form-item>

      </el-form>
    </div>
    <div style="margin-top:20px">
      <el-button size="small" type="primary" @click="Save('addMsg')" >{{$t('pub.saveBtn')}}</el-button>
    </div>

    <!-- 选择文件 -->
    <el-dialog :title="$t('objFill.xuanzhewj')" :visible.sync="changeState" width="1240px">
      <ChooseImg  @SelectId="SelectId"></ChooseImg>
    </el-dialog>
  </div>

</template>
<script>
  // import ChooseImg from "@/components/global/ChooseImg.vue";
  // import UE from "@/components/global/UE.vue";
  import MyEdit from "../../EditTemplate.vue";

  export default {
    components: {
      // ChooseImg,
      // UE,
      "my-edit": MyEdit
    },
    data() {
      return {
        addMsg: {
          ID: 0,
          Name:'',
          GuidePhoto:'',
          WorkYears:0,
          SiteId:'',
          Telephone:'',
          EmergencyPhone:'',
          Introduction:'',
        },
        toolbar: {
          clean: true,
          font: false, //字体
          narrative: false, //叙述,
          image:true,
          bold: true, //加粗
          underline: true, //下划线
          header1: true, //H1
          header2: true, //H2
          fontColor: true, //字体颜色
          fontBackgroundColor: true, //背景颜色
        },
        DefaultList: [],
        placeholder: this.$t('pub.pleaseImport'),

        defaultMsg: "",
        config: {
          initialFrameWidth: null,
          initialFrameHeight: 350
        },

        rules: {

          Name: [{
            required: true,
            message: this.$t('objFill.v101.qingshurdymc'),
            trigger: 'blur'
          }],
          WorkYears: [{
            required: true,
            message: this.$t('objFill.v101.qingsrgznxmic'),
            trigger: 'blur'
          }],
          Telephone: [{
            required: true,
            message: this.$t('objFill.v101.qingsrlxdhminc'),
            trigger: 'blur'
          }],
          EmergencyPhone: [{
            required: true,
            message: this.$t('objFill.v101.qiingsrlxidh'),
            trigger: 'blur'
          }],

        },
        loading: false,
        CarSiteList:[],
        changeState:false,
        imgType:0,
      };
    },
    created() {

      if(this.$route.query.ID){
        this.getData(this.$route.query.ID)
      }
      this.getAllGuideCarSiteList()//获取站点下拉
    },
    methods: {

      SelectId(msg){
        if(this.imgType==1){
          let url  = this.getIconLink(msg.url)
          this.addMsg.GuidePhoto = url
        }

        this.changeState = false;
      },
      openChangeDig(num) {
        this.changeState = true;
        this.imgType=num;



      },
      Save(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            if(this.addMsg.GuidePhoto==''){
              this.Error(this.$t('objFill.v101.qingsctoux'))
              return false
            }
            if(this.addMsg.teId==''){
              this.Error(this.$t('objFill.v101.qingxzzhand'))
              return false
            }
            // let content = this.$refs.ue.getUEContent();
            // this.addMsg.Introduction = content;
            this.lxymallapipost("/api/GuideCar/AddOrUpdateGuideCarGuide", this.addMsg, res => {
              if (res.data.resultCode == 1) {
                this.CommonJump('directorGuideList');
                this.Success(res.data.message);
              } else {
                this.Error(res.data.message);
              }
            })
          } else {
            return false;
          }
        });
      },
      getAllGuideCarSiteList(){
        this.lxymallapipost("/api/GuideCar/GetAllGuideCarSiteList", {}, res => {
          if (res.data.resultCode == 1) {
            this.CarSiteList = res.data.data
          } else {
            this.Error(res.data.message);
          }
        })
      },
      getData(ID) {
        this.loading = true;
        this.lxymallapipost("/api/GuideCar/GetGuideCarGuideModel", {
          ID: ID
        }, res => {
          this.loading = false;
          this.addMsg = res.data.data;
        })
      },
      //图片上传
      UploadAttachment(file) {
        let newArr = [];
        newArr.push(file.file);
        let fileName = file.file.name;
        var path = "/Upload/DMC/";
        this.UploadSelfFileT(path, newArr, x => {
          var str = x.data.FilePath;
          var imgUrl = this.domainManager().ViittoFileUrl + x.data.FilePath;
          this.addMsg.GuidePhoto = imgUrl
        });
      },
    },
    mounted() {
    }
  };
</script>
<style>
  @import './css/index.css';

  .app-add-cat .el-checkbox-group {
    font-size: 14px !important;
  }
  .app-add-cat .ql-toolbar span{
    line-height: 24px;
  }

  .app-add-cat .el-checkbox {
    margin-right: 0;
  }

  .app-add-cat .el-dialog__body {
    padding: 10px 20px !important;
  }

  .app-add-cat .tag-box .tag-item {
    margin-right: 5px;
  }

  .app-add-cat .tag-box {
    margin: 20px 0;
  }

  .app-add-cat .app-goods-cat-list .active {
    background: #FAFAFA;
  }

  .app-add-cat .app-goods-cat-list .cat-item {
    cursor: pointer;
    padding: 5px 10px;
  }

  .app-add-cat .app-goods-cat-list {
    border: 1px solid #E8EAEE;
    border-radius: 5px;
    margin-top: -5px;
    padding: 10px 0;
    overflow: scroll;
    height: 400px;
  }

  .addGuide .tip {
    margin-left: 10px;
    display: inline-block;
    height: 30px;
    line-height: 30px;
    color: #ff4544;
    background-color: #FEF0F0;
    padding: 0 20px;
    border-radius: 5px;
  }

  .addGuide .app-image {
    background-size: cover;
    background-position: center center;
    width: 80px;
    height: 80px;
    border-radius: 0%;
  }

  .addGuide .setTable .el-table__body .cell {
    display: flex;
    align-items: center;

  }

  .addGuide .commonLabel .el-form-item__label {
    margin-top: -4px;
  }

  .addGuide .discount .el-form-item__label {
    padding-right: 30px;
    margin-top: -4px;
  }

  .addGuide .el-form-item .elzk {
    position: absolute;
    left: -25px;
    top: 8px;
  }

  .addGuide .el-form-item {
    position: relative;
  }

  .addGuide .blue {
    color: #409EFF;

  }

  .addGuide .content {
    background: #fff;
    margin-top: 10px;
    padding: 20px;
    box-sizing: border-box;
  }
  .addGuide .gez_list{
    width: 650px;
    margin-bottom: 12px;
    padding: 20px;
    border: 1px solid #EBEEF5;
    background-color: #FFF;
    color: #303133;
    display: flex;
    flex-direction: row;
    justify-content: space-between;

  }
  .addGuide .quyu{
    background-color: #f4f4f5;
    color: #909399;
    padding: 10px;
    line-height: 30px;
    height: 30px;
    font-size: 12px;
    border-radius: 4px;
    white-space: nowrap;
    margin: 5px;
  }
  .addGuide .imgstyle{
    width: 32px;
    height: 32px;
    margin: 0 5px;
  }
  .addGuide .ql-toolbar.ql-snow .ql-formats {
    margin-right: 5px;
    line-height: 24px;
}
  </style>