<template>
  <view class="content">
    <view class="search card">
      <u--input
          prefixIcon="search"
          placeholder="请输入关键字"
          border="surround"
          v-model="KEYWORDS"
          clearable
          shape="circle"
      ></u--input>
      <view class="bth-mini ml-10">
        <u-button type="success" text="确定" @click="fnSearchList"></u-button>
      </view>

    </view>
    <u-list @scrolltolower="scrolltolower" v-if="list.length > 0">
      <u-list-item v-for="(item, index) in list" :key="index">
        <view class="flex-between main-title">
          <text>{{ item.VIDEONAME }}</text>
        </view>
        <view class="flex-between mt-10 subtitle">
          <text>
            播放地址：{{ item.VIDEOURL }}
          </text>
        </view>
		<view class="flex-between mt-10 subtitle" v-show="item.LATITUDE&&item.LONGITUDE">
		 <text>
		 坐标：{{ item.LATITUDE }}*{{item.LONGITUDE}}
		 </text>
		</view>
        <view class="flex-between mt-10 subtitle">
		  <text>
		    状态：{{ item.LATITUDE&&item.LONGITUDE? "已定位":"未定位" }}
		  </text>
		  <view class="flex-between">
			  <u-button style="margin-left: 20upx;"
			      size="mini"
			      round
			      type="primary"
			      class="bth-mini"
			      text="播放"
			      @click="fnVideo(item)"
			  />
		  </view>
        </view>
      </u-list-item>
    </u-list>
    <empty v-else></empty>
  </view>
</template>

<script>
import {getKeyProjectsVideoList} from "@/api";

export default {
  data() {
    return {
      state: {
        "-1": "检查人驳回",
        0: "待被检查人确认",
        1: "被检查人已确认",
        2: "已归档",
      },
      OUTSOURCED_ID: '',
      KEYWORDS: '',
      list: [],
      pageSize: 10,
      currentPage: 1,
      totalPage: 0,
    }
  },
  onLoad(options) {
    this.OUTSOURCED_ID = options.OUTSOURCED_ID
  },
  onShow() {
    this.fnSearchList()
  },
  computed: {
    userInfo() {
      return this.$store.getters.getUserInfo
    }
  },
  methods: {
    async fnGetData() {
      const resData = await getKeyProjectsVideoList({
        OUTSOURCED_ID: this.OUTSOURCED_ID,
        KEYWORDS: this.KEYWORDS,
        showCount: this.pageSize,
        currentPage: this.currentPage
      });
      this.list = [...this.list, ...resData.varList];
	  //换行
	  for(var i =0;i<this.list.length;i++){
		  var videourl = '';
		  var old = this.list[i].VIDEOURL;
		  var k = 1;
		  if(this.list[i].VIDEOURL){
			  for(var j =0;j<this.list[i].VIDEOURL.length;j++){
				  if(j/2==22*k){
					  videourl+='\n';
					  k++;
				  }
				videourl+=this.list[i].VIDEOURL[j];
			  }
		  }
		  console.log(videourl)
		  this.list[i].VIDEOURL = videourl
		  this.list[i].old = old
	  }
      this.totalPage = resData.page.totalPage;
    },
    scrolltolower() {
      this.currentPage++;
      if (this.totalPage >= this.currentPage) this.fnGetData();
    },
    fnSearchList() {
      this.pageSize = 10;
      this.currentPage = 1;
      this.list = [];
      this.fnGetData();
    },
	fnVideo(video) {
    const params = this.getUrlParams(video.old)
	  uni.$u.route({
	    url: '/pages/key-project-management/positioning_management/videoView',
	    params:  params
	  })
	},
    getUrlParams(url) {
      const params = {};
      const paramStr = url.split('?')[1]; // 获取问号后面的参数部分
      if (paramStr) {
        const paramArr = paramStr.split('&'); // 将参数字符串分割成键值对数组
        paramArr.forEach((param) => {
          const [key, value] = param.split('='); // 将键值对字符串分割成键和值
          params[key] = value; // 将键值对添加到params对象中
        });
      }
      return params;
    }
  },
}
</script>

<style lang="scss" scoped>
</style>
