创新实训(十九)

景点门票的展示页面和之前一样的思路。不过这次由于后端传给我的数据格式稍微复杂了那么一点点,所以对门票的数据处理多了几个步骤。

HTML:

<template>
  <div class="ticketinfos">
    <navbar :activeIndex="4" :activeIndex2="4"></navbar>
    <div class="searchbar">
      <el-col :span="4" :offset="2">
        <el-select
          v-model="province"
          filterable
          reserve-keyword
          placeholder="请选择省份"
          @change="findCitys"
        >
          <el-option
            v-for="item in provinces"
            :key="item"
            :label="item"
            :value="item"
          >
          </el-option>
        </el-select>
      </el-col>
      <el-col :span="4" :offset="2">
        <el-select
          v-model="city"
          filterable
          :disabled="!hasCity"
          placeholder="请选择城市"
        >
          <el-option
            v-for="item in citys"
            :key="item"
            :label="item"
            :value="item"
          >
          </el-option>
        </el-select>
      </el-col>
      <el-col :span="4" :offset="2">
        <el-input placeholder="请输入景点名称" v-model="params.scenic"></el-input>
      </el-col>
      <el-col :span="2" :offset="2">
        <el-button @click="findScenics" type="primary">搜索门票</el-button>
      </el-col>
    </div>

    <el-button
      class="return"
      type="text"
      @click="returnTo"
      icon="el-icon-arrow-left"
      >返回</el-button
    >

    <el-divider class="devider"></el-divider>

    <div class="hotcitys"></div>

    <div class="searchResults" v-loading="loading">
      <ul class="list"
      v-infinite-scroll="load"
        infinite-scroll-disabled="disabled"
        infinite-scroll-immediate="false"
        v-if="hasTicket"
        >
        <li v-for="i in count" :key="i" class="list-item">
          <scenicTicket
            :name="tickets[i].name"
            :discription="tickets[i].discription"
            :url="tickets[i].url"
            :type="tickets[i].type"
            :buy="tickets[i].buy"
            :from="tickets[i].from"
            :isReturnable="tickets[i].isReturnable"
            :bookTime="tickets[i].bookTime"
            :outTime="tickets[i].outTime"
            :useTime="tickets[i].useTime"
            :price="tickets[i].price"
          >
          </scenicTicket>
        </li>
      </ul>
      <p v-if="loadmore">加载中...</p>
      <p v-if="nomore">没有更多了</p>
      <h2 v-if="noTicket">抱歉,好像没有相关景点呢……</h2>
    </div>
  </div>
</template>

js:

import scenicTicket from "../components/scenicTicket.vue";
import NavBar from "../components/NavBar.vue";
export default {
  components: {
    "scenicTicket": scenicTicket,
    "navbar": NavBar,
  },
  data() {
    return {
        provinces:[],
      province:"",
      citys:[],
      city:"",
      tickets: [],
      alltickets:0,
      hasCity:false,
      hasTicket:false,
      noTicket:false,
      count:10,
      loading: false,
      params: {
        scenic: "",
      },
      loadmore:false,
    };
  },

  computed: {
    nomore() {
      return this.count>this.alltickets;
    },
    disabled() {
      return this.loadmore || this.nomore;
    },
  },

  methods: {
    onSubmitGet() {
      //   console.log(this.intro);
      //this.intro = [];
      this.$axios({
        method: "get",
        url: "http://127.0.0.1:8000/api/getTicketInfo",
        params: {
          keyword: this.params.scenic,
          city:this.city,
        },
      })
        // .get("api/tickets")
        .then((res) => {
          this.loading = false;
          var array = res.data.data;
        //   console.log(array);
          if (array == undefined || array.length <= 0) {
            this.hasTicket = false;
            this.noTicket = true;
          } else {
            this.hasTicket = true;
            this.noTicket = false;
            var infos = [];
            for(var key in array){
                var array1 = array[key];
                for (var key1 in array1){
                    var array2 = array1[key1];
                    for (var key2 in array2){
                        var list = array2[key2];
                        infos.push.apply(infos,list);
                        
            // console.log(list);
                    }
                }
            }
            this.tickets=infos;
            this.alltickets=infos.length;
          }
        })
        .catch((res) => {
          console.table(res);
          alert("出错了!!");
          //   this.hasHotel = false;
          // this.noHotel = true;
        });
    },

    findScenics() {
      if (this.params.scenic == ""||this.params.scenic == undefined) {
        alert("请输入景点名称!");
      } 
      else {
        if (this.city=="" || this.city==undefined){
            alert("请选择城市!");
        }
        else{
          this.$router.push({
            name: "scenicticket",

            //query/
            query: {
              scenic: this.params.scenic,
              city: this.city,
              province:this.province,
            },
          });
          
        }
      }
    },

    findCitys(prov) {
      this.city = "";
      this.citys = [];
      if (
        prov == "北京市" ||
        prov == "天津市" ||
        prov == "上海市" ||
        prov == "重庆市"
      ) {
        this.hasCity = false;
        this.city = prov;
      } else {
        this.hasCity = true;
        var url =
          "http://api.map.baidu.com/place/v2/search?query=" +
          encodeURIComponent("商圈") +
          "&region=" +
          encodeURIComponent(prov) +
          "&output=json&page_size=20&ak=000"+"&callback=getCitys";

            this.$jsonp(url)
            .then((res)=>{
                console.log(res);
                this.getCitys(res);
            }).catch((res) => {
            alert("出错了!");
          });
      }
    },

    getCitys(res){
        this.loading = false;
            var array = res.results;
            if (array == undefined || array.length <= 0) {
              console.log("no");
            } else {
              array.forEach((item, index, array) => {
                this.citys.push(item.name);
                this.$forceUpdate();
              });
                  console.log("good!")
            }
    },

    load(){
        this.loadmore=true;
        this.count+=6;
        this.loadmore=false;
    },

    returnTo() {
      this.$router.go(-1);
    },


  },
  mounted() {
    this.loading = true;
    this.province = this.$route.query.province;
    this.params.scenic=this.$route.query.scenic;
    this.findCitys(this.province);
    this.city = this.$route.query.city;
    // console.log(this.params);
    this.onSubmitGet();
  },
};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值