index.vue 19.1 KB
Newer Older
huyf's avatar
huyf committed
1 2 3 4 5
<template>
  <div class="app-container">

    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
6 7
      <el-form-item :label="$t('部门')" prop="deptId">
        <el-select v-model="queryParams.deptId" style="width: 300px;" :placeholder="$t('请选择部门')">
huyf's avatar
huyf committed
8 9 10
          <el-option v-for="item in this.deptData" :key="item.id" :label="item.name" :value="item.id"/>
        </el-select>
      </el-form-item>
11
      <el-form-item :label="$t('目标类型')" prop="targetType">
huyf's avatar
huyf committed
12
        <dict-selector :type="DICT_TYPE.TARGET_TYPE" v-model="queryParams.targetType" formatter="number"/>
huyf's avatar
huyf committed
13
      </el-form-item>
14
      <el-form-item :label="$t('运输方式')" prop="transportType">
huyf's avatar
huyf committed
15
        <dict-selector :type="DICT_TYPE.ECW_TRANSPORT_TYPE" v-model="queryParams.transportType" formatter="number"/>
huyf's avatar
huyf committed
16
      </el-form-item>
17 18
      <el-form-item :label="$t('出货渠道')" prop="shippingChannel">
        <el-select v-model="queryParams.shippingChannel" :placeholder="$t('请选择出货渠道')">
huyf's avatar
huyf committed
19 20
          <el-option v-for="item in channelList" :label="item.nameZh" :value="item.channelId"
                     :key="item.channelId"></el-option>
huyf's avatar
huyf committed
21 22 23
        </el-select>
      </el-form-item>
      <el-form-item>
24 25
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">{{$t('搜索')}}</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">{{$t('重置')}}</el-button>
huyf's avatar
huyf committed
26 27 28 29 30 31 32
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
33
                   v-hasPermi="['ecw:dept-target:create']">{{$t('目标设置')}}
huyf's avatar
huyf committed
34
        </el-button>
huyf's avatar
huyf committed
35 36 37 38 39 40
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
41
      <el-table-column :label="$t('目标名称')" align="center" width="180">
huyf's avatar
huyf committed
42
        <template slot-scope="scope">
huyf's avatar
huyf committed
43
          <router-link :to="{path: '/deptTarget/empAchievement',query: {row: scope.row}}" class="link-type">
44
            <span>{{scope.row.deptName}}{{scope.row.targetPeriodName}}{{$t('目标')}}</span>
huyf's avatar
huyf committed
45
          </router-link>
huyf's avatar
huyf committed
46 47
        </template>
      </el-table-column>
48 49
      <el-table-column :label="$t('部门')" align="center" prop="deptName"/>
      <el-table-column :label="$t('目标类型')" align="center" prop="targetType">
huyf's avatar
huyf committed
50
        <template slot-scope="scope">
huyufeng's avatar
huyufeng committed
51
          <dict-tag :type="DICT_TYPE.TARGET_TYPE" :value="scope.row.targetType"/>
huyf's avatar
huyf committed
52 53
        </template>
      </el-table-column>
54
      <el-table-column :label="$t('时间范围')" align="center" prop="targetPeriodName">
huyf's avatar
huyf committed
55
        <template slot-scope="scope">
huyf's avatar
huyf committed
56
          <span>{{dateFormat(scope.row.startTime)}}~{{dateFormat(scope.row.endTime)}}</span>
huyufeng's avatar
huyufeng committed
57 58
        </template>
      </el-table-column>
59 60 61
      <el-table-column :label="$t('部门人数')" align="center" prop="deptEmpCount"/>
      <el-table-column :label="$t('目标方数')" align="center" prop="cubeNum"/>
      <el-table-column :label="$t('运输方式')" align="center" prop="transportType">
huyufeng's avatar
huyufeng committed
62 63 64 65
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.TRANSPORT_TYPE" :value="scope.row.transportType"/>
        </template>
      </el-table-column>
66
      <el-table-column :label="$t('出货渠道')" align="center" prop="shippingChannel">
huyufeng's avatar
huyufeng committed
67 68 69 70
        <template slot-scope="scope">
          <span>{{ getShipChannelName(scope.row.shippingChannel) }}</span>
        </template>
      </el-table-column>
71 72
      <el-table-column :label="$t('已完成方数')" align="center" prop="completeCubeNum"/>
      <el-table-column :label="$t('完成比例')" align="center">
huyufeng's avatar
huyufeng committed
73 74
        <template slot-scope="scope">
          <span>{{ (scope.row.completeCubeNum/scope.row.cubeNum*100).toFixed(2)+'%' }}</span>
huyf's avatar
huyf committed
75 76
        </template>
      </el-table-column>
77
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width">
huyf's avatar
huyf committed
78 79
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
80
                     v-hasPermi="['ecw:dept-target:update']">{{$t('修改')}}
huyf's avatar
huyf committed
81
          </el-button>
huyf's avatar
huyf committed
82
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
83
                     v-hasPermi="['ecw:dept-target:delete']">{{$t('删除')}}
huyf's avatar
huyf committed
84
          </el-button>
huyf's avatar
huyf committed
85 86
<!--          <el-button size="mini" type="text" icon="el-icon-search" @click="handleView(scope.row)"-->
<!--                     v-hasPermi="['ecw:dept-target:create']"></el-button>-->
huyf's avatar
huyf committed
87 88 89 90 91 92 93 94 95 96
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>

    <!-- 对话框(添加 / 修改) -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
97 98
        <el-form-item :label="$t('部门')" prop="deptId">
          <el-select v-model="form.deptId" style="width: 300px;" :placeholder="$t('请选择部门')">
huyf's avatar
huyf committed
99 100 101
            <el-option v-for="item in this.deptData" :key="item.id" :label="item.name" :value="item.id"/>
          </el-select>
        </el-form-item>
102 103
        <el-form-item :label="$t('目标类型')" prop="targetType">
          <!-- <el-select v-model="form.targetType" :placeholder="$t('请选择运输方式')" @change="changeList">
huyf's avatar
huyf committed
104
            <el-option v-for="dict in getDictDatas(DICT_TYPE.TARGET_TYPE)"
huyf's avatar
huyf committed
105
                       :key="dict.value" :label="dict.label" :value="parseInt(dict.value)"/>
106 107
          </el-select> -->
          <dict-selector :type="DICT_TYPE.TARGET_TYPE" v-model="form.targetType" :placeholder="$t('请选择目标类型')" />
huyf's avatar
huyf committed
108
        </el-form-item>
109 110 111 112 113 114 115 116 117
        <div class="flex">
          <el-form-item :label="$t('计算周期')" prop="startTime">
            <el-date-picker v-model="form.startTime" placeholder="" value-format="yyyy-MM-dd HH:mm:ss" class="w-150"></el-date-picker>
          </el-form-item>
          <div class="ml-10 mr-10 flex flex-center" style="margin-bottom:22px">-</div>
          <el-form-item prop="endTime" label-width="0">
            <el-date-picker v-model="form.endTime" placeholder="" value-format="yyyy-MM-dd HH:mm:ss" class="w-150"></el-date-picker>
          </el-form-item>
        </div>
118
        <el-form-item :label="$t('运输方式')" prop="transportType">
huyf's avatar
huyf committed
119
          <dict-selector :type="DICT_TYPE.ECW_TRANSPORT_TYPE" v-model="form.transportType" formatter="number" @change="showChannel"/>
huyf's avatar
huyf committed
120
        </el-form-item>
121 122 123
        <el-form-item :label="$t('出货渠道')" prop="shippingChannel" v-if="this.showFlag">
          <el-select v-model="form.shippingChannel" :placeholder="$t('请选择出货渠道')">
            <el-option v-for="item in channelList" :label="$l(item, 'name')" :value="item.channelId"
huyf's avatar
huyf committed
124
                       :key="item.channelId"></el-option>
huyf's avatar
huyf committed
125 126
          </el-select>
        </el-form-item>
127 128
        <el-form-item :label="$t('立方数')" prop="cubeNum">
          <el-input v-model="form.cubeNum" :placeholder="$t('请输入立方数')"/>
huyf's avatar
huyf committed
129 130 131
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
132 133
        <el-button type="primary" @click="submitForm">{{$t('确定')}}</el-button>
        <el-button @click="cancel">{{$t('取消')}}</el-button>
huyf's avatar
huyf committed
134 135
      </div>
    </el-dialog>
huyf's avatar
huyf committed
136

huyf's avatar
huyf committed
137 138 139 140
  </div>
</template>

<script>
huyf's avatar
huyf committed
141 142 143 144 145 146 147 148 149 150 151 152 153
    import {
        createDeptTarget,
        updateDeptTarget,
        deleteDeptTarget,
        getDeptTarget,
        getDeptTargetPage,
        exportDeptTargetExcel,
        getCreateInitData,
        getPersonTargetPage
    } from "@/api/ecw/deptTarget";
    import {listSimpleDepts} from "@/api/system/dept";
    import {getChannelList} from '@/api/ecw/channel';
    import dayjs from "dayjs";
154
import { parseTime } from '@/utils/ruoyi';
huyf's avatar
huyf committed
155

huyf's avatar
huyf committed
156 157 158 159 160 161 162
    export default {
        name: "DeptTarget",
        components: {},
        data() {
            return {
                // 遮罩层
                loading: true,
huyf's avatar
huyf committed
163
                showFlag:false,
huyf's avatar
huyf committed
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
                // 导出遮罩层
                exportLoading: false,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                tableTotal: 0,
                // 部门业绩目标设置列表
                list: [],
                tableList: [],
                // 弹出层标题
                title: "",
                detail: {
                    deptName: null,
                    targetType: null,
                    cubeNum: null,
                    shippingChannel: null,
                    transportType: null,
                },
                // 是否显示弹出层
                open: false,
                tableOpen: false,
                dateRangeCreateTime: [],
                dateRangeStartTime: [],
                dateRangeEndTime: [],
                deptData: [],
                deptArr: [],
                channelList: [],
                monthList: [],
                quarterList: [],
                yearList: [],
                targetPeriod: [],
                // 查询参数
                queryParams: {
                    pageNo: 1,
                    pageSize: 10,
                    deptId: null,
                    targetType: null,
                    targetPeriodName: null,
                    transportType: null,
                    shippingChannel: null,
                    cubeNum: null,
                },
                tableQueryParams: {
                    pageNo: 1,
                    pageSize: 10,
                    id: null,
                },
                // 表单参数
                form: {},
                // 表单校验
                rules: {
216 217 218 219 220
                    deptId: [{required: true, message: this.$t("部门不能为空"), trigger: "blur"}],
                    targetType: [{required: true, message: this.$t("目标类型不能为空"), trigger: "change"}],
                    targetPeriodName: [{required: true, message: this.$t("计算周期不能为空"), trigger: "change"}],
                    transportType: [{required: true, message: this.$t("运输方式不能为空"), trigger: "change"}],
                    cubeNum: [{required: true, message: this.$t("立方数不能为空"), trigger: "blur"}],
221 222
                    startTime: [{required: true, message: this.$t("起始时间不能为空"), trigger: "change"}],
                    endTime: [{required: true, message: this.$t("截止时间不能为空"), trigger: "change"}],
huyf's avatar
huyf committed
223 224 225 226 227 228 229 230 231
                }
            };
        },
        computed: {
            getShipChannelName() {
                return shippingChannelId => {
                    for (let index in this.channelList) {
                        let channelItem = this.channelList[index];
                        if (channelItem.channelId == shippingChannelId) {
232
                            return $l(channelItem, 'name');
huyf's avatar
huyf committed
233 234 235 236 237 238 239 240 241 242
                        }
                    }
                    return '/'
                }
            }
        },
        created() {
            listSimpleDepts().then(res => {
                res.data.forEach((item) => {
                    if (item.parentId == 0) {
huyf's avatar
huyf committed
243

huyf's avatar
huyf committed
244
                        this.deptArr.push(item)
huyf's avatar
huyf committed
245

huyf's avatar
huyf committed
246 247 248 249 250 251 252 253 254
                    } else {
                        this.deptData.push(item)
                    }
                })
                this.deptData.forEach((value) => {
                    var dept = this.deptArr.filter(itt => itt.id == value.parentId)
                    if (dept.length > 0) {
                        value.name = dept[0].name + ' | ' + value.name
                    }
huyf's avatar
huyf committed
255

huyf's avatar
huyf committed
256 257 258 259 260 261 262 263
                })
            });
            getCreateInitData().then(res => {
                this.monthList = res.data.month;
                this.quarterList = res.data.quarter;
                this.yearList = res.data.year;
            });
            this.getChannelList();
huyf's avatar
huyf committed
264
            this.getList();
huyf's avatar
huyf committed
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
        },
        methods: {
            getChannelList() {
                getChannelList().then(res => this.channelList = res.data)
            },
            dateFormat(val) {
                return dayjs(val).format("YYYY-MM-DD");
            },
            changeList(val) {
                if (val === 1) {
                    this.form.targetPeriodName = undefined;
                    this.targetPeriod = this.monthList;
                } else if (val === 2) {
                    this.form.targetPeriodName = undefined;
                    this.targetPeriod = this.quarterList;
                } else {
                    this.form.targetPeriodName = undefined;
                    this.targetPeriod = this.yearList;
                }
            },
            setTime(item) {
                this.targetPeriod.forEach((i, index) => {
                    if (i.name === item) {
huyf's avatar
huyf committed
288 289
                        this.form.startTime = i.startDate + " 00:00:00";
                        this.form.endTime = i.endDate + " 23:59:59";
huyf's avatar
huyf committed
290 291 292
                    }
                })
            },
huyf's avatar
huyf committed
293 294 295 296 297 298 299 300
            showChannel(val){
                console.log(val);
                if(val===3 || val===4){
                    this.showFlag = true;
                } else {
                    this.showFlag = false;
                }
            },
huyf's avatar
huyf committed
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
            /** 查询列表 */
            getList() {
                this.loading = true;
                // 处理查询参数
                let params = {...this.queryParams};
                this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
                this.addBeginAndEndTime(params, this.dateRangeStartTime, 'startTime');
                this.addBeginAndEndTime(params, this.dateRangeEndTime, 'endTime');
                // 执行查询
                getDeptTargetPage(params).then(response => {
                    this.list = response.data.list;
                    this.total = response.data.total;
                    this.loading = false;
                });
            },
            /** 取消按钮 */
            cancel() {
                this.open = false;
                this.reset();
            },
            /** 表单重置 */
            reset() {
                this.form = {
                    id: undefined,
                    deptId: undefined,
                    targetType: undefined,
                    targetPeriodName: undefined,
                    startTime: undefined,
                    endTime: undefined,
                    transportType: undefined,
                    shippingChannel: undefined,
                    cubeNum: undefined,
                };
                this.resetForm("form");
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNo = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.dateRangeCreateTime = [];
                this.dateRangeStartTime = [];
                this.dateRangeEndTime = [];
                this.resetForm("queryForm");
                this.handleQuery();
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.targetPeriod = this.monthList;
                this.reset();
                this.open = true;
354
                this.title = this.$t("添加部门业绩目标设置");
huyf's avatar
huyf committed
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
            },
            /** 查看人员目标情况 */
            handleView(row) {
                this.detail = row;
                this.tableQueryParams.id = row.id;
                this.getTableList();
                this.tableOpen = true;
            },
            getTableList() {
                getPersonTargetPage(this.tableQueryParams).then(res => {
                    this.tableList = res.data.list;
                    this.tableTotal = res.data.total;
                });
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const id = row.id;
                getDeptTarget(id).then(response => {
                    this.form = response.data;
                    if (response.data.targetType === 1) {
                        this.targetPeriod = this.monthList;
                    } else if (response.data.targetType === 2) {
                        this.targetPeriod = this.quarterList;
                    } else {
                        this.targetPeriod = this.yearList;
                    }
382 383 384 385

                    this.form.startTime = parseTime(this.form.startTime)
                    this.form.endTime = parseTime(this.form.endTime)

huyf's avatar
huyf committed
386
                    this.open = true;
387
                    this.title = this.$t("修改部门业绩目标设置");
huyf's avatar
huyf committed
388 389 390 391 392 393 394 395 396 397 398
                });
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (!valid) {
                        return;
                    }
                    // 修改的提交
                    if (this.form.id != null) {
                        updateDeptTarget(this.form).then(response => {
399
                            this.$modal.msgSuccess(this.$t("修改成功"));
huyf's avatar
huyf committed
400 401 402 403 404 405 406
                            this.open = false;
                            this.getList();
                        });
                        return;
                    }
                    // 添加的提交
                    createDeptTarget(this.form).then(response => {
407
                        this.$modal.msgSuccess(this.$t("新增成功"));
huyf's avatar
huyf committed
408 409 410 411 412 413 414 415
                        this.open = false;
                        this.getList();
                    });
                });
            },
            /** 删除按钮操作 */
            handleDelete(row) {
                const id = row.id;
416
                this.$modal.confirm(this.$t('是否确认删除部门业绩目标设置编号为{id}的数据项?', {id})).then(function () {
huyf's avatar
huyf committed
417 418 419
                    return deleteDeptTarget(id);
                }).then(() => {
                    this.getList();
420
                    this.$modal.msgSuccess(this.$t("删除成功"));
huyf's avatar
huyf committed
421 422 423 424 425 426 427 428 429 430 431 432 433
                }).catch(() => {
                });
            },
            /** 导出按钮操作 */
            handleExport() {
                // 处理查询参数
                let params = {...this.queryParams};
                params.pageNo = undefined;
                params.pageSize = undefined;
                this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
                this.addBeginAndEndTime(params, this.dateRangeStartTime, 'startTime');
                this.addBeginAndEndTime(params, this.dateRangeEndTime, 'endTime');
                // 执行导出
434
                this.$modal.confirm(this.$t('是否确认导出所有部门业绩目标设置数据项?')).then(() => {
huyf's avatar
huyf committed
435 436 437 438 439 440 441 442
                    this.exportLoading = true;
                    return exportDeptTargetExcel(params);
                }).then(response => {
                    this.$download.excel(response, '${table.classComment}.xls');
                    this.exportLoading = false;
                }).catch(() => {
                });
            }
huyf's avatar
huyf committed
443
        }
huyf's avatar
huyf committed
444
    };
huyf's avatar
huyf committed
445
</script>