<template>
    <div>
        <pro-form ref="formRef_3f9a9bdc" :model="formData_3f9a9bdc" :rules="formRules_3f9a9bdc" label-width="120px">
            <pro-form-grid>
                <pro-input :ref="(el) => formRefs_3f9a9bdc.key = el" :formItemProps="{ label: '币种编号', prop: 'key' }"
                    v-model:value="formData_3f9a9bdc.key" placeholder="请输入" :allowClear="true"></pro-input>
                <pro-input :ref="(el) => formRefs_3f9a9bdc.name = el" :formItemProps="{ label: '币种名称', prop: 'name' }"
                    v-model:value="formData_3f9a9bdc.name" placeholder="请输入" :allowClear="true"></pro-input>
                <pro-select :ref="(el) => formRefs_3f9a9bdc.use_yn = el"
                    :formItemProps="{ label: '启用标志', prop: 'use_yn' }" v-model:value="formData_3f9a9bdc.use_yn"
                    placeholder="请选择" :allowClear="true" tableName="com_usertype_info" colName="use_yn"></pro-select>
                <pro-form-item>
                    <pro-button id="eaa14d90-c51b-11ea-8654-5d95137760bf" @click="queryHandler6da153cb"
                        :icon="h(SearchOutlined)">查询</pro-button>
                    <pro-button id="ec255580-c51b-11ea-8654-5d95137760bf"
                        @click="formRef_3f9a9bdc.getOrignRef().resetFields()" :icon="h(RedoOutlined)">重置</pro-button>
                    <Expand id="ef472ef0-c51b-11ea-8654-5d95137760bf" downText="收起" upText="展开"></Expand>
                </pro-form-item>
            </pro-form-grid>

            <pro-table ref="tableRef_594bc79c" :columns="columns_594bc79c" :queryRule="queryRule_594bc79c">
                <template v-slot:header="">
                    <OpenModelButton id="32ce0e30-c528-11ea-ac8a-91bf0c12e282" :modal="CurrencyManagerInsertView"
                        afterShow="CurrencyManager/clickInsertOrModifyBtn" text="新增" :icon="h(PlusOutlined)"
                        type="primary">
                    </OpenModelButton>
                </template>
            </pro-table>
        </pro-form>
    </div>
</template>
<script setup lang="jsx">
import { ref, onMounted, computed, h, useAttrs } from 'vue';
import settings from '@/settings';
import request from '@/utils/request';
import { useStore } from 'vuex';
import { SearchOutlined, RedoOutlined, EditOutlined, PlusOutlined } from "@ant-design/icons-vue";
import CurrencyManagerInsertView from "./CurrencyManagerInsertView.vue";
const store = useStore();
const attrs = useAttrs();
const formData_3f9a9bdc = ref({
    key: "",
    name: "",
    use_yn: "Y"
});
const formRules_3f9a9bdc = ref({});
const formRef_3f9a9bdc = ref(null);
const formRefs_3f9a9bdc = ref({
    key: "",
    name: "",
    use_yn: ""
});
const queryParams = ref({});
const systemPrefix = settings.systemPrefix;
const tableRef_594bc79c = ref(null);
const columns_594bc79c = ref([{
    prop: "ActionColumn",
    label: "操作",
    render: (scope) => {
        return <div>
            <OpenModelButton id="651rew123" modal={CurrencyManagerInsertView} afterShow="CurrencyManager/clickInsertOrModifyBtn" text="修改" icon={h(EditOutlined)} type="primary" payload={scope.record}></OpenModelButton>
        </div>
    }
}, {
    prop: "key",
    label: "币种编号",
    align: "left",
    width: "5"
}, {
    prop: "name",
    label: "币种名称",
    align: "left",
    width: "5"
}, {
    prop: "epn",
    label: "币种国际编码(简称)",
    align: "center",
    width: "5"
}, {
    prop: "sbl",
    label: "币种符号",
    align: "center",
    width: "5"
}, {
    prop: "correct_yn_zh",
    label: "是否是折算币种",
    align: "center",
    width: "5"
}, {
    prop: "use_yn",
    label: "启用标志",
    align: "center",
    width: "5",
    render: scop => showUseYn(scop.record.use_yn, scop.record)
}, {
    prop: "default_yn_zh",
    label: "是否是本位币",
    align: "center",
    width: "5"
}]);
function queryHandler6da153cb () {
    //校验表单
    formRef_3f9a9bdc.value.getOrignRef().validate().then(values => {
        //表单校验成功
        queryParams.value = values;
        tableRef_594bc79c.value.reload();
    });
}
const currencyData = computed(() => store.state.CurrencyManager.currencyData);
async function queryRule_594bc79c (payload, params) {
    let queryParam = {};
    if (queryParams) {
        queryParam = queryParams.value;
    }
    //向后台请求表格数据
    await store.dispatch('CurrencyManager/queryCurrency', {
        values: {
            page: payload.pageIndex,
            rows: payload.pageSize,
            ...params,
            ...queryParam
        }
    });
    const resp = currencyData.value;
    return {
        current: payload.pageIndex,
        pageSize: payload.pageSize,
        total: resp.total,
        data: resp.records
    };
}
var showUseYn = (text, record) => {
    let value = false;
    if (record.use_yn == 'Y') {
        value = true;
    }
    return <OptColumn type="Switch" checkedChildren="启用" unCheckedChildren="未启用" Coldata={record} defaultChecked={value} checked={value} onChange={(value, record) => changeUseYn(value, record)} />;
};
var renderStard = (e, ww, userNo, data, conversion, insertOrModify) => {
    let resData = [...data];
    if (insertOrModify == 1) {
        const toCurNo = conversion.records.filter(item => item.to_cur_no != e);
        if (toCurNo.length == 0) {
            resData = data;
        } else {
            toCurNo.forEach(item => {
                data.forEach((it, index) => {
                    if (it.item_no == item.to_cur_no) {
                        resData.splice(index, 1);
                    }
                });
            });
        }
    } else {
        const toCurNo = conversion.records.filter(item => item.to_cur_no != e);
        toCurNo.forEach(item => {
            resData.forEach((it, index) => {
                if (it.item_no == item.to_cur_no) {
                    resData.splice(index, 1);
                }
            });
        });
    }
    return <Select placeholder="请选择" onSelect={(value, record) => setStardList(value, record, ww.rowsId, ww.no)} defaultValue={e}>
        {resData.map(it => <Select.Option key={it.item_name} value={it.item_no}>
            {it.item_name}
        </Select.Option>)}
    </Select>;
};
var useYn = (text, record) => {
    if (record.use_yn == 'Y') {
        return "启用";
    } else {
        return "未启用";
    }
};
var addPageOnChange = async key => {
    if (key == null || key == '' || key == undefined) { } else {
        let ss = '';
        ss = await util.validateRecord("1", 'currency', "key", key);
        let formtype = actions.getFieldState('formtype', s => s.value);
        if ('2' == formtype) {
            //修改页面校验重复
            let oldKey = actions.getFieldState('oldKey', s => s.value);
            if (key == oldKey) {
                ss = '2';
            }
        }
        return new Promise(resolve => {
            if (ss == '0001') {
                resolve('该币种编号已存在!');
            } else {
                resolve('');
            }
        });
    }
}
</script>
