<template>
	<view class="qingjia-apply">
		<uni-nav-bar @clickLeft="goBack()" class="nav-bar" height="110rpx" leftWidth="200rpx" leftText="入厂项目"
			leftIcon="left" border backgroundColor="#2cade8" color="#fff" fixed statusBar shadow></uni-nav-bar>
		<view class="apply-info">
			<view class="form-content ">
				<view class="form-item border-bottom">
					<view class="form-left">
						<text class="star">*</text>
						<text class="form-left-text">名称</text>
					</view>
					<view class="form-right">
						<input type="text" v-model="formData.place" maxlength="50" placeholder="请输入项目名称" />
					</view>
				</view>
				<view class="form-item border-bottom">
					<view class="form-left">
						<text class="star">*</text>
						<text class="form-left-text">项目类型</text>
					</view>
					<view class="form-right">
						<uni-data-select v-model="formData.state_work" :localdata="range" label="项目类型">
						</uni-data-select>
					</view>
				</view>
				<view class="form-item border-bottom">
					<view class="form-left">
						<text class="star">*</text>
						<text class="form-left-text">合同编号</text>
					</view>
					<view class="form-right">
						<input type="text" v-model="formData.place" maxlength="50" placeholder="请输入" />
					</view>
				</view>
				<view class="form-item border-bottom">
					<view class="form-left">
						<text class="star">*</text>
						<text class="form-left-text">进厂时间</text>
					</view>
					<view class="form-right form-date">
						<picker mode="date" :value="formData.start_time" @change="bindStartDateChange">
							<view class="uni-input">{{formData.start_time}}</view>
						</picker>
					</view>
				</view>
				<view class="form-item border-bottom">
					<view class="form-left">
						<text class="star">*</text>
						<text class="form-left-text">离厂时间</text>
					</view>
					<view class="form-right form-date">
						<picker mode="date" :value="formData.end_time" @change="bindEndDateChange">
							<view class="uni-input">{{formData.end_time}}</view>
						</picker>
					</view>
				</view>
				<view class="form-item border-bottom">
					<view class="form-left">
						<text class="star">*</text>
						<text class="form-left-text">所属部门</text>
					</view>
					<view class="form-right">
						<uni-data-picker placeholder="请选择所属部门" popup-title="请选择所属部门" :localdata="dataTree"
							v-model="classes" @change="onchange" @nodeclick="onnodeclick" @popupopened="onpopupopened"
							@popupclosed="onpopupclosed">
						</uni-data-picker>
					</view>
				</view>

				<view class="form-item border-bottom">
					<view class="form-left">
						<text class="star">*</text>
						<text class="form-left-text">相关方</text>
					</view>
					<view class="form-right">
						<uni-data-select v-model="formData.area" :localdata="range" label="相关方">
						</uni-data-select>
					</view>
				</view>

			
				<view class="btn">
					<button type="default" class="save-btn">保存</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	/* 这是条件编译,意思是：只在APP中出现如下的代码，小程序是不支持的 */
	var that;
	var promise;
	export default {
		name: "fafangbaogao_apply",
		// mixins: [myMixin],
		watch: {
			/* 文件下载监听 */

			lsDownLoadImg(newVal, oldVal) {
				let val = newVal;
				if (String(newVal).indexOf(",") > -1) {
					val = String(newVal).split(",")[0] === "true";
				}
				this.$set(this.downFiles, 'downLoadImg' + this.lsFileId, val)
			},
			/* 文件下载监听 */
			principal(newVal, oldVal) {
				if (!this.itemId) {
					if (oldVal.roleId === undefined && newVal.roleId !== undefined) {
						this.formData.itemInfo.applicationDept = newVal.deptId
						this.formData.applicationDept = newVal.deptId
					}
				}
			},
		},
		data() {
			const currentDate = this.getDate({
				format: true
			})
			return {
				date: currentDate,
				formData: {
					name: '', //作业简述
					state: '', //作业状态
					place: '', //具体地点
					start_time: currentDate, //作业开始时间
					end_time: currentDate, //作业结束时间
					state_work: '', //生产状态
					belong_dept: '', //所属部门
					area: '', //作业区域
					dept_ter: '', //属地部门
					dept_bus: '', //业务部门
					coordinator: '', //业务部门协调员
				},

				depRange: [],
				publishRangeCon: '',
				menuId: "",
				itemId: "",
				detail: false,
				principal: {},
				pkId: '',
				isDisabled: false,
				btnShow: true,
				lsId: "",
				sta: null,
				eventStatus: "",
				execId: '',
				// 2022年3月20日
				result: [],
				// 文件进度
				imgFlag: false,
				//文件下载
				downFiles: {},
				timeShow: false,
				// 发布网站
				releaseWeb: [],
				createTimeFromShow: false,
				createTimeFromList: [],
				createTimeFromCon: '',
				depRange: [{
					label: "name1",
					id: 1
				}, {
					label: "name2",
					id: 2
				}],

				range: [{
						value: 0,
						text: "运行"
					},
					{
						value: 1,
						text: "停机"
					},
					{
						value: 2,
						text: "检修"
					},
				],
				dataTree: [{
					text: "曲阳金隅",
					value: "1",
					children: [{
							text: "设计部",
							value: "11",
							children: [{
									text: "设计一部",
									value: "111"
								},
								{
									text: "设计一部",
									value: "112"
								}
							]
						},
						{
							text: "12生产部",
							value: "12"
						}
					]
				}]

			}
		},
		computed: {
			startDate() {
				return this.getDate('start');
			},
			endDate() {
				return this.getDate('end');
			}
		},
		onLoad(params) {
			/* that = this;
	  
	  promise = new Promise(function(resolve, reject) {
		  that.nodeFn();
		  that.createTimeFromFn();
		  resolve()
	  })
	  promise.then(function(){
		  if (Object.keys(params).length > 0) {
			  console.log(params.itemId)
		    that.itemId = params.itemId;
		    that.pkId = params.pkId;
		    that.eventStatus = params.eventStatus;
		    that.execId = params.execId;
		    if (params.detail !== undefined && params.detail !== null && params.detail !== "") {
		      if (typeof params.detail === "string") {
		        that.detail = JSON.parse(params.detail);
		      } else if (typeof params.detail === "boolean") {
		        that.detail = params.detail
		      }
		    }
		    that._initPrintList()
		  }
	  })
      */
		},
		onShow() {
			/* that._getDeptListMenu();
	  var timestamp = (new Date()).valueOf();
	  that.formData.createTimeTo = that.happenTimeFun(timestamp); */
		},
		methods: {
			onnodeclick(e) {
				console.log(e);
			},
			onpopupopened(e) {
				console.log('popupopened');
			},
			onpopupclosed(e) {
				console.log('popupclosed');
			},
			onchange(e) {
				console.log('onchange:', e);
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			bindStartDateChange: function(e) {
				this.formData.start_time = e.detail.value
			},
			bindEndDateChange: function(e) {
				this.formData.end_time = e.detail.value
			},
			happenTimeFun(num) { //时间戳数据处理
				let date = new Date(num);
				//时间戳为10位需*1000，时间戳为13位的话不需乘1000
				let y = date.getFullYear();
				let MM = date.getMonth() + 1;
				MM = MM < 10 ? ('0' + MM) : MM; //月补0
				let d = date.getDate();
				d = d < 10 ? ('0' + d) : d; //天补0
				let h = date.getHours();
				h = h < 10 ? ('0' + h) : h; //小时补0
				let m = date.getMinutes();
				m = m < 10 ? ('0' + m) : m; //分钟补0
				let s = date.getSeconds();
				s = s < 10 ? ('0' + s) : s; //秒补0
				//         return y + '-' + MM + '-' + d + ' ' + h + ':' + m+ ':' + s;
				return y + '-' + MM + '-' + d;
			},
			createTimeToFn(e) {
				that.formData.createTimeTo = e.year + '-' + e.month + '-' + e.day;
			},
			createTimeFromYesFn(e) {
				console.log(e)
				var index = e[0]
				that.formData.createTimeFrom = that.createTimeFromList[index].id
				that.createTimeFromCon = that.createTimeFromList[index].label
			},
			//发布网站
			nodeFn() {
				var data = {
					dictCode: "FBWZ"
				}
				node(data).then(res => {
					console.log(res)
					if (res.statusCode === 200) {
						if (res.data.data !== undefined && res.data.data !== null && res.data.data !== "") {
							for (let i = 0; i < res.data.data.length; i++) {
								res.data.data[i].checked = false;
							}
						}
						that.releaseWeb = res.data.data;

					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						})
					}
				}).catch(err => {
					uni.showToast({
						title: '网络异常, 请求失败',
						icon: 'none'
					})
				})
			},
			//信息有效期
			createTimeFromFn() {
				var data = {
					dictCode: "XXYXSC"
				}
				node(data).then(res => {
					if (res.statusCode === 200) {
						if (res.data.data !== undefined && res.data.data !== null && res.data.data !== "") {
							that.createTimeFromList = res.data.data;
						}
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						})
					}
				}).catch(err => {
					uni.showToast({
						title: '网络异常, 请求失败',
						icon: 'none'
					})
				})
			},
			/* 文件删除 */
			delFile(index) {
				this.formData.newsBulletinFiles.splice(index, 1);
			},
			/* 文件上传 */
			onClickOpenMyFile() {
				if (this.imgFlag) return;
				var zzzzzzzzz = this;
				const token = uni.getStorageSync('my_token');
				let platform = uni.getSystemInfoSync().platform;



				plus.nativeUI.actionSheet({
						cancel: "取消",
						buttons: [{
								title: "照片"
							},
							{
								title: "相机"
							},
							{
								title: "手机文件"
							},
						]
					},
					function(e) {
						if (e.index == 1 || e.index == 2) {
							let sourceType = ["album", "camera"];
							if (e.index == 1) {
								sourceType = ["album"];
							} else if (e.index == 2) {
								sourceType = ["camera"];
							}
							uni.chooseImage({
								count: 1,
								sourceType,
								success: ((res1) => {
									zzzzzzzzz.imgFlag = true;
									if (res1.errMsg === "chooseImage:ok") {
										const tempFilePaths = res1.tempFilePaths[0];
										if (tempFilePaths !== undefined && tempFilePaths !== null &&
											tempFilePaths !== "") {
											let myFiles = []
											// 这种是直接从相册选的
											// 直接上传
											if (tempFilePaths.indexOf("file:") > -1) {
												let myFile = {};
												myFile.uri = tempFilePaths;
												myFile.name = "file";
												myFiles.push(myFile)
											} else {
												let myFile = {};
												var ccc = 'file://' + plus.io
													.convertLocalFileSystemURL(tempFilePaths);
												myFile.uri = ccc;
												myFile.name = "file";
												myFiles.push(myFile)
											}
											let uploadTask = uni.uploadFile({
												url: myUploadFileUrl,
												header: {
													'Content-Type': 'multipart/form-data',
													'Authorization': 'bearer ' + token
												},
												files: myFiles,
												success: ((res_c) => {
													if (res_c.statusCode === 200) {
														let fileData = {};
														if (typeof res_c.data ==
															"string") {
															fileData = JSON.parse(res_c
																.data).data;
														} else {
															fileData = res_c.data.data;
														}
														if (fileData.fileId !== null &&
															fileData.fileId !==
															undefined && fileData
															.fileName !== undefined &&
															fileData.fileName !== null
														) {
															zzzzzzzzz.imgFlag = false;

															zzzzzzzzz.$set(zzzzzzzzz
																.downFiles,
																'downLoadImg' +
																fileData.fileId,
																false);
															const obj = {};
															obj.fileId = fileData
																.fileId + "";
															obj.fileName = fileData
																.fileName;
															zzzzzzzzz.formData
																.newsBulletinFiles
																.push(obj);
															uni.showToast({
																icon: "none",
																title: "上传成功"
															})
														} else {
															zzzzzzzzz.imgFlag = false;
															uni.showToast({
																icon: "none",
																title: "缺少fileData.fileId, 上传文件失败"
															})
														}
													} else {
														zzzzzzzzz.imgFlag = false;
														uni.showToast({
															icon: "none",
															title: res_c.data
																.message ||
																"上传文件失败"
														})
													}
												}),
												fail: (() => {
													zzzzzzzzz.imgFlag = false;
													uni.showToast({
														icon: "none",
														title: "上传文件失败"
													})
												})
											})

										}
									} else {
										zzzzzzzzz.imgFlag = false;
										uni.showToast({
											icon: "none",
											title: "获取文件失败"
										})
									}
								}),
								fail: (() => {
									zzzzzzzzz.imgFlag = false;
									uni.showToast({
										icon: "none",
										title: "取消选择文件"
									})
								})
							});
						} else if (e.index == 3) {
							if (platform === "android") {
								plugin.chooseFileAction({
									maxNum: 1, // 最大数量
									isNeedDetail: true, // 是否返回具体的信息
									btnText: "选择", // 右下角的文字
									fileTypes: ["doc", "docx", "xls", "xlsx", "pdf", "png", "jpg"], // 支持的类型
									extraApps: ["qqbrowser", "dingtalk"], // 额外支持的应用，QQ浏览器、钉钉
								}, (res) => {
									if (res.code === "0") {
										// console.log(res.dataDetail[0].path);
										zzzzzzzzz.imgFlag = true;
										if (res.dataDetail[0].path !== undefined && res.dataDetail[0].path !==
											null && res.dataDetail[0].path !== "") {
											let url = decodeURI(res.dataDetail[0].path);
											plus.io.resolveLocalFileSystemURL(url, function(entry) {
												let result = 'file://' + entry.fullPath;

												let myFile = {};
												myFile.uri = result;
												myFile.name = "file";
												let myFiles = []
												myFiles.push(myFile)

												let uploadTask = uni.uploadFile({
													url: myUploadFileUrl,
													header: {
														'Content-Type': 'multipart/form-data',
														'Authorization': 'bearer ' + token
													},
													files: myFiles,
													success: ((res_c) => {
														if (res_c.statusCode === 200) {
															let fileData = {};
															if (typeof res_c.data ==
																"string") {
																fileData = JSON.parse(
																		res_c.data)
																	.data;
															} else {
																fileData = res_c.data
																	.data;
															}
															if (fileData.fileId !==
																null && fileData
																.fileId !==
																undefined && fileData
																.fileName !==
																undefined && fileData
																.fileName !== null) {
																zzzzzzzzz.imgFlag =
																	false;

																zzzzzzzzz.$set(
																	zzzzzzzzz
																	.downFiles,
																	'downLoadImg' +
																	fileData
																	.fileId, false);
																const obj = {};
																obj.fileId = fileData
																	.fileId + "";
																obj.fileName = fileData
																	.fileName;
																zzzzzzzzz.formData
																	.newsBulletinFiles
																	.push(obj);
																uni.showToast({
																	icon: "none",
																	title: "上传成功"
																})
															} else {
																zzzzzzzzz.imgFlag =
																	false;
																uni.showToast({
																	icon: "none",
																	title: "缺少fileData.fileId, 上传文件失败"
																})
															}
														} else {
															zzzzzzzzz.imgFlag = false;
															uni.showToast({
																icon: "none",
																title: res_c
																	.data
																	.message ||
																	"上传文件失败"
															})
														}
													}),
													fail: (() => {
														zzzzzzzzz.imgFlag = false;
														uni.showToast({
															icon: "none",
															title: "上传文件失败"
														})
													})
												})

											}, function(e) {
												zzzzzzzzz.imgFlag = false;
												console.log("读取文件出错: " + e.message);
												uni.showToast({
													icon: "none",
													title: "读取文件出错" + e.message
												})
											});
										} else {
											zzzzzzzzz.imgFlag = false;
											uni.showToast({
												icon: "none",
												title: "读取文件出错"
											})
										}
									} else {
										zzzzzzzzz.imgFlag = false;
										uni.showToast({
											icon: "none",
											title: res.msg
										})
									}
								});
								/*
                plug.filePicker({
                  bgcolor: "#42b983",
                  title: "文件选择",
                  max: 1,
                  fileTypes: ["doc", "docx", "xls", "xlsx", "pdf", "jpg", "png"]
                }, ret => {
									zzzzzzzzz.imgFlag = true;
                  if (ret.fileList[0].path !== undefined && ret.fileList[0].path !== null && ret.fileList[0].path !== "") {
                    let url = decodeURI(ret.fileList[0].path);
                    plus.io.resolveLocalFileSystemURL(url, function(entry) {
                      let result = 'file://' + entry.fullPath;

                      let myFile = {};
                      myFile.uri = result;
                      myFile.name = "file";
                      let myFiles = []
                      myFiles.push(myFile)

                      let uploadTask = uni.uploadFile({
                        url: myUploadFileUrl,
                        header: {
                          'Content-Type': 'multipart/form-data',
                          'Authorization': 'bearer ' + token
                        },
                        files: myFiles,
                        success: ((res_c) => {
                          if (res_c.statusCode === 200) {
                            let fileData = {};
                            if (typeof res_c.data == "string") {
                              fileData = JSON.parse(res_c.data).data;
                            } else {
                              fileData = res_c.data.data;
                            }
                            if (fileData.fileId !== null && fileData.fileId !== undefined && fileData.fileName !== undefined && fileData.fileName !== null) {
                             zzzzzzzzz.imgFlag = false;
                             															
                             zzzzzzzzz.$set(zzzzzzzzz.downFiles,'downLoadImg'+fileData.fileId,false);
															const obj = {};
                              obj.fileId = fileData.fileId + "";
                              obj.fileName = fileData.fileName;
                              zzzzzzzzz.formData.newsBulletinFiles.push(obj);
                              uni.showToast({
                                icon: "none",
                                title: "上传成功"
                              })
                            } else {
															zzzzzzzzz.imgFlag = false;
                              uni.showToast({
                                icon: "none",
                                title: "缺少fileData.fileId, 上传文件失败"
                              })
                            }
                          } else {
														zzzzzzzzz.imgFlag = false;
                            uni.showToast({
                              icon: "none",
                              title: res_c.data.message || "上传文件失败"
                            })
                          }
                        }),
                        fail: (() => {
													zzzzzzzzz.imgFlag = false;
                          uni.showToast({
                            icon: "none",
                            title: "上传文件失败"
                          })
                        })
                      })
                    
										}, function(e) {
											zzzzzzzzz.imgFlag = false;
                      console.log("读取文件出错: " + e.message);
                      uni.showToast({
                        icon: "none",
                        title: "读取文件出错" + e.message
                      })
                    });
                  } else {
										zzzzzzzzz.imgFlag = false;
                    uni.showToast({
                      icon: "none",
                      title: "读取文件出错"
                    })
                  }
                });
                */
							} else if (platform === "ios") {
								file.select({
									type: [
										"public.data",
										"com.microsoft.powerpoint.ppt",
										"com.microsoft.word.doc",
										"com.microsoft.excel.xls",
										"org.openxmlformats.presentationml.presentation", // pptx
										"org.openxmlformats.wordprocessingml.document", // docx
										"org.openxmlformats.spreadsheetml.sheet", // xlsx
										"public.avi",
										"public.3gpp",
										"public.mpeg-4",
										"com.compuserve.gif",
										"public.jpeg",
										"public.png",
										"public.plain-text",
										"com.adobe.pdf"
									],
									model: 0
								}, result => {
									zzzzzzzzz.imgFlag = true;
									if (result.filePath === undefined || result.filePath === null || result
										.filePath === "") {
										uni.showToast({
											icon: "none",
											title: "缺少路径, 无法上传"
										})
										return false;
									}
									let localPath = result.filePath;
									localPath = decodeURI(localPath)
									let myFiles = []
									let myFile = {};
									myFile.uri = localPath;
									myFile.name = "file";
									myFiles.push(myFile);
									let uploadTask = uni.uploadFile({
										url: myUploadFileUrl,
										header: {
											'Content-Type': 'multipart/form-data',
											'Authorization': 'bearer ' + token
										},
										files: myFiles,
										success: ((res_c) => {
											console.log(res_c);
											if (res_c.statusCode === 200) {
												let fileData = {};
												if (typeof res_c.data == "string") {
													fileData = JSON.parse(res_c.data).data;
												} else {
													fileData = res_c.data.data;
												}
												if (fileData.fileId !== null && fileData
													.fileId !== undefined && fileData
													.fileName !== undefined && fileData
													.fileName !== null) {
													zzzzzzzzz.imgFlag = false;

													zzzzzzzzz.$set(zzzzzzzzz.downFiles,
														'downLoadImg' + fileData.fileId,
														false);
													const obj = {};
													obj.fileId = fileData.fileId + "";
													obj.fileName = fileData.fileName;
													zzzzzzzzz.formData.newsBulletinFiles.push(
														obj);
													uni.showToast({
														icon: "none",
														title: "上传成功"
													})
												} else {
													zzzzzzzzz.imgFlag = false;
													uni.showToast({
														icon: "none",
														title: "缺少fileData.fileId, 上传文件失败"
													})
												}
											} else {
												zzzzzzzzz.imgFlag = false;
												uni.showToast({
													icon: "none",
													title: res_c.data.message ||
														"上传文件失败"
												})
											}
										}),
										fail: (() => {
											zzzzzzzzz.imgFlag = false;
											uni.showToast({
												icon: "none",
												title: "上传文件失败"
											})
										})
									})

								})
							}
						}
					}
				)
			},

			/* 回显 */
			_initPrintList() {
				console.log("sasdasasd")
				seeXinwenNew(this.itemId).then(res => {
					if (res.statusCode === 200) {
						let data = res.data.data
						that.formData.id = data.id;
						that.formData.writer = data.writer;
						that.formData.mailbox = data.mailbox;
						that.formData.contactNumber = data.contactNumber;
						that.formData.releaseColumn = data.releaseColumn;
						that.formData.newsInformation = data.newsInformation;
						if (data.typeList != '' && data.typeList != undefined && data.typeList != null) {
							for (let i = 0; i < data.typeList.length; i++) {
								for (let k = 0; k < that.releaseWeb.length; k++) {
									console.log(data.typeList[i], that.releaseWeb[k].id)
									if (data.typeList[i] == that.releaseWeb[k].id) {
										that.releaseWeb[k].checked = true
									}
								}
							}
						}

						console.log(data.validityPeriod)
						if (data.validityPeriod != '' && data.validityPeriod != undefined && data.validityPeriod !=
							null) {
							for (let i = 0; i < that.createTimeFromList.length; i++) {
								console.log('zhixingle', that.createTimeFromList[i].id)
								if (that.createTimeFromList[i].id == data.validityPeriod) {
									that.createTimeFromCon = that.createTimeFromList[i].label;
									that.formData.createTimeFrom = that.createTimeFromList[i].id;
								}
							}
						}

						that.formData.reason = data.reason;
						that.formData.createTimeTo = data.createTime.substring(0, 10);
						//文件数组
						let files = data.newsBulletinFiles;
						for (let val of files) {
							that.formData.newsBulletinFiles.push({
								fileId: val.fileId,
								fileName: val.fileName
							})
							//文件下载显示进度用
							this.$set(this.downFiles, 'downLoadImg' + val.fileId, false);
						}
						that.formData.itemInfo.itemName = data.itemInfo.itemName;
						that.formData.itemInfo.applicationDept = data.itemInfo.applicationDept;
						that.formData.itemInfo.applicant = data.itemInfo.applicant;

						if (data.itemInfo.eventStatus || data.itemInfo.eventStatus == 0) {
							this.sta = Number(data.itemInfo.eventStatus)
						} else {
							this.sta = null
						}
						if (data.itemInfo.eventStatus == 1 || data.itemInfo.eventStatus == 2) {
							this.btnShow = false;
						}
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						})
					}
				}).catch(err => {
					uni.showToast({
						title: '网络异常, 请求失败',
						icon: 'none'
					})
				})
			},


			onSubmit(type) {
				if (!this.paramsCheck()) return;

				if (this.detail && !this.formData.id) {
					uni.showToast({
						title: '缺少pkid',
						icon: "none"
					})
					return;
				}
				this._updatePrintList(this.formData, type);
			},
			/* 参数验证 */
			paramsCheck() {
				var typeArr = [];
				for (let i = 0; i < that.releaseWeb.length; i++) {
					if (that.releaseWeb[i].checked == true) {
						typeArr.push(that.releaseWeb[i].id)
					}
				}
				that.formData.typeList = typeArr;

				if (!nonNullCheck(this.formData.itemInfo.itemName)) {
					uni.showToast({
						title: '请输入标题',
						icon: "none"
					})
					return false;
				}
				if (!nonNullCheck(this.formData.itemInfo.applicationDept)) {
					uni.showToast({
						title: '请选择申请部门',
						icon: "none"
					})
					return false;
				}

				if (!nonNullCheck(this.formData.createTimeTo)) {
					uni.showToast({
						title: '请选择申请日期',
						icon: "none"
					})
					return false;
				}

				if (!nonNullCheck(this.formData.writer)) {
					uni.showToast({
						title: '请填写撰稿人',
						icon: "none"
					})
					return false;
				}
				if (!nonNullCheck(this.formData.mailbox)) {
					uni.showToast({
						title: '请填写联系邮箱',
						icon: "none"
					})
					return false;
				}
				if (emailRegular.test(this.formData.mailbox) === false) {
					uni.showToast({
						title: '联系邮箱格式不对，请重新填写',
						icon: "none"
					})
					return false;
				}
				if (!nonNullCheck(this.formData.contactNumber)) {
					uni.showToast({
						title: '请填写联系电话',
						icon: "none"
					})
					return false;
				}
				if (phoneRegular.test(this.formData.contactNumber) === false) {
					uni.showToast({
						title: '联系电话格式不对，请重新填写',
						icon: "none"
					})
					return false;
				}
				if (that.formData.typeList.length == 0) {
					uni.showToast({
						title: '请选择发布网站',
						icon: "none"
					})
					return false;
				}
				if (!nonNullCheck(this.formData.createTimeFrom)) {
					uni.showToast({
						title: '请选择信息有效期',
						icon: "none"
					})
					return false;
				}
				if (!nonNullCheck(this.formData.releaseColumn)) {
					uni.showToast({
						title: '请填写发布栏目',
						icon: "none"
					})
					return false;
				}
				if (!nonNullCheck(this.formData.newsInformation)) {
					uni.showToast({
						title: '请填写新闻信息',
						icon: "none"
					})
					return false;
				}
				if (!nonNullCheck(this.formData.reason)) {
					uni.showToast({
						title: '请填写申请理由',
						icon: "none"
					})
					return false;
				}


				return true;
			},

			/* 保存数据 */
			_updatePrintList(data, type) {
				this.formData.createTimeTo = this.formData.createTimeTo + ' ' + '00:00:00'
				this.isDisabled = true;
				let method = "post";
				if (this.detail) {
					/* 是详情页，就使用put请求，申请人自回显处得到。否则为新增页，申请人为当前登录人*/
					if (this.eventStatus == 4) { //未提交的数据
						method = "put";
					} else {
						method = "post";
						const newData = JSON.parse(JSON.stringify(data))
						delete newData.newsBulletinId;
						data = newData;
					}
				} else {
					this.formData.itemInfo.applicant = this.userId;
				}
				bulletinNew(method, data).then(res => {

					if (res.statusCode === 200) {
						this.itemId = res.data.data.itemId;
						if (type.indexOf("提交") > -1) {
							this.$refs.submitApproval.submitApproval(this.itemId); /* 创建审批数据  */
						} else {
							/* 临时保存，不需要审批的数据，直接跳转*/
							uni.showToast({
								title: '保存成功',
								icon: 'none',
								duration: 2000,
								success() {
									setTimeout(function() {
										this.isDisabled = false;
										uni.navigateBack({
											delta: 1
										})
									}, 2000)
								}
							})


						}
					} else {
						this.formData.createTimeTo = this.formData.createTimeTo.substring(0, 10);
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						})
					}
				}).catch(err => {
					this.formData.createTimeTo = this.formData.createTimeTo.substring(0, 10);
					uni.showToast({
						title: '网络异常, 请求失败',
						icon: 'none'
					})
				})
			},

			publishChange(e) {
				var i = e.detail.value;
				that.publishRangeCon = that.publishRange[i].name;
				that.formData.scopeOfPublication = that.publishRange[i].id;
			},
			goBack() {
				uni.navigateBack({
					delta: 1
				})
			},

			/*  获取部门列表 */
			_getDeptListMenu() {
				getDeptListMenu().then(res => {
					if (res.statusCode === 200) {
						let list = res.data.data;
						this.depRange = list;

						// 2022年3月20日
						this.result = [];
						if (list !== undefined && list !== null && list !== "" && Array.isArray(list) && list
							.length > 0) {
							this.result = flatten(list);
						}


					} else {
						if (res.data.message == "token无效") return;
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						})
					}
				}).catch(err => {
					uni.showToast({
						title: '网络异常, 请求失败',
						icon: 'none'
					})
				})
			},
			onPopupclosed() {
				if (this.lsId) {
					this.formData.itemInfo.applicationDept = this.lsId;
				}
			},
			onNodeClick(e) {
				if (e.id !== undefined && e.id !== null && e.id !== "") {
					this.lsId = e.id;


					// 2022年3月20日
					const currObj = this.result.find((item) => {
						return item.id == this.lsId
					});
					if (currObj !== undefined && currObj !== null && currObj !== "") {
						console.log(currObj);
						if (currObj.children === null || currObj.children === undefined || currObj.children === "") {
							this.formData.itemInfo.applicationDept = this.lsId;
						}
					}



				}
			},
			/* 选择部门后得到最后部门名称 */
			onchange(e) {
				const value = e.detail.value;
				let lastDepName = "";
				if (value.length > 0) {
					lastDepName = value[value.length - 1].text;
				}
				this.subscribeDeptName = lastDepName || "";
			},
			depChange(e) {
				const idx = e.detail.value;
				this.selectedDep = this.depRange[idx].name;
			},
			tiaoxiuChange(e) {
				const idx = e.detail.value;
				this.selectedtiaoxiu = this.tiaoxiuRange[idx].name;
				this.selectedtiaoxiuId = this.tiaoxiuRange[idx].id;
				that.formData.compensatoryLeave = this.tiaoxiuRange[idx].id;
			},

			typeChange(e) {
				const idx = e.detail.value;
				this.selectedtype = this.typeRange[idx].label;
				this.selectedtypeId = this.typeRange[idx].id;
				that.formData.leaveType = this.typeRange[idx].id;
			}
		}
	}
</script>

<style scoped>
	.qingjia-apply {
		background-color: #f3fbff;
		padding-bottom: 227rpx;
	}

	/* >>>.uni-status-bar {
		height: 0 !important;
	} */

	>>>.uni-navbar-btn-text text {
		font-size: 32rpx !important;
	}

	.apply-info {
		width: 720rpx;
		margin: 0 auto;
		background-color: #FFFFFF;
		border-radius: 10rpx;
		padding: 25rpx 32rpx;
		box-sizing: border-box;
		margin-top: 24rpx;
	}

	.border-bottom {
		border-bottom: 1rpx solid #eeeeee;
	}

	.star {
		color: red;
	}

	.top-title-text {
		padding-left: 24rpx;
		position: relative;
		font-family: PingFang-SC-Medium;
		font-size: 34rpx;
		line-height: 72rpx;
		color: #383838;
	}

	.top-title-text::before {
		content: "";
		width: 6rpx;
		height: 29rpx;
		background-image: linear-gradient(90deg, #164cc3 0%, #2c6fd9 100%);
		border-radius: 3rpx;
		display: block;
		position: absolute;
		left: -4rpx;
		top: 22rpx;
	}

	.form-item {
		/* display: flex; */
		font-family: PingFang-SC-Medium;
		font-size: 30rpx;
		/* line-height: 97rpx; */
		height: 200rpx;
		display: flex;
		flex-wrap: wrap;
		align-items: center;
	}

	.form-left-text {
		color: #212121;
		margin-bottom: 33rpx;
	}

	.form-left {
		/* min-width: 160rpx; */
		width: 100%;
	}

	.form-right {
		margin-left: 20rpx;
		flex: 1;
		color: #414141;
	}

	.form-right input {
		/* height: 100%; */
		/* height: 60rpx; */
		font-size: 30rpx;
	}

	.form-date>>>.uni-date__x-input {
		height: 97rpx;
		font-size: 30rpx;
	}

	.form-date>>>.uni-icons {
		display: none;
	}

	.qingjia-apply>>>uni-input {
		/* height: 100%; */
		font-size: 30rpx;
	}

	.apply-reason-text {
		width: 653rpx;
		height: 179rpx;
		background-color: #f6f8fc;
		border: solid 1rpx #e5e5e5;
		margin-top: 21rpx;
		padding: 14rpx 24rpx;
		font-size: 26rpx;
		box-sizing: border-box;
	}

	.apply_require {
		margin-top: 0rpx !important;
	}

	.file-list {
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;
		padding-top: 13rpx;
	}

	.file-wrap {

		margin-top: 20rpx;
		margin-right: 20rpx;
	}

	.file-item {
		width: 155rpx;
		height: 155rpx;
		border: solid 1rpx #e5e5e5;
		text-align: center;
		display: flex;

		align-items: center;
		position: relative;

	}

	.file-content {
		width: 100%;
	}

	.file-item .file-icon {
		width: 37rpx;
		height: 37rpx;

	}

	.file-item .file-name {
		font-family: PingFang-SC-Regular;
		font-size: 20rpx;
		line-height: 17rpx;
		color: #313131;
		margin-top: 11rpx;
		padding: 10rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.file-item>>>.uni-icons {
		width: 26rpx;
		height: 26rpx;
		position: absolute;
		right: -8rpx;
		top: -22rpx;
		/*
    background-color: #d81e06;
    border-radius: 50%;
    font-size: 20rpx !important;
    padding: 5rpx;
    */
		box-sizing: border-box;
	}

	.form-right {
		flex: 1;
		color: #414141;
	}

	/*部门*/
	uni-data-picker {
		width: 100%;
		border: none !important;
	}

	.my-data-picker>>>.input-value-border {
		border: none !important;
	}

	>>>.input-value {
		font-size: 30rpx !important;
		;
	}

	.my-data-picker uni-data-picker {
		width: 100% !important;
	}

	.my-data-picker {
		width: 100%;
		display: flex;
		align-items: center;
		margin-left: -10rpx;
	}

	/* 主体 */
	>>>.uni-navbar__header,>>>.uni-status-bar {
		background-image: linear-gradient(90deg, #164cc3 0%, #2c6fd9 100%), linear-gradient(#e60012, #e60012) !important;
	}

	hongtouwenjian-top {
		box-sizing: border-box;
		padding-top: 24rpx;
		padding-right: 15rpx;
		padding-bottom: 20rpx;
		padding-left: 15rpx;
	}

	.hongtouwenjian-top-c {
		background-color: #ffffff;
		border-radius: 10rpx;
		padding-left: 30rpx;
		padding-right: 30rpx;
		display: flex;
		flex-direction: column;
	}

	.hongtouwenjian-top-c-title {
		display: flex;
		align-items: center;
		height: 85rpx;
		border-bottom: 1px solid #eeeeee;
	}

	.hongtouwenjian-top-c-title-mark {
		width: 6rpx;
		height: 29rpx;
		background-image: linear-gradient(90deg, #164cc3 0%, #2c6fd9 100%), linear-gradient(#f3fbff, #f3fbff);
		background-blend-mode: normal, normal;
		border-radius: 3rpx;
	}

	.hongtouwenjian-top-c-title-txt {
		font-size: 34rpx;
		color: #383838;
	}

	.hongtouwenjian-top-c-item {
		/* display: flex; */
		align-items: center;
		/* height: 100rpx; */
		border-bottom: 1px solid #EEEEEE;
		box-sizing: border-box;
		padding-left: 3rpx;
		padding-right: 12rpx;
		width: 100%;
		line-height: 97rpx;
	}

	.hongtouwenjian-top-c-item:last-child {
		border-bottom: none;
	}

	.hongtouwenjian-top-c-item-left {
		display: flex;
		align-items: center;
		width: 164rpx;
	}

	.hongtouwenjian-top-c-item-left-mark {
		font-size: 30rpx;
		color: #f00808;
	}

	.hongtouwenjian-top-c-item-left-txt {
		font-size: 30rpx;
		color: #212121;
	}

	.hongtouwenjian-top-c-item-middle {
		margin-left: 20rpx;
		flex: 1;
		display: flex;
		align-items: center;
		height: 100%;
	}

	.hongtouwenjian-top-c-item-middle-txt {
		font-size: 30rpx;
		color: #414141;
	}

	.hongtouwenjian-top-c-item-middle-input {
		padding: 0;
		margin: 0;
		outline: none;
		border: none;
		background-color: transparent;
		width: 100%;
		/* height: 100%; */
		height: 60rpx;
		font-size: 30rpx;
		color: #414141;
		display: flex;
		align-items: center;
	}

	.hongtouwenjian-top-c-item-right {
		width: 22rpx;
		height: 25rpx;
	}

	.hongtouwenjian-addbtn {
		display: flex;
		justify-content: flex-end;
		box-sizing: border-box;
		padding-right: 19rpx;
	}

	.hongtouwenjian-addbtn-w {
		padding: 0;
		margin: 0;
		outline: none;
		background-color: transparent;
		width: 90rpx;
		height: 46rpx;
		line-height: 46rpx;
		text-align: center;
		background-color: #0075ff;
		border-radius: 10rpx;
		font-size: 26rpx;
		color: #f3fbff;
	}

	/* 物品列表 */
	.fixed-assets-listBig {
		width: 100%;
		padding: 0 20rpx;
		box-sizing: border-box;
		margin-bottom: 20rpx;
	}

	.fixed-assets-list {
		width: 100%;
		background-color: #FFFFFF;
		padding: 0 20rpx;
		box-sizing: border-box;
	}

	.fixed-assets-list .apply-info {
		padding-top: 0rpx;
	}

	.fixed-assets-list .top {
		height: 108rpx;
		line-height: 108rpx;
		border-bottom: 1rpx solid #eeeeee;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.fixed-assets-list .top-left-text {
		flex: 1;
		display: -webkit-box;
		overflow: hidden;
		text-overflow: ellipsis;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 1;
		font-size: 30rpx;
		color: #212121;
	}

	.fixed-assets-list .top-right image {
		width: 26rpx;
		height: 28rpx;
		vertical-align: middle;
	}

	.fixed-assets-list .top-right view {
		height: auto;
		padding-left: 10rpx;
		font-size: 26rpx;
		color: #8b8b8b;
	}

	/*  .fixed-assets-list .bottomBig{
      width: 100%;
    } */
	.fixed-assets-list .bottom {
		/* display: flex;
      justify-content: space-between;
      align-items: center; */
		padding-top: 25rpx;
		font-size: 28rpx;
		color: #616161;
		line-height: 72rpx;
	}

	.fixed-assets-list .bottom-left+.bottom-right {
		width: 50%;
	}

	/* 文件上传进度样式*/
	.u-progress-content {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.u-progress-dot {
		width: 10rpx;
		height: 10rpx;
		border-radius: 50%;
		background-color: #fb9126;
	}

	.u-progress-info {
		font-size: 24rpx;
		padding-left: 10rpx;
		letter-spacing: 2rpx
	}

	.is-hidden {
		visibility: hidden;
	}







	.title {
		font-size: 14px;
		font-weight: bold;
		margin: 20px 0 5px 0;
	}

	.data-pickerview {
		height: 400px;
		border: 1px #e5e5e5 solid;
	}

	.popper__arrow {
		top: -6px;
		left: 50%;
		margin-right: 3px;
		border-top-width: 0;
		border-bottom-color: #EBEEF5;
	}

	.popper__arrow {
		top: -6px;
		left: 50%;
		margin-right: 3px;
		border-top-width: 0;
		border-bottom-color: #EBEEF5;
	}
</style>
