<style>
  @import "../../assets/css/DMC.css";

</style>
<template>
  <div class="flexOne changInfo">
    <div class="resource-content clearfix">
      <el-form :model="addMsg" :rules="rules" ref="addMsg">
        <div class="resource-baseinfo">
          <span class="resource-lititle">{{$t('hotel.hotel_baseinfo')}}</span>
          <el-form-item :label="$t('hotel.hotel_name')" prop="Name">
            <el-input type="text" readonly v-model="addMsg.Name" maxlength="100" class="w300"></el-input>
          </el-form-item>
          <el-form-item :label="$t('ground.jiudianmingzi')">
            <el-input type="text" readonly v-model="addMsg.HotelRealName" maxlength="100" class="w300"></el-input>
          </el-form-item>
          <el-form-item :label="$t('hotel.hotel_describle')" prop="Descriptions">
            <el-input type="textarea" readonly v-model="addMsg.Descriptions" class="w300"></el-input>
          </el-form-item>
          <el-form-item :label="$t('hotel.hotel_openplatform')">
            <el-select disabled v-model="openplatString" class='multiple_input w300' multiple
              :placeholder="$t('pub.pleaseSel')">
              <el-option v-for="item in openplatform" :key="item.ID" :label="item.Name" :value="item.ID">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item :label="$t('hotel.hotel_brand')">
            <el-input readonly type="text" v-model="addMsg.ChainBrand" maxlength="50" class="w300"></el-input>
          </el-form-item>
          <el-form-item :label="$t('hotel.hotel_starlevel')">
            <el-select disabled class="w300" :placeholder="$t('pub.unlimitedSel')" v-model="addMsg.Star">
              <el-option :label="$t('pub.unlimitedSel')" :value='SelectDefaultValue'></el-option>
              <el-option v-for="item in starslevel" :key="item.ID" :label="item.Name" :value="item.ID"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item :label="$t('hotel.hotel_website')">
            <el-input readonly class="w300" v-model="addMsg.URL" maxlength="50">
              <template slot="prepend">https://</template>
            </el-input>
          </el-form-item>
          <el-form-item :label="$t('ground.shifouyuyue')">
            <el-switch disabled v-model="addMsg.AppointmentStyle" :active-value="inActive"
              :inactive-value="notInActive">
            </el-switch>
          </el-form-item>
          <el-form-item :label="$t('hotel.hotel_payType')">
            <el-select disabled v-model="addMsg.PayStyle" class='multiple_input w300' :placeholder="$t('pub.pleaseSel')"
              :disabled="IsHaveAuth==1?false:true">
              <el-option :label="$t('pub.unlimitedSel')" :value='SelectDefaultValue'></el-option>
              <el-option v-for="item in PayList" :key="item.Id" :label="item.Name" :value="item.Id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item :label="$t('ground.jiudianleixing')">
            <el-select disabled v-model="addMsg.HotelType" class='multiple_input w300'
              :placeholder="$t('pub.pleaseSel')">
              <el-option :label="$t('pub.unlimitedSel')" :value='SelectDefaultValue'></el-option>
              <el-option v-for="item in HotelTypeList" :key="item.ID" :label="item.Name" :value="item.ID">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item :label="$t('Operation.Op_price')">
            <el-select disabled v-model="addMsg.HotelPriceType" class='multiple_input w300'
              :placeholder="$t('pub.pleaseSel')">
              <el-option :label="$t('pub.unlimitedSel')" :value='SelectDefaultValue'></el-option>
              <el-option v-for="item in HotelPirceTypeList" :key="item.ID" :label="item.Name" :value="item.ID">
              </el-option>
            </el-select>
          </el-form-item>
          <span class="resource-lititle sheshi">{{$t('hotel.hotel_services')}}</span>
          <div class="res-span" v-for="item in serviceList" :key="item.subCode">
            <span class="common-lefttit">{{item.Content}}</span>
            <span>
              <el-select disabled multiple :placeholder="$t('pub.pleaseSel')" class='multiple_input w300'
                v-model="item.checked">
                <el-option v-for="subitem in item.list" :key="subitem.ID" :label="subitem.Content" :value="subitem.ID">
                </el-option>
              </el-select>
            </span>
          </div>
          <span class="resource-lititle sheshi">{{$t('ground.jiudianyouhui')}} <el-button icon="el-icon-plus" circle
              @click="addAir"></el-button>
          </span>

          <div class="jiudianyouhuiDiv">
            <el-row v-for="(list,index) in addMsg.DiscountList" :key="index">
              <el-col :span="6" :gutter="35">
                <el-form-item :label="$t('ground.kaishishuliang')">
                  <el-input readonly class='w80' type="text" v-model="list.StartNum"
                    @keyup.native="checkInteger(list,'StartNum')" maxlength="2"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6" :gutter="35">
                <el-form-item :label="$t('ground.jieshushuliang')">
                  <el-input readonly class='w80' type="text" v-model="list.EndNum"
                    @keyup.native="checkInteger(list,'EndNum')" maxlength="2"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6" :gutter="35">
                <el-form-item :label="$t('ground.fanhuanshuliang')">
                  <el-input readonly class='w80' type="text" v-model="list.DisCountNum"
                    @keyup.native="checkInteger(list,'DisCountNum')" maxlength="2"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6" :gutter="35" v-if="index==0">

              </el-col>
              <el-col :span="6" :gutter="35">
                <el-button icon="el-icon-minus" circle @click="deleteAir(index)" disabled> </el-button>
              </el-col>
            </el-row>
          </div>
          <span class="resource-lititle sheshi">{{$t('hotel.hotel_type')}}</span>
          <div class="res-span">
            <el-tree :data="categoryTree" disabled default-expand-all
              :props="{label: 'CategoryName', children: 'SubList'}" show-checkbox node-key="Id" ref="treeForm"
              @check-change="handleNodeClick">
            </el-tree>
          </div>
        </div>
        <div class="resource-imginfo">
          <div class="resourcerightTop">
            <div class="toolOne">
              <span class="fanbili">{{$t('restaurant.res_commissionColumn')}}</span>
              <div class="RabateDiv clearfix">
                <div class="RebateCount reOne">
                  <div class="leftPnum">{{$t('admin.admin_personNumber')}}</div>
                  <input type="text" disabled class="toolInput inpuOne" v-model="addMsg.RebateCount"
                    onkeyup="value=value.replace(/[^\d]/g,'')" maxlength="20">
                </div>
                <div class="RebateCount reTwo">
                  <div class="fanNum">{{$t('restaurant.res_return')}}</div>
                  <input type="text" disabled class="toolInput inpuTwo" v-model="addMsg.RebateRatio"
                    onkeyup="value=value.replace(/[^\d]/g,'')" maxlength="20">
                  <div class="percentCon">%</div>
                </div>
              </div>
            </div>
            <el-form-item :label="$t('hotel.hotel_landline')">
              <el-input type="text" readonly v-model="addMsg.Tel" maxlength="20"
                :placeholder="$t('hotel.hotel_landline')" class="w300"></el-input>
            </el-form-item>
            <el-form-item :label="$t('system.table_country')">
              <el-select disabled :placeholder="$t('visaT.qxzguojia')" filterable v-model="addMsg.Country"
                class='multiple_input w300' @change="GetSubAreaList(addMsg.Country,1)">
                <el-option :label="$t('pub.unlimitedSel')" :value='SelectDefaultValue'></el-option>
                <el-option v-for="childItem in CountryList" :key="childItem.ID" :label="childItem.Name"
                  :value="childItem.ID">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('hotel.hotel_province')">
              <el-select disabled :placeholder="$t('ground.qingxuanzesheng')" filterable class='multiple_input w300'
                v-model="addMsg.Province" @change="GetSubAreaList(addMsg.Province,2)">
                <el-option :label="$t('pub.unlimitedSel')" :value='SelectDefaultValue'></el-option>
                <el-option v-for="childItem in ProvinceList" :key="childItem.ID" :label="childItem.Name"
                  :value="childItem.ID">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('hotel.hotel_city')">
              <el-select disabled :placeholder="$t('ground.qingxuanzeshi')" filterable class='multiple_input w300'
                v-model="addMsg.City">
                <el-option :label="$t('pub.unlimitedSel')" :value='SelectDefaultValue'></el-option>
                <el-option v-for="childItem in CityList" :key="childItem.ID" :label="childItem.Name"
                  :value="childItem.ID">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('hotel.hotel_detailinfo')" prop="Address">
              <el-input readonly :placeholder="$t('fnc.qsrneirong')" class="w300 addAddress" v-model="addMsg.Address">
                <!-- <el-button slot="append" @click="selectAddress = true" icon="iconfont icon-img_dw"></el-button> -->
              </el-input>
            </el-form-item>
            <div class="toolOne">
              <span class="fanbili">{{$t('objFill.diliweizhi')}}</span>
              <div class="RabateDiv clearfix">
                <div class="RebateCount reOne">
                  <div class="leftPnum">{{$t('hotel.hotel_jingdu')}}</div>
                  <input readonly type="text" class="toolInput inpuOne" v-model="addMsg.Lng" maxlength="20">
                </div>
                <div class="RebateCount reTwo">
                  <div class="fanNum">{{$t('hotel.hotel_weidu')}}</div>
                  <input readonly type="text" class="toolInput inpuTwo" v-model="addMsg.Lat" maxlength="20">
                </div>
              </div>
            </div>
            <el-form-item :label="$t('hotel.hotel_fax')">
              <el-input readonly type="text" v-model="addMsg.Fax" maxlength="20" class="w300"></el-input>
            </el-form-item>
            <el-form-item :label="$t('hotel.hotel_deadday')" prop="DieLine">
              <el-input readonly type="text" onkeyup="value=value.replace(/[^\d]/g,'')" maxlength="50"
                v-model="addMsg.DieLine" class="w300"></el-input><span class="hotelDay">{{$t('hotel.hotel_day')}}</span>
            </el-form-item>
            <el-form-item :label="$t('hotel.hotel_remark')">
              <el-input readonly type="textarea" v-model="addMsg.Remark" class="w300"></el-input>
            </el-form-item>
            <el-form-item :label="$t('hotel.hotel_warm')">
              <el-input readonly type="textarea" v-model="addMsg.WarmTip" class="w300"></el-input>
            </el-form-item>
            <el-form-item>
              <el-switch disabled v-model="isBook" active-color="#13ce66" inactive-color="#ff4949"
                :active-text="$t('hotel.hotel_Supplier')" :inactive-text="$t('ground.ziding')"></el-switch>
            </el-form-item>
            <el-form-item>
              <el-switch disabled v-model="isDinner" active-color="#13ce66" @change="getDinnerList"
                inactive-color="#ff4949" :active-text="$t('commonPickUp.Pick_Ding')"
                :inactive-text="$t('ground.buyongcan')"></el-switch>
            </el-form-item>
            <el-form-item :label="$t('ground.yongcanleixing')" v-show="isDinner">
              <el-select disabled v-model="UseDinnerString" class='multiple_input w300' multiple
                :placeholder="$t('pub.pleaseSel')">
                <el-option v-for="item in dinerList" :key="item.Id" :label="item.Name" :value="item.Id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('ground.tingchechang')">
              <el-switch disabled v-model="addMsg.IsHavearking" :active-value="1" :inactive-value="0"></el-switch>
            </el-form-item>
            <el-form-item :label="$t('ground.tingchefei')" v-if="addMsg.IsHavearking==1">
              <el-input readonly type="text" v-model="addMsg.ParkFee" class="w300" maxlength="10"
                @keyup.native="checkPrice(addMsg,'ParkFee')"></el-input>
            </el-form-item>
            <el-form-item :label="$t('ground.rutangshui')">
              <el-input readonly type="text" v-model="addMsg.InTangTax" class="w300" maxlength="10"
                @keyup.native="checkPrice(addMsg,'InTangTax')"></el-input>
            </el-form-item>
            <el-form-item :label="$t('ground.chengshishui')">
              <el-input readonly type="text" v-model="addMsg.CityTax" class="w300" maxlength="10"
                @keyup.native="checkPrice(addMsg,'CityTax')"></el-input>
            </el-form-item>
            <el-form-item :label="$t('ground.fanyongleixing')">
              <el-select disabled v-model="addMsg.RebateType" class='multiple_input w300'
                :placeholder="$t('pub.pleaseSel')">
                <el-option :key="0" :label="$t('pub.unlimitedSel')" :value="0"> </el-option>
                <el-option :key="1" :label="$t('ground.hanshuifanyong')" :value="1"> </el-option>
                <el-option :key="2" :label="$t('ground.bhanshuifanyong')" :value="2"> </el-option>
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('ground.sidaojianshifoufany')">
              <el-select disabled v-model="addMsg.DriverGuideIsRebate" class='multiple_input w300'
                :placeholder="$t('pub.pleaseSel')">
                <el-option :key="0" :label="$t('ground.bufanyong')" :value="0"> </el-option>
                <el-option :key="1" :label="$t('hotel.hotel_commission')" :value="1"> </el-option>
              </el-select>
            </el-form-item>
          </div>
          <span class="resource-lititle">{{$t('hotel.hotel_imgintroduce')}}</span>
          <div class="resource-list">
            <div class="resource-imglist clearfix">
              <div class="re-img" v-for="(item,index) in HotelImageArray" :key="item.subCode">
                <div class="re-img">
                  <el-image style="height: 100px" :src="item.ShowPath" :preview-src-list="DiningImageUrlArray">
                  </el-image>
                </div>
              </div>
            </div>
          </div>
        </div>
      </el-form>
    </div>
    <el-dialog custom-class="resourceImgAdd" :title="$t('ground.xuanzetupian')" center :visible.sync="addimg">
      <DMCchooseImg @closeImg="closeDMCchooseImg" ref="DMCchooseImg1" @headCallBack="getDMCimg" v-bind:imgType="1">
      </DMCchooseImg>
    </el-dialog>
    <el-dialog custom-class="mapList" :title="$t('hotel.hotel_mapLocation')" center :visible.sync="selectAddress">
      <googleMap @refList="googleMap" v-bind:address="addMsg.Address" @headCallBack="headCall"></googleMap>
    </el-dialog>
    <div class="btn-list">
      <span class="common-lefttit"></span>
      <button class="cancel-Btn" @click="goUrl('HotelManagement')">{{$t('pub.returnBack')}}</button>
    </div>
    <viewer :images="images" :options='imageOptions' @inited="inited" class="viewer" ref="viewer">
      <img v-for="src in images" :src="src" :key="src">
    </viewer>
  </div>
</template>
<script>
  import DMCchooseImg from "../commonPage/DMCchooseImg.vue";
  import googleMap from "../commonPage/googleMap.vue";
  export default {
    data() {
      return {
        categoryTree: [],
        imageOptions: {
          navbar: false,
          title: false
        },
        //是否有权限操作支付方式
        IsHaveAuth: 0,
        images: [],
        //是否显示添加图片
        addimg: false,
        //地图选中地址
        selectAddress: false,
        //上传的文件数组
        HotelImageArray: [],
        DiningImageUrlArray: [],
        //删除的图片文件数组
        DeleteImageArray: [],
        //地接资源图片
        imglistArry: [],
        //地接图片搜索关键字
        imgKeyword: "",

        openplatform: "", //获取开放平台
        starslevel: "", //获取酒店星级
        serviceList: [], //获取酒店服务
        GetPolicy: "", //获取酒店政策
        OpenPlatformStrings: "",
        UseDinnerformString: "",
        totalimg: "",
        selecnum: 0,
        hotelID: "",
        openplatString: "",
        UseDinnerString: "",
        inActive: 1, //已选中
        notInActive: 0, //未选中
        SupplierList: "",
        imgBeforeFile: this.domainManager().ViittoFileUrl,
        isBook: true,
        isDinner: false,
        dinerList: "",
        //下拉框默认值
        SelectDefaultValue: 0,
        //国家列表
        CountryList: [],
        //省份列表
        ProvinceList: [],
        //城市列表
        CityList: [],
        //支付方式
        PayList: [],
        //酒店类型
        HotelTypeList: [],
        //酒店价格
        HotelPirceTypeList: [],
        addMsg: {
          ID: 0,
          Name: "",
          HotelRealName: "",
          Descriptions: "",
          Tel: "",
          Remark: "",
          //温馨提示
          WarmTip: "",
          Star: "",
          URL: "",
          Fax: "",
          QCountry: "",
          QProvince: "",
          QCity: "",
          District: 0,
          Address: "",
          Lng: "",
          Lat: "",
          HotelType: 0,
          HotelPriceType: 0,
          DieLine: "",
          HotelImageList: [], //现在的图片
          DeleteImageList: [], //要删除的图片
          DiscountList: [],
          RoomNumber: "",
          ChainBrand: "",
          FacilityServices: "",
          HotelPolicy: "",
          OpenPlatform: "",
          RebateCount: "",
          RebateRatio: "",
          IsSelfBook: "",
          IsUseDinner: "0",
          UseDinnerType: "",
          Country: 0,
          Province: 0,
          City: 0,
          //是否预约
          AppointmentStyle: 0,
          //支付方式
          PayStyle: 0,
          //是否有停车场
          IsHavearking: 0,
          //入汤税
          InTangTax: 0,
          //城市税
          CityTax: 0,
          //停车费
          ParkFee: 0,
          //返佣类型：1-含税返佣，2-不含税返佣
          RebateType: 0,
          //司导房是否返佣：0-不返佣，1-返佣
          DriverGuideIsRebate: 0,
        },
        DiscountList: {
          ID: 0,
          StartNum: '',
          EndNum: '',
          DisCountNum: ''
        },
        qMsg: {},
        rules: {
          //表单必填验证
          Name: [{
            required: true,
            message: this.$t('ground.qingtianxiemc'),
            trigger: "change"
          }],
          Address: [{
            required: true,
            message: this.$t('ground.qingxuanzedz'),
            trigger: "change"
          }],
          Descriptions: [{
            required: true,
            message: this.$t('ground.qingshuruwzms'),
            trigger: "change"
          }],
          DieLine: [{
            pattern: this.$commonUtils.Regex.el_isInteger,
            message: this.$t('ground.qingshuruzqdsz')
          }]
        }
      };
    },
    components: {
      googleMap: googleMap,
      DMCchooseImg: DMCchooseImg
    },
    methods: {
      deleteAir(i) {
        this.addMsg.DiscountList.splice(i, 1);
      },
      addAir() {
        this.addMsg.DiscountList.push(JSON.parse(JSON.stringify(this.DiscountList)));
      },
      //上传酒店图片
      UploadImage(file) {
        let newArr = [];
        newArr.push(file.file);
        let fileName = file.file.name;
        var path = "/Upload/DMC/";
        this.UploadSelfFileT(path, newArr, x => {
          var obj = this.$DMCUtils.DMCImageObj();
          var str = x.data.FilePath;
          var imgUrl = this.domainManager().ViittoFileUrl + x.data.FilePath;
          obj.Path = str;
          obj.ShowPath = imgUrl;
          this.HotelImageArray.push(obj);
        });
      },
      //更新酒店图片
      updatePic() {
        if (this.hotelID > 0) {
          var postMsg = {
            ID: this.hotelID,
            Name: this.addMsg.Name,
            HotelImageList: this.HotelImageArray, //新增修改
            DeleteImageList: this.DeleteImageArray //删除的图片
          };
          this.apipost(
            "hotel_post_UpateHotelPic",
            postMsg,
            res => {
              if (res.data.resultCode == 1) {
                this.Success(this.$t('ground.tupianczcg'));
              }
            },
            null
          );
        }
      },
      //删除图片
      delImg(index) {
        var item = this.HotelImageArray[index];
        this.DeleteImageArray.push(item);
        this.HotelImageArray.splice(index, 1);
      },
      inited(viewer) {
        this.$viewer = viewer
      },
      showImg: function (src) {
        let srcArr = src.split('?')
        src = srcArr[0]
        let isExsit = false
        this.images.forEach(x => {
          if (x === src)
            isExsit = true
        })
        if (!isExsit) {
          this.images.push(src)
        } else {
          this.$viewer.view(this.images.indexOf(src))
        }
        this.$viewer.show()
      },
      addImgOpen() {
        this.addimg = true;
        this.initimgList();
      },
      saveResource() {
        //保存酒店信息
        if (this.isBook) {
          this.addMsg.IsSelfBook = 1;
        } else {
          this.addMsg.IsSelfBook = 0;
        }
        this.addMsg.FacilityServices = `${JSON.stringify(this.serviceList)}`;
        this.addMsg.HotelPolicy = `${JSON.stringify(this.GetPolicy)}`;
        this.addMsg.OpenPlatform = this.openplatString.toString();
        this.addMsg.UseDinnerType = this.UseDinnerString.toString();
        if (this.addMsg.IsUseDinner == 0) {
          this.addMsg.UseDinnerType = "";
        }
        if (this.hoteID != "undefined") {
          this.addMsg.ID = this.hotelID;
        }

        this.addMsg.HotelImageList = this.HotelImageArray;
        this.addMsg.DeleteImageList = this.DeleteImageArray;
        // this.addMsg.WebSiteCategoryIds = this.checkedId.join(',')
        this.addMsg.WebSiteCategoryIds = this.getLastSubmitIds()
        this.apipost(
          "hotel_post_Set",
          this.addMsg,
          response => {
            //修改添加接口
            if (response.data.resultCode == 1) {
              this.Success(this.$t('tips.saveYes'));
              this.goUrl("HotelManagement");
            } else {
              this.Error(response.data.message);
            }
          },
          null
        );
      },
      init() {
        var msg = {};
        this.apipost(
          "hotel_post_GetStar",
          msg,
          response => {
            //初始化星级
            if (response.data.resultCode == 1) {
              this.starslevel = response.data.data;
            }
          },
          null
        );
        this.apipost("hotel_post_GetPlatform", msg, res => {
          //获取开放平台
          this.openplatform = res.data.data;
        });
      },
      inithotelService() {
        //初始化酒店服务
        let msg = {
          Key: "SK_HOTEL_SERVICE"
        };
        this.apipost("dict_post_GetList", msg, res => {
          if (res.data.resultCode == 1) {
            var tempArray = res.data.data;
            tempArray.forEach(item => {
              item.checked = [];
            });
            this.serviceList = tempArray;
          }
        });
      },
      inithotelPolicy() {
        //初始化酒店政策
        let msg = {
          Key: "SK_HOTEL_POLICY"
        };
        this.apipost("dict_post_GetList", msg, response => {
          if (response.data.resultCode == 1) {
            this.GetPolicy = response.data.data;
          }
        });
      },
      initimgList() {
        //初始化弹窗图片列表
        var keyWord = this.imgKeyword;
        this.imglistArry = [];
        let msg = {
          Name: keyWord
        };
        this.apipost(
          "hotel_post_GetPicList",
          msg,
          res => {
            if (res.data.resultCode == 1) {
              this.imglistArry = res.data.data;
              this.totalimg = this.imglistArry.length;
            }
          },
          null
        );
      },
      selectImg(index) {
        //选取弹窗图片
        this.imglistArry[index].isShow = !this.imglistArry[index].isShow;
        let num = 0;
        if (this.imglistArry != null) {
          this.imglistArry.forEach(x => {
            if (x.isShow == true) {
              num++;
            }
            this.selecnum = num;
          });
        }
      },
      initCategoryTree() {
        var msg = {};
        var _self = this;
        this.apipost(
          "ws_post_GetCategoryTreeList",
          msg,
          res => {
            if (res.data.resultCode == 1) {
              let categoryTree = res.data.data.filter(item => item.CategoryName === '住宿')
              this.addParentId(categoryTree, [])
              this.categoryTree = categoryTree
              this.setSelectedKeys()
            } else {
              _self.Error(res.data.message);
            }
          },
          null
        );
      },
      addParentId(tree, idArr) {
        tree.forEach(item => {
          item.ids = [...idArr, item.Id]
          if (item.SubList && item.SubList.length) {
            this.addParentId(item.SubList, item.ids)
          }
        })
      },
      setSelectedKeys() {
        this.arr = []
        if (this.checkedId.length && this.categoryTree.length) {
          this.findSelcetedKey(this.categoryTree)

          if (this.$refs.treeForm) {
            this.$refs.treeForm.setCheckedKeys(this.arr)
          }
        }
      },
      findSelcetedKey(tree, ) {
        tree.forEach(item => {
          if (item.SubList && item.SubList.length) {
            this.findSelcetedKey(item.SubList)
          } else {
            if (this.checkedId.includes(item.Id)) {
              this.arr.push(item.Id)
            }
          }
        })
      },
      getLastSubmitIds() {
        this.idsList = []
        this.selectedKeys = this.$refs.treeForm.getCheckedKeys()
        this.getSelcetedKeyIds(this.categoryTree)
        return [...new Set(this.idsList)].join(',')
      },
      getSelcetedKeyIds(tree) {
        tree.forEach(item => {
          if (item.SubList && item.SubList.length) {
            this.getSelcetedKeyIds(item.SubList)
          }
          if (this.selectedKeys.includes(item.Id)) {
            this.idsList = this.idsList.concat(item.ids)
          }
        })
      },
      handleNodeClick(data, checked, node) {},
      initHotelData() {
        var msg = {
          hotelID: this.hotelID
        };
        this.getDinnerList();
        var _self = this;
        this.apipost(
          "hotel_post_GetAll",
          msg,
          res => {
            if (res.data.resultCode == 1) {
              this.checkedId = res.data.data.WebSiteCategoryIds ? res.data.data.WebSiteCategoryIds.split(',').map(
                item => Number(item)) : []
              this.setSelectedKeys()
              _self.addMsg = res.data.data;
              if (_self.addMsg.Country > 0) {
                this.GetSubAreaList(_self.addMsg.Country, 1, 1);
              }
              if (_self.addMsg.Province > 0) {
                this.GetSubAreaList(_self.addMsg.Province, 2, 1);
              }
              if (_self.addMsg.IsUseDinner == 1) {
                _self.isDinner = true;
              } else {
                _self.isDinner = false;
              }
              if (_self.addMsg.UseDinnerType != "") {
                _self.UseDinnerformString = _self.addMsg.UseDinnerType.split(",");
                _self.UseDinnerformString.forEach(x => {
                  _self.UseDinnerString.push(Number(x));
                });
              }

              if (_self.addMsg.OpenPlatform != "") {
                _self.OpenPlatformStrings = _self.addMsg.OpenPlatform.split(",");
                _self.OpenPlatformStrings.forEach(x => {
                  _self.openplatString.push(Number(x));
                });
              }
              if (_self.addMsg.FacilityServices != "") {
                var itemArray = JSON.parse(_self.addMsg.FacilityServices);
                _self.serviceList.forEach(item => {
                  var isFind = false;
                  for (var i = 0; i < itemArray.length; i++) {
                    if (
                      item.ID == itemArray[i].ID &&
                      itemArray[i].hasOwnProperty("checked")
                    ) {
                      item.checked = itemArray[i].checked;
                      break;
                    }
                  }
                });
              }
              if (_self.addMsg.HotelPolicy != "") {
                _self.GetPolicy = JSON.parse(_self.addMsg.HotelPolicy);
              }
              _self.isBook = _self.addMsg.IsSelfBook;
              if (res.data.data.List != null) {
                //临时文件
                res.data.data.List.forEach(imgItem => {
                  var obj = this.$DMCUtils.DMCImageObj();
                  obj.ID = imgItem.ID;
                  obj.Path = imgItem.Path;
                  obj.PicID = imgItem.PicID;
                  obj.ShowPath =
                    _self.imgBeforeFile +
                    imgItem.Path;
                  this.HotelImageArray.push(obj);
                  this.DiningImageUrlArray.push(_self.imgBeforeFile +
                    imgItem.Path);
                });
              }
            } else {
              _self.Error(res.data.message);
            }
          },
          null
        );
      },
      goUrl(path) {
        this.$router.push({
          path: path,
          query: {
            cache: true
          }
        });
      },
      submitForm(addMsg) {
        //提交创建、修改表单
        let that = this;
        that.$refs[addMsg].validate(valid => {
          if (valid) {
            that.saveResource();
          } else {
            return false;
          }
        });
      },
      //选中的数组
      checkImgList() {
        if (this.imglistArry != null) {
          this.imglistArry.forEach(x => {
            if (x.isShow == true) {
              var obj = this.$DMCUtils.DMCImageObj();
              obj.Path = "/U" + this.$commonUtils.getCaption(x.Path, "Upload");
              obj.ShowPath = x.Path;
              obj.PicID = x.ID;
              this.HotelImageArray.push(obj);
            }
            x.isShow = false;
            this.selecnum = 0;
          });
        }
        this.addimg = false;
      },
      googleMap() {
        this.selectAddress = false;
      },
      closeDMCchooseImg() {
        this.addimg = false;
      },
      headCall(msg) {
        // this.addMsg.QCountry = msg.country;
        // this.addMsg.QProvince = msg.province;
        // this.addMsg.QCity = msg.city;
        // this.addMsg.Address = msg.address;
        this.addMsg.Lng = msg.lng;
        this.addMsg.Lat = msg.lat;
      },
      getDMCimg(imgArr) {
        imgArr.forEach(imgItem => {
          var obj = this.$DMCUtils.DMCImageObj();
          obj.ID = 0;
          obj.Path = this.$commonUtils.removeDomain(imgItem.Path);
          obj.PicID = imgItem.ID;
          obj.ShowPath = imgItem.Path + "?x-oss-process=image/resize,l_140";
          this.HotelImageArray.push(obj);
        });
      },
      getSuplier() {
        let msg = {
          Type: 1
        }; //HK新增查询条件
        this.apipost(
          "supplier_post_GetAllList",
          msg,
          response => {
            if (response.data.resultCode == 1) {
              this.SupplierList = response.data.data;
            }
          },
          null
        );
      },
      //获取用餐列表
      getDinnerList() {
        if (this.isDinner) {
          this.addMsg.IsUseDinner = 1;
        } else {
          this.addMsg.IsUseDinner = 0;
        }
        let msg = {};
        this.apipost(
          "hotel_get_GetUseDinnerTypeList",
          msg,
          res => {
            if (res.data.resultCode == 1) {
              this.dinerList = res.data.data;
            }
          },
          null
        );
      },
      //获取国家
      GetCounrty() {
        this.apipost(
          "dict_post_Destination_GetCountry", {},
          res => {
            this.CountryList = res.data.data;
          },
          err => {}
        );
      },
      //获取省份和城市
      GetSubAreaList(ID, type, isClear) {
        let msg = {
          Id: ID
        };
        if (type == 1) {
          if (isClear != 1) {
            this.addMsg.Province = 0;
            this.addMsg.City = 0;
          }
        } else if (type == 2) {
          if (isClear != 1) {
            this.addMsg.City = 0;
          }
        }
        if (this.addMsg.Country != 0) {
          this.apipost(
            "dict_post_Destination_GetChildList",
            msg,
            res => {
              if (type == 1) {
                this.ProvinceList = res.data.data;
              } else if (type == 2) {
                this.CityList = res.data.data;
              }
            },
            err => {}
          );
        }
      },
      //获取支付方式列表
      GetPayList() {
        this.apipost(
          "dmc_post_Get_GetPayStyleList", {},
          res => {
            if (res.data.resultCode == 1) {
              this.PayList = res.data.data;
            }
          },
          err => {}
        );
      },
      //获取酒店类型列表
      GetHotelTypeList() {
        this.apipost(
          "dmc_post_Get_GetHotelType", {},
          res => {
            if (res.data.resultCode == 1) {
              this.HotelTypeList = res.data.data;
            }
          },
          err => {}
        );
      },
      GetHotelPirceTypeList() {
        this.apipost(
          "dmc_post_Get_GetHotelPriceType", {},
          res => {
            if (res.data.resultCode == 1) {
              this.HotelPirceTypeList = res.data.data;
            }
          },
          err => {}
        );
      },
      //图片左移右移
      ExchangeImg(index, IsMove) {
        var imgItem = this.HotelImageArray[index];
        //左移
        if (IsMove == 0) {
          var upItem = this.HotelImageArray[index - 1];
          this.$set(this.HotelImageArray, index - 1, imgItem);
          this.$set(this.HotelImageArray, index, upItem);
        } else {
          //右移动
          var downItem = this.HotelImageArray[index + 1];
          this.$set(this.HotelImageArray, index + 1, imgItem);
          this.$set(this.HotelImageArray, index, downItem);
        }
      },


    },
    mounted() {
      this.checkedId = []
      let userInfo = this.getLocalStorage()
      //有权限操作的部门
      if (userInfo.RB_Department_Id == 240 || userInfo.RB_Department_Id == 1 || userInfo.RB_Department_Id == 3 ||
        userInfo.RB_Branch_id == 49 || userInfo.RB_Group_id == 100) {
        this.IsHaveAuth = 1;
      }
      this.GetPayList();
      this.GetHotelTypeList();
      this.GetHotelPirceTypeList();
      this.qMsg = this.$route.query.qMsg;
      this.hotelID = this.$route.query.id;
      this.GetCounrty();
      this.inithotelService(); //初始化酒店服务
      this.inithotelPolicy(); //初始化酒店政策
      this.init(); //初始化星级和开放平台
      this.getSuplier(); //初始化供应商

      if (this.hotelID > 0) {
        this.initHotelData();
      }
      this.initCategoryTree()
    }
  };

</script>
