<template>
	<view class="page-wrap">
		<view class="card">
			<uni-card margin="0" :is-shadow="true">
				<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="dataModel"
					ref="wForm" errorType="border-bottom">
					<u-form-item label="文件名称" prop="stepName" borderBottom>
						<u--input v-model="dataModel.FILE_NAME" disabled  border="none" disabledColor="#ffffff"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="讨论记录" prop="CONTENT" borderBottom>
					</u-form-item>
					<u--textarea v-model="dataModel.CONTENT"  border="none" 
						inputAlign="right"></u--textarea>
						
					<u-form-item label="附件" prop="UserFiles" borderBottom>
					</u-form-item>
					<u-link v-for="item in dataModel.UserFiles" :href="item.url" :text="item.name">
					</u-link>
					<u-form-item label="作业人员" prop="UserNames" borderBottom>
					</u-form-item>
					<u--textarea autoHeight type="textarea"  v-html="dataModel.UserNames" border="none" disabledColor="#ffffff"
						inputAlign="right">
					</u--textarea>
				</u--form>
			</uni-card>
		</view>
		<view class="bottom-button">
			<button type="primary" class="bottom" v-if="isLoadOK&&tableKey==='1'&&!isAudit" @click="onTableBtnAgree">确认</button>
			<!-- <button type="primary" class="bottom" v-if='isLoadOK&&tableKey==1' @click="onTableBtnAgree">签到</button> -->
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import {
		extendFilterGroup,
		extendGroupRule,
		extendInclude,
		extendOrder,
		extendRule,
		guid,
		initFilter,
		initFilterGroup,
		extendIgnoreDataRule
	} from '../../../../utils/common'
	import {
		getRequest,//getPreOperSchGet,
		getUserLists,
		savePreOperSchRecord,
		getOperSchRecordSign
	} from '../../../../services/apply/FOServices/FOServices.js'
	import config from '../../../../config/common'

	export default {
		data() {
			return {
				tableKey:0,
				isLoadOK :false,
				isAudit: false,
				userLists: [],
				dataModel: {
					CODE: '',
					NAME:'',
					JOB_LOCATION:'',
				},
				subDataModel: {},
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#f56c6c'
					}
				}],
				comPickerInfo: {
					showSheet: false,
					columns: [],
					title: '',
					dataIndex: undefined,
					formIndex: undefined,
					name: ''
				},
				currentOperateUser: {},
				showPopup: false,
			}
		},
		onLoad(opt) {
			this.handleGetPreOperSchGet(opt)
		},
		methods: {
			handleGetPreOperSchGet(opt) {
				this.TaskID = opt.taskID ? opt.taskID : '';
				this.ID = opt.ID ? opt.ID : '';
				this.tableKey = opt.tableKey ? opt.tableKey : '0'
				this.okApi = opt.okApi
				this.refuseApi = opt.refuseApi
				this.ApproveID = opt.ApproveID
				this.isAudit = opt.isAudit
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "")
				 extendRule(json, 'ID', 1, opt.ID)
				 extendInclude(json, 'Nav_PreOperSchFile.Nav_ImgFile.Nav_File');
				 extendInclude(json, 'Nav_User');
				  extendInclude(json, 'Nav_PreOperSchUser.Nav_User.Nav_Person.Nav_Post');
				// TODO: id 未获取
				getRequest(json,"/FO/PreOperSch/Get").then(res => {
					this.dataModel = res
					//数据组装
					let strUserFiles = [{
						url: '',
						name:''
					}]
					if (res.Nav_PreOperSchFile && res.Nav_PreOperSchFile.length > 0) {
						for (let i = 0; i < res.Nav_PreOperSchFile.length; i++) {
							strUserFiles.push({
								url: config.uni_app_web_local_api_url+res.Nav_PreOperSchFile[i].Nav_ImgFile.Nav_File.FILE_PATH,
								name:res.Nav_PreOperSchFile[i].Nav_ImgFile.FILE_NAME
							})
						}
					}
					//数据组装
					let strUserName = ''
					if (res.Nav_PreOperSchUser && res.Nav_PreOperSchUser.length > 0) {
						for (let i = 0; i < res.Nav_PreOperSchUser.length; i++) {
							if (res.Nav_PreOperSchUser[i].DEAL_STATUS == 0) {
								strUserName += (strUserName.length > 0 ? "&nbsp;&nbsp;" : "") + "<text style='color:red'>" +
									res.Nav_PreOperSchUser[i].Nav_User.NAME + "</text>";
							} else {
								let user=res.Nav_PreOperSchUser[i].USER_ID!=null?res.Nav_PreOperSchUser[i].Nav_User.NAME:'';
								strUserName += (strUserName.length > 0 ? "&nbsp;&nbsp;" : "") + user;
							}
					
						}
					}
					this.dataModel.UserNames = strUserName
					this.dataModel.UserFiles = strUserFiles
					this.isLoadOK = true
				})
			},
			onTableBtnAgree() {
				let json={};
				json.ID=this.ID;
				json.TaskID=this.TaskID;
				getOperSchRecordSign(json).then(res => {
					uni.$showMsgFunc('操作成功!', () => {
						uni.navigateBack()
					}, 'success', 1000)
				})
			
			}
		}
	}
</script>

<style scoped>
	.page-wrap {
		padding: 16px 16px 166px;
	}

	.card {
		margin-bottom: 18px;
	}

	.sub-form {
		margin-bottom: 16px;
	}

	.bottom-button {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		padding: 10px 16px;
		box-sizing: border-box;
		background: #fff;
		z-index: 999;
	}

	.upload-title {
		color: #303133;
		font-size: 15px;
		line-height: 22px;
		padding: 8px 0;
	}

	.page-wrap>>>.u-upload__button {
		margin-bottom: 0;
	}
</style>
