//import { UniversalDataService } from '/js/ApiDataServer/Universal.js?tf=202411131831';
import { TestDataService } from '/js/ApiDataServer/Test.js?tf=202506242300';
import { RESPONSE_STATUS } from '/js/constants.js';

var vMain = new Vue({
    el: "#dvMain",
    data: function () {
        return {
            pageTitle: "TEST API",
            authDesc: "",
            isSystemManager: false,
            isLoading: false,
            isFinishRequest: true,
            //query: "",
            //qrCode: "",
            //barCode: "",
            //referrerCode: "3080800050514780",
            //storeObj: {}
            result:""
        };
    },
    created: async function () {
        this.loadData();
        initAdminutil();
    },
    updated: function () {
        var v = this;
        initAdminutil();

        if (v.isFinishRequest) {
            setTimeout(function () {
                v.isLoading = false;
            }, 100);
        } else {
            v.isLoading = true;
        }
    },
    methods: {
        async loadData() {
        },
        //async getStoreByRefCode() {
        //    var v = this;
        //    if (v.referrerCode != null && v.referrerCode.length > 0) {
        //        let res = await TestDataService.GetStoreByRefCode(v.referrerCode);
        //        if (res.status == RESPONSE_STATUS.OK) {
        //            v.storeObj = res.data;
        //        } else {
        //            var data = res.data;
        //            showErrMsg(data.message, "", "", null);
        //        }
        //        v.isFinishRequest = true;
        //        v.isLoading = false;
        //    }
        //}
        triggerUpload(obj) {
            $(obj).trigger("click");
        },
        onFileChange(e) {
            var files = e.target.files || e.dataTransfer.files;
            if (!files.length) return;
            this.uploadFile(files[0], e);
        },
        async uploadFile(f, e) {
            //自動上傳
            var v = this;
            v.isFinishRequest = false;
            v.isLoading = true;
            var fData = new FormData();
            fData.append("files", f);

            let res = await TestDataService.UploadOrder(fData);
            if (res.status != RESPONSE_STATUS.OK) {
                alert('上傳失敗');
                v.resetFile();
                return;
            }
            else {
                v.result = res.data;
                v.resetFile();
            }
        },
        resetFile() {
            const input = this.$refs.fuFile;
            input.type = 'text';
            input.type = 'file';
            this.isLoading = false;
            this.isFinishRequest = true;
        }
    }
});
