<template>
	<view class="template-edit tn-safe-area-inset-bottom">
		<!-- 顶部自定义导航 -->
		<tn-nav-bar fixed customBack>
			<view slot="back" class='tn-custom-nav-bar__back' @click="goBack">
				<text class='icon tn-icon-left'></text>
			</view>
			<view slot="default" style="display: flex;">
				<view style="flex:1;margin-left:25px">
					<text :style="{fontSize:(wxFontSize)+'px'}">发布供应</text>
				</view>
				<view>
					<button plain="true" style="margin-right: 4px;border-radius: 24px;height:32px;line-height: 32px;font-size:15px;margin-top:4px;color:#1d60b1;border-color:#1d60b1;" @click="saveForm(1)"  :style="{fontSize:(wxFontSize-3)+'px'}">暂存</button>
				</view>
			</view>
		</tn-nav-bar>

		<view class="tn-safe-area-inset-bottom" :style="{paddingTop: vuex_custom_bar_height + 'px'}">

			<tn-steps style="pointer-events:none;" :list="selectValue=='个人'?stepList:stepList2" :current="stepIndex" mode="dotIcon" :fontSize="(wxFontSize-3)+'px'"></tn-steps>
			<view v-if="stepIndex==1">

				<view style="padding: 16px">
					<view style="line-height: 30px;" :style="{fontSize:(wxFontSize-1)+'px'}">
						发布主体：
						<uni-data-checkbox :multiple="false" v-model="selectValue" selectedColor="#01BEFF"
							:localdata="[{text: '个人',value: '个人'},{text: '公司',value: '公司'}]" :fontSize="(wxFontSize-3)+'px'"/>
					</view>
					<!-- <uni-data-select v-model="selectValue" :localdata="selectList" @change="changeSelect"
						:clear="false"></uni-data-select> -->
				</view>
				
				<view v-if="selectValue=='个人'" style="padding: 16px">
					<uni-forms :modelValue="formData" label-width="0">

						<text style="color: red;line-height: 30px;vertical-align: middle;margin-right: 4px;" :style="{fontSize:(wxFontSize-3)+'px'}">*</text><text :style="{fontSize:(wxFontSize-3)+'px'}">用户昵称:</text>
						 
						<uni-forms-item label="用户昵称" name="realName" label-width="0">
							<uni-easyinput type="text" disabled :inputSize="wxFontSize-3" :placeholder-style="styleString" v-model="formInfo.contactNickName" placeholder="请输入您的昵称" />
						</uni-forms-item>
						<text style="line-height: 30px;vertical-align: middle;" :style="{fontSize:(wxFontSize-3)+'px'}">真实姓名:</text>
						<uni-forms-item label="真实姓名" name="contactMethod">
							<uni-easyinput type="text" disabled="true" :inputSize="wxFontSize-3" :placeholder-style="styleString" v-model="formInfo.userRealName" placeholder="请输入真实姓名" />
						</uni-forms-item>
						<text style="color: red;line-height: 30px;vertical-align: middle;margin-right: 4px;" :style="{fontSize:(wxFontSize-3)+'px'}">*</text><text :style="{fontSize:(wxFontSize-3)+'px'}">联系方式:</text>
						<uni-forms-item label="联系方式" name="phone">
							<uni-easyinput type="text" disabled :inputSize="wxFontSize-3" :placeholder-style="styleString" v-model="formInfo.contactMethod" placeholder="请输入联系手机/微信/邮箱" />
						</uni-forms-item>

					</uni-forms>
					<text style="font-size: 13px;color:#999;" :style="{fontSize:(wxFontSize-4)+'px'}">如要更改个人信息,请在我的=><text>个人信息</text>页面更改</text>
				</view>

				<view v-if="selectValue=='公司'" style="padding: 16px">
					<uni-forms :modelValue="formData" label-width="0">
						<view style="margin-bottom:16px">
							<text style="color: red;line-height: 30px;vertical-align: middle;margin-right: 4px;" :style="{fontSize:(wxFontSize-3)+'px'}">*</text><text :style="{fontSize:(wxFontSize-3)+'px'}">公司名称:</text>
							<w-select style="width: 100%;" v-model='searchValue' :list='items' valueName='name'
								keyName="regNumber" @change='selectChange' :filterable="true" :fontSize="(wxFontSize-3)+'px'">
							</w-select>
						</view>
						<!-- <uni-forms-item label="公司名称" name="name">
					<uni-easyinput type="text" v-model="userInfo.company" placeholder="请输入所在公司名称" />
				</uni-forms-item> -->
						<text style="color: red;line-height: 30px;vertical-align: middle;margin-right: 4px;" :style="{fontSize:(wxFontSize-3)+'px'}">*</text><text :style="{fontSize:(wxFontSize-3)+'px'}">您的职称:</text>
						<uni-forms-item label="" name="realName" label-width="0">
							<uni-easyinput type="text" :clearable="false" :inputSize="wxFontSize-3" :placeholder-style="styleString" v-model="formInfo.jobTitle" placeholder="请输入您的职称" />
						</uni-forms-item>
						<text style="color: red;line-height: 30px;vertical-align: middle;margin-right: 4px;" :style="{fontSize:(wxFontSize-3)+'px'}">*</text><text :style="{fontSize:(wxFontSize-3)+'px'}">联系人姓名:</text>
						<uni-forms-item label="联系人姓名" name="contactMethod">
							<uni-easyinput type="text" :clearable="false" :inputSize="wxFontSize-3" :placeholder-style="styleString" v-model="formInfo.contactPerson" placeholder="请输入联系人姓名" />
						</uni-forms-item>
						<text style="color: red;line-height: 30px;vertical-align: middle;margin-right: 4px;" :style="{fontSize:(wxFontSize-3)+'px'}">*</text><text :style="{fontSize:(wxFontSize-3)+'px'}">联系方式:</text>
						<uni-forms-item label="联系方式" name="phone">
							<uni-easyinput type="text" :clearable="false" :inputSize="wxFontSize-3" :placeholder-style="styleString" v-model="formInfo.contactMethod" placeholder="请输入联系手机/微信/邮箱" />
						</uni-forms-item>

						 
					</uni-forms>
				</view>

				<!-- 悬浮按钮-->
				<view class="tn-flex tn-footerfixed">
					<!-- <view class="tn-flex-1 justify-content-item tn-margin-sm tn-text-center">
						<button type="default" plain="true" style="border-radius: 24px;"
							@click="preStep()">
							 上一步 
						</button>
						 
					</view> -->
					<view class="tn-flex-1 justify-content-item tn-margin-sm tn-text-center">
						<button type="default" plain="true" style="border-radius: 24px;"
							@click="nextStep()" :style="{fontSize:(wxFontSize-2)+'px'}">
							 下一步 
						</button>
					</view>
				</view>
			</view>
			<view v-if="stepIndex!=1">

				<view style="padding: 16px;padding-bottom: 0;" v-if="(selectValue=='公司'&&stepIndex==2)||(selectValue=='个人'&&stepIndex==2)">
					
					<text style="color: red;line-height: 30px;vertical-align: middle;margin-right: 4px;" :style="{fontSize:(wxFontSize-3)+'px'}">*</text><text :style="{fontSize:(wxFontSize-3)+'px'}">发布种类:</text>
					<uni-data-select v-model="selectValue2" :localdata="selectList2" @change="changeSelect2"
						:clear="false" :fontSize="(wxFontSize-3)+'px'"></uni-data-select>
				</view>

				<view v-if="selectValue2=='产品'" >
					<view style="padding: 16px" v-if="(selectValue=='公司'&&stepIndex==2)||(selectValue=='个人'&&stepIndex==2)">
						<text style="color: red;line-height: 30px;vertical-align: middle;margin-right: 4px;" :style="{fontSize:(wxFontSize-3)+'px'}">*</text><text :style="{fontSize:(wxFontSize-3)+'px'}">产品种类:</text>
						<uni-data-select v-model="selectValue4" :localdata="selectList4" @change="changeSelect4"
							placeholder="产品种类" :clear="false" style="margin-bottom:16px" :fontSize="(wxFontSize-3)+'px'"></uni-data-select>
						
						
						<view style="margin-top: 16px;">
						   <text style="color: red;line-height: 30px;vertical-align: middle;margin-right: 4px;" :style="{fontSize:(wxFontSize-3)+'px'}">*</text><text :style="{fontSize:(wxFontSize-3)+'px'}">产品品牌:</text>
						   <uni-easyinput type="text" :clearable="false" :inputSize="wxFontSize-3" :placeholder-style="styleString" required v-model="brand" placeholder="请输入产品品牌" />
						</view>
						<view style="margin-top: 16px;margin-bottom: 20px;">
							<text style="color: red;line-height: 30px;vertical-align: middle;margin-right: 4px;" :style="{fontSize:(wxFontSize-3)+'px'}">*</text><text :style="{fontSize:(wxFontSize-3)+'px'}">发布的产品是否属于医疗器械？</text>
							<uni-data-checkbox :multiple="false" v-model="isMedical" selectedColor="#01BEFF"
								:localdata="[{text: '是',value: '1'},{text: '否',value: '0'}]" :fontSize="(wxFontSize-3)+'px'"/>
							<text v-if="isMedical==1" style="font-size: 13px;color:#999;" :style="{fontSize:(wxFontSize-5)+'px'}">如若产品是医疗器械，请在上传附件步骤上传产品注册证，企业经营许可证等相关信息。</text>
						</view>

						<view v-for="item,itemIndex in extList">
							<view style="margin-bottom: 12px;">
							<uni-card >
											<template v-slot:title>
												<uni-list>
													<uni-list-item style="align-items: center;">
															<template v-slot:header>
																 <text :style="{fontSize:(wxFontSize-4)+'px'}">产品信息{{itemIndex+1}}</text>
															</template>
															<template v-slot:footer>
																<button type="default" style="color:#1d60b1;border-color:#1d60b1;" :style="{fontSize:(wxFontSize-5)+'px'}" plain="true" size="mini" v-if="(extList.length>1&&extList.length<6&&itemIndex==extList.length-1)||extList.length==1" @click="newItem">+新增产品</button>
																<button type="warn" plain="true" size="mini" :style="{fontSize:(wxFontSize-5)+'px'}" v-if="extList.length>1&&itemIndex!==extList.length-1" @click="delItem(itemIndex)">-删除产品</button>
																<!-- <tn-button fontColor="tn-color-white" shape="round" backgroundColor="#3668FC" v-if="extList.length==1" @click="newItem">+新增产品</tn-button>
																 <tn-button fontColor="tn-color-white" shape="round" backgroundColor="#3668FC" v-if="extList.length>1&&extList.length<6&&itemIndex==extList.length-1" @click="newItem">+新增产品</tn-button>
																 <tn-button fontColor="tn-color-white" shape="round" backgroundColor="#FF000C" v-if="extList.length>1&&itemIndex!==extList.length-1" @click="delItem(itemIndex)">-删除产品</tn-button> -->
															</template>
														</uni-list-item>
												</uni-list>
												
											</template>
										<uni-forms :modelValue="formData" label-width="0">
											 
											<uni-forms-item label="" name="prodName" label-width="0">
												<text style="color: red;line-height: 30px;vertical-align: middle;margin-right: 4px;" :style="{fontSize:(wxFontSize-4)+'px'}">*</text><text  :style="{fontSize:(wxFontSize-4)+'px'}">产品名称:</text>
												<uni-easyinput maxlength="50" type="text" :inputSize="wxFontSize-4" :placeholder-style="styleString"  :clearable="false" v-model="item.prodName"
													placeholder="请输入产品名称" />
											</uni-forms-item>
											<uni-forms-item label="" name="prodSpec" label-width="0">
												<text style="color: red;line-height: 30px;vertical-align: middle;margin-right: 4px;" :style="{fontSize:(wxFontSize-4)+'px'}">*</text><text :style="{fontSize:(wxFontSize-4)+'px'}">产品型号:</text>
												<uni-easyinput maxlength="100" type="text" :inputSize="wxFontSize-4" :placeholder-style="styleString" :clearable="false" v-model="item.prodSpec"
													placeholder="请输入产品型号" />
											</uni-forms-item>
											<uni-forms-item label="" name="prodDesc">
												<text style="line-height: 30px;vertical-align: middle;" :style="{fontSize:(wxFontSize-4)+'px'}">产品介绍:</text>
												<uni-easyinput maxlength="500" :inputSize="wxFontSize-4" :placeholder-style="styleString" type="textarea" v-model="item.prodDesc" placeholder="请输入产品介绍" />
											</uni-forms-item>

										</uni-forms>
										<template v-slot:actions v-if="itemIndex==extList.length-1" >
											<view style="margin: 12px;margin-top: -12px;" :style="{fontSize:(wxFontSize-5)+'px'}">
												<text style="color:#999">为保证排版整洁，最多一次上传六个产品哦</text>
											</view>
										</template>
							</uni-card>
							</view>
							 

						</view>


					</view>

				</view>
				<view v-if="selectValue2=='服务'&&stepIndex==2">
					<view style="padding: 16px">
						<text style="color: red;line-height: 30px;vertical-align: middle;margin-right: 4px;"  :style="{fontSize:(wxFontSize-3)+'px'}">*</text><text :style="{fontSize:(wxFontSize-3)+'px'}">服务类型:</text>
						<uni-data-select v-model="selectValue3" :localdata="selectList3" @change="changeSelect3"
							:clear="false" :fontSize="(wxFontSize-3)+'px'"></uni-data-select>
					</view>
				</view>
				
				<view v-if="selectValue2=='服务'&&stepIndex==2">
					<view style="padding: 16px">
					   <text style="line-height: 30px;vertical-align: middle;" :style="{fontSize:(wxFontSize-3)+'px'}">服务品牌:</text>
					   <uni-easyinput type="text" :clearable="false" :inputSize="wxFontSize-3" :placeholder-style="styleString" v-model="brand" placeholder="请输入服务品牌" />
					</view>
				</view>
					
				<view>
 
					 <view v-if="selectValue2=='服务'&&stepIndex==2" style="padding: 16px;padding-bottom: 0;margin-bottom: -30rpx;">
					    <text style="color: red;line-height: 30px;vertical-align: middle;margin-right: 4px;">*</text><text>服务介绍:</text>
					 </view>
					<view v-if="selectValue2=='服务'&&stepIndex==2" class="tn-margin tn-bg-gray--light tn-padding"
						style="border-radius: 10rpx;">
						
						<textarea maxlength="500" v-model="content" placeholder="请输入服务介绍"
							placeholder-style="color:#AAAAAA" :style="{fontSize:(wxFontSize-3)+'px'}" :placeholder-style="styleString"></textarea>
					</view>

					<view class="tn-flex tn-flex-row-between tn-flex-col-center  tn-margin" style="margin-bottom: 0;" v-if="stepIndex==3">
						<view class="tn-flex justify-content-item">
							<view class="tn-text-center"
								style="border-radius: 100rpx;margin-right: 8rpx;width: 45rpx;height: 45rpx;line-height: 45rpx;">
								<text class="tn-icon-image" style="font-size: 20px;" :style="{fontSize:(wxFontSize+3)+'px'}"></text>
							</view>
							<view class="tn-padding-right-xs tn-text-bold" style="font-size: 16px;" :style="{fontSize:(wxFontSize-1)+'px'}">上传图片（选填）</view>
						</view>
						<!-- <view class="justify-content-item tn-text-df tn-color-grey" @tap="clear">
					 					<text class="tn-padding-xs">清空上传</text>
					 					<text class="tn-icon-delete"></text>
					 				</view> -->
					</view>






					<view class="tn-margin-left tn-padding-top-xs"  v-if="stepIndex==3">
						<uni-file-picker v-model="imgList" :limit="6" :auto-upload="false" @select="select"
							@success="success" @delete="deleteFile">


						</uni-file-picker>
						<view style="margin-top: 8px;">
							<text style="color: #999;font-size: 12px;" :style="{fontSize:(wxFontSize-5)+'px'}">一次只能上传六张图片</text>
						</view>
						 

					</view>

					<view class="tn-flex tn-flex-row-between tn-flex-col-center tn-margin tn-padding-top-xs" style="margin-top:32px;margin-bottom: 0;" v-if="stepIndex==3">
						<view class="tn-flex justify-content-item">
							<view class="tn-text-center"
								style="border-radius: 100rpx;margin-right: 8rpx;width: 45rpx;height: 45rpx;line-height: 45rpx;">
								<text class="tn-icon-link" style="font-size: 20px;" :style="{fontSize:(wxFontSize+3)+'px'}"></text>
							</view>
							<view class="tn-padding-right-xs tn-text-bold"  style="font-size: 16px;"  :style="{fontSize:(wxFontSize-1)+'px'}">上传相关文件（选填）</view>
						</view>
						<!-- <view class="justify-content-item tn-text-df tn-color-grey" @tap="clear">
					 					<text class="tn-padding-xs">清空上传</text>
					 					<text class="tn-icon-delete"></text>
					 				</view> -->
					</view>

					<view class="tn-margin-left tn-padding-top-xs"  v-if="stepIndex==3">
						<uni-file-picker v-model="fileList" :limit="3" mode="grid" file-mediatype="all"
							file-extname="pdf,docx,doc,xls,xlsx" :auto-upload="false" @select="select" @success="success" @delete="deleteFile">
							<view style="text-align: left;">
								<button size="mini" style="color:#1d60b1;border-color:#1d60b1;display: inline-block;" plain="true"  :style="{fontSize:(wxFontSize-5)+'px'}">上传文件</button>
							</view>
							
						
						</uni-file-picker>
						<view style="margin-top: 4px;">
							<text style="color: #999;font-size: 12px;" :style="{fontSize:(wxFontSize-5)+'px'}">一次只能上传三个文件，支持格式 pdf .doc .xls，不超过5MB。</text>
						</view>
						 
						 
						<view style="margin-top:6px" v-if="selectValue2=='产品'">
							<text style="color: #999;font-size: 12px;" :style="{fontSize:(wxFontSize-5)+'px'}">如若产品属于医疗器械，请上传相关资质证明。</text>
						</view>
						 

					</view>
				</view>

				<view label="11" name="check" style="padding:16px;margin-top:20px" v-if="stepIndex==3">
					<tn-checkbox v-model="formInfo.agree" activeColor="#45c05d" :size="wxFontSize+17" name="选项1"  >
						<text :style="{fontSize:(wxFontSize-4)+'px',color:formInfo.agree?'#45c05d':'#666666'}">同意平台核查所填信息的真实性</text>
					</tn-checkbox>
					<!-- <uni-data-checkbox :multiple="true" v-model="formInfo.agree" selectedColor="#45c05d" 
						:localdata="[{text: '同意平台核查所填信息的真实性',value: '是'}]" /> -->
				</view>
				
				<!-- 悬浮按钮-->
				<view class="tn-flex tn-footerfixed" >
					<view class="tn-flex-1 justify-content-item tn-margin-sm tn-text-center">
						<button type="default" plain="true" style="border-radius: 24px;"
							@click="preStep()" :style="{fontSize:(wxFontSize-2)+'px'}">
							 上一步 
						</button>
					</view>
					<view class="tn-flex-1 justify-content-item tn-margin-sm tn-text-center">
						<button type="default" plain="true" style="border-radius: 24px;"
							@click="nextStep()" :style="{fontSize:(wxFontSize-2)+'px'}">
							 下一步 
						</button>
						<!-- <tn-button backgroundColor="#3668FC" padding="40rpx 0" width="60%" shadow fontBold
							@click="nextStep()">
							<text class="tn-color-white">下一步</text>
						</tn-button> -->
					</view>
				</view>

				<view class="tn-flex tn-footerfixed"  v-if="(stepIndex==3)">
					<view class="tn-flex-1 justify-content-item tn-margin-sm tn-text-center">
						<button type="default" plain="true" style="border-radius: 24px;"
							@click="preStep()" :style="{fontSize:(wxFontSize-2)+'px'}">
							 上一步 
						</button>
						 
					</view>
					<view class="tn-flex-1 justify-content-item tn-margin-sm tn-text-center">
						<button type="primary" style="background-color:#1d60b1;border-radius: 23px" @click="saveForm()" :style="{fontSize:(wxFontSize-2)+'px'}">提交审核</button>
						<!-- <tn-button backgroundColor="#3668FC" padding="40rpx 0" width="60%" shadow fontBold
							@click="saveForm()">
							<text class="tn-color-white">提交审核</text>
						</tn-button> -->
					</view>
				</view>
			</view>
		</view>



		<view class='tn-tabbar-height'></view>

	</view>
</template>

<script>
	import template_page_mixin from '@/libs/mixin/template_page_mixin.js';
	import request from '../utils/request';
	export default {
		name: 'TemplateEdit',
		mixins: [template_page_mixin],
		data() {
			return {
				wxFontSize: 17,
				styleString:'font-size:'+14+'px',
				showTips:false,
				canSave:true,
				isMedical: '1',
				content: '',
				selectValue: '个人',
				selectList: [{
						value: '个人',
						text: '个人'
					},
					{
						value: '公司',
						text: '公司'
					}
				],
				selectValue2: '产品',
				selectList2: [{
						value: '产品',
						text: '产品'
					},
					{
						value: '服务',
						text: '服务'
					}
				],
				selectValue3: '维修维保',
				brand: '',
				// 维修维保/改造升级/验证/搬迁/厂房建设/其他
				selectList3: [{
						value: '维修维保',
						text: '维修维保'
					},
					{
						value: '改造升级',
						text: '改造升级'
					},
					{
						value: '验证',
						text: '验证'
					},
					{
						value: '搬迁',
						text: '搬迁'
					},
					{
						value: '厂房建设',
						text: '厂房建设'
					},
					{
						value: '其他',
						text: '其他'
					}
				],
				selectValue4: '机械五金',
				selectList4: [{
						value: '机械五金',
						text: '机械五金'
					},
					{
						value: '仪器仪表',
						text: '仪器仪表'
					},
					{
						value: '耗材',
						text: '耗材'
					},
					{
						value: '其他',
						text: '其他'
					}
				],
				extList: [],
				// 机械五金/仪器仪表/耗材/其他
				formInfo: {
					jobTitle: '',
					userRealName:JSON.parse(uni.getStorageSync('userInfo')).userRealName,
					// contactPerson:JSON.parse(uni.getStorageSync('userInfo')).contactNickName?JSON.parse(uni.getStorageSync('userInfo')).contactNickName:'用户'+JSON.parse(uni.getStorageInfoSync('userInfo')).userName.splice(-4),
					agree: false,
					contactNickName: JSON.parse(uni.getStorageSync('userInfo')).contactNickName||'用户'+JSON.parse(uni.getStorageSync('userInfo')).userName.slice(-4),
					contactMethod: JSON.parse(uni.getStorageSync('userInfo')).contactMethod || JSON.parse(uni
						.getStorageSync('userInfo')).userName
				},
				imgList: [],
				fileDetailList: [],
				stepIndex: 1,
				stepList: [{
						name: '填写个人信息',
						icon: 'circle',
						selectIcon: 'circle-fill'
					},
					{
						name: '填写供应信息',
						icon: 'trusty',
						selectIcon: 'trusty-fill'
					},
					{
						name: '上传附件',
						icon: 'folder',
						selectIcon: 'folder-fill'
					}
				],
				stepList2 : [{
						name: '填写公司信息',
						icon: 'circle',
						selectIcon: 'circle-fill'
					},
					{
						name: '填写供应信息',
						icon: 'trusty',
						selectIcon: 'trusty-fill'
					},
					{
						name: '上传附件',
						icon: 'folder',
						selectIcon: 'folder-fill'
					}
				],
				action: 'https://www.hualigs.cn/api/upload',
				// action: '',
				formData: {
					apiType: 'this,ali',
					token: 'dffc1e06e636cff0fdf7d877b6ae6a2e',
					image: null
				},
				fileList: [],
				showUploadList: true,
				customBtn: false,
				autoUpload: true,
				showProgress: false,
				deleteable: true,
				customStyle: false,
				maxCount: 9,
				disabled: false,
				searchValue: '',
				items: [],
				org: {},
				isEdit:false,
				editItem:{}
			}
		},
		watch: {
			searchValue(val, oldval) {
				console.error(val, this.org.name);
				if (val !== this.org.name) {
					this.current = null;
				}
				if(this.selectValue!='个人'){
					this.search(val)
				}
				
			}
		},
		onLoad(props) {
			const appBaseInfo = wx.getAppBaseInfo();
			this.wxFontSize = uni.getStorageSync('fontSize')||appBaseInfo.fontSizeSetting||17;
			this.styleString='font-size:'+(this.wxFontSize-3)+'px';
			//从暂存里面编辑
			if(props.sid){
				this.isEdit = true;
				this.editItem = JSON.parse(uni.getStorageSync(props.sid)||'{}');
				
				this.content = this.editItem.content;
				this.selectValue2 = this.editItem.type==1?'产品':'服务';
				this.selectValue3 = this.editItem.secType;
				this.brand = this.editItem.brand;
				this.selectValue = this.editItem.subject=='1'?'公司':'个人';
				
				
				this.fileDetailList = this.editItem.fileDetailList;
				
				for(let i=0;i<this.fileDetailList.length;i++){
					this.fileDetailList[i].path = this.fileDetailList[i].ftpUrl
					if(this.isImage(this.fileDetailList[i].fileName)){
						this.imgList.push({
							name: this.fileDetailList[i].fileName,
							url: this.fileDetailList[i].ftpUrl,
							path: this.fileDetailList[i].path
						})
					}else{
						this.fileList.push({
							name: this.fileDetailList[i].fileName,
							url: this.fileDetailList[i].ftpUrl,
							path: this.fileDetailList[i].path
						})
					}
				}
				
				if(this.selectValue2=='产品'){
					this.selectValue4 = this.editItem.secType;
				    this.isMedical = this.editItem.isMedical;
					this.extList = this.editItem.shareExt;
				}
				
				this.org.name = this.editItem.company;
				this.formInfo.jobTitle = this.editItem.jobTitle;
				this.formInfo.contactPerson = this.editItem.contactPerson;
				this.formInfo.contactMethod = this.editItem.contactMethod;
				this.formInfo.contactNickName = this.formInfo.contactNickName;
			}
			this.getCompany();
		},
		methods: {
			isImage(fileName) {
							const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'ico']
							const extension = fileName.split('.').pop().toLowerCase();
							return imageExtensions.includes(extension);
			},
			showSet(){
				uni.navigateTo({
				  url: '/minePages/set',
				});
			},
			preStep(){
				this.stepIndex = this.stepIndex-1;
			},
			nextStep() {
				//todo 检查
				 let that = this;
				 if(this.stepIndex==1&&this.extList.length==0){
					 this.extList.push({
					 	prodDesc: "",
					 	prodName: "",
					 	prodSpec: "",
					 })
				 }
				 if(that.selectValue=='公司'){
					 console.error(this.org);
					 //判断必填项
					 // 公司
					 if(!this.org.name){
					 	uni.showToast({
					 		title: '请输入公司名称',
					 		duration: 2000,
					 		icon:'none'
					 	});
					 	return false;
					 }
					 
					 if(this.formInfo.jobTitle.length<1){
					 	uni.showToast({
					 		title: '请输入您的职称',
					 		duration: 2000,
					 		icon:'none'
					 	});
					 	return false;
					 }
					 if(this.formInfo.contactPerson.length<1){
					 	uni.showToast({
					 		title: '请输入联系人姓名',
					 		duration: 2000,
					 		icon:'none'
					 	});
					 	return false;
					 }
					 if(this.formInfo.contactMethod.length<1){
					 	uni.showToast({
					 		title: '请输入联系手机/微信/邮箱',
					 		duration: 2000,
					 		icon:'none'
					 	});
					 	return false;
					 }
				 }
					if(this.stepIndex==2&&that.selectValue2=='产品'){
						if(this.brand.length<1){
							uni.showToast({
								title: '请输入产品品牌',
								duration: 2000,
								icon:'none'
							});
							return false;
						}
						for(let i=0;i<this.extList.length;i++){
							if(!this.extList[i].prodName||!this.extList[i].prodSpec){
								uni.showToast({
									title: !this.extList[i].prodName?'请输入产品'+(i+1)+'的产品名称':'请输入产品'+(i+1)+'的产品型号',
									duration: 2000,
									icon:'none'
								});
								return false;
							}
						}
						
					}
					if(this.stepIndex==2&&that.selectValue2=='服务'){
							 if(!this.selectValue3){
								uni.showToast({
									title: '请选择服务类型',
									duration: 2000,
									icon:'none'
								});
								return false;
							 }
							if(!this.content){
								uni.showToast({
									title: '请输入服务介绍',
									duration: 2000,
									icon:'none'
								});
								return false;
							}
						 
					}
				 
				this.stepIndex = this.stepIndex+1;
			},
			getCompany(){
				let that = this;
					request.post('/slbUserCompanyRel/show/my', {
						userNo: uni.getStorageSync('userNo')
					}).then(res => {
						if (res.success) {
							let list = res.list || [];
							for(let i=0;i<list.length;i++){
								list[i].name = list[i].company;
								list[i].regNumber= list[i].company;
								if(!that.isEdit&&list[i].isDefault=='1'){
									that.searchValue = list[i].name
									that.current = list[i].name;
									that.formInfo.jobTitle = list[i].jobTitle;
									that.formInfo.contactPerson = list[i].contactPerson;
									that.formInfo.contactMethod = list[i].contactMethod;
									that.org = list[i];
									
									that.getAddress(list[i].name);
								}
								if(that.isEdit&&list[i].name==that.editItem.company){
									that.searchValue = list[i].name
									that.current = list[i].name;
									that.formInfo.jobTitle = list[i].jobTitle;
									that.formInfo.contactPerson = list[i].contactPerson;
									that.formInfo.contactMethod = list[i].contactMethod;
									that.org = list[i];
									
									that.getAddress(list[i].name);
								}
								 
							}
							that.items = list;
							console.warn(that.items);
						}  
					})
			},
			changeSelect(e) {
				this.selectValue = e;
			},
			changeSelect2(e) {
				this.selectValue2 = e;
			},
			changeSelect3(e) {
				this.selectValue3 = e;
			},
			changeSelect4(e) {
				this.selectValue4 = e;
			},
			newItem(){
				this.extList.push({
					prodDesc: "",
					prodName: "",
					prodSpec: "",
				})
			},
			delItem(index){
				this.extList.splice(index,1);
			},
			saveForm(status) {
				if(!this.canSave){
					return false;
				}
				let that = this;
				
				if(status!=1&&that.selectValue2=='服务'){
					
					if(!this.content){
						uni.showToast({
							title: '请输入服务介绍',
							duration: 2000,
							icon:'none'
						});
						return false;
					}
				}
				
				if(status!=1&&that.selectValue2=='产品'){
					 
					for(let i=0;i<this.extList.length;i++){
						if(!this.extList[i].prodName||!this.extList[i].prodSpec){
							uni.showToast({
								title: !this.extList[i].prodName?'请输入产品'+(i+1)+'的产品名称':'请输入产品'+(i+1)+'的产品型号',
								duration: 2000,
								icon:'none'
							});
							return false;
						}
					}
				}
				
				if(status!=1&&!this.formInfo.agree){
					uni.showToast({
						title: '请勾选同意平台核查所填信息的真实性',
						duration: 2000,
						icon:'none'
					});
					return false;
				}
				
				let params = {

				};
				let postData = {
						type: that.selectValue2=='服务'?'2':'1',
						secType: that.selectValue3,
						company: that.selectValue=='公司'?this.org.name:'',
						subject: that.selectValue=='公司'?'1':'2',
						jobTitle: this.formInfo.jobTitle,
						contactPerson: that.selectValue=='公司'?this.formInfo.contactPerson:(this.formInfo.userRealName||this.formInfo.contactNickName),
						contactMethod: this.formInfo.contactMethod,
						contactNickName: this.formInfo.contactNickName,
						content: that.content,
						userNo: uni.getStorageSync('userNo'),
						status: status==1?status:3,
						brand: that.brand,
						id: that.isEdit?that.editItem.id:undefined,
						bisNo: that.isEdit?that.editItem.bisNo:undefined,
						version: that.isEdit?that.editItem.version:undefined
				}
				if(that.selectValue=='公司'){
					postData.companyEntity = {};
					postData.companyEntity.company = postData.company;
					postData.companyEntity.jobTitle = postData.jobTitle;
					postData.companyEntity.creditCode = this.org.creditCode;
					postData.companyEntity.address = this.org.base;
					postData.companyEntity.regStatus = this.org.regStatus;
					
					postData.companyEntity.contactPerson = postData.contactPerson;
					postData.companyEntity.contactMethod = postData.contactMethod;
					postData.companyEntity.contactNickName = postData.contactNickName;
					
					// postData.companyEntity.address = this.org.creditCode;
					// postData.companyEntity.company = postData.company;
					
					postData.slbUserExt = {};
					postData.slbUserExt.userContactMethod = postData.contactMethod;
					postData.slbUserExt.contactPerson = postData.contactPerson;
					postData.slbUserExt.contactMethod = postData.contactMethod;
					postData.slbUserExt.contactNickName = postData.contactNickName;
					postData.slbUserExt.userRealName = this.formInfo.userRealName;
					
				}else{
					postData.slbUserExt = {};
					postData.slbUserExt.userContactMethod = postData.contactMethod;
					postData.slbUserExt.contactPerson = postData.contactPerson;
					postData.slbUserExt.contactMethod = postData.contactMethod;
					postData.slbUserExt.contactNickName = postData.contactNickName;
					postData.slbUserExt.userRealName = this.formInfo.userRealName;
				}
				if(postData.type=='1'){
					postData.secType = that.selectValue4;
					postData.isMedical = that.isMedical;
					postData.content = '';
					postData.shareExt = that.extList;
				}

				params.slbResourceShare = JSON.stringify(postData);
				 

				params.fileDetailList = JSON.stringify(this.fileDetailList);
				uni.showToast({
					title: '提交中...',
					icon:'none'
				});
				that.canSave = false;
				request.post(that.isEdit?'/slbResourceShare/update':'/slbResourceShare/add', params).then(res => {
					that.canSave = true;
					if (res.success) {
						uni.showToast({
							title: status==1?'信息已暂存，请在我的供应中查看暂存信息':'发布已提交，请在我的供应中查看进度',
							icon: 'none',
							success: () => {
								setTimeout(() => {
									uni.redirectTo({
										url: "/pages/mine/share?tab="+(status==1?2:1)
									});
								}, 2500)
							}
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
					console.warn(res);
				})
			},
			// 跳转
			tn(e) {
				uni.navigateTo({
					url: e,
				});
			},
			// 手动上传文件
			upload() {
				console.warn(121212);
			},
			// 手动清空列表
			clear() {
				this.$refs.imageUpload.clear()
			},
			// 图片拖拽重新排序
			onSortList(list) {
				console.log(list);
			},
			select(e) {
				console.log('选择文件：', e)
				let tempFiles = e.tempFiles;
				for (let i in tempFiles) {
					this.upfile(tempFiles[i])
				}
			},
			upfile(file) {
				let that = this;
				console.warn(file);
				uni.uploadFile({
					url: 'https://slb-m.lx-device.com/oss/upload/userFeedback', //仅为示例，非真实的接口地址
					filePath: file.url,
					name: 'file',
					success: (uploadFileRes) => {
						console.warn(JSON.parse(uploadFileRes.data));
						let resultMap = JSON.parse(uploadFileRes.data).resultMap;
						that.fileDetailList.push({
							name: file.name,
							fileName: file.name, // 原始文件名
							ftpUrl: resultMap.uploadUrl, // 文件访问url
							path: file.path
						})
					}
				});
			},
			// 上传成功
			success(e) {
				console.log('上传成功')
			},
			deleteFile(e, index) {
				for(let i=0;i<this.fileDetailList.length;i++){
					if(e.tempFile.path===this.fileDetailList[i].path){
						this.fileDetailList.splice(i, 1);
					}
				}
				console.error(this.fileDetailList);
			},
			selectChange(e) {
				this.searchValue = e.name
				this.current = e.regNumber;
				if(e.jobTitle){
					this.formInfo.jobTitle = e.jobTitle;
					this.formInfo.contactPerson = this[i].contactPerson;
					this.formInfo.contactMethod = this[i].contactMethod;
				}
				this.org = e;
				this.getAddress(e.name);
			},
			getAddress(name){
				let that = this;
				request.post('/member/getEnterPriseInfo', {
					keyWord:  name
				}).then(res => {
					if(res&&res.success&&res.resultMap.data){
					  if( res.resultMap.data.creditCode){
					  	 that.org.creditCode = res.resultMap.data.creditCode
					  }
					  if( res.resultMap.data.regStatus){
					  	 that.org.regStatus = res.resultMap.data.regStatus
					  }
					  if( res.resultMap.data.regLocation){
						 that.org.base = res.resultMap.data.regLocation
					  }
					}
				})
			},
			search: function(val) {
				let that = this;

				if (val && val.length > 3) {
					request.post('/member/searchCompys', {
						keyWord: val
					}).then(res => {
						if (res.success) {
							let list = res.resultMap.data || [];
							that.items = list;
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							})
						}
					})

				} else {
					that.items = [];
					that.org = {};
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.template-edit {}

	/* 胶囊*/
	.tn-custom-nav-bar__back {
		width: 60%;
		height: 100%;
		position: relative;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		box-sizing: border-box;
		// background-color: rgba(0, 0, 0, 0.15);
		border-radius: 1000rpx;
		border: 1rpx solid rgba(255, 255, 255, 0.5);
		// color: #FFFFFF;
		font-size: 18px;

		.icon {
			display: block;
			flex: 1;
			margin: auto;
			text-align: center;
		}

		&:before {
			content: " ";
			width: 1rpx;
			height: 110%;
			position: absolute;
			top: 22.5%;
			left: 0;
			right: 0;
			margin: auto;
			transform: scale(0.5);
			transform-origin: 0 0;
			pointer-events: none;
			box-sizing: border-box;
			opacity: 0.7;
			background-color: #FFFFFF;
		}
	}

	/* 底部悬浮按钮 start*/
	.tn-tabbar-height {
		min-height: 100rpx;
		height: calc(120rpx + env(safe-area-inset-bottom) / 2);
	}

	.tn-footerfixed {
		position: fixed;
		width: 100%;
		bottom: calc(env(safe-area-inset-bottom));
		z-index: 1024;
		box-shadow: 0 1rpx 6rpx rgba(0, 0, 0, 0);
		background: #fff;
	}

	/* 底部悬浮按钮 end*/

	/* 标签内容 start*/
	.tn-tag-content {
		&__item {
			display: inline-block;
			line-height: 45rpx;
			padding: 10rpx 30rpx;
			margin: 20rpx 20rpx 5rpx 0rpx;

			&--prefix {
				padding-right: 10rpx;
			}
		}
	}

	/deep/ .uni-forms-item__label {
		display: none;
	}
	
	/deep/ .uni-list-item__container {
		align-items: center;
	}
	/deep/.uni-card--shadow {
		margin:0 !important;
	}



	/* 标签内容 end*/
</style>