<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>数据导入</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <el-card shadow="hover">
            <!-- 搜索 -->
            <el-form :inline="true" size="small" v-model="listQuery">
                <el-form-item label="业务线">
                    <el-select v-model="listQuery.businessType" placeholder clearable>
                        <el-option value="保洁" label="保洁"></el-option>
                        <el-option value="保姆" label="保姆"></el-option>
                        <el-option value="品类" label="品类"></el-option>
                        <el-option value="搬家" label="搬家"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="目标分类">
                    <el-select v-model="listQuery.category" placeholder clearable>
                        <el-option value="销售GMV" label="销售GMV"></el-option>
                        <el-option value="服务GMV" label="服务GMV"></el-option>
                        <el-option value="服务单量" label="服务单量"></el-option>
                        <!-- <el-option value="招商人数" label="招商人数"></el-option>
            <el-option value="月初人数" label="月初人数"></el-option>
            <el-option value="线索" label="线索"></el-option>-->
                    </el-select>
                </el-form-item>
                <el-form-item label="小分类">
                    <el-select v-model="listQuery.type" placeholder clearable>
                        <!-- <el-option value="单次" label="单次"></el-option>
            <el-option value="周期" label="周期"></el-option>
            <el-option value="品类" label="品类"></el-option>
            <el-option value="日保" label="日报"></el-option>-->
                        <el-option value="合计" label="合计"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="城市">
                    <el-select v-model="listQuery.city" placeholder clearable>
                        <el-option value="北京" label="北京"></el-option>
                        <el-option value="上海" label="上海"></el-option>
                        <el-option value="深圳" label="深圳"></el-option>
                        <el-option value="南京" label="南京"></el-option>
                        <el-option value="苏州" label="苏州"></el-option>
                        <el-option value="无锡" label="无锡"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="时间段">
                    <el-date-picker v-model="listQuery.timePart" type="monthrange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
                </el-form-item>
                <el-form-item>
                    <el-button icon="el-icon-search" type="primary" plan @click="querySearch">查询</el-button>
                    <!-- <el-button type="default" plan @click="queryReset">重置</el-button> -->
                </el-form-item>
            </el-form>

            <!-- 新增 -->
            <el-row class="btn-margin">
                <el-button type="primary" icon="el-icon-plus" @click="addSalesTarget">新增目标值</el-button>
                <a href="https://jzmall.lifejingzhi.com/file/apk/billGoalTemplate.xlsx" download="目标值模板.xlsx">
                    <el-button type="danger" icon="el-icon-download">目标值模版下载</el-button>
                </a>
                <el-button type="primary" icon="el-icon-upload2" @click="uploadHisBtn">导入目标值</el-button>
                <a href="https://jzmall.lifejingzhi.com/file/apk/template.xlsx" download="离职或流失原因模板.xlsx">
                    <el-button type="danger" icon="el-icon-download">离职或流失原因模版下载</el-button>
                </a>
                <el-button type="primary" icon="el-icon-upload2" @click="uploadReasonBtn">离职或流失原因导入</el-button>
                <a href="https://jzmall.lifejingzhi.com/file/apk/14daysStockTemplate.xlsx" download="14天库存率模版模板.xlsx">
                    <el-button type="danger" icon="el-icon-download">14天库存率模版下载</el-button>
                </a>
                <el-button type="primary" icon="el-icon-upload2" @click="upload3Btn">14天库存率导入</el-button>
            </el-row>
            <el-row class="btn-margin" style="margin-bottom:20px;">
                <a href="https://jzmall.lifejingzhi.com/file/apk/30daysStockTemplate.xlsx" download="30天商品库存模板.xlsx">
                    <el-button type="danger" icon="el-icon-download">30天商品库存模版下载</el-button>
                </a>
                <el-button type="primary" icon="el-icon-upload2" @click="upload4Btn">30天商品库存导入</el-button>
                <a href="https://jzmall.lifejingzhi.com/file/apk/clockTemplate.xlsx" download="打卡记录模板.xlsx">
                    <el-button type="danger" icon="el-icon-download">打卡记录模版下载</el-button>
                </a>
                <el-button type="primary" icon="el-icon-upload2" @click="upload5Btn">打卡记录导入</el-button>
                <a href="https://jzmall.lifejingzhi.com/file/apk/evaluateTemplate.xlsx" download=">生活服务评价模板.xlsx">
                    <el-button type="danger" icon="el-icon-download">生活服务评价模版下载</el-button>
                </a>
                <el-button type="primary" icon="el-icon-upload2" @click="upload6Btn">生活服务评价导入</el-button>
                <a href="https://jzmall.lifejingzhi.com/file/apk/rebuyTemplate.xlsx" download="复购模板.xlsx">
                    <el-button type="danger" icon="el-icon-download">复购模版下载</el-button>
                </a>
                <el-button type="primary" icon="el-icon-upload2" @click="upload7Btn">复购导入</el-button>

                <a href="https://jzmall.lifejingzhi.com/file/apk/templatePaiban.xlsx" download="排班模版下载.xlsx">
                    <el-button type="danger" icon="el-icon-download">排班模版下载</el-button>
                </a>
                <a href="https://jzmall.lifejingzhi.com/file/apk/templateQingjia.xlsx" download="请假模版下载.xlsx">
                    <el-button type="danger" icon="el-icon-download">请假模版下载</el-button>
                </a>
                <el-button type="primary" icon="el-icon-upload2" @click="upload8Btn">盒马排班请假导入</el-button>

                <a href="https://jzmall.lifejingzhi.com/file/apk/kucunliyonglv-city-station.xlsx" download="库存利用率模版下载.xlsx">
                    <el-button type="danger" icon="el-icon-download">库存利用率模版下载</el-button>
                </a>
                <el-button type="primary" icon="el-icon-upload2" @click="upload9Btn">库存利用率导入</el-button>
            </el-row>

            <!-- 列表数据 -->
            <el-table :data="listData" border style="width: 100%" class="table">
                <!-- <el-table-column prop="index" label="序号" type="index" width="50px"></el-table-column> -->
                <el-table-column prop="businessType" label="业务线" width="120px" fixed="left"></el-table-column>
                <el-table-column prop="category" label="目标分类"></el-table-column>
                <el-table-column prop="type" label="小分类"></el-table-column>
                <el-table-column prop="city" label="城市"></el-table-column>
                <el-table-column prop="startMonth" label="开始时间"></el-table-column>
                <el-table-column prop="endMonth" label="结束时间"></el-table-column>
                <el-table-column prop="updateTime" label="更新时间" :formatter="dateFormatA" width="180px"></el-table-column>
                <el-table-column prop="goal" label="指标值"></el-table-column>
                <el-table-column prop label="操作" fixed="right" width="180px">
                    <template slot-scope="scope">
                        <el-button type="text" @click="editGoalItem(scope.row)">修改</el-button>

                        <el-button type="text" @click="delGoalItem(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>

            <!-- 分页 -->
            <pagination :total="total" :page.sync="currentPage" :limit.sync="pageSize" @pagination="querySearch" />
        </el-card>
        <!-- 导入文件弹框 -->
        <el-dialog title="导入" :visible.sync="inputFilesVisible" width="500px" :close-on-click-modal="false" center>
            <input type="file" @change="getFile($event)" ref="file" />
            <span slot="footer" class="dialog-footer">
                <el-button @click="inputFilesVisible = false">取 消</el-button>
                <el-button type="primary" @click="importSalesTarget">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 导入提示,导出失败记录 -->
        <!-- <el-dialog
            title="导入失败提示"
            :visible.sync="failVisible"
            width="500px"
            :close-on-click-modal="false"
            center
        >
            <div class="tipText">成功导入{{successNum}} 条信息数据，失败{{errorNum}}条！</div>

            <form method="get" :action="exportFailurl" class="form-style" v-if="errorNum!=0">
                <input type="hidden" name="token" :value="this.token" />
                <input type="hidden" name="uuid" :value="this.failUuid" />
                <input type="submit" style="display:none;" ref="daochuFail" />
                <input type="button" class="handleDownloadFail" @click="daochuFail" value="导出失败记录" />
            </form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="failVisible = false">关 闭</el-button>
            </span>
    </el-dialog>-->

        <!-- 导入离职和流失率文件弹框 -->
        <el-dialog title="导入" :visible.sync="inputReasonFilesVisible" width="500px" :close-on-click-modal="false" center>
            <input type="file" @change="getReasonFile($event)" ref="reasonFile" />
            <span slot="footer" class="dialog-footer">
                <el-button @click="inputReasonFilesVisible = false">取 消</el-button>
                <el-button type="primary" @click="importResignAndLossReason">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 新增目标值 -->
        <el-dialog title="新增目标值" :visible.sync="addTargetGoalVisible" width="500px" :close-on-click-modal="false" center>
            <el-form ref="addTargetGoalForm" :rules="rules" label-width="120px" :model="addTargetGoalForm" size="medium" inline>
                <el-form-item label="业务线" prop="businessType">
                    <el-select v-model="addTargetGoalForm.businessType" placeholder="请选择" clearable>
                        <el-option value="保洁" label="保洁"></el-option>
                        <el-option value="保姆" label="保姆"></el-option>
                        <el-option value="品类" label="品类"></el-option>
                        <el-option value="搬家" label="搬家"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="目标分类" prop="category">
                    <el-select v-model="addTargetGoalForm.category" placeholder="请选择" clearable>
                        <el-option value="销售GMV" label="销售GMV"></el-option>
                        <el-option value="服务GMV" label="服务GMV"></el-option>
                        <el-option value="服务单量" label="服务单量"></el-option>
                        <el-option value="线索数" label="线索数"></el-option>
                        <el-option value="目标招商数" label="目标招商数"></el-option>
                        <!-- <el-option value="招商人数" label="招商人数"></el-option>
            <el-option value="月初人数" label="月初人数"></el-option>
            <el-option value="线索" label="线索"></el-option>-->
                    </el-select>
                </el-form-item>

                <el-form-item label="小分类" prop="type">
                    <el-select v-model="addTargetGoalForm.type" placeholder="请选择" clearable>
                        <!-- <el-option value="单次" label="单次"></el-option>
            <el-option value="周期" label="周期"></el-option>
            <el-option value="品类" label="品类"></el-option>
            <el-option value="日保" label="日报"></el-option>-->
                        <el-option value="合计" label="合计"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="城市" prop="city">
                    <el-select v-model="addTargetGoalForm.city" placeholder="请选择" clearable>
                        <el-option value="北京" label="北京"></el-option>
                        <el-option value="上海" label="上海"></el-option>
                        <el-option value="深圳" label="深圳"></el-option>
                        <el-option value="南京" label="南京"></el-option>
                        <el-option value="苏州" label="苏州"></el-option>
                        <el-option value="无锡" label="无锡"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="时间段" prop="timePart">
                    <el-date-picker v-model="addTargetGoalForm.timePart" type="monthrange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
                </el-form-item>
                <el-form-item label="目标值" prop="goal">
                    <el-input v-model.number="addTargetGoalForm.goal" autocomplete="off" placeholder clearable></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="addTargetGoalVisible= false">取 消</el-button>
                <el-button type="primary" @click="confAddTarget('addTargetGoalForm')">确 定</el-button>
            </span>
        </el-dialog>

        <!-- 编辑目标值 -->
        <el-dialog title="新增目标值" :visible.sync="editTargetGoalVisible" width="500px" :close-on-click-modal="false" center>
            <el-form ref="editTargetGoalForm" :rules="rules" label-width="120px" :model="editTargetGoalForm" size="medium" inline>
                <el-form-item label="业务线" prop="businessType">
                    <el-select v-model="editTargetGoalForm.businessType" placeholder="请选择" clearable>
                        <el-option value="保洁" label="保洁"></el-option>
                        <el-option value="保姆" label="保姆"></el-option>
                        <el-option value="品类" label="品类"></el-option>
                        <el-option value="搬家" label="搬家"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="目标分类" prop="category">
                    <el-select v-model="editTargetGoalForm.category" placeholder="请选择" clearable>
                        <el-option value="销售GMV" label="销售GMV"></el-option>
                        <el-option value="服务GMV" label="服务GMV"></el-option>
                        <el-option value="服务单量" label="服务单量"></el-option>
                        <!--  <el-option value="招商人数" label="招商人数"></el-option>
            <el-option value="月初人数" label="月初人数"></el-option>
            <el-option value="线索" label="线索"></el-option>-->
                    </el-select>
                </el-form-item>

                <el-form-item label="小分类" prop="type">
                    <el-select v-model="editTargetGoalForm.type" placeholder="请选择" clearable>
                        <!-- <el-option value="单次" label="单次"></el-option>
            <el-option value="周期" label="周期"></el-option>
            <el-option value="品类" label="品类"></el-option>
            <el-option value="日保" label="日报"></el-option>-->
                        <el-option value="合计" label="合计"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="城市" prop="city">
                    <el-select v-model="editTargetGoalForm.city" placeholder="请选择" clearable>
                        <el-option value="北京" label="北京"></el-option>
                        <el-option value="上海" label="上海"></el-option>
                        <el-option value="深圳" label="深圳"></el-option>
                        <el-option value="南京" label="南京"></el-option>
                        <el-option value="苏州" label="苏州"></el-option>
                        <el-option value="无锡" label="无锡"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="时间段" prop="timePart">
                    <el-date-picker v-model="editTargetGoalForm.timePart" type="monthrange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
                </el-form-item>
                <el-form-item label="目标值" prop="goal">
                    <el-input v-model.number="editTargetGoalForm.goal" autocomplete="off" placeholder clearable></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editTargetGoalVisible= false">取 消</el-button>
                <el-button type="primary" @click="confEditTarget('editTargetGoalForm')">确 定</el-button>
            </span>
        </el-dialog>

        <!-- 14天库存率导入 -->
        <el-dialog title="导入" :visible.sync="inputVisible3" width="500px" :close-on-click-modal="false" center>
            <input type="file" @change="getFile3($event)" ref="file3" />
            <span slot="footer" class="dialog-footer">
                <el-button @click="inputVisible3 = false">取 消</el-button>
                <el-button type="primary" @click="importConfirm3">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 30天商品库存 -->
        <el-dialog title="导入" :visible.sync="inputVisible4" width="500px" :close-on-click-modal="false" center>
            <input type="file" @change="getFile4($event)" ref="file4" />
            <span slot="footer" class="dialog-footer">
                <el-button @click="inputVisible4 = false">取 消</el-button>
                <el-button type="primary" @click="importConfirm4">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 打卡记录导入 -->
        <el-dialog title="导入" :visible.sync="inputVisible5" width="500px" :close-on-click-modal="false" center>
            <input type="file" @change="getFile5($event)" ref="file5" />
            <span slot="footer" class="dialog-footer">
                <el-button @click="inputVisible5 = false">取 消</el-button>
                <el-button type="primary" @click="importConfirm5">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 生活服务评价导入 -->
        <el-dialog title="导入" :visible.sync="inputVisible6" width="500px" :close-on-click-modal="false" center>
            <input type="file" @change="getFile6($event)" ref="file6" />
            <span slot="footer" class="dialog-footer">
                <el-button @click="inputVisible6 = false">取 消</el-button>
                <el-button type="primary" @click="importConfirm6">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 复购导入 -->
        <el-dialog title="导入" :visible.sync="inputVisible7" width="500px" :close-on-click-modal="false" center>
            <input type="file" @change="getFile7($event)" ref="file7" />
            <span slot="footer" class="dialog-footer">
                <el-button @click="inputVisible7 = false">取 消</el-button>
                <el-button type="primary" @click="importConfirm7">确 定</el-button>
            </span>
        </el-dialog>

        <el-dialog title="盒马排班，盒马请假导入" :visible.sync="inputVisible8" width="500px" :close-on-click-modal="false" center>
            盒马排班：<input type="file" ref="fileScheduler" /><br /><br />
            <hr /><br />
            盒马请假：<input type="file" ref="fileOnleave" /><br />
            <span slot="footer" class="dialog-footer">
                <el-button @click="inputVisible8 = false">取 消</el-button>
                <el-button type="primary" @click="importConfirm8">确 定</el-button>
            </span>
        </el-dialog>

        <el-dialog title="盒马库存利用率导入" :visible.sync="inputVisible9" width="500px" :close-on-click-modal="false" center>
            数据所属月份： <el-date-picker v-model="ofMonth" type="month" value-format="yyyy-MM" :picker-options="{}"></el-date-picker>
            <br />
            <br />
            库存利用率(城市-服务站)：<input type="file" ref="fileStockAvailability" /><br />
            <span slot="footer" class="dialog-footer">
                <el-button @click="inputVisible9 = false">取 消</el-button>
                <el-button type="primary" @click="importConfirm9">确 定</el-button>
            </span>
        </el-dialog>

    </div>
</template>
<script>
import moment from "moment";
import Pagination from "./common/Pagination";
import Service from "../script/api/service";
import globalData from "@/components/common/globaldata/global.data.vue";
// import addTrainHisDia from './components/addTrainHisDia';
export default {
    components: { Pagination },
    data() {
        return {
            ofMonth: null,
            inputVisible9: false,
            inputVisible8: false,
            importCount: "",
            inputFilesVisible: false,
            inputReasonFilesVisible: false,
            inputVisible3: false,
            inputVisible4: false,
            inputVisible5: false,
            inputVisible6: false,
            inputVisible7: false,
            reasonFile: "",
            file3: "",
            file4: "",
            file5: "",
            file6: "",
            file7: "",
            failVisible: false,
            listData: [],
            total: 0,
            pageSize: 10,
            currentPage: 1, //当前页
            listQuery: {
                businessType: "",
                category: "",
                type: "",
                city: "",
                timePart: [],
            },
            file: "",
            addTargetGoalVisible: false,
            addTargetGoalForm: {
                businessType: "",
                category: "",
                type: "",
                city: "",
                timePart: [],
            },
            editTargetId: "",
            editTargetGoalVisible: false,
            editTargetGoalForm: {
                businessType: "",
                category: "",
                type: "",
                city: "",
                timePart: [],
            },
            rules: {
                businessType: [
                    {
                        required: true,
                        message: "请选择业务线",
                        trigger: "change",
                    },
                ],
                category: [
                    {
                        required: true,
                        message: "请选择目标分类",
                        trigger: "change",
                    },
                ],
                type: [
                    {
                        required: true,
                        message: "请选择小分类",
                        trigger: "change",
                    },
                ],
                city: [
                    {
                        required: true,
                        message: "请选择城市",
                        trigger: "change",
                    },
                ],
                timePart: [
                    {
                        required: true,
                        message: "请选择时间段",
                        trigger: "change",
                    },
                ],
                goal: [
                    {
                        required: true,
                        message: "请输入目标值",
                        trigger: "change",
                    },
                    { type: "number", message: "目标值必须为数字值" },
                ],
            },
        };
    },
    created() {
        this.querySearch();
    },
    methods: {
        //查询
        querySearch() {
            let temp = {
                pageNo: this.currentPage,
                pageSize: this.pageSize,
                businessType: this.listQuery.businessType,
                category: this.listQuery.category,
                type: this.listQuery.type,
                category: this.listQuery.category,
                city: this.listQuery.city,
            };
            if (
                this.listQuery.timePart != "" &&
                this.listQuery.timePart != undefined
            ) {
                temp.startMonth = moment(this.listQuery.timePart[0]).format(
                    "YYYY-MM"
                );
                temp.endMonth = moment(this.listQuery.timePart[1]).format(
                    "YYYY-MM"
                );
            }

            Service.$axiosTargetPageData(temp)
                .then((res) => {
                    // console.log(res);
                    this.listData = res.data.data.dataList;
                    this.total = res.data.data.total;
                })
                .catch((err) => {
                    console.log(err);
                });
        },
        //重置
        queryReset() {
            this.listQuery.workerName = "";
            this.listQuery.workerTel = "";
            this.querySearch();
        },
        //新增培训记录
        addNewHisBtn() {
            this.$refs.addTrainHisDiaRef.addTrainHisRow();
        },
        //导入
        uploadHisBtn() {
            this.inputFilesVisible = true;
            if (this.file != "") {
                this.$refs.file.value = "";
            }
        },
        uploadReasonBtn() {
            this.inputReasonFilesVisible = true;
            if (this.reasonFile != "") {
                this.$refs.reasonFile.value = "";
            }
        },
        upload3Btn() {
            this.inputVisible3 = true;
            if (this.file3 != "") {
                this.$refs.file3.value = "";
            }
        },
        upload4Btn() {
            this.inputVisible4 = true;
            if (this.file4 != "") {
                this.$refs.file4.value = "";
            }
        },
        upload5Btn() {
            this.inputVisible5 = true;
            if (this.file5 != "") {
                this.$refs.file5.value = "";
            }
        },
        upload6Btn() {
            this.inputVisible6 = true;
            if (this.file6 != "") {
                this.$refs.file6.value = "";
            }
        },
        upload7Btn() {
            this.inputVisible7 = true;
            if (this.file7 != "") {
                this.$refs.file7.value = "";
            }
        },

        //获取上传文件
        getFile: function (event) {
            this.file = event.target.files[0];
            // console.log(this.file);
        },
        getReasonFile: function (event) {
            this.reasonFile = event.target.files[0];
            // console.log(this.reasonFile);
        },
        getFile3: function (event) {
            this.file3 = event.target.files[0];
            // console.log(this.file3);
        },
        getFile4: function (event) {
            this.file4 = event.target.files[0];
            // console.log(this.file4);
        },
        getFile5: function (event) {
            this.file5 = event.target.files[0];
            // console.log(this.file5);
        },
        getFile6: function (event) {
            this.file6 = event.target.files[0];
            // console.log(this.file6);
        },
        getFile7: function (event) {
            this.file7 = event.target.files[0];
            // console.log(this.file7);
        },

        //流失离职确定导入
        importResignAndLossReason() {
            if (this.reasonFile == "") {
                this.$message.warning("请选择文件！");
                return;
            }
            var formData = new window.FormData(); // vue 中使用 window.FormData(),否则会报 'FormData isn't definded'
            formData.append("file", this.reasonFile);
            // formData.append("updateUser", globalData.userInfo.id);
            Service.$axiosImportResignAndLossReason(formData)
                .then((res) => {
                    // console.log(res);
                    if (res.data.errno == 0) {
                        this.$message.success("离职或流失原因导入成功！");
                        this.inputReasonFilesVisible = false;
                    }
                })
                .catch((err) => {
                    console.log(err);
                });
        },

        //确定导入
        importSalesTarget() {
            if (this.file == "") {
                this.$message.warning("请选择文件！");
                return;
            }
            var formData = new window.FormData(); // vue 中使用 window.FormData(),否则会报 'FormData isn't definded'
            formData.append("file", this.file);
            formData.append("updateUser", globalData.userInfo.id);
            Service.$axiosSalesTargetImport(formData)
                .then((res) => {
                    // console.log(res);
                    if (res.data.errno == 0) {
                        this.$message.success("导入目标值成功！");
                        this.querySearch();
                        this.inputFilesVisible = false;
                    }
                })
                .catch((err) => {
                    console.log(err);
                });
        },
        importConfirm3() {
            if (this.file3 == "") {
                this.$message.warning("请选择文件！");
                return;
            }
            var formData = new window.FormData(); // vue 中使用 window.FormData(),否则会报 'FormData isn't definded'
            formData.append("file", this.file3);
            // formData.append("updateUser", globalData.userInfo.id);
            Service.$axiosImportCity14DaysStockRadio(formData)
                .then((res) => {
                    // console.log(res);
                    if (res.data.errno == 0) {
                        this.$message.success("各城市14天库存率导入成功！");
                        this.inputVisible3 = false;
                    }
                })
                .catch((err) => {
                    console.log(err);
                });
        },
        importConfirm4() {
            if (this.file4 == "") {
                this.$message.warning("请选择文件！");
                return;
            }
            var formData = new window.FormData(); // vue 中使用 window.FormData(),否则会报 'FormData isn't definded'
            formData.append("file", this.file4);
            // formData.append("updateUser", globalData.userInfo.id);
            Service.$axiosImport30DaysProductStock(formData)
                .then((res) => {
                    // console.log(res);
                    if (res.data.errno == 0) {
                        this.$message.success("30天商品库存结果导入成功！");
                        this.inputVisible4 = false;
                    }
                })
                .catch((err) => {
                    console.log(err);
                });
        },
        importConfirm5() {
            if (this.file5 == "") {
                this.$message.warning("请选择文件！");
                return;
            }
            var formData = new window.FormData(); // vue 中使用 window.FormData(),否则会报 'FormData isn't definded'
            formData.append("file", this.file5);
            // formData.append("updateUser", globalData.userInfo.id);
            Service.$axiosClockLog(formData)
                .then((res) => {
                    // console.log(res);
                    if (res.data.errno == 0) {
                        this.$message.success("打卡记录导入成功！");
                        this.inputVisible5 = false;
                    }
                })
                .catch((err) => {
                    console.log(err);
                });
        },
        importConfirm6() {
            if (this.file6 == "") {
                this.$message.warning("请选择文件！");
                return;
            }
            var formData = new window.FormData(); // vue 中使用 window.FormData(),否则会报 'FormData isn't definded'
            formData.append("file", this.file6);
            // formData.append("updateUser", globalData.userInfo.id);
            Service.$axiosEvaluateLifeService(formData)
                .then((res) => {
                    // console.log(res);
                    if (res.data.errno == 0) {
                        this.$message.success("生活服务评价导入成功！");
                        this.inputVisible6 = false;
                    }
                })
                .catch((err) => {
                    console.log(err);
                });
        },
        importConfirm7() {
            if (this.file7 == "") {
                this.$message.warning("请选择文件！");
                return;
            }
            var formData = new window.FormData(); // vue 中使用 window.FormData(),否则会报 'FormData isn't definded'
            formData.append("file", this.file7);
            // formData.append("updateUser", globalData.userInfo.id);
            Service.$axiosRebuy(formData)
                .then((res) => {
                    // console.log(res);
                    if (res.data.errno == 0) {
                        this.$message.success("复购导入成功！");
                        this.inputVisible7 = false;
                    }
                })
                .catch((err) => {
                    console.log(err);
                });
        },

        //导入失败提示
        confirmImportfailed() {},

        //删除目标项
        delGoalItem(row) {
            this.$confirm("确定删除该项数据吗？")
                .then((_) => {
                    this.salesTargetDelete(row);
                })
                .catch((_) => {});
        },
        salesTargetDelete(row) {
            Service.$axiosSalesTargetDel({ id: row.id })
                .then((res) => {
                    this.querySearch();
                })
                .catch((err) => {
                    console.log(err);
                });
        },
        addSalesTarget() {
            this.addTargetGoalVisible = true;
        },
        confAddTarget(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    let params = {
                        businessType: this.addTargetGoalForm.businessType,
                        category: this.addTargetGoalForm.category,
                        type: this.addTargetGoalForm.type,
                        city: this.addTargetGoalForm.city,
                        startMonth:
                            this.addTargetGoalForm.timePart != undefined
                                ? moment(
                                      this.addTargetGoalForm.timePart[0]
                                  ).format("YYYY-MM")
                                : "",
                        endMonth:
                            this.addTargetGoalForm.timePart != undefined
                                ? moment(
                                      this.addTargetGoalForm.timePart[1]
                                  ).format("YYYY-MM")
                                : "",
                        goal: this.addTargetGoalForm.goal,
                        updateUser: globalData.userInfo.id,
                    };

                    Service.$axiosSalesTargetAdd(params).then((res) => {
                        if (res.data.errno == 0) {
                            this.$message.success("添加成功");
                            this.addTargetGoalVisible = false;
                            this.querySearch();
                        } else {
                            this.$message.error(res.data.data);
                        }
                    });
                } else {
                    console.log("error submit!!");
                    return false;
                }
            });
        },
        editGoalItem(row) {
            this.editTargetGoalForm = {
                businessType: row.businessType,
                category: row.category,
                type: row.type,
                city: row.city,
                timePart: [row.startMonth, row.endMonth],
            };
            this.editTargetId = row.id;
            this.editTargetGoalVisible = true;
        },
        confEditTarget(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    let params = {
                        id: this.editTargetId,
                        businessType: this.editTargetGoalForm.businessType,
                        category: this.editTargetGoalForm.category,
                        type: this.editTargetGoalForm.type,
                        city: this.editTargetGoalForm.city,
                        startMonth:
                            this.editTargetGoalForm.timePart != undefined
                                ? moment(
                                      this.editTargetGoalForm.timePart[0]
                                  ).format("YYYY-MM")
                                : "",
                        endMonth:
                            this.editTargetGoalForm.timePart != undefined
                                ? moment(
                                      this.editTargetGoalForm.timePart[1]
                                  ).format("YYYY-MM")
                                : "",
                        goal: this.editTargetGoalForm.goal,
                        updateUser: globalData.userInfo.id,
                    };

                    Service.$axiosSalesTargetUpdate(params).then((res) => {
                        if (res.data.errno == 0) {
                            this.$message.success("编辑成功");
                            this.editTargetGoalVisible = false;
                            this.querySearch();
                        } else {
                            this.$message.error(res.data.data);
                        }
                    });
                } else {
                    console.log("error submit!!");
                    return false;
                }
            });
        },
        downloadReasonBtn() {},
        upload8Btn() {
            this.inputVisible8 = true;
            if (this.$refs.fileScheduler) {
                this.$refs.fileScheduler.value = null;
            }
            if (this.$refs.fileOnleave) {
                this.$refs.fileOnleave.value = null;
            }
        },
        importConfirm8() {
            //盒马排班，盒马请假导入
            if (
                this.$refs.fileScheduler.files.length == 0 ||
                this.$refs.fileOnleave.files.length == 0
            ) {
                this.$message.error("请同时导入排班和请假数据");
                return;
            }
            console.log(this.$refs.fileScheduler.files[0]);
            console.log(this.$refs.fileOnleave.files[0]);

            var formData = new window.FormData();
            formData.append("fileScheduler", this.$refs.fileScheduler.files[0]);
            formData.append("fileOnleave", this.$refs.fileOnleave.files[0]);
            Service.$axiosScheduleAndOnleave(formData)
                .then((res) => {
                    // console.log(res);
                    if (res.data.errno == 0) {
                        this.$message.success("盒马排班，盒马请假导入成功！");
                        this.inputVisible8 = false;
                    } else {
                        this.$message.error(res.data.data);
                    }
                })
                .catch((err) => {
                    console.log(err);
                });
        },
        upload9Btn() {
            this.inputVisible9 = true;
            if (this.$refs.fileStockAvailability) {
                this.$refs.fileStockAvailability.value = null;
            }
        },
        importConfirm9() {
            //盒马库存利用率导入
            if (this.ofMonth == null || this.ofMonth == "") {
                this.$message.error("请选数据所属月份");
                return;
            }
            if (this.$refs.fileStockAvailability.files.length == 0) {
                this.$message.error("请选文件");
                return;
            }

            var formData = new window.FormData();
            formData.append("file", this.$refs.fileStockAvailability.files[0]);
            formData.append("ofMonth", this.ofMonth);
            Service.$axiosImportHmStockAvailability(formData)
                .then((res) => {
                    // console.log(res);
                    if (res.data.errno == 0) {
                        this.$message.success("导入成功！");
                        this.inputVisible9 = false;
                    } else {
                        this.$message.error(res.data.data);
                    }
                })
                .catch((err) => {
                    console.log(err);
                });
        },
    },
};
</script>
<style scoped>
.crumbs {
    margin: 0 0 10px 0;
}
.btn-margin .el-button--small {
    margin: 10px 12px 0 0;
}
</style>