<!-- 页面顶部公共按钮 -->
<template lang="">
	<div class="page-top">
		<el-button-group class="s-p-t-g1" v-if="btnType.includes('s-p-t-g11')">
			<el-button
				@click="actionhandel('edit')"
				:disabled="isDisable"
				:class="{ isDisable: isDisable }"
				>修改</el-button
			>
		</el-button-group>
		<el-button-group class="s-p-t-g1" v-if="!btnType.includes('s-p-t-g1')">
			<el-button
				@click="actionhandel('add')"
				v-if="!btnType.includes('add')"
				:disabled="isDisable"
				:class="{ isDisable: isDisable }"
				><span class="iconfont icon-tianjia iconfont-mg"></span
				>新增</el-button
			>
			<el-button
				@click="actionhandel('save')"
				v-if="!btnType.includes('save')"
				:disabled="isDisable"
				:class="{ isDisable: isDisable }"
				><span class="iconfont icon-baocun iconfont-mg"></span
				>保存</el-button
			>
			<el-button
				@click="actionhandel('copy')"
				v-if="!btnType.includes('copy')"
				:disabled="isDisable"
				:class="{ isDisable: isDisable }"
				><span class="iconfont icon-fuzhi iconfont-mg"></span
				>克隆</el-button
			>
		</el-button-group>
		<el-button-group class="s-p-t-g2" v-if="!btnType.includes('s-p-t-g2')">
			<el-button
				@click="actionhandel('submit')"
				v-if="!btnType.includes('submit')"
				:disabled="isDisable"
				:class="{ isDisable: isDisable }"
				>提交</el-button
			>
			<el-button
				@click="actionhandel('revoke')"
				v-if="!btnType.includes('revoke')"
				:disabled="isDisable"
				:class="{ isDisable: isDisable }"
				>撤销</el-button
			>
		</el-button-group>
		<el-button-group class="s-p-t-g7" v-if="!btnType.includes('s-p-t-g7')">
			<el-button
				@click="actionhandel('push-order')"
				v-if="btnType.includes('push-order')"
				:disabled="isDisable"
				:class="{ isDisable: isDisable }"
				>下单</el-button
			>
			<el-button
				ref="getRefresh"
				@click="actionhandel('batch-edit')"
				v-if="btnType.includes('batch-edit')"
				:disabled="isDisable"
				:class="{ isDisable: isDisable }"
				>批量修改</el-button
			>
		</el-button-group>
		<el-button-group class="s-p-t-g6" v-if="btnType.includes('s-p-t-g6')">
			<el-button
				@click="actionhandel('querenorder')"
				v-if="!btnType.includes('querenorder')"
				>确认订单</el-button
			>
			<el-button
				@click="actionhandel('scruku')"
				v-if="!btnType.includes('scruku')"
				>生产入库</el-button
			>
			<el-button
				@click="actionhandel('songhuo')"
				v-if="!btnType.includes('songhuo')"
				>送货</el-button
			>
		</el-button-group>
		<el-button-group class="s-p-t-g3" v-if="!btnType.includes('s-p-t-g3')">
			<el-button
				@click="actionhandel('audit')"
				v-if="!btnType.includes('audit')"
				:disabled="isDisable || isExmaineTop == 1"
				:class="{ isDisable: isDisable || isExmaineTop == 1 }"
				>审核</el-button
			>
			<el-button
				@click="actionhandel('de-approval')"
				v-if="!btnType.includes('de-approval')"
				:disabled="isDisable || isExmaineTop == 1"
				:class="{ isDisable: isDisable || isExmaineTop == 1 }"
				>反审</el-button
			>
			<el-button
				@click="actionhandel('setIntoNum')"
				v-if="btnType.includes('setIntoNum')"
				>调整入库数量</el-button
			>
			<el-button
				@click="actionhandel('Receiving')"
				v-if="btnType.includes('Receiving')"
				>收货</el-button
			>
			<el-button
				@click="actionhandel('delet')"
				v-if="!btnType.includes('delete')"
				:disabled="isDisable"
				:class="{ isDisable: isDisable }"
				>删除</el-button
			>
			<el-button
				@click="actionhandel('gys-close')"
				v-if="btnType.includes('gys-close')"
				>关闭</el-button
			>
			<el-button
				@click="actionhandel('gys-declose')"
				v-if="btnType.includes('gys-declose')"
				>反关闭</el-button
			>
		</el-button-group>
		<el-button-group class="s-p-t-g8" v-if="!btnType.includes('s-p-t-g8')">
			<el-button
				@click="actionhandel('out-export')"
				v-if="btnType.includes('out-export')"
				:disabled="isDisable"
				:class="{ isDisable: isDisable }"
				>导出</el-button
			>
		</el-button-group>
		<el-button-group class="s-p-t-g4" v-if="!btnType.includes('s-p-t-g4')">
			<div class="btn-flex">
				<el-button
					@click="actionhandel('push-down')"
					v-if="!btnType.includes('push-down')"
					:disabled="isDisable || isExmaineTop == 1"
					:class="{ isDisable: isDisable || isExmaineTop == 1 }"
					>下推</el-button
				>
				<el-dropdown
					v-if="!btnType.includes('operation')"
					:trigger="click"
					:hide-on-click="true"
					:disabled="isDisable || isExmaineTop == 1"
					@visible-change="dropDownEnter"
					placement="bottom-start"
					class="btn-action"
				>
					<span
						class="el-dropdown-link"
						:class="{ isDisable: isDisable || isExmaineTop == 1 }"
					>
						操作<i class="iconfont icon-gengduo f-12"> </i
					></span>
					<template #dropdown>
						<el-dropdown-menu class="insert-row" style="padding: 0">
							<el-dropdown-item
								class="dropdownselect"
								@click="actionhandel('disabled')"
							>
								<span
									style="margin-right: 4px"
									v-if="btnType.includes('disabled')"
									>禁用</span
								>
							</el-dropdown-item>
							<el-dropdown-item
								class="dropdownselect"
								@click="actionhandel('de-disabled')"
							>
								<span
									style="margin-right: 4px"
									v-if="btnType.includes('de-disabled')"
									>反禁用</span
								>
							</el-dropdown-item>
							<el-dropdown-item
								class="dropdownselect"
								@click="actionhandel('close')"
							>
								<span
									style="margin-right: 4px"
									v-if="!btnType.includes('close')"
									>关闭</span
								>
							</el-dropdown-item>
							<el-dropdown-item
								class="dropdownselect"
								@click="actionhandel('de-close')"
							>
								<span
									style="margin-right: 4px"
									v-if="!btnType.includes('de-close')"
									>反关闭</span
								>
							</el-dropdown-item>
							<el-dropdown-item
								class="dropdownselect"
								v-if="!btnType.includes('export')"
							>
								<el-dropdown
									placement="right-start"
									trigger="hover"
									style="
										line-height: 36px;
										text-align: center;
										padding-left: 14px;
									"
								>
									<span class="el-dropdown-link f-12 zdyspan"
										>导出<i
											class="iconfont icon-youbian f-12"
										></i
									></span>

									<template #dropdown>
										<el-dropdown-menu>
											<el-dropdown-item
												index="2-4-1"
												@click="
													actionhandel('list-export')
												"
												v-if="
													!btnType.includes(
														'list-export'
													)
												"
												>按列表字段导出</el-dropdown-item
											>
											<el-dropdown-item
												index="2-4-2"
												@click="
													actionhandel('all-export')
												"
												v-if="
													!btnType.includes(
														'all-export'
													)
												"
												>按全部字段导出</el-dropdown-item
											>
										</el-dropdown-menu>
									</template>
								</el-dropdown>
							</el-dropdown-item>
							<!-- 新增盘点导入 -->
							<el-dropdown-item
								class="dropdownselect"
								v-if="btnType.includes('out-import')"
								click.stop
							>
								<el-dropdown
									style="
										line-height: 36px;
										text-align: center;
										padding-left: 14px;
									"
								>
									<!-- https://login.ops.f2b211.com/api/v1/TrayCount/Import -->
									<!--https://proxy.ops.f2b211.com/api/  -->
									<!-- https://dev.proxy.ops.f2b211.com/api/ -->
									<el-upload
										:action="httpUrl"
										:on-success="handleSuccess"
										:on-error="handleError"
										accept=".xlsx,.xls"
										:on-exceed="handleExceed"
										ref="upload"
										:limit="1"
										:headers="{
											Authorization: token,
										}"
										:show-file-list="false"
									>
										<span
											class="el-dropdown-link f-12 zdyspan"
											>导入</span
										>
									</el-upload>
								</el-dropdown>
							</el-dropdown-item>
							<!-- 新增盘点下载导入模板 -->
							<!-- https://opstestfile.f2b211.com/temp_pandian.xlsx -->
							<el-dropdown-item
								class="dropdownselect"
								click.stop
								v-if="
									btnType.includes('download-import-template')
								"
							>
								<el-dropdown
									style="
										line-height: 36px;
										text-align: center;
										padding-left: 14px;
									"
								>
									<!-- https://opsfile.f2b211.com/temp_pandian.xlsx -->
									<!-- https://opstestfile.f2b211.com/temp_pandian.xlsx -->
									<a
										class="el-dropdown-link f-12 zdyspan"
										href="https://opsfile.f2b211.com/temp_pandian.xlsx"
										download="p.xlsx"
										style="color: #606266"
									>
										下载导入模板
									</a>
								</el-dropdown>
							</el-dropdown-item>

							<el-dropdown-item class="dropdownselect">
								<span
									style="margin-right: 4px"
									@click="actionhandel('print-aterial-list')"
									v-if="
										!btnType.includes('print-aterial-list')
									"
									>打印用料清单</span
								>
							</el-dropdown-item>
							<el-dropdown-item
								class="dropdownselect"
								@click="actionhandel('finish')"
							>
								<span
									style="margin-right: 4px"
									v-if="!btnType.includes('finish')"
									>完工</span
								>
							</el-dropdown-item>
							<el-dropdown-item
								class="dropdownselect"
								@click="actionhandel('close-case')"
							>
								<span
									style="margin-right: 4px"
									v-if="!btnType.includes('close-case')"
									>结案</span
								>
							</el-dropdown-item>
							<el-dropdown-item
								class="dropdownselect"
								@click="actionhandel('de-excute-start')"
							>
								<span
									style="margin-right: 4px"
									v-if="!btnType.includes('de-excute-start')"
									>反执行至开工</span
								>
							</el-dropdown-item>
							<el-dropdown-item
								class="dropdownselect"
								@click="actionhandel('de-excute-finish')"
							>
								<span
									style="margin-right: 4px"
									v-if="!btnType.includes('de-excute-finish')"
									>反执行至完工</span
								>
							</el-dropdown-item>
							<el-dropdown-item
								class="dropdownselect"
								@click="actionhandel('print-brower')"
							>
								<span
									style="margin-right: 4px"
									v-if="!btnType.includes('print-brower')"
									>打印/预览</span
								>
							</el-dropdown-item>
							<!-- 7.5 jx BOM 正查 反查 -->
							<el-dropdown-item
								class="dropdownselect"
								@click="actionhandel('just-check')"
							>
								<span
									style="margin-right: 4px"
									v-if="btnType.includes('just-check')"
									>BOM正查</span
								>
							</el-dropdown-item>
							<el-dropdown-item
								class="dropdownselect"
								@click="actionhandel('back-check')"
							>
								<span
									style="margin-right: 4px"
									v-if="btnType.includes('back-check')"
									>BOM反查</span
								>
							</el-dropdown-item>
						</el-dropdown-menu>
					</template>
				</el-dropdown>
				<el-dropdown
					v-if="!btnType.includes('query')"
					trigger="click"
					:hide-on-click="true"
					@visible-change="dropDownEnter"
					placement="bottom-start"
					:disabled="isDisable"
					class="btn-action"
				>
					<span
						class="el-dropdown-link"
						:class="{ isDisable: isDisable }"
					>
						查询<i class="iconfont icon-gengduo f-12"> </i
					></span>
					<template #dropdown>
						<el-dropdown-menu>
							<el-dropdown-item
								class="dropdownselect"
								@click="actionhandel('up-check')"
							>
								<span
									style="margin-right: 4px"
									v-if="!btnType.includes('up-check')"
									>上查</span
								>
							</el-dropdown-item>
							<el-dropdown-item
								class="dropdownselect"
								@click="actionhandel('down-check')"
							>
								<span
									style="margin-right: 4px"
									v-if="!btnType.includes('down-check')"
									>下查</span
								>
							</el-dropdown-item>
							<el-dropdown-item
								class="dropdownselect"
								@click="actionhandel('exDetails')"
							>
								<span
									style="margin-right: 4px"
									v-if="!btnType.includes('exDetails')"
									>查看流程图</span
								>
							</el-dropdown-item>
						</el-dropdown-menu>
					</template>
				</el-dropdown>
			</div>
		</el-button-group>
		<el-button-group class="s-p-t-g12" v-if="btnType.includes('s-p-t-g12')">
			<el-button
				@click="actionhandel('adjustInventory')"
				v-if="btnType.includes('adjustInventory')"
				>库存调整</el-button
			>
			<el-button
				@click="actionhandel('addMaterial')"
				v-if="btnType.includes('addMaterial')"
				>添加物料</el-button
			>
			<el-button
				@click="actionhandel('dayin')"
				v-if="!btnType.includes('dayin')"
				>打印</el-button
			>
			<el-button
				@click="actionhandel('daochu')"
				v-if="!btnType.includes('daochu')"
				>导出</el-button
			>
		</el-button-group>
		<el-button-group class="s-p-t-g5" v-if="!btnType.includes('s-p-t-g5')">
			<el-button
				ref="getRefresh"
				@click="actionhandel('refresh')"
				v-if="!btnType.includes('refresh')"
				:disabled="isDisable"
				:class="{ isDisable: isDisable }"
				><span class="iconfont icon-shuaxin iconfont-mg"></span
				>刷新</el-button
			>
		</el-button-group>
		<el-button-group class="s-p-t-g9" v-if="!btnType.includes('s-p-t-g9')">
			<el-button
				ref="getRefresh"
				@click="actionhandel('global-refresh')"
				v-if="btnType.includes('global-refresh')"
				:disabled="isDisable"
				:class="{ isDisable: isDisable }"
				><span class="iconfont icon-shuaxin iconfont-mg"></span
				>全局刷新</el-button
			>
		</el-button-group>
		<el-button-group
			class="s-p-t-g10"
			v-if="!btnType.includes('s-p-t-g10')"
		>
			<el-button
				ref="getRefresh"
				@click="actionhandel('tick-refresh')"
				v-if="btnType.includes('tick-refresh')"
				:disabled="isDisable"
				:class="{ isDisable: isDisable }"
				><span class="iconfont icon-shuaxin iconfont-mg"></span
				>勾选刷新</el-button
			>
		</el-button-group>
	</div>
</template>
<script>
export default {
	name: 'toolBtn',
};
</script>
<script setup>
import { toRefs, defineComponent, watch, ref } from 'vue';
import { ElMessage } from 'element-plus';
const props = defineProps({
	btnType: {
		type: Array,
		default: function () {
			return [];
		},
	},
	isDisable: {
		type: Boolean,
		default: function () {
			return false;
		},
	},
	isExmaineTop: {
		type: Number,
	},
});
const companyId = ref(localStorage.getItem('companyId') || 1);
const token = ref(localStorage.getItem('userToken'));
const httpUrl = ref(
	`https://proxy.ops.f2b211.com/api/v1/TrayCount/Import?c=${companyId.value}`
);
const emits = defineEmits(['actionhandel']);
const { isDisable, isExmaineTop, btnType } = toRefs(props);
const upload = ref(null);

const actionhandel = (type) => {
	emits('actionhandel', type); // type 代表操作类型 type === add 或者 copy 或者... 代表操作状态
};

const handleSuccess = (res) => {
	upload.value.clearFiles();
	if (res.status === 200) {
		ElMessage.success('数据导入成功!');
	} else {
		ElMessage.error(res.message);
	}
};
const handleError = (res) => {
	upload.value.clearFiles();
	ElMessage.error(res.message);
};
</script>
<style lang="scss" scoped>
@import './toolBtn.scss';

.isDisable {
	color: var(--el-text-color-placeholder) !important;
	cursor: not-allowed !important;
}
</style>
