<template>
  <div>
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="酒店" name="1"></el-tab-pane>
      <el-tab-pane label="餐食" name="2"></el-tab-pane>
      <el-tab-pane label="门票" name="3"></el-tab-pane>
      <el-tab-pane label="线路" name="4"></el-tab-pane>
    </el-tabs>
    <div>
      <span>类型：</span>
      <el-select v-if="activeName=='1'" size="mini" v-model="msg.HotelProductType"
        @change="msg.pageIndex=1,getCommonSerch()" clearable @clear="msg.pageIndex=1,getCommonSerch()">
        <el-option label="国际酒店" value='1'></el-option>
        <el-option label="国内酒店" value='2'></el-option>
      </el-select>
      <el-select v-if="activeName=='2'" size="mini" v-model="msg.DinnerProductType"
        @change="msg.pageIndex=1,getCommonSerch()" clearable @clear="msg.pageIndex=1,getCommonSerch()">
        <el-option label="国际餐厅" value='0'></el-option>
        <el-option label="国内餐厅" value='1'></el-option>
      </el-select>
      <el-select v-if="activeName=='3'" size="mini" v-model="msg.TicketProductType"
        @change="msg.pageIndex=1,getCommonSerch()" clearable @clear="msg.pageIndex=1,getCommonSerch()">
        <el-option label="国际景点" value='0'></el-option>
        <el-option label="国内景点" value='1'></el-option>
      </el-select>
      <el-input size="mini" style="width:350px;" v-if="activeName!='4'" v-model="msg.Name" placeholder="根据名称搜索"
        :clearable="true" @clear="msg.pageIndex=1,getCommonSerch()"
        @keyup.enter.native="msg.pageIndex=1,getCommonSerch()">
        <el-button slot="append" @click="msg.pageIndex=1,getCommonSerch()">搜索</el-button>
      </el-input>
      <template v-else>
        <el-select size="mini" v-model="travelMsg.QTeamType" @change="msg.pageIndex=1,getCommonSerch()" clearable
          @clear="msg.pageIndex=1,getCommonSerch()">
          <el-option label="常规团" value='0'></el-option>
          <el-option label="小包团" value='1'></el-option>
          <el-option label="一日游" value='2'></el-option>
          <el-option label="地接团" value='3'></el-option>
        </el-select>
      </template>
    </div>
    <template v-if="activeName=='1'">
      <el-table ref="multipleTable" :data="dataList" tooltip-effect="dark" height="450" style="width: 100%"
        @selection-change="handleSelectionChange" v-loading="loading">
        <template v-if="isSingle">
          <el-table-column width="50px" label="">
            <template slot-scope="scope">
              <el-radio v-model="scope.row.IsChecked" @change.native="getTemplateRow(scope.$index,scope.row)">&nbsp;
              </el-radio>
            </template>
          </el-table-column>
        </template>
        <template v-else>
          <el-table-column type="selection" width="50px">
          </el-table-column>
        </template>
        <el-table-column label="ID" width="80px">
          <template slot-scope="scope">{{ scope.row.HotelId }}</template>
        </el-table-column>
        <el-table-column prop="HotelName" label="名称">
          <template slot-scope="scope">
            <div flex="cross:center dir:left">
              <img style="width:50px;height:50px;margin-right:10px;" :src="scope.row.CoverImg" />
              <div>{{ scope.row.HotelName }}</div>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <template v-if="activeName=='2'">
      <el-table ref="multipleTable" :data="dataList" tooltip-effect="dark" height="450" style="width: 100%"
        @selection-change="handleSelectionChange2" v-loading="loading">
        <template v-if="isSingle">
          <el-table-column width="50px" label="">
            <template slot-scope="scope">
              <el-radio v-model="scope.row.IsChecked" @change.native="getTemplateRow(scope.$index,scope.row)">&nbsp;
              </el-radio>
            </template>
          </el-table-column>
        </template>
        <template v-else>
          <el-table-column type="selection" width="50px">
          </el-table-column>
        </template>
        <el-table-column label="ID" width="80px">
          <template slot-scope="scope">{{ scope.row.ID }}</template>
        </el-table-column>
        <el-table-column prop="HotelName" label="名称">
          <template slot-scope="scope">
            <div flex="cross:center dir:left">
              <img style="width:50px;height:50px;margin-right:10px;" :src="scope.row.CoverImg" />
              <div>{{ scope.row.Name }}</div>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <template v-if="activeName=='3'">
      <el-table ref="multipleTable" :data="dataList" tooltip-effect="dark" height="450" style="width: 100%"
        @selection-change="handleSelectionChange3" v-loading="loading">
        <template v-if="isSingle">
          <el-table-column width="50px" label="">
            <template slot-scope="scope">
              <el-radio v-model="scope.row.IsChecked" @change.native="getTemplateRow(scope.$index,scope.row)">&nbsp;
              </el-radio>
            </template>
          </el-table-column>
        </template>
        <template v-else>
          <el-table-column type="selection" width="50px">
          </el-table-column>
        </template>
        <el-table-column label="ID" width="80px">
          <template slot-scope="scope">{{ scope.row.ID }}</template>
        </el-table-column>
        <el-table-column prop="HotelName" label="名称">
          <template slot-scope="scope">
            <div flex="cross:center dir:left">
              <img style="width:50px;height:50px;margin-right:10px;" :src="scope.row.CoverImg" />
              <div>{{ scope.row.Name }}</div>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <template v-if="activeName=='4'">
      <el-table ref="multipleTable" :data="dataList" tooltip-effect="dark" height="450" style="width: 100%"
        @selection-change="handleSelectionChange4" v-loading="loading">
        <template v-if="isSingle">
          <el-table-column width="50px" label="">
            <template slot-scope="scope">
              <el-radio v-model="scope.row.IsChecked" @change.native="getTemplateRow(scope.$index,scope.row)">&nbsp;
              </el-radio>
            </template>
          </el-table-column>
        </template>
        <template v-else>
          <el-table-column type="selection" width="50px">
          </el-table-column>
        </template>
        <el-table-column label="TCID" width="80px">
          <template slot-scope="scope">{{ scope.row.TCID }}</template>
        </el-table-column>
        <el-table-column label="出发日期" width="100px">
          <template slot-scope="scope">{{ scope.row.StartDate }}</template>
        </el-table-column>
        <el-table-column prop="Title" label="名称">
          <template slot-scope="scope">
            <div flex="cross:center dir:left">
              <img style="width:50px;height:50px;margin-right:10px;" :src="scope.row.CoverImg" />
              <div>{{ scope.row.Title }}</div>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <el-pagination style="text-align:center" background :current-page.sync="currentPage"
      @current-change="handleCurrentChange" :page-size="msg.pageSize" layout="prev, pager, next" :total="total">
    </el-pagination>
  </div>
</template>
<script>
  export default {
    props: ['ckGoods', "isSingle", "IsGetSpec"],
    data() {
      return {
        dataList: [],
        msg: {
          pageIndex: 1,
          pageSize: 15,
          Name: '',
          HotelProductType: "", //1-国际酒店，2-国内酒店
          DinnerProductType: "", //0-国际酒店，1-国内酒店
          TicketProductType: "", //0-国际景点，1-国内景点
        },
        travelMsg: {
          pageIndex: 1,
          pageSize: 15,
          Title: "",
          QTeamType: "", //团队使用
        },
        activeName: "1",
        currentPage: 1,
        total: 0,
        selectRow: [],
        selectRow1: [],
        selectRow2: [],
        selectRow3: [],
        selectRow4: [],
        loading: false,
      };
    },
    created() {
      if (this.IsGetSpec) {
        this.msg.IsGetSpec = this.IsGetSpec;
      }
    },
    methods: {
      handleClick() {
        this.msg.Name = '';
        this.msg.pageIndex = 1;
        this.currentPage = 1;
        this.travelMsg.pageIndex = 1;
        if (this.activeName == '1') {
          this.getHotelPage();
        }
        if (this.activeName == '2') {
          this.getDinnerPage();
        }
        if (this.activeName == '3') {
          this.getTicket();
        }
        if (this.activeName == '4') {
          this.getTravelPage();
        }
      },
      //搜索
      getCommonSerch() {
        if (this.activeName == '1') {
          this.getHotelPage();
        }
        if (this.activeName == '2') {
          this.getDinnerPage();
        }
        if (this.activeName == '3') {
          this.getTicket();
        }
        if (this.activeName == '4') {
          this.getTravelPage();
        }

      },
      //获取酒店分页
      getHotelPage() {
        this.loading = true;
        this.apipost("/api/Hotel/GetHotelPage", this.msg, res => {
          this.loading = false;
          if (res.data.resultCode == 1) {
            this.total = res.data.data.count;
            var tempArray = res.data.data.pageData;
            if (tempArray && tempArray.length > 0) {
              tempArray.forEach(item => {
                item.IsChecked = false;
              });
            }
            this.dataList = JSON.parse(JSON.stringify(tempArray));
          } else {
            this.Error(res.data.message);
          }
        })
      },
      handleSelectionChange(val) {
        this.selectRow1 = JSON.parse(JSON.stringify(val));
      },
      handleSelectionChange2(val) {
        this.selectRow2 = JSON.parse(JSON.stringify(val));
      },
      handleSelectionChange3(val) {
        this.selectRow3 = JSON.parse(JSON.stringify(val));
      },
      handleSelectionChange4(val) {
        this.selectRow4 = JSON.parse(JSON.stringify(val));
      },
      //获取餐食分页
      getDinnerPage() {
        this.loading = true;
        this.apipost("/api/AppletDining/GetDiningPage", this.msg, res => {
          this.loading = false;
          if (res.data.resultCode == 1) {
            this.total = res.data.data.count;
            var tempArray = res.data.data.pageData;
            if (tempArray && tempArray.length > 0) {
              tempArray.forEach(item => {
                item.IsChecked = false;
              });
            }
            this.dataList = JSON.parse(JSON.stringify(tempArray));
          } else {
            this.Error(res.data.message);
          }
        })
      },
      //获取门票分页
      getTicket() {
        this.loading = true;
        this.apipost("/api/AppletDining/GetTicketCouponsPage", this.msg, res => {
          this.loading = false;
          if (res.data.resultCode == 1) {
            this.total = res.data.data.count;
            var tempArray = res.data.data.pageData;
            if (tempArray && tempArray.length > 0) {
              tempArray.forEach(item => {
                item.IsChecked = false;
              });
            }
            this.dataList = JSON.parse(JSON.stringify(tempArray));
          } else {
            this.Error(res.data.message);
          }
        })
      },
      //获取团期 列表
      getTravelPage() {
        this.loading = true;
        this.apipost("/api/Hotel/GetTravelPage", this.travelMsg, res => {
          this.loading = false;
          if (res.data.resultCode == 1) {
            this.total = res.data.data.count;
            var tempArray = res.data.data.pageData;
            this.dataList = JSON.parse(JSON.stringify(tempArray));
          } else {
            this.Error(res.data.message);
          }
        })
      },
      getTemplateRow(index, row) {
        this.selectRow = [];
        if (this.dataList && this.dataList.length > 0) {
          this.dataList.forEach(item => {
            if (item.Id != row.Id) {
              item.IsChecked = false;
            }
          })
        }
        this.selectRow.push(JSON.parse(JSON.stringify(row)));
      },
      handleCurrentChange(val) {
        if (this.activeName == '4') {
          this.travelMsg.pageIndex = val;
        } else {
          this.msg.pageIndex = val;
        }
        this.getCommonSerch();
      },
      //父组件调用方法
      getChoicedDijie() {
        this.selectRow = [];
        this.selectRow = this.selectRow.concat(this.selectRow1).concat(this.selectRow2).concat(this.selectRow3).concat(
          this.selectRow4);
        return this.selectRow;
      },
      //清空多选方法
      toggleSelection(rows) {
        if (rows) {
          rows.forEach(row => {
            this.$refs.multipleTable.toggleRowSelection(row);
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },
    },
    mounted() {
      this.getHotelPage();
    }
  };

</script>
