<template>
	<view>
		<u-table style="margin-bottom: 100rpx;" v-if="dataList.length > 0">
			<u-tr>
				<u-th width="80rpx">序号</u-th>
				<u-th>品名</u-th>
				<u-th>规格</u-th>
				<u-th>采购数量</u-th>
				<u-th>计量单位</u-th>
				<u-th>备注</u-th>
			</u-tr>
			<u-tr v-for="(item,index) in dataList" :key="index">
				<u-td class="fixedList" width="80rpx">{{index+1}}</u-td>
				<u-td class="fixedList"><text @click="tips(item.feeName)">{{item.feeName}}</text></u-td>
				<u-td class="fixedList"><text @click="tips(item.fCurrencyName)">{{item.fCurrencyName}}</text></u-td>
				<u-td class="fixedList"><text @click="tips(item.fPurchase)">{{item.fPurchase}}</text></u-td>
				<u-td class="fixedList"><text @click="tips(item.fFeeunitName)">{{item.fFeeunitName}}</text></u-td>
				<u-td class="fixedList"><text @click="tips(item.remark)">{{item.remark}}</text></u-td>
			</u-tr>
		</u-table>
		<u-empty v-else style="width: 50%;
			margin: 0 auto;
			height: 220rpx;
			align-items: center;
			position: absolute;
			top: 45%;
			left: 50%;
			transform:translate(-50%,-50%)" text="列表为空" mode="data"></u-empty>
		<view v-if="toExamine == true"
			style="width: 100%;position:fixed; bottom:0rpx;background-color: #FFFFFF;padding-left: 40rpx;padding-right: 40rpx;margin-bottom: 30rpx;margin-top: 100rpx;">
			<view style="float: left;width: 49%;">
				<u-button type="primary" @click="appToExamine(true)">审核通过</u-button>
			</view>
			<view style="float: right;width: 49%;">
				<u-button type="primary" @click="appToExamine(false)">审核拒绝</u-button>
			</view>
		</view>
		<view v-else-if="this.deptName == '外部用户'"
			style="width: 100%;position:fixed; bottom:0rpx;background-color: #FFFFFF;padding-left: 40rpx;padding-right: 40rpx;margin-bottom: 30rpx;margin-top: 100rpx;">
			<view style="float: left;width: 49%;">
				<u-button type="primary" @click="appCheckCode(true)">接单</u-button>
			</view>
			<view style="float: right;width: 49%;">
				<u-button type="primary" @click="appCheckCode(false)">拒绝</u-button>
			</view>
		</view>
		<u-modal v-model="show" :title="title" :show-cancel-button="true" :content-style="{margin: '40rpx auto'}"
			@confirm="confirm">
			<view class="slot-content">
				<rich-text v-if="tpye == true && dataList.length > 0" :nodes="content" style="text-align: center;">
				</rich-text>
				<u-form v-else style="width: 90%;margin: 0 auto;">
					<u-form-item label="拒绝理由:" label-width="130rpx">
						<u-input height="20rpx" :clearable="false" type="textarea" v-model="value" />
					</u-form-item>
				</u-form>
			</view>
		</u-modal>
		<u-modal v-model="showTwo" :title="titleTwo" :show-cancel-button="true" :content-style="{margin: '40rpx auto'}"
			@confirm="confirmTwo">
			<view class="slot-content">
				<!-- <rich-text v-if="ToExamineType == true && dataList.length > 0" :nodes="content" style="text-align: center;"></rich-text> -->
				<u-form v-if="ToExamineType == true && dataList.length > 0" style="width: 90%;margin: 0 auto;">
					<u-form-item label="同意意见:" label-width="130rpx">
						<u-input height="20rpx" :clearable="false" type="textarea" v-model="valueTwo" />
					</u-form-item>
				</u-form>
				<u-form v-else style="width: 90%;margin: 0 auto;">
					<u-form-item label="拒绝理由:" label-width="130rpx">
						<u-input height="20rpx" :clearable="false" type="textarea" v-model="valueTwo" />
					</u-form-item>
				</u-form>
			</view>
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				showTwo: false,
				title: '',
				titleTwo: '',
				value: '',
				valueTwo: '',
				content: `是否接单`,
				dataList: [],
				form: {},
				textw: false,
				deptName: '',
				tpye: '',
				ToExamineType: '',
				toExamine: false,
			};
		},
		onLoad(option) {
			this.deptName = uni.getStorageSync('deptName')
			// console.log(uni.getStorageSync('deptName'))
			this.toExamine = JSON.parse(option.toExamine)
			console.log(JSON.parse(option.form))
			this.formData = JSON.parse(option.form)
			let data = this.toExamine == true ? JSON.parse(option.form).billId : JSON.parse(option.form).fId
			this.$u.get('/anPin/anPinApp/' + data).then(res => {
				// console.log(res)
				this.form = res.data.warehouseBills
				this.dataList = res.data.tWarehousebillsfees
			})
		},
		methods: {
			tips(text) {
				console.log(this.textw)
				uni.showToast({
					icon: 'none',
					title: text,
					position: "center"
				})
			},
			appCheckCode(tpye) {
				this.tpye = tpye
				this.show = true
				if (tpye == true) {
					this.title = '提示'
				} else {
					this.title = '是否拒绝'
				}
			},
			confirm() {
				if (this.tpye == false) {
					if (this.value) {
						this.operationSucceeded()
					} else {
						this.show = true
						uni.showToast({
							icon: 'none',
							title: '请填写拒绝理由',
							position: "center"
						})
					}
				} else {
					this.operationSucceeded()
				}
			},
			appToExamine(ToExamineType) {
				console.log(ToExamineType)
				this.ToExamineType = ToExamineType
				this.showTwo = true
				if (ToExamineType == true) {
					this.titleTwo = '确认同意'
				} else {
					this.titleTwo = '确认拒绝'
				}
			},
			confirmTwo() {
				if (this.ToExamineType == false) {
					if (this.valueTwo) {
						this.$u.post('/warehouse/paths/approvalRejected', {
							actId: 520,
							auditItem: new Date().getFullYear() + '-' + Number(new Date().getMonth()+1) + '-' + new Date().getDate(),
							auditMsg: this.valueTwo,
							auditUserId: uni.getStorageSync('userId'),
							billId: this.form.fId,
							id: this.form.fId
						}).then(res => {
							uni.navigateBack();
						})
					} else {
						this.showTwo = true
						uni.showToast({
							icon: 'none',
							title: '请填写拒绝理由',
							position: "center"
						})
					}
				} else {
					// let tiem = moment(Date.parse(new Date())).format('YYYY-MM-DD')
					if (this.valueTwo) {
						this.$u.post('/warehouse/paths/approved', {
							actId: 520,
							auditItem: new Date().getFullYear() + '-' + Number(new Date().getMonth()+1) + '-' + new Date().getDate(),
							auditMsg: this.valueTwo,
							auditUserId: uni.getStorageSync('userId'),
							billId: this.form.fId,
							id: this.form.fId
						}).then(res => {
							uni.navigateBack();
						})
					} else {
						this.showTwo = true
						uni.showToast({
							icon: 'none',
							title: '请填写同意意见',
							position: "center"
						})
					}
				}
			},
			approve(type) {
				if (type == true) {} else {
					this.$u.post('/warehouse/paths/approvalRejected', {}).then(res => {
						console.log(res)
						// uni.navigateBack();
					})
				}
			},
			operationSucceeded() {
				this.$u.post('/anPin/anPinApp/updateMessage', {
					fTakeOrders: this.tpye == true ? 1 : 2,
					fId: this.form.fId,
					fReason: this.value,
				}).then(res => {
					uni.showToast({
						icon: 'none',
						title: '操作成功',
						position: "center"
					})
					uni.navigateBack();
				})
			}
		}
	};
</script>

<style scoped lang="scss">
	.fixedList {
		height: 62rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		display: block;
		z-index: 1;
	}
</style>
