<template>
	<view class="cust_detail">
		<view class="cust_item">
			<view class="cust_item_head">
				<view class="head_info">
					<image :src="BASE_IMG_URL+'fujian.png'" class="peopleimg" mode="scaleToFill"></image>
					<view>附件</view>
				</view>
			</view>
			<view class="item_doc">
				<view class="doc_item" v-for="(item,index) in file_list" :key="index" @click.stop="lookDetail(item)">
					<view class="iconfont icon--task"></view>
					<input type="text" :disabled="item.disabled" :focus="item.focus" :data-index="index"
						v-model="item.name" @confirm="changeName" @blur="changeName" class="doc_name"/>
					<view class="doc_size">{{item.size}}</view>
					<!-- <image :src="BASE_IMG_URL+'edit.png'" class="editimg" @click.stop="edit(index)" v-if="type == 1" mode="scaleToFill"></image> -->
				</view>
			</view>
		</view>
		 
	</view>
</template>

<script>
	import {
		netCluesFiles,
	} from '@/api/clues.js'
	import {netKehuFileList,netEditFileName, netContractFileList} from '@/api/kehu.js'
	import { BASE_IMG_URL } from '@/util/api.js'
	export default {
		data() {
			return {
				file_list: [], //附件 列表
				BASE_IMG_URL:BASE_IMG_URL,
				id:'',
				contract_id:'',
				types:Number,    //3合同   2客户
				type:1
			}
		},
		onLoad(options) {
			this.id = options.id
			this.types = options.types
			this.type = options.type
		},
		onShow() {
			//附件 列表、
			this.getFile()
		},
		created() {
			
		},
		methods: {
			//附件 列表
			getFile() {
				if(this.types == 2){
					let params = {
						customer_id: this.id
					}
					netKehuFileList(params).then(res=>{
						res.data.forEach(item=>{
							item.disabled = true
							item.focus = false
						})
						this.file_list = res.data
					})
				}else{
					let params = { contract_id:this.id }
					netContractFileList(params).then(res=>{
						res.data.forEach(item=>{
							item.disabled = true
							item.focus = false
						})
						this.file_list = res.data
					})
				}
			},
			// 点击 附件  查看
			lookDetail(item) {
				if(item.types.indexOf('image') != -1){
					uni.previewImage({
						urls: [ item.file_path ]
					})
				}else{
					uni.downloadFile({
						url: item.file_path,
						success:(res)=>{
							uni.openDocument({
								filePath:res.tempFilePath,
								success:(res)=>console.log('成功打开文档')
							})
						},
						fail:(err)=>{
							console.log(err,'shibai')
						}
					})
				}
			},
			// 编辑
			edit(index) {
				let obj = this.file_list[index]
				obj.disabled = false
				obj.focus = true
				this.file_list[index] = obj
			},
			changeName(e) {
				let name = e.detail.value
				let index = e.currentTarget.dataset.index
				let params = {
					id: this.file_list[index].id,
					name: this.file_list[index].name,
				}
				netEditFileName(params).then(res => {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					setTimeout(() => {
						this.getFile()
					}, 2000)
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.cust_detail {

		.cust_item {
			padding: 0 24rpx;
			background-color: #fff;
			margin-bottom: 20rpx;

			.cust_item_head {
				display: flex;
				justify-content: space-between;
				line-height: 100rpx;
				border-bottom: 1rpx solid #EAEAEA;

				.head_info {
					display: flex;
					align-items: center;

					.icon--task {
						margin-right: 10rpx;
					}
				}

				.head_new {
					display: flex;
					align-items: center;
					color: #1c9bfc;

					.icon-clock {
						margin-right: 10rpx;
					}
				}
			}

			.lxr_con_list {
				padding-bottom: 20rpx;
				border-bottom: 1rpx solid #C0C0C0;

				&:last-child {
					border-bottom: none;
				}

				.name {
					font-size: 28rpx;
					color: #333333;
					margin-top: 15rpx;
				}

				.info {
					font-size: 24rpx;
					color: #999999;
					margin: 10rpx 0;
				}

				.proce_li {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.pro_li_left {
						display: flex;
						justify-content: flex-start;
						align-items: center;

						.protext {
							font-size: 24rpx;
							color: #999999;
						}

						.probox {
							width: 120rpx;
							height: 15rpx;
							border-radius: 8rpx;
							background: #C0C0C0;
							margin: 0 15rpx;

							.proin {
								width: 20%;
								height: 15rpx;
								border-radius: 8rpx;
								background: #ff7800;
							}
						}

						.pronum {
							font-size: 24rpx;
							color: #999999;
						}
					}

					.pro_li_right {
						color: #ec7f51;
						font-size: 28rpx;
						font-weight: 500;
					}
				}

				.con_status {
					font-size: 24rpx;
					color:$uni-text-color;
					margin-top: 10rpx;
				}
			}

			.cust_item_con {
				border-bottom: 1rpx solid #EAEAEA;
				padding: 15rpx 0;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.con_info {
					padding: 10rpx 0;

					:first-child {
						color: #060606;
						font-weight: 700;
						line-height: 50rpx;
						font-size: 28rpx;
					}

					:last-child {
						color: #469369;
						line-height: 50rpx;
					}
				}

				.con_money {
					color: #ec7f51;
					font-size: 28rpx;
					line-height: 150rpx;
					font-weight: 700;
				}
			}

			.item_doc {
				
				
				.doc_item {
					padding: 30rpx 0;
					display: flex;
					justify-content: space-between;
					align-items: center;
					background-color: #f7faff;
					line-height: 60rpx;
					margin-bottom: 20rpx;

					.icon--task {
						width: 50rpx;
						padding-left: 10rpx;
					}

					.doc_name {
						flex: 1;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
					}

					.doc_size {
						width: 130rpx;
					}

					.editimg {
						width: 40rpx;
						height: 40rpx;
					}

					.icon-clear {
						width: 50rpx;
					}
				}
			}

			.operation_record {
				padding: 40rpx 20rpx 40rpx 60rpx;

				.record_item {
					display: flex;
					justify-content: space-between;
					line-height: 86rpx;
					margin-top: 20rpx;
					
					.record_img {
						position: relative;
						display: flex;
						line-height: 200rpx;

						image {
							width: 80rpx;
							height: 80rpx;
						}

						.record_info {
							margin-top: 16rpx;
							margin-left: 15rpx;
							line-height: 50rpx;
							font-size: 28rpx;

							:last-child {
								font-size: 24rpx;
							}
						}

						.record_line {
							position: absolute;
							top: -102rpx;
							left: -26rpx;
							height: 105rpx;
							border-left: 4rpx dotted #dedede;
						}

						&::before {
							content: '';
							display: block;
							position: absolute;
							top: 6rpx;
							left: -34rpx;
							width: 15rpx;
							height: 15rpx;
							border: 5rpx solid #dedede;
							border-radius: 15rpx;
						}
					}
				}
			}
		}
	}

	.peopleimg {
		width: 35rpx;
		height: 35rpx;
		margin-right: 15rpx;
	}

	.phoneimg {
		width: 40rpx;
		height: 60rpx;
		margin-right: 20rpx;
	}

	.con-name,
	.con-mobile {
		line-height: 50rpx;
	}

	.con-mobile {
		color: #999;
	}
	.cline_li{
		padding:20rpx 0;
		border-bottom:1rpx solid #CCCCCC;
		&:last-child{
			border-bottom:0;
		}
	}
	.clineInfo {
		.info_head {
			display: flex;
			justify-content: space-between;
			:first-child {
				font-size: 28rpx;
				font-weight: 700;
				color: #999;
			}
	
			:last-child {
				&::before {
					position: relative;
					display: block;
					content: '';
					width: 10rpx;
					height: 10rpx;
					top: 24rpx;
					left: -22rpx;
					background-color: #52c1f5;
					border-radius: 5rpx;
				}
			}
		}
	
		.info_main {
			display: flex;
			justify-content: space-between;
	
			.main_left {
				.left_followUp {
					display: flex;
					padding: 20rpx 0;
				}
	
				.left_star {
					display: flex;
					padding-bottom: 20rpx;
				}
			}
	
			.main_right {
				text-align: center;
				padding: 20rpx 20rpx 0 0;
	
				image {
					width: 44rpx;
					height: 44rpx;
					margin-bottom: 5rpx;
				}
			}
		}
	}
</style>
