<template>
    <div>
         <div class="feature ">

            <ul >
                <li @click="slideshow = true">
                    <span>
                        <img :src="new1" alt="" style="width:40px;height:40px">
                        <p>轮播图</p>  
                    </span>
                </li>
                <li @click="hospitaAddress()">
                    <span>
                        <img :src="new2" alt="" style="width:40px;height:40px">
                        <p>医院地址</p>  
                    </span>
                </li>
                <li @click="contact = true">
                    <span>
                        <img :src="new3" alt="" style="width:40px;height:40px">
                        <p>联系方式</p>  
                    </span>
                </li>
                <li @click="time = true">
                    <span>
                        <img :src="new4" alt="" style="width:40px;height:40px">
                        <p>工作时间</p>  
                    </span>
                </li>
                <li @click="type = true">
                    <span>
                        <img :src="new5" alt="" style="width:40px;height:40px">
                        <p>乘车方式</p>  
                    </span>
                </li>
            </ul>
         </div>
  <!-- 新增轮播图 -->
   <el-dialog
    title="新增轮播图"
    :visible.sync="slideshow"
    width="35%"
     center>
    <el-form ref="rotationform" :model="rotationform" label-width="90px" :rules="rules" >
      <el-form-item label="模块标题:" required prop="title">
        <el-input v-model="rotationform.title"></el-input>
      </el-form-item>
      <el-form-item label="排序值:" required prop="sort">
        <el-input v-model="rotationform.sort" type="number"></el-input>
        <p class="tips">请输入1-99的整数，数值越小，模块排序越靠前</p>
      </el-form-item>
     <el-form-item label="添加图片:">
         <div class="flex-img">
              <div class="el-upload-list el-upload-list--picture-card" >            
                  <div class="el-upload-list__item is-success" v-for="(item,index) in this.rotationdata" :key="item.id">             
                    <img class="flex-img__image" :src="item.images">              
                    <label class="el-upload-list__item-status-label">
                     <i class="el-icon-upload-success el-icon-check"></i>
                    </label>
                     <span class="el-upload-list__item-actions">
                    <span class="el-upload-list__item-delete">
                    <i class="el-icon-edit-outline" @click="editcenterDialogVisible = true;editRotationEmages(item.id)"></i>
                    <i class="el-icon-delete" @click="deleteImages(item.id,index)"></i>
                    </span>
                    </span>
                   </div>         
                </div>     
                <div class="addrot" @click="addVisible = true;showpic = false" v-show="isNoEpity">
                 <div class="docone">
                  <li class="el-icon-plus"></li>  
                   <div class="doctwo">
                    <span>新增图片</span>
                   </div>
                  </div>  
                </div>
             </div>
            <p class="tips">图片已上传{{totalImages}}张,最多上传9张</p>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="slideshow = false">取 消</el-button>
      <el-button type="primary" @click="addrotationImage('rotationform')">确 定</el-button>
    </span>
  </el-dialog>


  <!-- 医院地址 -->
  <el-dialog
    title="新增医院地址"
    :visible.sync="hostaddress"
    width="35%"
    center>
    <el-form ref="hospitalform" :model="hospitalform" label-width="90px" :rules="rules">
      <el-form-item label="模块标题:" required prop="title">
        <el-input v-model="hospitalform.title" ></el-input>
      </el-form-item>
      <el-form-item label="排序值:" required prop="sort">
        <el-input v-model="hospitalform.sort" type="number"></el-input>
        <!-- <p class="tips">请输入1-99的整数，数值越小，模块排序越靠前</p> -->
      </el-form-item>
       <el-form-item label="医院地址:" required prop="address">
         <el-input v-model="hospitalform.address"></el-input>
       </el-form-item>
       <!-- <el-form-item label="医院地图:">  
           <baidu-map>
              <bm-overview-map anchor="BMAP_ANCHOR_BOTTOM_RIGHT" :isOpen="true"></bm-overview-map>
              <bm-local-search :keyword="hospitalform.address" :auto-viewport="true" style="display:none" :center="location"  :zoom="zoom"></bm-local-search>
              <bm-view class="map"></bm-view>
         </baidu-map>
       </el-form-item> -->
    
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="hostaddress=false">取 消</el-button>
      <el-button type="primary" @click="addHospital('hospitalform');">确 定</el-button>
    </span>
  </el-dialog>


<!-- 新增联系方式 -->
<el-dialog
    title="新增联系方式"
    :visible.sync="contact"
    width="550px"
    center>
    <el-form ref="contractform" :model="contractform" label-width="90px" :rules="rules">
      <el-form-item label="模块标题:" required prop="title">
        <el-input v-model="contractform.title"></el-input>
      </el-form-item>
      <el-form-item label="排序值:" required prop="sort">
        <el-input v-model="contractform.sort" type="number"></el-input>
        <p class="tips">请输入1-99的整数，数值越小，模块排序越靠前</p>
      </el-form-item>
      <el-form-item label="联系方式:">
        <div class="used">
             <ul>
                 <li v-for="(item,index) in this.connectionway" :key="item.id">
                    <span class="name">{{item.title}}</span>
                    <span class="icon"> 
                        <i class="el-icon-edit-outline" @click="editLink=true;editConnecWay(item.id)"></i>
                        <i class="el-icon-delete" @click="deleteConnecWay(item.id,index)"></i>
                    </span>
                 </li>
             </ul>
        </div>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="addLink = true">添加联系方式</el-button>      
      <el-button @click="contact = false">取 消</el-button>
      <el-button type="primary" @click="addContract('contractform');">确 定</el-button>
    </span>
  </el-dialog>

  <!-- 添加联系方式内容 -->
  <el-dialog
    title="新增联系方式"
    :visible.sync="addLink"
    width="550px"
    >
    <el-form ref="connecform" :model="connecform" label-width="90px" :rules="rules" >
      <el-row>
        <el-col :span="20">
        <el-form-item label="标题:" required prop="title">
            <el-input v-model="connecform.title" style="width:400px"></el-input>
        </el-form-item>
        </el-col>
      </el-row>
        <el-form-item label="联系方式:" required prop="connecway">
          <el-row>
            <el-col :span="20">
            <el-radio-group v-model="connecform.connecway">
            <el-radio :label="way.id" :value="way.id" v-for="(way,index) in connections" :key="index">{{way.name}}</el-radio>
            </el-radio-group>
            </el-col>
          </el-row>  
        </el-form-item>

        <el-form-item label="内容:" required prop="content">
          <el-row>
            <el-col :span="20">
            <el-input v-model="connecform.content" style="width:400px"></el-input>
            </el-col>
          </el-row>'
        </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
        <el-button @click="addLink = false">取 消</el-button>
        <el-button type="primary" @click="addconnection('connecform');addLink = false">确 定</el-button>
    </span>
  </el-dialog>

<!-- 编辑联系方式 -->
  <el-dialog
    title="编辑联系方式"
    :visible.sync="editLink"
    width="550px"
    >
    <el-form ref="editconnecform" :model="editconnecform" label-width="90px" :rules="rules" >
      <el-row>
        <el-col :span="20">
        <el-form-item label="标题:" required prop="title">
            <el-input v-model="editconnecform.title" style="width:400px"></el-input>
        </el-form-item>
        </el-col>
      </el-row>
        <el-form-item label="联系方式:" required prop="connecway">
          <el-row>
            <el-col :span="20">
            <el-radio-group v-model="editconnecform.connecway">
            <el-radio :label="way.id" :value="way.id" v-for="(way,index) in connections" :key="index">{{way.name}}</el-radio>
            </el-radio-group>
            </el-col>
          </el-row>  
        </el-form-item>

        <el-form-item label="内容:" required prop="content">
          <el-row>
            <el-col :span="20">
            <el-input v-model="editconnecform.content" style="width:400px"></el-input>
            </el-col>
          </el-row>'
        </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
        <el-button @click="editLink = false">取 消</el-button>
        <el-button type="primary" @click="saveConnecform('editconnecform')">确 定</el-button>
    </span>
  </el-dialog>

 <!-- 工作时间 -->
 <el-dialog
    title="新增工作时间"
    :visible.sync="time"
    width="550px"
   center>
    <el-form ref="woketimeform" :model="woketimeform" label-width="90px" :rules="rules">
      <el-form-item label="模块标题:" required prop="title">
        <el-input v-model="woketimeform.title"></el-input>
      </el-form-item>
      <el-form-item label="排序值:" required prop="sort">
        <el-input v-model="woketimeform.sort" type="number"></el-input>
        <p class="tips">请输入1-99的整数，数值越小，模块排序越靠前</p>
      </el-form-item>
      <el-form-item label="工作时间:" required prop="worktime">
        <el-input
          type="textarea"
          :rows="6"
          placeholder="请输入内容"
          v-model="woketimeform.worktime">
        </el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="time = false">取 消</el-button>
      <el-button type="primary" @click="addWorkTime('woketimeform');">确 定</el-button>
    </span>
  </el-dialog>

  <!-- 新增乘车方式 -->
 <el-dialog
    title="新增乘车方式"
    :visible.sync="type"
    width="550px"
    center>
    <el-form ref="rideform" :model="rideform" label-width="90px" :rules="rules" :label-position="labelPosition">
      <template>
      <el-form-item label="模块标题:" required prop="title">
        <el-input v-model="rideform.title"></el-input>
      </el-form-item>
      <el-form-item label="排序值:" required prop="sort">
        <el-input v-model="rideform.sort" type="number"></el-input>
        <p class="tips">请输入1-99的整数，数值越小，模块排序越靠前</p>
      </el-form-item>
      <el-form-item label="乘车方式:" required prop="content">
        <el-input
          type="textarea"
          :rows="6"
          placeholder="请输入内容"
          v-model="rideform.content">
        </el-input>
      </el-form-item>
       </template>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="type = false">取 消</el-button>
      <el-button type="primary" @click="addRideWay('rideform');">确 定</el-button>
    </span>
   </el-dialog>

  

 <!-- 编辑图片 -->
 <el-dialog
     class="avatar-uploader"
     title="编辑图片"
     :visible.sync="addVisible"
     width="30%"
     center>
  <el-form ref="picform" :model="picform" label-width="90px" :rules="rules">
    <el-form-item label="图片编辑:" required prop="Images">
      <el-col :span="5">  
         <el-upload
         :data="Data"   
          class="avatar-uploader"
          action="https://upload.qiniup.com/"
          :show-file-list="false"
          :on-success="RotationSuccess"
          :before-upload="RotationUpload"
          :limit="9">
            <img v-if="picform.Images" :src="picform.Images" class="avatar" style="width:100px;height:98px">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>  
      </el-col>
      <!-- <el-col :span="19">
          <div class="tpic" v-show="showpic"> 
            <img :src="picform.Images" style="width:200px;height:100px">
          </div>
      </el-col> -->
    </el-form-item>
    <el-form-item label="排序值:" required prop="sort">
       <el-col :span="15">
         <el-input v-model="picform.sort" type="number"></el-input>
       </el-col>   
    </el-form-item>
    <el-form-item label="图片链接:">
        <el-radio-group v-model="picform.piclink">
           <el-radio :label="gender.id" :value="gender.id" v-for="(gender, index) in genderOptions" :key="index" @change="selectGender(gender.id)">{{gender.name}}</el-radio>
        </el-radio-group>
    </el-form-item>
    <el-form-item label="链接地址:" v-show="definetwo">
      <el-col :span="10">
      <el-input v-model="picform.linkaddress"  :disabled="true"></el-input>
      </el-col>
      <el-col :span="5">
       <el-button size="medium"  @click="addVisibleThree = true">设置链接</el-button>
      </el-col>
    </el-form-item>
  </el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="addVisible = false">取 消</el-button>
    <el-button type="primary" @click="addrotationpic('picform');">确 定</el-button>
  </span>
</el-dialog>

   <el-dialog
    title="添加图片"
    :visible.sync="addVisibletwo"
    width="30%"
    center>
    <el-form>
      <el-form-item label="添加图片:">
        <el-upload
         :data="Data"   
          class="avatar-uploader"
          action="https://upload.qiniup.com/"
          :show-file-list="false"
          :on-success="RotationSuccess"
          :before-upload="RotationUpload">
          <div class="addimage">
            <img v-if="picform.Images" :src="picform.Images" class="avatar" style="width:100px;height:98px">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </div>
        </el-upload>
      </el-form-item>
    </el-form>
     <span slot="footer" class="dialog-footer">
       <el-button @click="addVisibletwo = false">取 消</el-button>
       <el-button type="primary" @click="addVisibletwo = false">确 定</el-button>
   </span>
  </el-dialog>

  <el-dialog
    title="设置图片链接地址:"
    :visible.sync="addVisibleThree"
    width="30%"
    center>
    <el-form label-width="120px" :model="linkform" ref="linkform">
      <el-form-item label="站外链接:">
         <el-input v-model="linkform.defineaddress"></el-input>
      </el-form-item>
    </el-form>
   <span slot="footer" class="dialog-footer">
     <el-button @click="addVisibleThree = false">取 消</el-button>
     <el-button type="primary" @click="AddPiCLink('linkform');addVisibleThree = false">确 定</el-button>
   </span>
 </el-dialog>

 <el-dialog 
   title="编辑轮播图"
   :visible.sync="editcenterDialogVisible"
   width="35%"
   center>
    <el-form label-width="90px" :model="editrotationform" ref="editrotationform">
        <el-form-item label="图片编辑">
          <el-col :span="5">
             <el-upload
              :data="rotationData"
              class="avatar-uploader"
              action="https://upload.qiniup.com/"
             :show-file-list="false"
             :on-success="handleAvatarSuccess"
             :before-upload="beforeAvatarUpload">
             <img v-if="editrotationform.images" style="width:100%;height:100px" :src="editrotationform.images" class="avatar">
             <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>    
          </el-col>
       </el-form-item> 
        <el-form-item label="排序值:" required prop="sort">
           <el-col :span="24">
             <el-input v-model="editrotationform.sort" style="width:410px" type="number"></el-input>
           </el-col>   
         </el-form-item>
         <el-form-item label="图片链接:">
             <el-radio-group v-model="editrotationform.piclink">
               <el-radio :label="gender.id" :value="gender.id" v-for="(gender, index) in genderOptions" :key="index" @change="select(gender.id)">{{gender.name}}</el-radio>
             </el-radio-group>
         </el-form-item>
         <el-form-item label="链接地址:">
           <el-col :span="15">
             <el-input v-model="editrotationform.linkaddress" style="width:300px" :disabled="true"></el-input>
           </el-col>
           <el-col :span="4">
             <el-button size="medium" @click="linkVisible = true;getOutRotationlink(editrotationform.linkid)" >设置链接</el-button>
           </el-col>
         </el-form-item>
    </el-form>
      <span slot="footer" class="dialog-footer">
      <el-button @click="editcenterDialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="UpdatedConrotation('editrotationform')">确 定</el-button>
    </span>
 </el-dialog>

   <el-dialog
       title="设置图片链接地址"
       :visible.sync="linkVisible"
       width="30%"
       center>
     <el-form  label-width="90px" ref="rotationformTwo" :model="rotationformTwo" :rules="rules">
       <el-form-item label="站外链接" required prop="defineaddress">
         <el-input v-model="rotationformTwo.defineaddress"></el-input>
       </el-form-item>
     </el-form>
   <span slot="footer" class="dialog-footer">
      <el-button @click="linkVisible = false">取 消</el-button>
      <el-button type="primary" @click="UpdatedRolinkAddress('rotationformTwo')">确 定</el-button>
    </span>
   </el-dialog>
  </div>
</template>


<script>
 import { getToken } from '@/api/qiniu'
 import { getFileExtension} from '@/utils/tools'
 import { addRotationUpload,addHospital,addRideWay,addWorkTime,addconnection,queryConnetion,deleteConnecWay,editConnecWay,
 saveConnecform,addContract,addrotationpic,GetRotationImages,addrotationImage,deleteImages,getArticleType,GetArticleById,GetAllActivity,
 AddPiCLink,editRotationEmages,GetOutRotationlink,UpdatedRolinkAddress,UpdatedConrotation} from '@/api/site/site'  
import { truncateSync } from 'fs';
import {checkNumber} from "@/utils/tools";
export default {
  name: "addcontact",
  data() {
        var checkNumberRule = (rule, value, callback) => {
            if (!checkNumber(value)) {
                 callback(new Error('请输入1-99的整数'));
              }else {
               callback(); 
             }
          };

    return {
       location: {
        lng: 116.404,
        lat: 39.915
      },
      zoom: 12.8,
      keyword:"",
      show:false,
      imageUrl:false,
      dialogshow:false,
      slideshow:false,
      address:false,
      hostaddress:false,
      contact:false,
      addLink:false,
      editLink:false,
      time:false,
      type:false,
      disabled: false,
      dialogFormVisibleAdd:true,
      editcenterDialogVisible:false,
      showone:false,
      showtwo:false,
      showthree:false,
      showFour:false,
      showFive:false,
      linkVisible:false,
      definetwo:true,
      labelPosition: 'left',
      qiniuDomain: 'https://images.shengws.com/',
      Data: { token:'',key: '' },
      rotationData: { token:'',key: '' },
      new1: require("../../../assets/preview/轮播图.png"),
      new2: require("../../../assets/preview/医院地址.png"),
      new3: require("../../../assets/preview/联系方式.png"),
      new4: require("../../../assets/preview/工作时间.png"),
      new5: require("../../../assets/preview/公交.png"),    
      form: {
        name: "",
        sort:"",
        title:"",
      },
      userlocation: {lng: "", lat: ""},
      rotationform:{
        title:"",
        sort:"",
        rotationImages:[],
        ids:[],
      },
      rotationdata:[],
      rideform:{
        title:"",
        sort:"",
        content:"",
      },
      woketimeform:{
       title:"",
       sort:"",
       worktime:"",
      },
      hospitalform:{
        title:"",
        sort:"",
        address:"",
      },
      connecform:{
        title:"",
        connecway:"",
        content:"",
      },
      editconnecform:{
        title:"",
        connecway:"",
        content:"",
      },
      connections:[
         {id:1,name:'电话'},
         {id:2,name:'非电话'},
      ],
      connectionway:[],
      contractform:{
        title:"",
        sort:"",
      },
      linkform:{
        defineaddress:"",
      },
      linkType:[
        {id:1,name:'无'},
        {id:2,name:'站内链接:'},
        {id:3,name:'站外链接:'},
      ],
       options:[
         {id:1,name:'文章'},
         {id:2,name:'活动'},
       ],
       editrotationform:{
         images:"",  
         sort:"",
         piclink:1,
         linkaddress:"",
         linkid:"",
       },
       rotationformTwo:{
          id:"",
          defineaddress:"",
       },
      rules: {
        title: [{required: true, message: "请填写模块标题",},],
        sort: [{required: true,message:"请填写排序值"},{validator:checkNumberRule}],
        rotationImages:[{required:true,message:"请填写添加图片"}],
        content:[{required:true,message:"请填写乘车方式"}],
        worktime:[{required:true,message:"请填写工作时间"}],
        connecway:[{required:true,message:"请选择联系方式"}],
        linkaddress:[{required:true,message:"请填写链接地址"}],
        address:[{required:true,message:"请填写医院地址"}],
        Images:[{required:true,message:"请上传图片"}],
        defineaddress:[{required:true,message:"请填写站外链接"}]
      },
     addVisible:false,  
     addVisibletwo:false,
     addVisibleThree:false,
       picform:{
         sort:"",
         Images:"",
         piclink:2,
         linkaddress:"",
         linkid:"",
      },
      showpic:false,
      genderOptions:[
        {id:1, name:'无'},
        {id:2, name:'自定义'},
       ],
       genderPicLink:[
         {id:1,name:"自定义"},
         {id:2,name:"不跳转"},
       ],
       define:false,
       articeTypelist:[],
       articeNamelist:[],
       isNoEpity:true,
       totalImages:0,
    };
  },
  methods:{
        changeInput(e){
            this.$forceUpdate();
          },
        selectGender(id){
          if(id == 1){
             this.definetwo = false;
        }
        if(id == 2){
           this.definetwo = true;
        }
     },
       selectItem(id){
         if(id == 1){
            this.showone = false;
            this.showtwo = false;
            this.showthree = false;
            this.showFour = false;
            this.showFive = false;
         }
         if(id == 2){
           this.showone = true;
           this.showtwo = false;
           this.showthree = false;
           this.showFive = true;
         }
         if(id == 3){
           this.showone = false;
           this.showtwo = false;
           this.showthree = true;
           this.showFive = false;
         }
       },
       changeType(id){
          if(id == 1){
             this.showFour = true;

          }
          if(id == 2){
            this.showFour = false;
              GetAllActivity(this.articeNamelist).then(response=>{
               if(response.data.state == 1){
               var activtity = response.data.data.activtity;
              this.articeNamelist = response.data.data.activtity;
             }
            })
          }
       },
       GetArticleById(id){
         GetArticleById(id,this.linkform).then(response=>{
         if(response.data.state == 1){
          var articlelist = response.data.data.articlelist;
          this.articeNamelist = response.data.data.articlelist;        
        }
      })
    },
    AddPiCLink(formName){
       this.$refs[formName].validate((valid)=>{
         if(valid){
           AddPiCLink(this.linkform).then(response=>{
               if(response.data.state == 1){
               var conlinkaddress = response.data.data.conlinkaddress;
               console.log("conlinkaddress是什么",conlinkaddress)
                this.picform.linkaddress = conlinkaddress.defineaddress;
                this.picform.linkid = conlinkaddress.id;
             }
           })
         }
       })
    },
       RotationSuccess(res,file,filelist){         
         this.picform.Images =this.qiniuDomain + res.url;
         this.showpic = true;
      },
         RotationUpload(file){
             var fileType = file.type
            const isJPG = fileType.indexOf("image") > -1;
            const isLt2M = file.size / 1024 / 1024 < 2;
            if (!isJPG) {
                this.$message.error("只能上传图片");
                return false;
            }
            if (!isLt2M) {
                this.$message.error("图片大小不能超过 2MB!");
                return false;
         }
      
         var date = new Date()
            var ext = getFileExtension(file.name)
            var key = date.getFullYear() + (date.getMonth() + 1) + date.getDate() + date.getHours()  + date.getMinutes()  + date.getSeconds()  +'_o_' + file.uid + '.' + ext;
            const _self = this
            return new Promise((resolve, reject) => {
                getToken().then(response => {
                    const token= response.data.data.uptoken
                    console.log("联系我们轮播图token是什么?",token)
                    _self._data.Data.token = token;
                    _self._data.Data.key = key;
                    resolve(true)
                }).catch(err => {
                    reject(false)
                })
            })
          return isJPG && isLt2M;
      },

      handleAvatarSuccess(res,file){
        this.editrotationform.images =   this.qiniuDomain +res.url;
        console.log("是什么",this.editrotationform.imageUrl)
      },
      beforeAvatarUpload(file){
          var fileType = file.type
            const isJPG = fileType.indexOf("image") > -1;
            const isLt2M = file.size / 1024 / 1024 < 2;
            if (!isJPG) {
                this.$message.error("只能上传图片");
                return false;
            }
            if (!isLt2M) {
                this.$message.error("图片大小不能超过 2MB!");
                return false;
         }
      
         var date = new Date()
            var ext = getFileExtension(file.name)
            var key = date.getFullYear() + (date.getMonth() + 1) + date.getDate() + date.getHours()  + date.getMinutes()  + date.getSeconds()  +'_o_' + file.uid + '.' + ext;
            const _self = this
            return new Promise((resolve, reject) => {
                getToken().then(response => {
                    const token= response.data.data.uptoken
                    console.log("联系我们轮播图token是什么?",token)
                    _self._data.rotationData.token = token;
                    _self._data.rotationData.key = key;
                    resolve(true)
                }).catch(err => {
                    reject(false)
                })
            })
          return isJPG && isLt2M;
      },
    
      //新增医院地址
      addHospital(formName){
            var sorts = this.hospitalform.sort
             var sort = parseInt(sorts)
             this.hospitalform.sort = sort
            this.$refs[formName].validate((valid)=>{
            if(valid){
             addHospital(this.hospitalform).then(response=>{
                if(response.data.state ==1){
                  this.hostaddress = false;
                  var hosaddress =  response.data.data.hosaddress;
                  console.log('新增医院地址数据',hosaddress);
                  this.$emit('getOrderModel');
                }
             })
            }
         })
      },

      //新增联系方式
      addconnection(formName){
        this.$refs[formName].validate((valid)=>{
          if(valid){
            addconnection(this.connecform).then(response=>{
              if(response.data.state==1){
                 var cooection =  response.data.data.connection;
                //  console.log("返回数据",cooection);
                 this.queryConnetion();
                 this.connecform.title = "";
                 this.connecform.content = "";
              }
            })
          }
        })
      },

      //获取联系方式
      queryConnetion(){
        queryConnetion().then(response=>{
           if(response.data.state ==1){
             this.connectionway = response.data.data.conection;
            //  console.log("联系方式返回数据",this.connectionway);
           }
        })
      },

      //删除联系方式
      deleteConnecWay(id,index){
         this.$confirm('确定要删除该信息么?,删除后将无法恢复!',{
         dangerouslyUseHTMLString:true,
         confirmButtonText: '确定',
         cancelButtonText: '取消',
          type: 'warning'
         }).then(()=>{
            deleteConnecWay(id).then(response=>{
             if(response.data.state==1){
                this.connectionway.splice(index,1);
             }
           }).catch(e=>{}); 
         }).catch(e=>{});
      },

      //编辑联系方式
      editConnecWay(id){
        console.log("id是啥",id);
        editConnecWay(id).then(response=>{
            if(response.data.state == 1){
              this.editconnecform = response.data.data.connection;
              // console.log("返回数据",this.connecform);
            }
        })      
      },

      //编辑保存后的联系方式
      saveConnecform(formName){
         this.$refs[formName].validate((valid)=>{
           if(valid){
              saveConnecform(this.editconnecform.id,this.editconnecform).then(response=>{
                  if(response.data.state == 1){
                     var connection =  response.data.data.connection;
                    //  console.log("返回数据",connection);
                      this.editLink =false;
                      this.queryConnetion();
                  }    
              }) 
           }
         })
      },

      //添加联系方式
      addContract(formName){
            var sorts = this.contractform.sort
             var sort = parseInt(sorts)
             this.contractform.sort = sort
         this.$refs[formName].validate((valid)=>{
            if(valid){
              addContract(this.contractform).then(response=>{
                  if(response.data.state == 1){
                    this.contact = false;
                   var connectway = response.data.data.connectway;
                   var ordmodel = response.data.data.ordmodel;
                    this.$emit('getOrderModel');
                  //  console.log("返回数据",connectway);
                  //  console.log("返回数据",ordmodel)    
                  }
              })           
            }
         })
      },

      //添加工作时间
      addWorkTime(formName){
             var sorts = this.woketimeform.sort
             var sort = parseInt(sorts)
             this.woketimeform.sort = sort
        this.$refs[formName].validate((valid)=>{
          if(valid){
            addWorkTime(this.woketimeform).then(response=>{
                  if(response.data.state==1){
                    this.time = false;
                    var ordmodel = response.data.data.ordmodel;
                    var patientWorktime = response.data.data.patientWorktime
                    // console.log("返回数据",ordmodel);
                    // console.log("返回数据",patientWorktime)
                    this.time = false;
                     this.$emit('getOrderModel');
                }
            })
          }
        })
      },

      //添加乘车方式
      addRideWay(formName){
         var sorts = this.rideform.sort
         var sort = parseInt(sorts)
         this.rideform.sort = sort
        this.$refs[formName].validate((valid)=>{
          if(valid){
            addRideWay(this.rideform).then(response=>{
              if(response.data.state==1){
                 var rideway = response.data.data.rideway;
                //  console.log("返回数据",rideway);
                 var ordemodel = response.data.data.ordemodel;
                //  console.log("返回数据",ordemodel)
                 this.type = false;
                     this.$emit('getOrderModel');
              }
            })
          }
        })
      },
      hospitaAddress(){
        this.hostaddress = true;
      },
      addrotationpic(formName){
        if(this.picform.linkid == ""){
           this.picform.linkid = 0;
        }
         var sorts = this.picform.sort
         var sort = parseInt(sorts)
         this.picform.sort = sort
       this.$refs[formName].validate((valid)=>{
         if(valid){
            addrotationpic(this.picform).then(response=>{
               if(response.data.state ==1){
                 this.addVisible = false;
                 var conrotation  = response.data.data.conrotation;
                 var total = response.data.data.total;
                 this.totalImages = total;
                 if(total >=9){
                   this.isNoEpity = false;
                 }
                 this.picform.Images = "";
                 this.picform.sort = "";
                 this.picform.linkaddress = "";
                 this.GetRotationImages();
               }
            })
         }
       })  
      },
      GetRotationImages(){
        GetRotationImages(this.picform.id).then(response=>{
           if(response.data.state == 1){
             var conrotations =   response.data.data.conrotations;
             console.log("获取轮播图片",conrotations)
             this.rotationdata =   response.data.data.conrotations;
            
           }
        })
      },
      addrotationImage(formName){
        var sorts =  this.rotationform.sort;
        var sort = parseInt(sorts);
        this.rotationform.sort = sort;
        for (let index = 0; index < this.rotationdata.length; index++) {
          this.rotationform.rotationImages.push(this.rotationdata[index].images);  
          this.rotationform.ids.push(this.rotationdata[index].id);     
        }
        console.log("this.rotationform.raotationimages",this.rotationform.rotationImages)
        this.$refs[formName].validate((valid)=>{
          if(valid){
            addrotationImage(this.rotationform).then(response=>{
                 if(response.data.state == 1){
                   var oldrotation  = response.data.data.oldrotation;
                   this.slideshow = false;
                    this.$emit('getOrderModel');
                    this.rotationform.title = "";
                    this.rotationform.sort = "";
                    this.rotationdata = [];
                    this.rotationform.ids = [];
                    this.totalImages = 0;
                 } 
            })
          }
        })
      },
      deleteImages(id,imgshow,index){
        deleteImages(id).then(response=>{
           if(response.data.state == 1){
               this.rotationdata.splice(index,1);
              var total =  response.data.data.total;
              this.totalImages = total;
               this.isNoEpity = true;
           }
        })
      },

       getArticleType(){
          getArticleType(this.articeTypelist).then(response=>{
           if(response.data.state == 1){
             var  category = response.data.data.category;
             this.articeTypelist = response.data.data.category;
            console.log("文章分类是什么",this.articeTypelist)
          }
      })
    },
    editRotationEmages(id){
       editRotationEmages(id).then(response=>{
           if(response.data.state == 1){
             var conrotation =  response.data.data.conrotation;
             this.editrotationform = conrotation;
            //  console.log("conrotation是什么",conrotation)
           }
       })
    },
    getOutRotationlink(linkid){
       GetOutRotationlink(linkid).then(response=>{
          if(response.data.state == 1){
             var conlinkaddress =  response.data.data.conlinkaddress;
             console.log("conlinkaddress",conlinkaddress)
             this.rotationformTwo.defineaddress =   conlinkaddress.defineaddress;
             this.rotationformTwo.id = conlinkaddress.id;
             console.log("hh",this.rotationformTwo.defineaddress)
             console.log(this.rotationformTwo.id)
          }
       })
    },
   
   

    UpdatedRolinkAddress(formName){
        this.$refs[formName].validate((valid)=>{
          if(valid){
             UpdatedRolinkAddress(this.rotationformTwo.id,this.rotationformTwo).then(response=>{
                 if(response.data.state == 1){
                   this.linkVisible = false;
                    var conlinkaddress =   response.data.data.conlinkaddress;
                    this.editrotationform.linkaddress = conlinkaddress.defineaddress;
                 }
             })
          }
        })
    },

    UpdatedConrotation(formName){
        var sort =  this.editrotationform.sort;
         var sorts =  parseInt(sort);
         this.editrotationform.sort  = sorts;
       this.$refs[formName].validate((valid)=>{
         if(valid){
            UpdatedConrotation(this.editrotationform.id,this.editrotationform).then(response=>{
                 if(response.data.state == 1){
                   this.editcenterDialogVisible = false;
                    var conrotation =  response.data.data.conrotation;
                    conrotation.log("conrotation",conrotation)                   
                 }
            })
         }
       })
    }
  },   
        created(){
          this.queryConnetion();
          this.GetRotationImages();
          this.getArticleType();
        },
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
   .tpic{
     margin-left: 50px;
   }
   .map {
        width: 100%;
        height: 400px;
    }
  .tips {
    font-size: 12px;
    line-height: 18px;
   }

   .addrot{
     width: 100px;
     height: 100px;
     border: dashed 1px #409EFF;
   }

  .docone{
    width: 30px;
    height: 30px;
    // border: solid 1px red;
    margin-top: 30px;
    margin-left: 30px;
    font-size: 30px;
  }
   .doctwo{
    width: 70px;
    height: 30px;
    font-size: 14px;
    // border: solid 1px red;
    margin-left: -8px;
    margin-top: -10px;
  }


  .el-upload-list--picture-card .el-upload-list__item {
    overflow: hidden; 
    background-color: #fff; 
    border: 1px solid #c0ccda;
    border-radius: 6px;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    width: 100px;
    height: 100px;
    margin: 0 8px 8px 0;
    display: inline-block;
   }

   .flex-img__image{
     width: 100%;
     height: 100%;
   }

   .addimage{
     width: 100px;
     height: 100px;
     border: dashed 1px #409EFF;
     font-size: 30px;
   }

   .avatar-uploader-icon{
     margin-top: 30px;
     margin-left: 25px;
   }
   .avatar-uploader{
     border-color: #409EFF;
     border:dashed 1px #409eff;
     width: 100px;
     height: 100px;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 50px;
    height: 50px;
    line-height: 50px;
    margin-left: 25px;
    margin-top: 25px;
    text-align: center;
  }  

   
.used {
  ul {
    li {
      height: 44px;
      line-height: 44px;
      font-size: 14px;
      display: flex;
      color: #606266;      
      align-items: center;
      justify-content: space-between;
      border: 1px solid #e4e7ed;
      padding: 0 10px;
      margin-bottom: 10px;
      border-radius: 4px;
      i {
        font-size: 19px;
        margin: 0 6px;
        cursor: pointer;
      }
    }
  }
}
</style>
