<template>
	<CommonPageByDevice
		ref="commonPageByDeviceRef"
		navTitle="码牌立牌管理"
		searchTitle="搜索立牌名称、编号"
		searchType="qrc"
		searchStateField="qrcState"
		:bottomBtnTitle="ak.ent.has('ENT_MCH_QR_CODE_ADD') ? '绑定立牌' : null"
		@bottomBtnClickFunc="bottomBtnClickFunc"
		:reqTableDataFunc="reqTableDataFunc"
	></CommonPageByDevice>
	<JSinglePopup ref="bindPopup" :list="codeBind" />
</template>

<script setup>
import { reactive, ref } from 'vue';
import { onReachBottom, onUnload, onShow } from '@dcloudio/uni-app';
import emit from '@/commons/utils/emit.js';
import CommonPageByDevice from '../commons/CommonPageByDevice.vue';
import { reqLoad, API_URL_SYS_CODE_LIST, $parseQrCodeUrl } from '@/http/apiManager.js';
import go from '@/commons/utils/go.js';
import DeviceCommonsRender from '@/pages/list/render/DeviceCommonsRender.vue';
import infoBox from '@/commons/utils/infoBox.js';
import ak from '@/commons/utils/ak.js';

const bindPopup = ref(null);
const reqTableDataFunc = (params) => {
	return reqLoad.list(API_URL_SYS_CODE_LIST, params);
};
function bottomBtnClickFunc() {
	bindPopup.value.open();
}
uni.$on(emit.ENAME_REF_QRC_LIST, (data) => {
	commonPageByDeviceRef.value.refTable(true);
});
const commonPageByDeviceRef = ref(null);
// 点击绑定新码 事件
const codeBind = [
	{
		label: '扫码绑定',
		value: 'scanCode',
		fun: () => {
			uni.scanCode({
				success: ({ result }) => {
					console.log('result', result);
					$parseQrCodeUrl(result).then(({ bizData }) => {
						console.log('bizData', bizData);
						go.to('PAGES_APP_CODE_BIND', { qrcId: bizData });
					});
				},
				fail: (err) => {
					// infoBox.showErrorToast('扫码失败')
				}
			});
		}
	},
	{
		label: '手动绑定',
		value: 'handBind',
		fun: () => {
			go.to('PAGES_APP_CODE_BIND');
		}
	}
];
onUnload(() => uni.$off(emit.ENAME_REF_QRC_LIST));
onReachBottom(() => {});

onShow(() => {
	console.log('进入页面了============');
	reqTableDataFunc();
	commonPageByDeviceRef.value.refTable(true);
});
</script>

<style lang="scss" scoped></style>
