<template>
    <view>
       <!-- <cu-custom bgColor="bg-white" :isBack="true">
			<block slot="content">
				服务需求详情
			</block>
            <block slot="right"></block>
            <block slot="right">
				
			</block>
 		</cu-custom> -->
        
		<view >
			<view style="font-size: 32rpx;font-weight: bold;color: #111111; margin: 40rpx 30rpx;">
				<text>{{info.name }}</text>
			</view>
			<view style="margin: 0 20rpx; background: #F7F8F9;border-radius: 15rpx; padding: 20rpx; font-size: 26rpx;font-weight: 500;color: #7A8FB4;">
				<view class="flex align-start justify-start" style="margin-bottom: 20rpx;">
					<view style="width: 130rpx; min-width: 130rpx; ">服务类型：</view>
					<view style=" max-width: 530rpx;">
						{{info.parentCategoryName == null ? info.categoryName :  info.parentCategoryName + "-" +  info.categoryName}}
					</view>
				</view>
				<view class="flex align-start justify-start">
					<view style="width: 130rpx; min-width: 130rpx; ">服务地址：</view>
					<view style=" max-width: 530rpx;">{{info.publishAddress.address + "-" + info.publishAddress.detailed}}</view>
				</view>
			</view>
			
			<view class="flex justify-between align-center" style="padding: 20rpx 30rpx 10rpx 30rpx">
				<view style="color: #999999; font-size: 26rpx;">{{ $timefilter('YY-MM-DD HH:MM',info.createTime)}}</view>
				
				<view style="color: #111111; font-size: 26rpx;">
					<text>有</text>
					<text style="color: #FC6035;">{{info.quoteCount}}</text>
					<text>人报价</text>
				</view>
			</view>
			
			<view style="margin: 30rpx;">
				<view style="font-size: 30rpx;font-weight: 500;color: #111111; margin-bottom: 30rpx;word-wrap:break-word">
					{{info.publishDesc}}
				</view>
				<!-- <view v-if="info.publishImageList.length > 0" v-for="(item, index) in info.publishImageList"> -->
					<!-- <image :src="item.faceImage" style="width: 100%;"></image> -->
					<!-- <view style="position: relative; margin-bottom: 20rpx;">
						<u-image width="690rpx" height="auto" mode="widthFix" v-if="item.type=='001'" :src="item.url" :border-radius="10" ></u-image>
						<u-image width="690rpx" height="auto" mode="widthFix" :lazy-load="false" v-if="item.type=='002'" :src="item.faceImg" :border-radius="10" ></u-image>
						<image src="../../static/common/play.png" v-if="item.type=='002'" class="play-btn-img"></image>
					</view>
					
				</view> -->
				
				<view class="bg-f8 flex align-center justify-center margin-bottom-xs"
					v-for="(ele,index) in  info.publishImageList" :key="index"
					style="border-radius: 6rpx;overflow: hidden;margin-right:11rpx;margin-top: 10rpx;"
					@tap.stop="$videoList(index,item.resourceList,'resourceType')">
					<video :src="ele.url" v-if="ele.type=='002'" 
					:poster="ele.faceImg"
						style="width: 690rpx;height:'auto';"></video>
					<image :src="ele.url" v-else-if="ele.type=='001'" style="width: 690rpx;height: 'auto';"  mode="aspectFill">
					</image>
				</view>	
				
			</view>
			<view style="width: 750rpx;height: 15rpx;background: #F6F6F6;"></view>
			<view class="flex align-center justify-between" style="padding: 20rpx 30rpx;">
				<view style="font-size: 32rpx;font-weight: bold;color: #111111;">服务人员报价</view>
				<view v-if="info.serverQuoteCount==0 && info.publishState == '001' && showQuoteButton" style="width: 160rpx;height: 56rpx;background: #FC6035;border-radius: 8rpx; " class="flex align-center justify-center" @click="showQuote()">
					<view style="font-size: 26rpx;font-weight: 500;color: #FFFFFF; line-height: 26rpx;" @click="insertQuote()" >我要报价</view>
				</view>
			</view>	
			<view style="width: 680rpx;height: 2rpx;background: #F6F6F6; margin: 0 35rpx;"></view>
			<view class="content text-df flex align-center justify-center flex-direction" v-show="empty" style="margin-top: 84rpx;">
				<image src="../../static/empty.png" class="empty-img"></image>
				<view class="color-66" style="margin: 0rpx 0 80rpx 0;">暂无报价数据</view>
			</view>
			<view v-for="(item, index) in quoteList"  v-show="!empty">		  
			<!-- 报价 -->
				<view style="padding: 30rpx;" class="flex justify-center align-start">
					
					<view style="width: 80rpx; height: 80rpx; margin-right: 10rpx;">
						<u-image :src="item.serverUser.avatar" :fade="true" duration="450" width="80rpx" height="80rpx" shape="circle" >
							<view slot="error" style="font-size: 24rpx;"><image src="../../static/publish/defalut_avatar.png" mode="" style="width: 80rpx;height: 80rpx;"></image></view>
						</u-image>
					</view>					
					<view style="width: 590rpx;">
						<view class="flex align-center justify-between" style="width: 590rpx;">
							<view style="">
								<view class="flex align-center justify-start">
									<view style="font-size: 28rpx;font-weight: bold;color: #111111;word-wrap:break-word"> {{item.serverUser.nikeName != null ? item.serverUser.nikeName : item.serverUser.realName}}</view>
									<view style="font-size: 24rpx;font-weight: 500;color: #D99864; padding-left: 14rpx;">{{item.serverUser.serverLevelName}}</view>
								</view>
								
							</view>
							<view style="font-size: 24rpx;font-weight: 500;color: #999999;">{{ $timefilter('YY-MM-DD HH:MM',item.createTime)}}</view>
						</view>
						<view>
							<text style="font-size: 22rpx;background: #FAFAFA;border: 2rpx solid #CCCCCC;border-radius: 8rpx;font-weight: 500;color: #333333; padding: 2rpx 6rpx; text-align: center; margin-top: 20rpx;">
								{{item.serverUser.serverAge}}年工龄
							</text>
						</view>
						<view class="flex align-center justify-between" style="margin-top: 6rpx;" v-if="item.serverUser.score != '' && item.serverUser.score > 0">
							<view >
								<text style="font-size: 22rpx;font-weight: 500;color: #999999;">综合评分：</text>
								<text style="font-size: 24rpx;font-weight: 500;color: #999999;">{{item.serverUser.score}}</text>
							</view>
							<view style="background: #FFFFFF;border: 2rpx solid #FF9396;border-radius: 8rpx;font-size: 22rpx;font-weight: 500;color: #FF0000; padding: 0rpx 6rpx;" v-if="item.serverUser.rate > 0">好评率 {{item.serverUser.rate}}%</view>
						</view>
						<view style="margin-top: 6rpx;" v-if="item.serverUser.merchantType == 0">
							<text style="font-size: 22rpx;font-weight: 500;color: #999999; ">{{item.serverUser.merchantName}}</text>
						</view>
						<view style="width: 100%; background-color: #F7F8F9;border-radius: 10px; margin-top: 20rpx; padding: 20rpx;word-wrap:break-word">
							<text style="font-size: 28rpx;font-weight: 500;color: #111111;">{{item.quoteDesc}}</text>
						</view>
						<view class="flex align-center justify-between" style="margin-top: 20rpx;">
							<view class="flex align-center justify-start" style="background: #FFEDED;border-radius: 8rpx;">
								<view style="background: #FF6368;border-radius: 8rpx;font-size: 22rpx;font-weight: 500;color: #FFFFFF; width: 64rpx; height: 40rpx; line-height: 40rpx; text-align: center;">报价</view>
								<view style="padding: 0 10rpx;">
									<text style="font-size: 26rpx;font-weight: 500;color: #FF0000; line-height: 40rpx;">{{item.totalPrice}}</text>
									<text style="font-size: 22rpx;font-weight: 500;color: #FF0000; line-height: 40rpx;">元</text>
								</view>
							</view>
							<view class="flex align-center justify-end" v-if="item.serverUserId == serverId && info.publishState == '001'" >
								<view style="padding: 6rpx 20rpx">
									<image src="../../static/publish/delete.png" style="width: 38rpx; height: 38rpx;" @click="deleteQuote(item)"></image>
								</view>
								<view style="padding: 6rpx 20rpx">
									<image src="../../static/publish/reply.png" style="width: 38rpx; height: 38rpx;" @click="addReply(item)"></image>
								</view>
								<view style="padding: 6rpx 20rpx">
									<image src="../../static/publish/edit.png" style="width: 38rpx; height: 38rpx;"  @click="editQuote(item)"></image>
								</view>
							</view>
						</view>
						<view style="width: 590rpx;height: 2rpx;background: #F6F6F6; margin-top: 20rpx;"></view>
						<!-- ---回复---- -->
						<view class="flex justify-between align-start" style="margin-top: 20rpx;"  v-for="(itemm, index) in item.quoteReplyVoList">
							<view style="width: 60rpx; height: 60rpx; margin-right: 10rpx;">
								<u-image :src="itemm.avatar" :fade="true" duration="450" width="60rpx" height="60rpx" shape="circle" v-if="itemm.replyType == '0'">
									<view slot="error" style="font-size: 24rpx;"><image src="../../static/common/avatar_icon.png" mode="" style="width: 80rpx;height: 80rpx;"></image></view>
								</u-image>
								
								
								<u-image :src="itemm.serverAvatar" :fade="true" duration="450" width="60rpx" height="60rpx" shape="circle" v-if="itemm.replyType == '1'">
									<view slot="error" style="font-size: 24rpx;"><image src="../../static/publish/defalut_avatar.png" mode="" style="width: 80rpx;height: 80rpx;"></image></view>
								</u-image>
							</view>
							
							 
							<view style="width: 520rpx; ">
								<view class="flex align-center justify-between" style="padding: 10rpx 0;">
									<view>
										<text style="font-size: 28rpx;font-weight: 500;color: #111111;" v-if="itemm.replyType == '0'">{{itemm.name}}</text>
										<text style="font-size: 28rpx;font-weight: 500;color: #111111;" v-if="itemm.replyType == '1'">{{itemm.serverName}}</text>
										<text style="font-size: 28rpx;font-weight: 500;color: #999999; margin: 0 8rpx;" >回复</text>
			
										<text style="font-size: 28rpx;font-weight: 500;color: #111111;" v-if="itemm.replyType =='1'">{{itemm.name}}</text>
										<text style="font-size: 28rpx;font-weight: 500;color: #111111;" v-if="itemm.replyType =='0'">{{itemm.serverName}}</text>
									</view>
									<view>
										
										<text style="font-size: 22rpx;font-weight: 500;color: #999999;">{{ $timefilter('YY-MM-DD HH:MM',itemm.createTime)}}</text>
									</view>
								</view>
								<view>
									<text style="font-size: 28rpx;font-weight: 500;color: #111111;word-wrap:break-word">{{itemm.replyDesc}}</text>
								</view>
								<view class="flex align-center justify-end" v-if="itemm.replyType =='1' && info.publishState == '001'">
								        <text style="font-size: 28rpx;font-weight: 500;color: #FC6035;" v-if="itemm.serverUserId == serverId" @click="deleteReply(itemm)">删除</text>
								</view>
								<view style="width: 520rpx;height: 2rpx;background: #F6F6F6; margin-top: 20rpx;"></view>
							</view>
						</view>
					</view>
					
				</view>
			</view>
			<u-loadmore :status="status" :load-text="loadText" @loadmore="loadmore()" v-show="quoteList.length > 0"  />
			<view style="height: 20rpx;"></view>
			
			<view>
				<u-popup border-radius="20" v-model="quoteShow" mode="bottom" :safe-area-inset-bottom="true">
					<view class="flex align-center justify-end" style="padding: 38rpx 54rpx; color: #111111;">
						<span class="font-34 text-bold">我要报价</span>
						<view style="width:30rpx;height:30rpx; margin-left: 228rpx;"  @tap="quoteShow=false">
							<image src="../../static/common/close.png" style="width:30rpx;height:30rpx; "></image>
						</view>
						
					</view>
					
					<view style="width: 700rpx; margin: 0 25rpx; ">
						<u-input v-model="quote.quoteDesc" :type="inputArea.type" :border="inputArea.border" :height="inputArea.height" :auto-height="inputArea.autoHeight" :borderColor="inputArea.borderColor" :placeholder="inputArea.placeholder"
								 style="padding: 20rpx 30rpx; background-color: #FAFAFA; font-size: 30rpx;"/>
					</view>
					<view class="flex justify-between align-center" style="width: 680rpx; padding: 14rpx; margin: 0 35rpx; ">
						<view style="font-size: 30rpx;font-weight: bold;color: #111111;">单价</view>
						<view class="flex justify-end align-center">
							<view style="width: 160rpx; text-align: right;">
								<input  maxlength="10" v-model="quote.singlePrice" style="text-align: right;" placeholder="请输入单价" type="digit" 
										@blur="replaceInput" placeholder-style="text-align: right; font-size: 26rpx;font-weight: 500;color: #C0C0C0;"></input>
							</view>
							<view style="font-size: 30rpx;font-weight: 500;color: #111111; text-align: right; width: 50rpx;">元</view>
						</view>
					</view>
					<view class="flex justify-between align-center" style="width: 680rpx; padding: 14rpx; margin: 0 35rpx; " @click="chooseUnit()">
						<view style="font-size: 30rpx;font-weight: bold;color: #111111;">单位</view>
						<view class="flex justify-end align-center" >
							<view style="width: 160rpx; text-align: right;" v-if="quote.quoteUnit == ''">
								<!-- <u-input style="text-align: right;" placeholder="请选择单位" :disabled="true"></u-input> -->
								<text style="font-size: 26rpx;font-weight: 500;color: #C0C0C0;">请选择单位</text>
							</view>
							<view style="text-align: right;" v-else>
								<!-- <u-input style="text-align: right;" placeholder="请选择单位" :disabled="true"></u-input> -->
								<text style="font-size: 26rpx;font-weight: 500;color: #111111;" v-if="quote.quoteUnit == needInputUnitId">{{quote.otherUnit}}</text>
								<text style="font-size: 26rpx;font-weight: 500;color: #111111;" v-else>{{getUnitName(quote.quoteUnit) }}</text>
							</view>
							<view style="font-size: 30rpx;font-weight: 500;color: #111111; text-align: right; width: 50rpx;">
								<u-icon name="arrow-right" color="#666666" size="28"></u-icon>
							</view>
						</view>
					</view>
					<view class="flex justify-between align-center" style="width: 680rpx; padding: 14rpx; margin: 14rpx 35rpx; " @click="chooseTime()">
						<view style="font-size: 30rpx;font-weight: bold;color: #111111;">单个服务时长</view>
						<view class="flex justify-end align-center">
							<view style="width: 190rpx; text-align: right;"  v-if="quote.singleTime == ''">
								<text style="font-size: 26rpx;font-weight: 500;color: #C0C0C0;">请选择单位时长</text>
							</view>
							<view style="text-align: right;"  v-else>
								<text style="font-size: 26rpx;font-weight: 500;color: #111111;">{{quote.singleTime + "小时"}}</text>
							</view>
							<view style="font-size: 30rpx;font-weight: 500;color: #111111; text-align: right; width: 50rpx;">
								<u-icon name="arrow-right" color="#666666" size="28"></u-icon>
							</view>
						</view>
					</view>
					<view class="flex justify-between align-center" style="width: 680rpx; padding: 14rpx; margin: 0 35rpx; ">
						<view style="font-size: 30rpx;font-weight: bold;color: #111111;">服务数量</view>
						<view class="flex justify-end align-center">
							<u-number-box v-model="quote.quoteCounts" :input-width="60" :input-height="60" bg-color="#FFFFFF" :disabled-input="true" :min="1" :max="99"></u-number-box>
						</view>
					</view>
					<view style="width: 700rpx;height: 2rpx;background: #F6F6F6; margin: 10rpx 25rpx;"></view>
					
					<view class="flex justify-end align-center" style="width: 680rpx; padding: 14rpx; margin: 0 35rpx; ">
						<view style="font-size: 30rpx;font-weight: bold;color: #111111;">合计:</view>
						<view style="font-size: 34rpx;font-weight: bold;color: #FF511B;">{{quote.totalPrice == "" ? "--" : "￥" + quote.totalPrice }}元</view>
						<view style="font-size: 34rpx;font-weight: bold;color: #FF511B; margin: 0 10rpx;">/</view>
						<view style="font-size: 34rpx;font-weight: bold;color: #FF511B;">{{quote.totalTime == "" ? "--" : quote.totalTime  }}小时</view>
					</view>
							
					<view style="padding: 30rpx 70rpx;" @click="saveQuote">
						<view class="select_time_sure">提交</view>
					</view>
					
				</u-popup>
			</view>
			
			<view>
				<u-popup border-radius="20" v-model="unitShow" mode="bottom" :safe-area-inset-bottom="true" @close="closeUnit">
					<view class="flex align-center justify-end" style="padding: 38rpx 54rpx; color: #111111;">
						<span class="font-34 text-bold">选择单位</span>
						<view style="width:30rpx;height:30rpx; margin-left: 228rpx;"  @tap="unitShow=false">
							<image src="../../static/common/close.png" style="width:30rpx;height:30rpx; "></image>
						</view>
						
					</view>
					
					<view class="flex justify-between align-center">
						<picker-view :indicator-style="indicatorStyle" @change="selectUnit" :value="unitValue" class="picker-view">
							<picker-view-column>
								<view class="item" v-for="(item,index) in unitList" :key="item.dictSort">{{item.dictLabel}}</view>
							</picker-view-column>
							
						</picker-view>
						<view v-if="showInputUnit" style="width: 400rpx; ">
							<u-input v-model="inputUnit" type="text" input-align="center" placeholder="请输入单位"
									 :border="true"  border-color="#DDDDDD" height="96" style="margin-top: 20rpx;"/>
						</view>
					</view>
					<view style="padding: 30rpx 70rpx;" @click="saveUnit">
						<view class="select_time_sure">确定</view>
					</view>
					
				</u-popup>
			</view>
			
			<view>
				<u-popup border-radius="20" v-model="timeShow" mode="bottom" :safe-area-inset-bottom="true" @close="closeTime">
					<view class="flex align-center justify-end" style="padding: 38rpx 54rpx; color: #111111;">
						<span class="font-34 text-bold">选择时长</span>
						<view style="width:30rpx;height:30rpx; margin-left: 228rpx;"  @tap="timeShow=false">
							<image src="../../static/common/close.png" style="width:30rpx;height:30rpx; "></image>
						</view>
						
					</view>
					
					<picker-view :indicator-style="indicatorStyle" @change="selectTime" :value="timeValue" class="picker-view">
						<picker-view-column>
							<view class="item" v-for="(item,index) in timeList" :key="item">{{item}}小时</view>
						</picker-view-column>
						
					</picker-view>
					<view style="padding: 30rpx 70rpx;" @click="saveTime">
						<view class="select_time_sure">确定</view>
					</view>
					
				</u-popup>
			</view>
		</view>
		<view>
			<u-popup border-radius="20" v-model="replyShow" mode="bottom" :safe-area-inset-bottom="true">
				<view class="flex align-center justify-end" style="padding: 38rpx 54rpx; color: #111111;">
					<span class="font-34 text-bold">我要留言</span>
					<view style="width:30rpx;height:30rpx; margin-left: 228rpx;"  @tap="replyShow=false">
						<image src="../../static/common/close.png" style="width:30rpx;height:30rpx; "></image>
					</view>
					
				</view>
				
				<view style="width: 700rpx; margin: 0 25rpx; ">
					<u-input v-model="reply.replyDesc" :type="replyInputArea.type" :border="inputArea.border" :height="inputArea.height" :auto-height="inputArea.autoHeight" :borderColor="inputArea.borderColor" :placeholder="replyInputArea.placeholder"
							 style="padding: 20rpx 30rpx; background-color: #FAFAFA; font-size: 30rpx;"/>
				</view>
			 		
				<view style="padding: 30rpx 70rpx;" @click="saveReply">
					<view class="select_time_sure">提交</view>
				</view>
				
			</u-popup>
		</view>
		
		<u-modal v-model="showModel" :content="modelContent" confirm-color="#FC6035" :showCancelButton="true"
		      confirmText='确认' @confirm="confirmDeleteQuote()">
		</u-modal>
		<u-modal v-model="replyModel" :content="modelContent" confirm-color="#FC6035" :showCancelButton="true"
		      confirmText='确认' @confirm="confirmDeleteReply()">
		</u-modal>
		<u-toast ref="uToast" />
    </view>
	
</template>
<script>
export default {
	components: {},
	   data() {
		  return {
			needInputUnitId: "999",
			status: "loadmore",
			loadText: {
				loadmore: '点击或上拉加载更多',
				loading: '努力加载中',
				nomore: '没有更多了'
			},
			indicatorStyle: `height: 100rpx;`,
			unitList: [],
			timeList: [0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6],
			timeValue: [0],
			unitValue: [0],
			inputUnit: "",
			selectedUnit: "",
			selectedTime: "",
			quoteShow: false,
			replyShow: false,
			unitShow: false,
			timeShow: false,
			showInputUnit: false,
			quote: {
				publishId: "",
				quoteDesc: "",
				quoteUnit: "",
				otherUnit: "",
				singleTime: "",
				quoteCounts: "",
				singlePrice: "",
				totalPrice: "",
				totalTime: "",
				quoteCounts: 1
			},
			reply:{
				replyDesc:"",
			},
			inputArea: {
				value: '',
				type: 'textarea',
				border: true,
				height: 100,
				autoHeight: true,
				borderColor: '#E3E3E3',
				placeholder: '请输入说明'
			},
			replyInputArea: {
				placeholder: '请输入留言'
			},
			icon: "http://fresh-life.oss-cn-shanghai.aliyuncs.com/uploadimages/2022/01/14/1642141148408.jpeg",
			info: {
				publishAddress:{
					address:"",
					detailed:"",
				},
			},
			quoteList:[],
			serverId:'',
			showModel: false,
			replyModel: false,
			editQuoteId:'',
			editReolyId:'',
			modelContent: "",
			empty:true,
			showQuoteButton: false,
		  }
	   },
	 watch: {
	},
	// 接收 上个页面传递过来的参数
	onLoad(option) {	
		this.getUserInfo();
		this.id = option.publishId;
	},
	created(){
		//根据字典类型查询字典信息（查询报价单位）
		this.getUnitList();
		//查询数据（获取发布需求详细信息）
		this.publishInfo();
		//获取报价分页数据
		this.getQuoteList(1);
		this.showQuoteButtonMethod();
	},
	mounted(){
	},
	watch: {
		'quote.singlePrice'(newVal,oldVal){
			this.calculateTotal()
		},
		'quote.singleTime'(newVal,oldVal){
			this.calculateTotal()
		},
		'quote.quoteCounts'(newVal,oldVal){
			this.calculateTotal()
		}
	},
	onPullDownRefresh() {
		// this.load();
		// setTimeout(() => {
		 //  uni.stopPullDownRefresh();
		// }, 1000)
		this.publishInfo();
		this.getQuoteList(1);
	},
	methods:{
		//获取当前服务人员id
		getUserInfo() {
		  var that = this;
		  that.serverId = uni.getStorageSync('userInfo').serverId;
		  //未获取到时跳转到登录页面
		  if (that.serverId == undefined || that.serverId == null || that.serverId == '') {
		    uni.reLaunch({
		      url: '../login/indexChoice'
		    })
		  }
		},
		showQuote() {
			this.quoteShow = true;
			
		},
		showQuoteButtonMethod() {
			var that = this;
			let params = {
				serverId: uni.getStorageSync('userInfo').serverId
			};
			that.$u.api.showQuote(params).then(res => {
				 
				if(res.code === 200) {
					that.showQuoteButton = true;
				}else{
					that.$api.msg(res.msg)
				}
			}).catch(err =>{
				console.log(err)
			})
		},
		getUnitName(unitId) {
			console.log("unitId" , unitId)
			for(let i = 0; i < this.unitList.length; i ++) {
				if (this.unitList[i].dictSort == unitId) {
					return this.unitList[i].dictLabel
				}
			}
		},
		calculateTotal() {
			if (this.quote.singleTime == "") {
				this.quote.totalTime = ""
			} else {
				this.quote.totalTime = this.quote.singleTime * this.quote.quoteCounts;
			}
			if (this.quote.singlePrice == "") {
				this.quote.totalPrice = ""
			} else {
				this.quote.totalPrice = this.quote.singlePrice * this.quote.quoteCounts;
			}
			console.log("calculate")
		},
		chooseUnit() {
			console.log("unit--", this.quote.quoteUnit)
			if (this.quote.quoteUnit != "") {
				for(let i = 0; i < this.unitList.length; i ++) {
					if (this.unitList[i].dictSort == this.quote.quoteUnit) {
						this.unitValue = [i];
						this.selectedUnit = this.unitList[i].dictSort;
						if (this.unitList[i].dictSort == this.needInputUnitId) {
							this.showInputUnit = true;
						} else {
							this.showInputUnit = false;
						}
						break;
					}
				}
			}
			if (this.selectedUnit == "") {
				this.selectedUnit = this.unitList[0].dictSort;
			}
			this.inputUnit = this.quote.otherUnit;
			this.unitShow = true;
			this.quoteShow = false;
		},
		selectUnit: function(e) {
			const val = e.detail.value
			console.log(e)
			this.selectedUnit = this.unitList[val].dictSort;
			if (this.unitList[val].dictSort == this.needInputUnitId) {
				this.showInputUnit = true;
			} else {
				this.showInputUnit = false;
			}
		},
		closeUnit() {
			console.log("close--------")
			this.quoteShow = true;
		},
		chooseTime() {
			console.log("--", this.quote.singleTime)
			if (this.quote.singleTime != "") {
				for(let i = 0; i < this.timeList.length; i ++) {
					if (this.timeList[i] === this.quote.singleTime) {
						this.selectedTime = this.timeList[i];
						this.timeValue = [i];
						break;
					}
				}
			}
			if (this.selectedTime == "") {
				this.selectedTime = this.timeList[0]
			}
			console.log(this.timeValue)
			this.timeShow = true;
			this.quoteShow = false;
		},
		selectTime: function(e) {
			const val = e.detail.value
			console.log(e)
			console.log(this.timeValue)
			this.selectedTime = this.timeList[val];
		},
		closeTime() {
			console.log("close--------")
			this.quoteShow = true;
		},
		saveUnit() {
			console.log(this.selectedUnit)
			if (this.selectedUnit == this.needInputUnitId) {
				// todo 判断输入单位，弹窗
				if (this.inputUnit == "") {
					alert("请输入单位")
				} else {
					this.quote.quoteUnit = this.selectedUnit;
					this.quote.otherUnit = this.inputUnit;
					console.log(",,,,", this.quote)
				}
			} else {
				this.quote.quoteUnit = this.selectedUnit;
			}
			this.unitShow = false;
		},
		//点击选择时长
		saveTime() {
			this.quote.singleTime = this.selectedTime;
			this.timeShow = false;		
		},
		//查询数据（获取发布需求详细信息）
		publishInfo(){
			var that = this;
			let params = {
				serverId: that.serverId,
				publishId:that.id,
			};
			that.$u.api.getPublishInfo(params).then(res => {
				 
				if(res.code === 200) {
					that.info=res.data;	 
				}else{
					that.$api.msg(res.msg)
				}
			}).catch(err =>{
				console.log(err)
			})
		},
		//获取报价分页数据
		getQuoteList(pageNum){
			var that = this;
			let params = {
				pageNum:pageNum,
				pageSize: that.$store.state.pageSizes,
				serverId: that.serverId,
				publishId:that.id,
			};
			that.$u.api.quoteList(params).then(res => {
				if(res.code === 200) {
					if(res.pageNum == 1) {
						that.quoteList=res.rows
					} else {
						this.quoteList = this.quoteList.concat(res.rows)
					}
					this.hasNextPage = res.hasNextPage;
					this.pageNum = res.pageNum;
					if (this.hasNextPage) {
						this.status = "loadmore";
					} else {
						this.status = "nomore";
					}
 
				}else{
					that.$api.msg(res.msg)
					that.$api.msg(res.msg)
					if (this.hasNextPage) {
						this.status = "loadmore";
					} else {
						this.status = "nomore";
					}
				}
				
				if(this.quoteList.length>0){
					this.empty=false;
				}else{
					this.empty=true;
				}
			}).catch(err =>{
				console.log(err)
				console.log(err)
				if (this.hasNextPage) {
					this.status = "loadmore";
				} else {
					this.status = "nomore";
				}
			}).finally(()=>{
				uni.stopPullDownRefresh();
			})
		},
		onReachBottom() {
			this.loadmore()
		},
		loadmore() {
			console.log("loadmore")
			if (this.status == "loadmore" && this.hasNextPage) {
				this.getQuoteList(this.pageNum + 1)
			}
		},
		
		//根据字典类型获取报价单位数据
		getUnitList(){
			var that = this;
			let params= "goods_unit";
			that.$u.api.getType(params).then(res => {		
				 
				console.log(res)
				if (res.code === 200) {
					that.unitList=res.data;
					 
				}else{
					that.$api.msg(res.msg)
				}
				
			}).catch(err =>{
				console.log(err)
			})
		},
		// 点击删除报价
		deleteQuote(res){ 
			console.log(res)
			this.showModel = true;
			this.editQuoteId =res.quoteId;
			this.modelContent = "确定删除此报价吗？";
		},
		//调用删除报价接口
		confirmDeleteQuote(){	 
			var that = this;
			console.log(that.editQuoteId);
			that.$u.api.delQuote(that.editQuoteId).then(res => {
				console.log(res)
				if (res.code === 200) {
					that.$api.msg('操作成功')
					that.publishInfo();
					//重新查询列表数据
					that.getQuoteList(1);
				}else{	 
					that.$api.msg(res.msg)
				}
				that.editQuoteId ='';
				that.modelContent='';
				that.followIds=[];
			}).catch(err =>{
				console.log(err)
			})
		},
		//点击我要报价
		insertQuote(){
			this.quote={
				publishId: "",
				quoteDesc: "",
				quoteUnit: "",
				otherUnit: "",
				singleTime: 0.5,
				quoteCounts: "",
				singlePrice: "",
				totalPrice: "",
				totalTime: "",
				quoteCounts: 1
			} 
			this.quoteShow = true;
		},
		//点击修改报价按钮
		editQuote(res){
			console.log("点击修改报价按钮");
			console.log(res);
				
			this.quote=res;
			this.quoteShow = true;
		},
		replaceInput: function(event) {
			console.log(event)
            event.target.value = event.target.value.replace(/[^\d.]/g, "");  //清除“数字”和“.”以外的字符
			event.target.value = event.target.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
			event.target.value = event.target.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
			event.target.value = event.target.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');//只能输入两个小数
			if (event.target.value.indexOf(".") < 0 && event.target.value != "") {//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
				event.target.value = parseFloat(event.target.value);
			}
			console.log("---", event.target.value)
			this.quote.singlePrice = event.target.value;
        },
		//点击提交报价按钮
		saveQuote(){
			console.log("点击提交数据报价");		
			console.log(this.quote);
			console.log(this.quote.singlePrice)
			
			if(this.quote.quoteDesc == ''){
				this.$refs.uToast.show({
					title:'报价说明不能为空',	
				})	 
				return
			}
			if(this.quote.singlePrice == ''){
				this.$refs.uToast.show({
					title:'请输入单价',	
				})	 
				return
			}
			if(this.quote.singlePrice < 0.01){
				this.$refs.uToast.show({
					title:'请输入单价金额',	
				})	 
				return
			}
			//进行更新
			var that = this;
			let params =this.quote;
			//判断报价信息中是否有报价id
			if(params.quoteId != undefined){
			
				that.$u.api.editQuote(params).then(res => {
					if(res.code === 200) {	 	
						that.$api.msg('操作成功')
						that.quoteShow = false;
						//重新查询列表数据
						that.getQuoteList(1);
					}else{ 		 
						that.$refs.uToast.show({
							title: res.msg,	
						})
						//重新查询列表数据
						that.getQuoteList(1);
					}
				}).catch(err =>{
					console.log(err)
				})
			}else{
				console.log("添加");		
				//进行添加
				params.publishId=that.id;
				params.serverUserId=that.serverId;
				that.$u.api.addQuote(params).then(res => {
					if(res.code === 200) {
						that.$api.msg('操作成功')
						that.quoteShow = false;
						that.publishInfo();
						//重新查询列表数据
						that.getQuoteList(1);
					}else{
						that.$refs.uToast.show({
							title: res.msg,	
						})
						that.quoteShow = false;
						that.publishInfo();
						//重新查询列表数据
						that.getQuoteList(1);
					}
				}).catch(err =>{
					console.log(err)
				})
			}	
		},
		//点击删除留言按钮
		deleteReply(res){
			console.log(res)
			this.replyModel = true;
			this.editReolyId =res.replyId;
			this.modelContent = "确定删除此留言吗？";	
		},
		//调用删除报价接口
		confirmDeleteReply(){	 
			var that = this;
			console.log(that.editReolyId);
			that.$u.api.delReply(that.editReolyId).then(res => {
				console.log(res)
				if (res.code === 200) {
					that.$api.msg('操作成功')
					//重新查询列表数据
					that.getQuoteList(1);
				}else{	 
					that.$api.msg(res.msg)
				}
				that.editReolyId ='';
				that.modelContent='';
				that.followIds=[];
			}).catch(err =>{
				console.log(err)
			})
		},
		//点击留言按钮
		addReply(res){
			console.log("点击留言按钮")
			console.log(res)
			this.reply={
				replyDesc:"",
			};
			this.reply.quoteId=res.quoteId;
			this.replyShow = true;
		},
		//提交留言
		saveReply(){
			var that = this;
			that.reply.memberId=that.info.memberId;
			let params =that.reply;
			params.publishId=that.id;
			params.serverUserId=that.serverId;
			console.log("++++++++")
			console.log(params.replyDesc)
			if(params.replyDesc == "" ){
				that.$refs.uToast.show({
					title:'留言不能为空',	
				})	 
				return
			}
			
			that.$u.api.insertReply(params).then(res => {
				if(res.code === 200) {
					that.$api.msg('操作成功')
					that.replyShow = false;
					//重新查询列表数据
					that.getQuoteList(1);
				}else{
					that.$refs.uToast.show({
						title: res.msg,	
					})
					// that.replyShow = false;
					//重新查询列表数据
					that.getQuoteList(1);
				}
			}).catch(err =>{
				console.log(err)
			})
		},
		
		
	}


}
</script>
<style lang='scss' scoped>
	page {
		background: #FFFFFF;
	}
	
	.play-btn-img {
		position: absolute;
		top: calc(50% - 30rpx);
		left: calc(50% - 30rpx);
		width: 60rpx;
		height: 60rpx;
	}
	.select_time_sure {
		background: #fc6035;
		box-shadow: 0rpx 5rpx 14rpx 0rpx #eb4553;
		border-radius: 50rpx;
		color: #ffffff;
		font-size: 32rpx;
		font-weight: 400;
		text-align: center;
		padding-top: 29rpx;
		padding-bottom: 29rpx;
	}
	/deep/ .u-icon-minus {
	    font-weight: bold;
		border: 2rpx solid #CCCCCC;
		border-radius: 8rpx;
	}
	/deep/ .u-icon-plus {
	    font-weight: bold;
		border: 2rpx solid #CCCCCC;
		border-radius: 8rpx;
	}
	.picker-view {
		width: 750rpx;
		height: 400rpx;
		margin-top: 20rpx;
	}
	.item {
		height: 100rpx;
		align-items: center;
		justify-content: center;
		text-align: center;
		font-size: 32rpx;
		line-height: 100rpx;
	}
	.empty-img {
	    width: 380rpx;
	    height: 380rpx;
	    margin-bottom: 32rpx;
	}
	.border-top {
	    border-top: 2rpx solid #eee;
	}
</style>

