<!-- 我的面试 -->
<template>
	<view class="interview">
		<z-paging
			ref="paging"
			v-model="interviewList"
			@query="queryList"
		>
			<view class="interview-list">
				<view class="interview-list-item" v-for="(item, index) in interviewList" :key="index">
					<view class="interview-list-item-title">
						<view>{{ getDictLabel(item.status, 'deliveryStatusList') }}</view>
						<view>
							<image src="../../static/img/shijian.png"/>
						</view>
					</view>
					<view class="interview-list-item-date">{{ item.interviewTime }}</view>
					<view class="interview-list-item-way">{{ item.interviewAddress }}</view>
					<view class="interview-list-item-position">
						<view class="left">
							<view>
								<image :src="item.companyLogoUrl"/>
							</view>
							<view class="info">
								<view>{{ item.postName }}</view>
								<view>{{ `${item.workPlace} | 经验${item.workYear}年 | ${item.educationBg}` }}</view>
								<view>{{ item.companyName }}</view>
							</view>
						</view>
						<view class="right">
							<view>{{ `${item.lowestSalary}k ~ ${item.highestSalary}k` }}</view>
							<view v-if="item.updateTime">{{ item.updateTime.split(' ')[0] }}</view>
							<view v-else>{{ item.createTime.split(' ')[0] }}</view>
						</view>
					</view>
					<!-- <view class="interview-list-item-button">
						<view class="submit btn" @click="submit">发起视频面试</view>
					</view> -->
					<view class="interview-list-item-button" v-if="Number(item.status) === 20 && new Date('2021-10-29 10:00').valueOf() > new Date().valueOf()">
						<view class="submit btn">发起视频面试</view>
					</view>
					
					<view class="interview-list-item-button" v-else-if="Number(item.status) === 20 && new Date('2021-10-29 10:00').valueOf() <= new Date().valueOf()">
						<view class="not btn">未到视频面试</view>
					</view>
					
					<view class="interview-list-item-button double" v-else-if="Number(item.status) === 50">
						<view class="btn">接受</view>
						<view class="btn">拒绝</view>
					</view>
				</view>
			</view>
		</z-paging>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import TRTCCalling from 'trtc-calling-js';
	import {tim} from 'tim-js-sdk';
	export default {
		data() {
			return {
				// 面试列表
				interviewList: [],
				// 面试状态
				deliveryStatusList: []
			}
		},
		onLoad() {
			this.getDict('delivery_status')
		},
		methods: {
			/**
			 * 获取我的面试列表
			 * @param { Number } pageNum 
			 * @param { Number } pageSize
			 */
			getInterviewList(pageNum, pageSize) {
				this.$u.api.interview.getInterviewList({ pageNum, pageSize }).then(res => {
					if (res.code === 200) {
						this.$refs.paging.complete(res.rows)
					} else {
						this.$refs.paging.complete([])
						this.$refs.uToast.show({
							title: res.msg,
							type: 'error'
						})
					}
				}).catch(err => {
					this.$refs.uToast.show({
						title: '系统异常!',
						type: 'error'
					})
				})
			},
			/**
			 * 组件下拉加载触发
			 * @param { Number } pageNo
			 * @param { Number } pageSize
			 */
			queryList(pageNo, pageSize) {
				this.getInterviewList(pageNo, pageSize);
			},
			/**
			 * 获取数据字典
			 * @param { String } key
			 */
			getDict(key) {
				this.$u.api.getDictdataUrl({ key }).then(res => {
					if (res.code === 200) {
						switch(key) {
							case 'delivery_status':
								this.deliveryStatusList = res.data;
								break;
						}
					}
				})
			},
			/**
			 * 获取字典名称
			 * @param { String } val
			 * @param { String } key
			 */
			getDictLabel(val, key) {
				let label;
				this[key].forEach(item => {
					if (Number(item.text) === Number(val)) {
						label = item.label
					}
				})
				return label;
			},
			submit () {
				const userID = '2000'
				let options = {
				  SDKAppID: 1400594521, // 接入时需要将0替换为您的 SDKAppID
				  // 从v0.10.2起，新增 tim 参数
				  // tim 参数适用于业务中已存在 TIM 实例，为保证 TIM 实例唯一性
				  tim: tim
				};
				const trtcCalling = new TRTCCalling(options);
				trtcCalling.login({
				  userID,
				  userSig: 'eJw1zFELgjAUhuH-suuQ49xOKXRpEC4KSrwWnHqMYtmwZvTfG60uv*eD98VO6hhNemQZ4xGwxXdTo6*WWgoM8Pd7c66NoYZlsQCQqZA8Do*li-aKCYpkCUkaVD8Njd4RxArg16DOR*Wm3M0V9lxVzmGptoPc4*T6Q30rHtBO1oJGXnTDnK-Z*wMZFTAC',
				});
				trtcCalling.call({
				  userID: '2001',  //用户 ID
				  type: 2, //通话类型，0-未知， 1-语音通话，2-视频通话
				  timeout: 10000  //邀请超时时间, 单位 s(秒)
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
@import './myInterview.scss';
</style>
