<template>
  <!-- 旅游：创建、编辑 -->
  <div>
    <h4>{{title}}</h4>
    <el-form :model="form" :rules="rules" ref="form" label-width="90px">
      <el-row>
        <el-col :span="8">
          <el-form-item label="旅行名称" prop="name">
            <el-input v-model="form.name" placeholder="请输入旅行名称"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="描述">
            <el-input v-model="form.describe" placeholder="请输入描述"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="4">
          <el-form-item label="旅行原价" prop="price">
            <el-input v-model="form.price" type="number" min="0" placeholder="请输入旅行原价"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="儿童价" prop="childPrice">
            <el-input v-model="form.childPrice" type="number" min="0" placeholder="请输入儿童价"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="4">
          <el-form-item label="是否为推荐">
            <el-radio class="radio" v-model="form.recommend" label="1">是</el-radio>
            <el-radio class="radio" v-model="form.recommend" label="0">否</el-radio>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="会员价格">
            <el-radio class="radio" v-model="form.isMember" label="1">启用会员价</el-radio>
            <el-radio class="radio" v-model="form.isMember" label="0">不启用会员价</el-radio>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="">
        <el-radio class="radio" v-model="form.isOutside" label="0">省内</el-radio>
        <el-radio class="radio" v-model="form.isOutside" label="1">省外</el-radio>
      </el-form-item>
      <el-row>
        <el-col :span="4">
          <el-form-item label="库存" prop="stock">
            <el-input v-model="form.stock" placeholder="请输入总人数" type="number" min="0"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <!--<el-col :span="24">-->
        <el-form-item label="出发地">
          <el-input style="display: inline-block;margin-right: 10px;width: 240px;" v-model="item.name"
                    v-for="item in departureList"
                    :key="item.id" readonly placeholder="请输入内容"></el-input>
          <el-button size="small" class="el-button el-button--primary" type="button" icon="edit"
                     @click="editDeparture(departureList)">编辑
          </el-button>
          <!--<el-autocomplete-->
          <!--v-for="item in departureList"-->
          <!--:key="item.id"-->
          <!--class="inline-input"-->
          <!--style="margin-left: 10px;"-->
          <!--v-model="item.name"-->
          <!--:fetch-suggestions="querySearch"-->
          <!--placeholder="请输入内容"-->
          <!--@select="handleSelect"-->
          <!--&gt;</el-autocomplete>-->
        </el-form-item>
        <!--</el-col>-->
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="目的地">
            <el-input v-model="destinationObj.address" readonly placeholder="请选择目的地" :on-icon-click="selectDestination"
                      icon="edit"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <!--<el-col :span="6">-->
        <el-form-item label="途径地">
          <!--<el-input  v-for="item in pathway" style="display: inline-block;margin-right: 10px;width: 240px;"-->
          <!--:key="item.id" v-model="item.name" readonly placeholder="请选择途径地" :data-rowId="item.id" :on-icon-click="selectPathway" icon="edit"></el-input>-->
          <el-button v-for="item in pathway"
                     :key="item.id" size="small" class="el-button el-button--primary" type="button"
                     @click="editPathway(item)">{{item.name}}<i class="el-icon-edit el-icon--right"></i></el-button>
          <el-button size="small" class="el-button el-button--primary" type="button" icon="plus" @click="addPathway()">
            添加
          </el-button>
        </el-form-item>
        <!--</el-col>-->
      </el-row>
      <el-row>
        <el-form-item prop="operator" label="活动日期">
          <!--tourDepartTimeVo-->
          <el-button v-for="item in form.tourDepartTimeVo" disabled
                     :key="item.id" class="el-button el-button--default" type="button">
            {{item.startTime}}~{{item.endTime}}
          </el-button>

          <el-button size="small" class="el-button el-button--primary" type="button" icon="edit" @click="editTime()">
            编辑
          </el-button>
          <!--<el-input v-model="form.operator" placeholder="请选择活动日期"></el-input>-->
        </el-form-item>
      </el-row>
      <el-form-item label="旅行标签">
        <span v-for="item in form.tagDTOS"
              :key="item.id" style="border: 1px solid #ccc; padding: 5px 10px;border-radius: 5px;margin-right: 10px;">{{item.name}}</span>
        <!--<el-checkbox-group v-model="checkList">-->
        <!--<el-checkbox  v-for="item in allLabelList"-->
        <!--:key="item.id" :label="item.name"></el-checkbox>-->
        <!--</el-checkbox-group>-->
        <el-button size="small" class="el-button el-button--primary" type="button" icon="edit"
                   @click="editLable(form.tagDTOS)">编辑
        </el-button>
      </el-form-item>
      <el-row>
        <el-col :span="4">
          <el-form-item label="浏览量">
            <el-input v-model="form.viewCount" placeholder="请输入浏览量" type="number" min="0"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="排序">
            <el-input v-model="form.rank" placeholder="请输入排序值" type="number" min="0"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="单位">
            <el-input v-model="form.unit" placeholder="人"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="销量">
            <el-input v-model="form.saleCount" type="number" min="0" placeholder="请输入销量"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <!--BASE_API + -->
      <el-form-item label="封面图" :style="{display:'block'}">
        <el-upload
          class="upload-demo"
          :headers="getHeaderWithToken"
          :action="BASE_API+'/api/universal/file/app/unauth/admin/upload'"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :on-progress="uploadProcess"
          list-type="picture">
          <div slot="tip" class="el-upload__tip"><span style="color: red;">建议尺寸：320*228px</span></div>
          <el-progress v-show="imgFlag == true" type="circle" :percentage="percent"
                       style="margin-top: 20px"></el-progress>
          <img v-if="$utils.isString(form.cover) && !$utils.isEmpty(form.cover) && !imgFlag" :src="form.cover"
               style="width:300px;max-height:300px;">
          <i v-else-if="!imgFlag" class="el-icon-plus avatar-uploader-icon"
             style="lineHeight:100px;width:300px;height: 100px;border: 1px dashed #ccc;"></i>
        </el-upload>
      </el-form-item>
      <el-row>
        <el-col :span="8">
          <el-form-item label="alt">
            <el-input v-model="form.alt" type="text" placeholder="请输入替代文本"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="img-title">
            <el-input v-model="form.imgTitle" type="text" placeholder="请输入图片title"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="img-keyword">
            <el-input v-model="form.imgKeyword" type="text" placeholder="请输入图片关键字"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="img-desc">
            <el-input v-model="form.imgDesc" type="text" placeholder="请输入图片描述"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="海报背景" :style="{display:'block'}">
        <el-upload
          class="upload-demo"
          :headers="getHeaderWithToken"
          :action="BASE_API+'/api/universal/file/app/unauth/admin/upload'"
          :show-file-list="false"
          :on-success="handlePosterSuccess"
          :on-progress="uploadPosterProcess"
          list-type="picture">
          <div slot="tip" class="el-upload__tip"><span style="color: red;">建议尺寸：320*228px</span></div>
          <el-progress v-show="imgPosterFlag == true" type="circle" :percentage="percent_poster"
                       style="margin-top: 20px"></el-progress>
          <img v-if="$utils.isString(form.posterBackground) && !$utils.isEmpty(form.posterBackground)&& !imgPosterFlag"
               :src="form.posterBackground" style="width:300px;max-height:300px;">
          <i v-else-if="!imgPosterFlag" class="el-icon-plus avatar-uploader-icon"
             style="lineHeight:100px;width:300px;height: 100px;border: 1px dashed #ccc;"></i>
        </el-upload>
      </el-form-item>
      <el-form-item label="轮播图" :style="{display:'block'}">
        <el-upload
          class="upload-demo"
          :headers="getHeaderWithToken"
          :action="BASE_API+'/api/universal/file/app/unauth/admin/upload'"
          :on-remove="handleRemove"
          :file-list="fileList2"
          :on-success="handleBannerSuccess"
          list-type="picture">
          <div slot="tip" class="el-upload__tip">最多上传5张 <span style="color: red;">建议尺寸：1080*644px</span></div>
          <el-button v-if="fileList2.length<5" size="small" type="primary">点击上传</el-button>
        </el-upload>
      </el-form-item>
      <el-tabs v-model="activeName2" type="card" @tab-click="handleClick">
        <el-tab-pane label="行程亮点" name="first">
          <div class="editor-container" v-if="activeName2=='first'">
            <UE :editorId="activeName2" :defaultMsg="form.content" :config=config ref="ue"
                @ready="editorReadyEvent"></UE>
          </div>
          <!--<Editor  v-if="activeName2=='first'" @input="handelContentIncrease" :value="form.content" :myQuillEditor="'myQuillEditorContent'" :activeName2="activeName2"></Editor>-->
        </el-tab-pane>
        <el-tab-pane label="行程介绍" name="second">
          <div class="editor-container" v-if="activeName2=='second'">
            <UE :editorId="activeName2" :defaultMsg="form.introduce" :config=config ref="ue"
                @ready="editorReadyEvent"></UE>
          </div>
          <!--<Editor v-if="activeName2=='second'" @input="handelIntroduceIncrease" :value="form.introduce" :myQuillEditor="'myQuillEditorIntroduce'" :activeName2="activeName2"></Editor>-->
        </el-tab-pane>
        <el-tab-pane label="费用说明" name="third">
          <div class="editor-container" v-if="activeName2=='third'">
            <UE :editorId="activeName2" :defaultMsg="form.explain" :config=config ref="ue"
                @ready="editorReadyEvent"></UE>
          </div>
          <!--<Editor v-if="activeName2=='third'" @input="handelExplainIncrease" :value="form.explain" :myQuillEditor="'myQuillEditorExplain'" :activeName2="activeName2"></Editor>-->
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancelTour">取 消</el-button>
      <el-button type="primary" v-if="title=='创建' && !isCreate" @click="create('form')">确 定</el-button>
      <el-button type="primary" v-if="title=='编辑' && !isCreate&&good_btn_update" @click="update('form')">确 定</el-button>
    </div>
    <!--编辑出发地-->
    <departureModal v-if="editDepartureVisible" :list="departureList"
                    v-on:departureEvent="departureEvent"></departureModal>
    <!--编辑目的地-->
    <destination v-if="showDestinationVisible" :obj="destinationObj"
                 v-on:destinationEvent="destinationEvent"></destination>
    <!--编辑途径地-->
    <destination v-if="showPathWayVisible" :obj="onePathObj" v-on:pathWayEvent="pathWayEvent"></destination>
    <!--编辑活动时间-->
    <tourTime v-if="showTimeVisible" :list="form.tourDepartTimeVo" :number="form.number"
              v-on:tourDepartTimeEvent="tourDepartTimeEvent"></tourTime>
    <!--编辑旅游标签-->
    <tourLabelModal v-if="editLableVisible" :allLabelList="allLabelList" :checkList="checkList"
                    v-on:tourLabelEvent="tourLabelEvent"></tourLabelModal>
  </div>
</template>
<style>
  textarea {
    display: none;
  }

  .el-upload-list {
    display: flex;
    width: 100px;
  }

  .el-upload-list li {
    margin-left: 10px;
  }
</style>
<script>
    //  import Editor from "../../modal/editorTool";//富文本
    import UE from '../../modal/Ueditor';//百度ue富文本
    import Destination from "./destinationModal";//目的地弹框
    import tourTime from "./tourTime";//活动时间
    import tourLabelModal from "./tourLabelModal";//旅游标签
    import departureModal from "./departureModal";//出发地弹框
    import {
        page,
        goodsEdit,
        getOneGoodsById
    } from 'api/tourManage';

    import {
        getSonRegionByCodes,
        getRegionByCodes,
    } from 'api/base_info/region/';

    import rsCode from '../../../utils/rsCode';
    import {
        getToken
    } from '../../../utils/auth';
    import {mapGetters} from 'vuex';
    import {
        getAllCompany,
        getAll
    } from 'api/base_info/branch_company/';
    import {
        getTourTagList,
        getAllTourTag
    } from 'api/tourManage';
    import ElRow from "element-ui/packages/row/src/row";

    export default {
        props: ["oneTourRow", "title", "good_btn_update"],
        name: 'upkeepDialog',
        components: {
//      Editor,
            ElRow,
            UE,
            Destination,
            tourTime,
            tourLabelModal,
            departureModal
        },
        data() {
            return {
                imgPosterFlag: false,
                percent_poster: 0,
                BASE_API: process.env.BASE_API,
                config: {
                    initialFrameWidth: null,
                    initialFrameHeight: 350
                },
                percent: 0,//上传进度
                imgFlag: false,
                onePathObj: {name: ""},//待编辑的途径地
                destinationObj: {},//目的地
                departureList: [],//出发地列表
                departureObj: {name: ""},//出发地
                pathway: [],//途径地
                isCreate: false,//是否点击了创建-确定
                fileList2: [],
                activeName2: '',//行程亮点
                form: {
                    alt: undefined,
                    imgTitle: undefined,
                    imgKeyword: undefined,
                    imgDesc: undefined,
                    childPrice: undefined,//儿童价
                    isOutside: "0",
                    tourDepartVo: undefined,//type：0出发地  1途径地  2目的地
                    content: "",//行程亮点
                    cover: undefined,//封面图
                    describe: undefined,//描述
                    introduce: "",//行程介绍
                    crtTime: undefined,
                    explain: "",//费用说明
                    name: undefined,//旅行名称
                    price: undefined,//成人价
                    rank: undefined,
                    recommend: "0",//是否设置为推荐，默认不推荐
                    saleCount: undefined,//初始销量
                    status: undefined,//0：未发布，1：上架 2：下架
                    stock: undefined,//总人数
                    unit: undefined,//单位
                    updTime: undefined,//更新时间
                    viewCount: undefined,//浏览量
                    isMember: "0",//是否是会员商品
                    tagDTOS: [],//旅行标签
                    bannerDTOS: [],//banner轮播
                    posterBackground: '',//海报背景
                },
                showDestinationVisible: false,//编辑目的地
                showPathWayVisible: false,//编辑途径地
                showTimeVisible: false,//编辑时间
                rules: {
                    name: {
                        type: 'string',
                        required: true,
                        message: '请输入旅游名称',
                        trigger: 'blur'
                    },
                    price: {
                        required: true,
                        message: '请输入价格',
                    },
                    childPrice: {
                        required: true,
                        message: '请输入儿童价格'
                    },
                    stock: {
                        required: true,
                        message: '请输入库存'
                    }
                },
                checkList: [],//已选中的标签
                allCompanies: {},
                allCompaniesArr: [],
                oneTourDialogVisible: false,
                editLableVisible: false,//旅游标签
                editDepartureVisible: false,//出发地弹框
                allUpkeepItems: null,
                dialogStatus: undefined,
                allLabelList: [],//全部旅游标签
            }
        },
        created() {
            getAll()
                .then(response => {
                    this.allCompaniesArr = response.data;
                })
            getAllCompany(codeAndBranchCompany => {
                this.allCompanies = codeAndBranchCompany;
            });
            this.getAllLabelList();
        },
        watch: {
            oneTourDialogVisible(newValue, oldValue) {
                if (!newValue) {
                    this.cleanForm();
                }
            },
        },
        mounted() {
            this.cleanForm();
            if (this.title == "编辑") {
                let row = this.oneTourRow;
                this.getOneGoods(row.id);
            } else {
                this.activeName2 = "first";
            }
            this.oneTourDialogVisible = true;
        },
        computed: {
            getHeaderWithToken() {
                return {Authorization: getToken()};
            },
        },
        methods: {
            /**
             * 封面图
             * */
            uploadProcess(event, file, fileList) {
                this.imgFlag = true;
                console.log(event.percent);
                this.percent = Math.floor(event.percent);
            },
            handleClick(tab, event) {
                console.log(tab, event);
            },
            getWeek(week, name) {
                let weekStr = "";
                switch (week) {
                    case 0:
                        weekStr = name + "天";
                        break;
                    case 1:
                        weekStr = name + "一";
                        break;
                    case 2:
                        weekStr = name + "二";
                        break;
                    case 3:
                        weekStr = name + "三";
                        break;
                    case 4:
                        weekStr = name + "四";
                        break;
                    case 5:
                        weekStr = name + "五";
                        break;
                    case 6:
                        weekStr = name + "六";
                        break;
                }
                return weekStr;
            },
            /**
             * 编辑出发地
             * */
            editDeparture(list) {
                console.log(list);
                this.editDepartureVisible = true;
            },
            /**
             * 关闭出发地弹框
             * */
            departureEvent(obj) {
                this.editDepartureVisible = false;
                if (obj) {
                    this.departureList = obj;
                    console.log(obj);
                }
            },
            /**
             * 编辑旅游标签
             * */
            editLable(list) {
                console.log(list);
                this.editLableVisible = true;
            },
            /**
             * 创建
             * */
            create(formName) {
                const set = this.$refs;
                set[formName].validate(valid => {
                    if (valid) {
                        //旅游标签
                        let tagDTOS = [];
                        this.form.tagDTOS.map(function (item) {
                            if (item.tagId) {
                                tagDTOS.push({tagId: item.tagId});
                            } else {
                                tagDTOS.push({tagId: item.id});
                            }
                        });
                        let siteDTOS = [];
                        //出发地
                        this.departureList.map(function (item) {
                            let pp = item.province ? item.province : item.addrProvince;
                            let c = item.addrCity ? item.addrCity : item.city;
                            let provinceObj = pp ? getRegionByCodes([pp]) : [{name: ""}];
                            let cityObj = c ? getRegionByCodes([c]) : [{name: ""}];
                            let p = {
                                name: item.name,
                                departTime: item.departTime ? item.departTime : 0,
                                address: item.addrDetail ? item.addrDetail : item.address,
                                companyId: item.companyId,
                                province: item.addrProvince ? item.addrProvince : item.province,
                                provinceName: provinceObj[0].name,
                                cityName: cityObj[0].name,
                                city: item.addrCity ? item.addrCity : item.city,
                                longitude: item.longitude,
                                latitude: item.latitude,
                                type: 0,
                                rank: item.rank
                            };
                            siteDTOS.push(p);
                        });
                        if (this.departureList.length <= 0) {
                            this.$notify({
                                title: '警告',
                                message: '请选择出发地',
                                type: 'warning',
                                duration: 2000
                            });
                            return;
                        }
                        //途径地
                        this.pathway.map(function (item) {
                            let provinceObj = item.province ? getRegionByCodes([item.province]) : [{name: ""}];
                            let cityObj = item.city ? getRegionByCodes([item.city]) : [{name: ""}];
//          let provinceObj = getRegionByCodes([item.province]);
//          let cityObj = getRegionByCodes([item.city]);
                            let p = {
                                name: item.name,
                                address: item.addrDetail ? item.addrDetail : item.address,
//            companyId: item.id,
                                province: item.addrProvince ? item.addrProvince : item.province,
                                provinceName: provinceObj[0].name,
                                cityName: cityObj[0].name,
                                city: item.addrCity ? item.addrCity : item.city,
                                longitude: item.longitude,
                                latitude: item.latitude,
                                type: 1,
                                rank: item.rank
                            };
                            siteDTOS.push(p);
                        });
                        //destinationObj目的地
                        let destinationObj = this.destinationObj;
                        if (!destinationObj.name) {
                            this.$notify({
                                title: '警告',
                                message: '请选择目的地',
                                type: 'warning',
                                duration: 2000
                            });
                            return;
                        }
                        let provinceObj = destinationObj.province ? getRegionByCodes([destinationObj.province]) : [{name: ""}];
                        let cityObj = destinationObj.city ? getRegionByCodes([destinationObj.city]) : [{name: ""}];
                        let p = {
                            name: destinationObj.name,
                            address: destinationObj.addrDetail ? destinationObj.addrDetail : destinationObj.address,
                            province: destinationObj.addrProvince ? destinationObj.addrProvince : destinationObj.province,
                            provinceName: provinceObj[0].name,
                            cityName: cityObj[0].name,
                            city: destinationObj.addrCity ? destinationObj.addrCity : destinationObj.city,
                            longitude: destinationObj.longitude,
                            latitude: destinationObj.latitude,
                            type: 2
                        };
                        siteDTOS.push(p);
                        this.isCreate = true;
                        let params = {
                            isOutside: this.form.isOutside,//省内、省外
                            name: this.form.name,//旅游路线名称
                            cover: this.form.cover,//封面图
                            price: this.form.price,//成人价
                            childPrice: this.form.childPrice,//儿童价
                            viewCount: this.form.viewCount,//商品浏览量
                            saleCount: this.form.saleCount,//商品销售量
                            describe: this.form.describe,//商品描述
                            content: this.form.content,//商品详情(行程亮点)
                            introduce: this.form.introduce,//行程介绍
                            explain: this.form.explain,//费用说明
                            rank: this.form.rank,//旅行排序
                            recommend: this.form.recommend,//是否推荐:0-未推荐；1-已推荐
                            isMember: this.form.isMember,//是否启用会员价
                            stock: this.form.stock,//库存
                            unit: this.form.unit,//单位
                            number: this.form.number,//活动天数
                            bannerDTOS: this.form.bannerDTOS,//banner轮播图
                            siteDTOS: siteDTOS,//出发地type=0,途径地type=1,目的地type=2
                            priceDTOS: this.form.tourDepartTimeVo,//活动日期
                            tagDTOS: tagDTOS,//旅游标签
                            posterBackground: this.form.posterBackground,//海报背景
                            alt: this.form.alt, //seo 标签优化
                            imgTitle: this.form.imgTitle,
                            imgKeyword: this.form.imgKeyword,
                            imgDesc: this.form.imgDesc
                        };
                        console.log(params);
                        goodsEdit(params).then(response => {
                            this.isCreate = false;
                            if (response.status === 200) {
                                this.$notify({
                                    title: '成功',
                                    message: '添加成功',
                                    type: 'success',
                                    duration: 2000
                                });
                                this.$emit("oneTourDialogEvent", true);
                            } else {
                                this.$notify({
                                    title: '添加失败',
                                    message: rsCode.msg[response.code] ? rsCode.msg[response.code] : '操作失败！',
                                    type: 'error',
                                    duration: 2000
                                });
                            }
                        });
                    } else {
                        return;
                    }
                });
            },
            /**
             * 编辑
             * */
            update(formName) {
                //旅游标签
                const set = this.$refs;
                set[formName].validate(valid => {
                    if (valid) {
                        let tagDTOS = [];
                        this.form.tagDTOS.map(function (item) {
                            if (item.tagId) {
                                tagDTOS.push({tagId: item.tagId});
                            } else {
                                tagDTOS.push({tagId: item.id});
                            }
                        });
                        let siteDTOS = [];
                        //出发地
                        this.departureList.map(function (item) {
                            let pp = item.province ? item.province : item.addrProvince;
                            let c = item.addrCity ? item.addrCity : item.city;
                            let provinceObj = pp ? getRegionByCodes([pp]) : [{name: ""}];
                            let cityObj = c ? getRegionByCodes([c]) : [{name: ""}];
                            let p = {
                                id: item.id,
                                name: item.name,
                                departTime: item.departTime ? item.departTime : 0,
                                address: item.addrDetail ? item.addrDetail : item.address,
                                companyId: item.companyId,
                                province: item.addrProvince ? item.addrProvince : item.province,
                                provinceName: provinceObj[0].name,
                                cityName: cityObj[0].name,
                                city: item.addrCity ? item.addrCity : item.city,
                                longitude: item.longitude,
                                latitude: item.latitude,
                                type: 0,
                                rank: item.rank
                            };
                            siteDTOS.push(p);
                        });
                        if (this.departureList.length <= 0) {
                            this.$notify({
                                title: '警告',
                                message: '请选择出发地',
                                type: 'warning',
                                duration: 2000
                            });
                            return;
                        }
                        //途径地
                        this.pathway.map(function (item) {
                            let provinceObj = item.province ? getRegionByCodes([item.province]) : [{name: ""}];
                            let cityObj = item.city ? getRegionByCodes([item.city]) : [{name: ""}];
                            let p = {
                                id: item.id,
                                name: item.name,
                                address: item.addrDetail ? item.addrDetail : item.address,
//            companyId: item.id,
                                province: item.addrProvince ? item.addrProvince : item.province,
                                provinceName: provinceObj[0].name,
                                cityName: cityObj[0].name,
                                city: item.addrCity ? item.addrCity : item.city,
                                longitude: item.longitude,
                                latitude: item.latitude,
                                type: 1,
                                rank: item.rank
                            };
                            siteDTOS.push(p);
                        });
                        //destinationObj目的地
                        let destinationObj = this.destinationObj;
                        if (!destinationObj.name) {
                            this.$notify({
                                title: '警告',
                                message: '请选择目的地',
                                type: 'warning',
                                duration: 2000
                            });
                            return;
                        }
                        let provinceObj = destinationObj.province ? getRegionByCodes([destinationObj.province]) : [{name: ""}];
                        let cityObj = destinationObj.city ? getRegionByCodes([destinationObj.city]) : [{name: ""}];
                        let p = {
                            id: destinationObj.id,
                            name: destinationObj.name,
                            address: destinationObj.addrDetail ? destinationObj.addrDetail : destinationObj.address,
                            province: destinationObj.addrProvince ? destinationObj.addrProvince : destinationObj.province,
                            provinceName: provinceObj[0].name,
                            cityName: cityObj[0].name,
                            city: destinationObj.addrCity ? destinationObj.addrCity : destinationObj.city,
                            longitude: destinationObj.longitude,
                            latitude: destinationObj.latitude,
                            type: 2
                        };
                        siteDTOS.push(p);
                        let params = {
                            id: this.form.id,
                            isOutside: this.form.isOutside,//省内、省外
                            name: this.form.name,//旅游路线名称
                            cover: this.form.cover,//封面图
                            price: this.form.price,//成人价
                            childPrice: this.form.childPrice,//儿童价
                            viewCount: this.form.viewCount,//商品浏览量
                            saleCount: this.form.saleCount,//商品销售量
                            describe: this.form.describe,//商品描述
                            content: this.form.content,//商品详情(行程亮点)
                            introduce: this.form.introduce,//行程介绍
                            explain: this.form.explain,//费用说明
                            rank: this.form.rank,//旅行排序
                            recommend: this.form.recommend,//是否推荐:0-未推荐；1-已推荐
                            isMember: this.form.isMember,//是否启用会员价
                            stock: this.form.stock,//库存
                            unit: this.form.unit,//单位
                            number: this.form.number,//活动天数
                            bannerDTOS: this.form.bannerDTOS,//banner轮播图
                            siteDTOS: siteDTOS,//出发地type=0,途径地type=1,目的地type=2
                            priceDTOS: this.form.tourDepartTimeVo,//活动日期
                            tagDTOS: tagDTOS,//旅游标签
                            posterBackground: this.form.posterBackground,//海报背景
                            alt: this.form.alt, //seo 标签优化
                            imgTitle: this.form.imgTitle,
                            imgKeyword: this.form.imgKeyword,
                            imgDesc: this.form.imgDesc
                        };
                        console.log(params);
                        this.isCreate = true;
                        console.log(this.form);
                        goodsEdit(params).then(response => {
                            this.isCreate = false;
                            if (response.status === 200) {
                                this.$notify({
                                    title: '成功',
                                    message: '编辑成功',
                                    type: 'success',
                                    duration: 2000
                                });
                                this.$emit("oneTourDialogEvent", true);
                            } else {
                                this.$notify({
                                    title: '编辑失败',
                                    message: rsCode.msg[response.code] ? rsCode.msg[response.code] : '操作失败！',
                                    type: 'error',
                                    duration: 2000
                                });
                            }
                        });
                    } else {
                        return;
                    }
                });
            },
            /**
             * 获取全部旅游标签
             * */
            getAllLabelList() {
                getAllTourTag().then(response => {
                    this.allLabelList = response.data;
                });
            },

            /**
             * 关闭目的地弹框
             * */
            destinationEvent(obj) {
                this.showDestinationVisible = false;
                if (obj) {
                    this.destinationObj = obj;
                    console.log(obj);
                }
            },
            /**
             * 选择目的地
             * */
            selectDestination() {
                let that = this;
                this.destinationObj.showTitle = "目的地编辑";
                this.destinationObj.headTitle = "目的地名称";
                this.destinationObj.eventName = 'destinationEvent';
                this.destinationObj.keyword = this.destinationObj.address;
                this.showDestinationVisible = true;
            },
            /**
             * 关闭活动日期
             * */
            tourDepartTimeEvent(params) {
                this.showTimeVisible = false;
                if (params) {
                    this.form.number = params.num;
                    this.form.tourDepartTimeVo = params.priceDTOS;
                    console.log(params);
                }
            },
            /**
             * 关闭途径地弹框
             * */
            pathWayEvent(obj) {
                this.showPathWayVisible = false;
                if (obj) {
                    if (obj.showTitle == "途径地编辑") {
                        if (obj.method == "delete") {
                            //删除当前路径
                            this.pathway.splice(obj, 1);
                        } else {
                            this.onePathObj = obj;
                        }
                    } else {
                        this.pathway.push(obj);
                    }
                    console.log(obj);
                }
            },
            /**
             * 编辑一条途径地数据
             * */
            selectPathway(obj) {
                let that = this;
                console.log(obj);
                this.onePathObj = obj;
                this.onePathObj.showTitle = "途径地编辑";
                this.onePathObj.headTitle = "途径地名称";
            },
            /**
             * 关闭旅游标签弹框
             * */
            tourLabelEvent(obj) {
                let that = this;
                this.editLableVisible = false;
                let arr = [];
                let ckeckList = [];
                if (obj) {
                    this.allLabelList.map(function (item) {
                        obj.map(function (b) {
                            if (item.name == b) {
                                arr.push(item);
                                ckeckList.push(b);
                            }
                        });
                    });
                    this.form.tagDTOS = arr;
                    this.checkList = ckeckList;
                    console.log(obj);
                }
            },
            /**
             * 编辑一条途径地
             **/
            editPathway(item) {
                this.onePathObj = item;
                this.onePathObj.showTitle = "途径地编辑";//弹框名称
                this.onePathObj.headTitle = "途径地名称";
                this.onePathObj.keyword = item.address,//根据关键词查找经纬度
                    this.onePathObj.eventName = "pathWayEvent";
                this.showPathWayVisible = true;
            },
            /**
             * 添加途径地
             * */
            addPathway() {
                let that = this;
                this.onePathObj = {
                    showTitle: "途径地添加",//弹框名称
                    headTitle: "途径地名称",
                    name: undefined,//地址名称
                    keyword: "东莞市",//根据关键词查找经纬度
                    address: undefined,//详细地址
                    longitude: 113.758993,
                    latitude: 23.031565,
                    eventName: "pathWayEvent"
                };
                this.showPathWayVisible = true;
            },
            /**
             * 添加时间
             * */
            editTime() {
                this.showTimeVisible = true;
            },
            /**
             * 获取一条旅游路线
             * */
            getOneGoods(id) {
                let params = {
                    id: id
                };
                let that = this;
                getOneGoodsById(params).then(response => {
                    that.pathway = [];
                    response.data.tourDepartVo.map(function (item) {
                        if (item.type == 0) {
                            //出发地
                            that.departureList.push(item);
                        }
                        if (item.type == 2 && that.destinationObj.name == "") {
                            //目的地
                            that.destinationObj = item;
                        }
                        if (item.type == 1) {
                            //途径地
                            that.pathway.push(item);
                        }
                    });
                    let arr = [];
                    this.form = response.data;
                    this.allLabelList.map(function (b) {
                        response.data.tagDTOS.map(function (item) {
                            if (item.tagId == b.id) {
                                arr.push(item.name);
                            }
                        });
                    });
                    this.checkList = arr;

                    //轮播
                    let fileList2 = [];
                    response.data.bannerDTOS.map(function (item) {
                        let p = {
                            url: item.cover
                        };
                        fileList2.push(p);
                    });
                    this.fileList2 = fileList2;
                    this.form.isMember = this.form.isMember + "";
                    this.form.recommend = this.form.recommend + "";
                    this.form.isOutside = this.form.isOutside + "";
                    this.activeName2 = "first";
                })
            },
            querySearch(queryString, cb) {
                let selectArry = [];
                this.allCompaniesArr.map(function (item) {
                    item.value = item.name;
                    selectArry.push(item);
                });
                this.selectArry = selectArry;
                var results = queryString ? selectArry.filter(this.createFilter(queryString)) : selectArry;
                // 调用 callback 返回建议列表的数据
                cb(results);
            },
            handleSelect(item) {
                this.departureObj = item;
                console.log(item);
            },
            createFilter(queryString) {
                return (restaurant) => {
                    return (restaurant.name.indexOf(queryString.toLowerCase()) != -1);
                };
            },
            /**
             * 旅游-弹框-取消
             * */
            cancelTour() {
                this.cleanForm();
                this.$emit("oneTourDialogEvent", false);
            },
            /**
             * 富文本  旅游
             * */
            editorReadyEvent(instance) {
                let t = this;
                instance.addListener('contentChange', () => {
                    if (t.activeName2 == "first") {
                        t.form.content = instance.getContent();
                    } else if (t.activeName2 == "second") {
                        t.form.introduce = instance.getContent();
                    } else if (t.activeName2 == "third") {
                        t.form.explain = instance.getContent();
                    }
                });
            },
//      /**
//       * 富文本内容  费用说明
//       * @param step
//       */
//      handelExplainIncrease(step) {
//        this.form.explain = step;
//      },
//      /**
//       * 行程介绍  富文本
//       * */
//      handelIntroduceIncrease(step){
//        this.form.introduce = step;
//      },
//      /**
//       * 富文本  content行程亮点
//       * */
//      handelContentIncrease(step){
//        this.form.content = step;
//      },
            /**
             * 删除banner
             * */
            handleRemove(file, fileList) {
                let list = [];
                fileList.map(function (item) {
                    if (item.url != file.url) {
                        list.push(item);
                    }
                });
                this.fileList2 = list;
                let arr = [];
                this.form.bannerDTOS.map(function (item) {
                    if (item.cover != file.url) {
                        arr.push(item);
                    }
                });
                this.form.bannerDTOS = arr;
            },
            /**
             * 封面图上传
             * **/
            handleAvatarSuccess(res, file) {
                this.percent = 0;
                this.imgFlag = false;
                this.form.cover = res.data;
            },
            /**
             * 海报背景上传
             * **/
            handlePosterSuccess(res, file) {
                this.percent_poster = 0;
                this.imgPosterFlag = false;
                this.form.posterBackground = res.data;
            },
            /**
             * 海报背景图上传进度
             * */
            uploadPosterProcess(event, file, fileList) {
                this.imgPosterFlag = true;
                console.log(event.percent);
                this.percent_poster = Math.floor(event.percent);
            },
            /**
             * banner上传
             * */
            handleBannerSuccess(res, file) {
                this.fileList2.push({url: res.data});
                this.form.bannerDTOS.push({cover: res.data});
            },
            /**
             * 清空旅游弹框数据
             */
            cleanForm() {
                this.onePathObj = {name: ""};//待编辑的途径地
                this.destinationObj = {name: ""},//目的地
                    this.departureList = [],//出发地列表
                    this.departureObj = {name: ""},//出发地
                    this.pathway = [],//途径地
                    this.fileList2 = [],
                    this.activeName2 = '',//行程亮点
                    this.form = {
                        isOutside: "0",//省内、省外
                        childPrice: undefined,//儿童价
                        tourDepartVo: undefined,//type：0出发地  1途径地  2目的地
                        content: "",//行程亮点
                        cover: undefined,//封面图
                        describe: undefined,//描述
                        introduce: "",//行程介绍
                        crtTime: undefined,
                        explain: "",//费用说明
                        name: undefined,//旅行名称
                        price: undefined,//成人价
                        rank: undefined,
                        recommend: "0",//是否推荐0：不推荐，1推荐
                        saleCount: undefined,//初始销量
                        status: undefined,//0：未发布，1：上架 2：下架
                        stock: undefined,//总人数
                        unit: undefined,//单位
                        updTime: undefined,//更新时间
                        viewCount: undefined,//浏览量
                        isMember: "0",//是否是会员商品0不启用，1启用
                        tagDTOS: [],//旅行标签
                        bannerDTOS: [],//banner轮播
                        tourDepartTimeVo: [],//活动时间
                        posterBackground: '',//海报背景
                        alt: '',
                        imgTitle: undefined,
                        imgKeyword: undefined,
                        imgDesc: undefined
                    },
                    this.showDestinationVisible = false,//编辑目的地
                    this.showPathWayVisible = false,//编辑途径地
                    this.showTimeVisible = false;//编辑时间
                this.activeName2 = "";
            }
        }
    }
</script>
