exp.js 5.02 KB
import areaList from '@common/area.js'
import {
    Toast
} from 'vant';

export default {
    data() {
        return {
            key: 'value',
            fileList: [],

            areaVisible: false,
            areaList: [],
            // 姓名、手机号、省市区、详细地址
            editable: false,
            formData: { // 奖品信息。抽奖后显示
                "winCode": "",
                "name": "",
                "mobile": "",
                "province": "",
                "city": "",
                "district": "",
                "address": "",
                "extData": "",
                "prize": { // 奖品信息
                    "prizeName": "",
                    "prizePic": "",
                    "prizeThumb": "",
                    "prizeType": "", // 如果不中奖,奖品标识为lose
                    "outParams": "",
                    "extParams": "",
                    "outParamsVo": { // outParams参数格式化}
                    }
                }
            },

            page: 1,
            size: 10,
            loading: false,
            finished: false,
            list: [],
        }
    },
    components: {},
    computed: {
        areaStr() {
            let result = "";
            let {
                province,
                city,
                district
            } = this.formData;
            if (province && city && district) {
                result = `${province}-${city}-${district}`
            }
            return result;
        }
    },
    methods: {
        resetPage() {
            this.loading = false;
            this.page = 1;
            this.total = 0;
            this.list = [];
            this.finished = false;
        },
        onLoad() {
            if (this.finished) {
                this.loading = false;
            } else {
                this.page++;
                this.queryList();
            }

        },

        queryList() {
            app.get({
                url: app.api.list,
                data: {
                    page: this.page,
                    size: this.size
                }
            }).then((result) => {
                this.list = this.list.concat(result.list);
                this.finished = this.list.length >= result.total;
                this.loading = false;
            }).catch((err) => {
                this.loading = false;
                this.finished = true;
            });
        },


        // 显示地区
        onShowAreaSelect() {
            if (!this.editable) return;
            this.areaVisible = true;
        },
        // 确认省市区
        onAreaConfirm(val) {
            this.areaVisible = false;
            if (val && val.length >= 3) {
                this.formData.province = val[0].name || "";
                this.formData.city = val[1].name || "";
                this.formData.district = val[2].name || "";

                this.formData.provinceCode = val[0].code || "";
                this.formData.cityCode = val[1].code || "";
                this.formData.districtCode = val[2].code || "";
            }
        },

        beforeAvatarUpload(file) {
            const size = 10 * 1024 * 1024;
            if (file.size > size) {
                Toast('上传图片大小不能超过10M');
                return false;
            }
            return true;
        },
        afterRead(file) {
            console.log("file:", file);
            if (file.length == undefined) {
                this.uploadFile(file);
            } else {
                for (let index = 0; index < file.length; index++) {
                    this.uploadFile(file[index]);
                }
            }
        },
        uploadFile(file) {
            file.status = 'uploading';
            file.message = '上传中...';
            this.loading = true;
            app.uploadFile({
                    url: app.api.upload,
                    // data: formData
                    data: {
                        file: file.file,
                        subPath: this.subPath
                    }
                })
                .then(res => {
                    file.status = 'done';
                    file.message = '';
                    file.url = res;
                    console.log("file:", file);
                    console.log("fileList:", this.fileList);
                    this.loading = false;
                })
                .catch(e => {
                    file.status = 'failed';
                    file.message = '上传失败';
                    this.loading = false;
                    this.refreshFileList();
                    Toast("上传失败,请上传体积小于10的文件")
                });
        },
        refreshFileList() {
            let fileList = this.fileList.filter(item => {
                return item.url
            });
            this.fileList = fileList
        },
        initData() {
            this.editable = true;
        }
    },
    mounted() {
        this.areaList = areaList;
        this.initData();
    },
    created() {}
}