<template>
	<div class="content-main">
		<el-row class="search-bm-boder">
			<el-form
				:inline="true"
				:model="searchForm"
				class="demo-form-inline"
			>
			<el-row>
				<el-form-item label="上报期数:">
					<el-date-picker
						v-model="searchForm.sbqs"
						type="month"
						clearable
						value-format="yyyy-MM"
						placeholder="请选择上报期数"
					></el-date-picker>
				</el-form-item>
				<el-form-item label="承储单位:">
					<el-input
						clearable
						v-model="searchForm.sskdmc"
						placeholder="请输入"
					></el-input>
				</el-form-item>
				<el-form-item>
				  <div class="search-button">
				    <span class="search-line"></span>
				    <div class="search-select" @click="searchShowMore">
				      更多条件
				      <i class="el-icon-arrow-up" v-show="searchShowMoreBool"></i
				      ><i class="el-icon-arrow-down" v-show="!searchShowMoreBool"></i>
				    </div>
				    <el-button
				    	type="primary"
				    	size="small"
				    	class="iconfont iconchaxun"
				    	@click="findList(pageForm.pageNum = 1)"
				    	>查询</el-button
				    >
				   <el-button
				   	type="primary"
				   	@click="reSetForm"
				   	size="small"
				   	class="iconfont iconzhongzhi"
				   	>重置</el-button
				   >
				  </div>
				</el-form-item>
			</el-row>
			<el-row v-show="searchShowMoreBool">
				<el-form-item label="表名:">
				   <el-select
				    @change="changeBm"
				     clearable
				     class="inputCompatible"
				     v-model="searchForm.bmName"
				     placeholder="请选择"
				   >
				     <el-option
				       v-for="item in bmOptions"
				       :key="item.value"
				       :label="item.label"
				       :value="item.value"
				     ></el-option>
				   </el-select>
				</el-form-item>
				<el-form-item label="状态:">
				   <el-select
				     clearable
				     class="inputCompatible"
				     v-model="searchForm.status"
				     placeholder="请选择"
				   >
				     <el-option
				       v-for="item in statusOptions"
				       :key="item.value"
				       :label="item.label"
				       :value="item.value"
				     ></el-option>
				   </el-select>
				</el-form-item>
			</el-row>
			</el-form>
		</el-row>
		<el-row>
			<el-table
				:data="tableData"
				v-loading="listLoading"
				stripe
				border
				fit
				highlight-current-row
				style="width: 100%"
			>
				<el-table-column align="center" label="序号" width="70">
					<template slot-scope="scope">
						<span>{{ scope.$index + 1 }}</span>
					</template>
				</el-table-column>
				<el-table-column
					align="center"
					prop="tjVO.sskdmc"
					show-overflow-tooltip
					label="承储单位"
				>
          			<template slot-scope="scope">
          			  <span v-if="scope.row.tjVO">
          			    {{ scope.row.tjVO.sskdmc }}
          			  </span>
          			  <span v-else>
          			    {{ scope.row.tjnfVO.sskdmc }}
          			  </span>
          			</template>
				</el-table-column>
				<el-table-column
					align="center"
					prop="tjVO.sbqs"
					show-overflow-tooltip
					label="上报期数"
				>
          			<template slot-scope="scope">
          			  <span v-if="scope.row.tjVO">
          			    {{ scope.row.tjVO.sbqs }}
          			  </span>
          			  <span v-else>
          			    {{ scope.row.tjnfVO.sbqs }}
          			  </span>
          			</template>
				</el-table-column>
				<!-- <el-table-column
					align="center"
					prop="sbsj"
					label="提交时间"
					show-overflow-tooltip
				>
					<template slot-scope="scope">
						{{ scope.row.sbsj ? scope.row.sbsj : '--' }}
					</template>
				</el-table-column> -->
				<!-- <el-table-column
					align="center"
					prop="shry"
					label="审核人"
					show-overflow-tooltip
				></el-table-column> -->
				<el-table-column
					align="center"
					label="非调节进销存上报"
				>
					<el-table-column
						prop="tjVO.ztmc"
						align="center"
						label="状态"
					>
					</el-table-column>
					<el-table-column
						prop="grsl"
						align="center"
						label="操作"
          				class-name="control-btn"
					>
						<template slot-scope="scope">
							<div v-if="scope.row.tjVO">
							<el-tooltip
								class="item"
								effect="light"
								content="查看"
								placement="top"
								v-if="scope.row.tjVO.ztmc != '未上报'"
							>
								<el-button
									class="operate_show_btn iconfont iconchakan2"
									@click="showList(scope.row, 0)"
									type="primary"
									size="small"
								></el-button>
							</el-tooltip>
							<el-tooltip
								class="item"
								effect="light"
								content="审核"
								placement="top"
							>
								<el-button
									class="operate_edit_btn iconfont iconshenhe"
									@click="openUpdateDialog(scope.row, 0)"
									type="primary"
									size="small"
									v-show="scope.row.tjVO.ztmc == '待审核'"
								></el-button>
							</el-tooltip>
							<el-tooltip
								class="item"
								effect="light"
								content="驳回"
								placement="top"
							>
								<el-button
									class="operate_edit_btn iconfont iconbohui"
									@click="reject(scope.row.tjVO.id, 0)"
									type="primary"
									size="small"
									v-show="
										scope.row.tjVO.ztmc == '审核通过' &&
										scope.row.tjVO.isReject
									"
								></el-button>
							</el-tooltip>

							<el-tooltip
								class="item"
								effect="light"
								content="导出"
								placement="top"
								v-if="scope.row.tjVO.ztmc != '未上报'"
							>
								<el-button
									@click="daochuData(scope.row, 0)"
									type="primary"
									size="small"
									class="operate_show_btn iconfont icondaochu11"
								></el-button>
							</el-tooltip>
							</div>
						</template>
					</el-table-column>
				</el-table-column>
				<el-table-column
					align="center"
					label="库存年限上报"
				>
					<el-table-column
						prop="tjnfVO.ztmc"
						align="center"
						label="状态"
					>
					</el-table-column>
					<el-table-column
						prop="grsl"
						align="center"
						label="操作"
          				class-name="control-btn"
					>
						<template slot-scope="scope">
							<div v-if="scope.row.tjnfVO">
							<el-tooltip
								class="item"
								effect="light"
								content="查看"
								placement="top"
								v-if="scope.row.tjnfVO.ztmc != '未上报'"
							>
								<el-button
									class="operate_show_btn iconfont iconchakan2"
									@click="showList(scope.row, 1)"
									type="primary"
									size="small"
								></el-button>
							</el-tooltip>
							<el-tooltip
								class="item"
								effect="light"
								content="审核"
								placement="top"
							>
								<el-button
									class="operate_edit_btn iconfont iconshenhe"
									@click="openUpdateDialog(scope.row, 1)"
									type="primary"
									size="small"
									v-show="scope.row.tjnfVO.ztmc == '待审核'"
								></el-button>
							</el-tooltip>
							<el-tooltip
								class="item"
								effect="light"
								content="驳回"
								placement="top"
							>
								<el-button
									class="operate_edit_btn iconfont iconbohui"
									@click="reject(scope.row.tjnfVO.id, 1)"
									type="primary"
									size="small"
									v-show="
										scope.row.tjnfVO.ztmc == '审核通过' &&
										scope.row.tjnfVO.isReject
									"
								></el-button>
							</el-tooltip>
							<el-tooltip
								class="item"
								effect="light"
								content="导出"
								placement="top"
								v-if="scope.row.tjnfVO.ztmc != '未上报'"
							>
								<el-button
									@click="daochuData(scope.row, 1)"
									type="primary"
									size="small"
									class="operate_show_btn iconfont icondaochu11"
								></el-button>
							</el-tooltip>
							</div>
						</template>
					</el-table-column>
				</el-table-column>
				<!-- <el-table-column align="center" label="操作" width="160">
					<template slot-scope="scope">
						<el-tooltip
							class="item"
							effect="light"
							content="查看"
							placement="top"
							v-if="scope.row.ztmc != '未上报'"
						>
							<el-button
								class="operate_show_btn iconfont iconchakan2"
								@click="showList(scope.row, 0)"
								type="primary"
								size="small"
							></el-button>
						</el-tooltip>
						<el-tooltip
							class="item"
							effect="light"
							content="审核"
							placement="top"
						>
							<el-button
								class="operate_edit_btn iconfont iconshenhe"
								@click="openUpdateDialog(scope.row, 1)"
								type="primary"
								size="small"
								v-show="scope.row.ztmc == '待审核'"
							></el-button>
						</el-tooltip>
						<el-tooltip
							class="item"
							effect="light"
							content="驳回"
							placement="top"
						>
							<el-button
								class="operate_edit_btn iconfont iconbohui"
								@click="reject(scope.row.id)"
								type="primary"
								size="small"
								v-show="
									scope.row.ztmc == '审核通过' &&
									scope.row.isReject
								"
							></el-button>
						</el-tooltip>

						<el-tooltip
							class="item"
							effect="light"
							content="导出"
							placement="top"
							v-if="scope.row.ztmc != '未上报'"
						>
							<el-button
								@click="daochuData(scope.row)"
								type="primary"
								size="small"
								class="operate_show_btn iconfont icondaochu11"
							></el-button>
						</el-tooltip>
					</template>
				</el-table-column> -->
			</el-table>
		</el-row>
		<el-row>
			<el-pagination
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				:current-page.sync="pageForm.pageNum"
				:page-sizes="[10, 20, 30, 40]"
				:page-size="pageForm.pageSize"
				layout="total, sizes, prev, pager, next, jumper"
				:total="pageForm.total"
			></el-pagination>
		</el-row>
	</div>
</template>

<script>
import { authorityControl } from '@/api/login/login'
import {
	selectList,
	update,
	updateKcnd,
} from '@/api/unregulatedReserves/reportDataReview/index'
import { getNowDate1 } from '@/utils'

export default {
	data() {
		return {
			searchShowMoreBool:false,
			buttonNameList: [],
			listLoading: true,
			bmStatus:'',
			searchForm: {
				sbqs: '',
				sskdmc: '',
				bmName:'',
				status:'',
			},
			pageForm: {
				pageNum: 1,
				pageSize: 10,
				total: 0,
			},
			tableData: [],
			bmOptions:[
				{
					label:'进销存表',
					value:'1',
				},
				{
					label:'库存年限表',
					value:'2',
				}
			],
			statusOptions:[
				{
					label:'未上报',
					value:'未上报',
				},
				{
					label:'待审核',
					value:'待审核',
				},
				{
					label:'审核通过',
					value:'审核通过',
				},
				{
					label:'上报驳回',
					value:'上报驳回',
				}
			],
		}
	},
	methods: {
		changeBm(e){
			this.bmStatus=e
			console.log(e,'22222')
		},
		searchShowMore(){
			this.searchShowMoreBool=!this.searchShowMoreBool
		},
		//驳回
		reject(id, status) {
			this.$confirm('是否确认驳回？', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning',
			})
				.then(() => {
					if (status == 0) {
						this.doRejectTodo(id)
					}else if (status == 1) {
						this.doKcndRejectTodo(id)
					}
				})
				.catch(() => {
					this.$message({
						type: 'info',
						message: '已取消驳回',
					})
				})
		},
		doRejectTodo(id) {
			let data = {
				id: id,
				zt: '91000004',
				ztmc: '上报驳回',
			}
			update(data)
				.then((res) => {
					if (res.infoCode == '200') {
						this.$message({
							message: '驳回成功',
							type: 'success',
						})
						this.findList()
					} else {
						this.$message({
							message: '驳回失败',
							type: 'error',
						})
					}
				})
				.catch((res) => {
					this.$message({
						message: res.msg,
						type: 'error',
					})
				})
		},
		// 库存年限驳回
		doKcndRejectTodo(id) {
			let data = {
				id: id,
				zt: '91000004',
				ztmc: '上报驳回',
			}
			updateKcnd(data)
				.then((res) => {
					if (res.infoCode == '200') {
						this.$message({
							message: '驳回成功',
							type: 'success',
						})
						this.findList()
					} else {
						this.$message({
							message: '驳回失败',
							type: 'error',
						})
					}
				})
				.catch((res) => {
					this.$message({
						message: res.msg,
						type: 'error',
					})
				})
		},
		getButtonList(menuCode, userCode) {
			let codeData = {
				resourceCode: menuCode,
				userId: userCode,
			}
			authorityControl(codeData).then((res) => {
				res.data.forEach((item) => {
					this.buttonNameList.push(item.resourceName)
				})
				this.findList('start')
			})
		},
		reSetForm() {
			this.searchForm.sbqs = ''
			this.searchForm.sskdmc = ''
			this.searchForm.status=''
			this.searchForm.bmName=''
			this.pageForm.pageNum = 1
			this.findList()
		},
		//导出
		daochuData(row, state) {
			if (state == 0) {
				this.$router.push({
					name: 'reportDataReviewDetail',
					query: {
						state: 'export',
						id: row.tjVO.id,
					},
				})
			}else if (state == 1) {
				this.$router.push({
					name: 'reportDataReviewDetailYear',
					query: {
						state: 'export',
						id: row.tjnfVO.id,
					},
				})
			}
		},

		//查找对应的列表
		findList(type) {
      		if (type != "start") {
      		  //非初始化调用：查询、分页
      		  sessionStorage.setItem("searchData", JSON.stringify(this.searchForm));
      		  sessionStorage.setItem("pageData", JSON.stringify(this.pageForm));
      		} else {
      		  //初始化分两种情况，详情页等返回后的初始化，以及第一次进入此菜单的初始化
      		  if (JSON.parse(sessionStorage.getItem("searchData"))) {
      		    //详情页返回后，将对应查询条件和分页的字段赋值，页面回显参数
      		    this.searchForm = JSON.parse(sessionStorage.getItem("searchData"));
      		    this.pageForm = JSON.parse(sessionStorage.getItem("pageData"));
			  	console.log(this.searchForm,"this.searchForm---------");
      		  } else {
      		    //第一次进去此菜单时，保存上方默认的data
				this.$set(this.searchForm, 'sbqs', getNowDate1())
      		    sessionStorage.setItem("searchData", JSON.stringify(this.searchForm));
      		    sessionStorage.setItem("pageData", JSON.stringify(this.pageForm));
      		  }
      		}
			// console.log(this.searchForm,"data_________");
			
			if(this.bmStatus == 2){
				var data = {
					sbqs: this.searchForm.sbqs,
					sskdmc: this.searchForm.sskdmc,
					pageNum: this.pageForm.pageNum,
					pageSize: this.pageForm.pageSize,
					pageType: 2,
					nfztmc:this.searchForm.status
				}
			}else{
				var data = {
					sbqs: this.searchForm.sbqs,
					sskdmc: this.searchForm.sskdmc,
					pageNum: this.pageForm.pageNum,
					pageSize: this.pageForm.pageSize,
					pageType: 2,
					tjztmc:this.searchForm.status
				}
			}
			this.listLoading = true
			selectList(data)
				.then((res) => {
					this.listLoading = false
					if (res.infoCode == 200) {
						this.pageForm.total = res.data.total
						this.tableData = res.data.items
					} else {
						this.$message({
							type: 'error',
							message: '获取失败!',
						})
					}
				})
				.catch((err) => {
					this.listLoading = false
				})
		},

		//编辑
		openUpdateDialog(row, state) {
			if (state == 0) {
				this.$router.push({
					name: 'reportDataReviewDetail',
					query: {
						state: 'audit',
						id: row.tjVO.id,
					},
				})
			}else if (state == 1) {
				this.$router.push({
					name: 'reportDataReviewDetailYear',
					query: {
						state: 'audit',
						id: row.tjnfVO.id,
					},
				})
			}
		},
		//查看
		showList(row, state) {
			if (state == 0) {
				this.$router.push({
					name: 'reportDataReviewDetail',
					query: {
						state: 'detail',
						id: row.tjVO.id,
					},
				})
			}else if(state == 1){
				this.$router.push({
					name: 'reportDataReviewDetailYear',
					query: {
						state: 'detail',
						id: row.tjnfVO.id,
					},
				})
			}
		},
		handleSizeChange(val) {
			this.pageForm.pageSize = val
			this.findList()
		},
		handleCurrentChange(val) {
			this.pageForm.pageNum = val
			this.findList()
		},
	},
	created() {
		// this.searchForm.sbqs = getNowDate1()
		console.log(this.searchForm,"_________");
		this.getButtonList(
			sessionStorage.getItem('resourceCode'),
			sessionStorage.getItem('userCode')
		)
		// this.getList();
	},
	mounted() {},
}
</script>

<style scoped lang="scss">
/deep/ .control-btn {
  .cell {
    display: flex;
    justify-content: center;
  }
}
</style>
