Infsea.vue 21 KB
Newer Older
fukai committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 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 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 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 354 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 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
<template>
  <div class="eibs-tab">
    <c-col :span="24">
      <c-col :span="8">
        <el-form-item label="币种">
          <c-select v-model="model.cur" placeholder="请选择币种" dbCode="CURTXT" :isShowKeyAndLabel="true" sort="SRT"
            @change="changeCur()" />
        </el-form-item>
      </c-col>
      <c-col :span="8">
        <el-form-item label="月份" prop="dat" :rules="rules.dat">
          <el-date-picker v-model="model.dat" type="month" value-format="yyyy-MM" format="yyyy-MM" placeholder="选择月份" />
        </el-form-item>
      </c-col>
      <c-col :span="8" style="text-align: center">
        <el-button type="primary" icon="el-icon-search" size="small" :loading="searchLoading" @click="changeModel()">查询
        </el-button>
        <el-button size="small" icon="el-icon-refresh" @click="handleReset">重置</el-button>
        <el-tooltip effect="dark" content="双击日历格空白处可添加节假日,单击颜色按钮可删除节假日" placement="bottom">
          <el-button size="small" icon="el-icon-info">说明</el-button>
        </el-tooltip>
      </c-col>
    </c-col>

    <el-calendar v-model="value">
      <template slot="dateCell" slot-scope="{date, data}">
        <p style="width: 100%;height: 100%;padding: 8px;" @dblclick="addTdh(data)">
          <template v-if="tdhDataDateList.includes(data.day)">
            <div>
              {{ (data.day.split('-').slice(1).join('-')) }}
              <div class="btn-wrap">
                <div v-for="item in tdhDat" :key="item.inr" style="position: relative;">
                  <!-- CNY -->
                  <el-popover placement="top-start" title="节假日信息" width="200" trigger="hover"
                    v-if="item.cur.toUpperCase() == 'CNY' && item.dat == data.day">
                    <span style="display:block;color:#FF0000;">币种: CNY - 人民币</span>
                    <span style="display:block;color:#FF0000;">日期: {{item.dat}}</span>
                    <el-button slot="reference" style="width: 20px;height: 10px;background:#FF0000;margin-right:8px;"
                      @click="handleClick(item)" v-if="item.cur.toUpperCase() == 'CNY' && item.dat == data.day">
                    </el-button>
                  </el-popover>
                  <!-- USD -->
                  <el-popover placement="top-start" title="节假日信息" width="200" trigger="hover"
                    v-if="item.cur.toUpperCase() == 'USD' && item.dat == data.day">
                    <span style="display:block;color:#336699;">币种: USD - 美元</span>
                    <span style="display:block;color:#336699;">日期: {{item.dat}}</span>
                    <el-button slot="reference" style="width: 20px;height: 10px;background:#336699;margin-right:8px;"
                      @click="handleClick(item)" v-if="item.cur.toUpperCase() == 'USD' && item.dat == data.day">
                    </el-button>
                  </el-popover>
                  <!-- EUR -->
                  <el-popover placement="top-start" title="节假日信息" width="200" trigger="hover"
                    v-if="item.cur.toUpperCase() == 'EUR' && item.dat == data.day">
                    <span style="display:block;color:#f7ce31;">币种: EUR - 欧元</span>
                    <span style="display:block;color:#f7ce31;">日期: {{item.dat}}</span>
                    <el-button slot="reference" style="width: 20px;height: 10px;background:#f7ce31;margin-right:8px;"
                      @click="handleClick(item)" v-if="item.cur.toUpperCase() == 'EUR' && item.dat == data.day">
                    </el-button>
                  </el-popover>
                  <!-- GBP -->
                  <el-popover placement="top-start" title="节假日信息" width="200" trigger="hover"
                    v-if="item.cur.toUpperCase() == 'GBP' && item.dat == data.day">
                    <span style="display:block;color:#009966;">币种: GBP - 英镑</span>
                    <span style="display:block;color:#009966;">日期: {{item.dat}}</span>
                    <el-button slot="reference" style="width: 20px;height: 10px;background:#009966;margin-right:8px;"
                      @click="handleClick(item)" v-if="item.cur.toUpperCase() == 'GBP' && item.dat == data.day">
                    </el-button>
                  </el-popover>
                  <!-- JPY -->
                  <el-popover placement="top-start" title="节假日信息" width="200" trigger="hover"
                    v-if="item.cur.toUpperCase() == 'JPY' && item.dat == data.day">
                    <span style="display:block;color:#CCCCCC;">币种: JPY - 日元</span>
                    <span style="display:block;color:#CCCCCC;">日期: {{item.dat}}</span>
                    <el-button slot="reference" style="width: 20px;height: 10px;background:#CCCCCC;margin-right:8px;"
                      @click="handleClick(item)" v-if="item.cur.toUpperCase() == 'JPY' && item.dat == data.day">
                    </el-button>
                  </el-popover>
                  <!-- HKD -->
                  <el-popover placement="top-start" title="节假日信息" width="200" trigger="hover"
                    v-if="item.cur.toUpperCase() == 'HKD' && item.dat == data.day">
                    <span style="display:block;color:#FFC0CB;">币种: HKD - 港币</span>
                    <span style="display:block;color:#FFC0CB;">日期: {{item.dat}}</span>
                    <el-button slot="reference" style="width: 20px;height: 10px;background:#FFC0CB;margin-right:8px;"
                      @click="handleClick(item)" v-if="item.cur.toUpperCase() == 'HKD' && item.dat == data.day">
                    </el-button>
                  </el-popover>
                  <!-- other -->
                  <el-popover placement="top-start" title="节假日信息" width="200" trigger="hover"
                    v-if="commonCurList.indexOf(item.cur.toUpperCase()) == -1 && item.dat == data.day">
                    <span style="display:block;color:#161414;">币种: {{item.curname}}</span>
                    <span style="display:block;color:#161414;">日期: {{item.dat}}</span>
                    <el-button slot="reference" style="width: 20px;height: 10px;background:#161414;margin-right:8px;"
                      @click="handleClick(item)"
                      v-if="commonCurList.indexOf(item.cur.toUpperCase()) == -1 && item.dat == data.day">
                    </el-button>
                  </el-popover>
                </div>
              </div>
            </div>
          </template>
          <template v-else>
            {{ (data.day.split('-').slice(1).join('-')) }}
          </template>
        </p>
      </template>
    </el-calendar>
    <c-col :span="24">
      <c-col :span="20" style="margin-left:20px;margin-top:-20px;margin-bottom:20px;">
        <span style="display: inline-block;width: 20px;height: 13px;background: #FF0000;"></span>CNY-人民币
        <span
          style="display: inline-block;width: 20px;height: 13px;background: #336699; margin-left:12px;"></span>USD-美元
        <span
          style="display: inline-block;width: 20px;height: 13px;background: #f7ce31; margin-left:12px;"></span>EUR-欧元
        <span
          style="display: inline-block;width: 20px;height: 13px;background: #009966; margin-left:12px;"></span>GBP-英镑
        <span
          style="display: inline-block;width: 20px;height: 13px;background: #CCCCCC; margin-left:12px;"></span>JPY-日元
        <span
          style="display: inline-block;width: 20px;height: 13px;background: #FFC0CB; margin-left:12px;"></span>HKD-港币
        <span v-if="curNameSkipCommonCur != ''"
          style="display: inline-block;width: 20px;height: 13px;background: #161414; margin-left:12px;"></span>{{curNameSkipCommonCur}}
      </c-col>
    </c-col>
    <c-col :span="24">
      <c-col :span="24" style="text-align: center">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" ref="tdhInsertBtn" v-if="isShowPBtn"
          @click="dialog = true">节假日导入
        </el-button>
      </c-col>
    </c-col>
    <c-col :span="24">
      <c-paging-table :data="tdhTableData" :columns="tdhColumns" :pageNumber="model.pageNum" :pageSize="model.pageSize"
        :total="model.total" v-on:queryFunc="queryFunc" :border="true">
      </c-paging-table>
    </c-col>

    <c-col>
      <el-dialog title="节假日导入" :visible.sync="dialog" :close-on-click-modal="false" @close="cancel" center>
        <c-col :span="24">
          <c-col :span="24">
            <div class="upload-file">
              <el-upload action="/webapi/manager/tdh/upload" :accept="accept" :limit="1"
                :before-upload="handleBeforeUpload" :file-list="fileList" :on-exceed="handleExceed" :auto-upload="false"
                ref="uploadff">
                <!--上传按钮-->
                <el-button slot="trigger" size="mini" type="primary">选取文件</el-button>
                <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">确 认</el-button>
                <!--上传提示-->
                <div slot="tip" class="el-upload__tip">只能上传xlxs/xls文件,且不超过10M</div>
              </el-upload>
              <!-- 文件列表 -->
              <transition-group class="upload-file-list el-upload-list el-upload-list--text" name="el-fade-in-linear"
                tag="ul">
                <li :key="file.uid" class="el-upload-list__item ele-upload-list__item-content"
                  v-for="(file, index) in fileList">
                  <el-link :href="file.url" :underline="false" target="_blank">
                    <span class="el-icon-document"> {{ getFileName(file.name) }} </span>
                  </el-link>
                  <div class="ele-upload-list__item-content-action">
                    <el-link :underline="false" @click="handleDelete(index)" type="danger">删除</el-link>
                  </div>
                </li>
              </transition-group>
            </div>
          </c-col>
        </c-col>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="cancel">取 消</el-button>
        </span>
      </el-dialog>
    </c-col>
  </div>
</template>

<script>
  import codes from "~/config/CodeTable";
  import moment from 'moment';
  import commonFunctions from "~/mixin/commonFunctions.js";
  import Tdh, {
    Pattern
  } from "./Tdh.js";
  import {
    queryByPage,
    add,
    edit,
    deleteById,
    getCurName,
    queryAll,
    uploadfile
  } from "~/service/manage/tdh.js";

  export default {
    name: "",
    props: ["model"],
    inject: ["root"],
    mixins: [commonFunctions],
    data() {
      var checkCur = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('请选择币种!'));
        } else {
          return callback();
        }
      };
      var checkDat = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('请选择月份!'));
        } else {
          return callback();
        }
      };
      return {
        rules: {
          cur: [{
            required: true,
            validator: checkCur,
            trigger: 'change'
          }],
          dat: [{
            required: true,
            validator: checkDat,
            trigger: 'change'
          }]
        },
        tdhModel: {},
        tdhDat: [],
        value: new Date(),
        tdhTableData: [],
        tdhColumns: [{
            label: '币种',
            prop: 'curname',
            width: 'auto'
          },
          {
            label: '日期',
            prop: 'datStr',
            width: 'auto'
          }
        ],
        dialogFlg: false,
        form: new Tdh().data,
        // 已选择文件列表
        fileList: [],
        // 是否显示文件上传弹窗
        dialog: false,
        // 可上传的文件类型
        accept: '.xls,.xlsx',
        action: 'action',
        isShowPBtn: false,
        isEditBtn: false,
        searchLoading: false,
        currentSelectCurName: '',
        curNameSkipCommonCur: '',
        commonCurList: ['CNY', 'USD', 'EUR', 'GBP', 'JPY', 'HKD'],
      };
    },
    computed: {
      tdhDataDateList() {
        return this.tdhDat.map((item) => {
          return item.datStr
        })
      }
    },
    created() {
      this.model.dat = this.getNowDate()
      this.onSearch()
    },
    activated() {
      const {
        update
      } = this.$route.params
      if (update) {
        this.onDbltdhSearch()
      }
    },
    mounted() {
      this.$nextTick(() => {
        // 上个月
        let prevBtn = document.querySelector(
          ".el-calendar__button-group .el-button-group>button:nth-child(1)"
        );
        prevBtn.addEventListener("click", () => {
          this.model.dat = moment(this.value).format("yyyy-MM");
          this.onSearch();
        });
        // 今天
        let dayBtn = document.querySelector(
          ".el-calendar__button-group .el-button-group>button:nth-child(2)"
        );
        dayBtn.addEventListener("click", () => {
          this.model.dat = moment(this.value).format("yyyy-MM");
          this.onSearch();
        });
        // 下个月
        let nextBtn = document.querySelector(
          ".el-calendar__button-group .el-button-group>button:nth-child(3)"
        );
        nextBtn.addEventListener("click", () => {
          this.model.dat = moment(this.value).format("yyyy-MM");
          this.onSearch();
        });
      });
      this.getHiddenButtonVue();
    },
    methods: {
      // 获取当前选择的币种名称
      changeCur() {
        var temp = new Tdh().data;
        if (this.model.cur != '') {
          temp.cur = this.model.cur;
          getCurName(temp).then((res) => {
            this.currentSelectCurName = res.data;
            if (this.commonCurList.indexOf(this.model.cur) == -1) {
              this.curNameSkipCommonCur = res.data;
            } else {
              this.curNameSkipCommonCur = '';
            }
          });
        } else {
          this.currentSelectCurName = '';
          this.curNameSkipCommonCur = '';
        }
      },
      getNowDate() {
        const timeOne = new Date()
        const year = timeOne.getFullYear()
        let month = timeOne.getMonth() + 1
        month = month < 10 ? '0' + month : month
        const NOW_MONTHS = `${year}-${month}`
        return NOW_MONTHS
      },
      getHiddenButtonVue() {
        this.$buttonControlService.hiddenBtnList()
          .then((res) => {
            //节假日倒入
            let hasInsert = res.some((item) => {
              return item.ITEMID === 'tdhInsertBtn';
            })
            if (hasInsert) {
              this.isShowPBtn = false;
            } else {
              this.isShowPBtn = true;
            }

            //界面编辑
            let hasEdit = res.some((item) => {
              return item.ITEMID === 'tdhEditBtn';
            })
            if (hasEdit) {
              this.isEditBtn = false;
            } else {
              this.isEditBtn = true;
            }
          })
      },
      // 【查询】按钮
      changeModel() {
        this.value = this.model.dat;
        this.onSearch();
      },
      getCodesByKey(key) {
        return codes[key] || [];
      },
      // 【重置】按钮
      handleReset() {
        this.model.cur = '';
        this.model.dat = '';
        this.currentSelectCurName = '';
        this.curNameSkipCommonCur = '';
      },
      // 列表分页查询
      queryFunc(pageNumber, pageSize) {
        this.model.pageNum = pageNumber
        this.model.pageSize = pageSize
        this.onDbltdhSearch()
      },
      // 查询操作
      onSearch() {
        this.model.pageSize = PageSize;
        this.model.pageNum = 1;
        this.onDbltdhSearch();
      },
      // 【列表节假日查询】和【日历节假日】查询
      onDbltdhSearch() {
        delete this.model.modifySet;
        if (this.model.dat == null || this.model.dat == '') {
          this.$notify.error("月份不能为空!");
          return;
        }
        const loading = this.loading();
        this.searchLoading = true;
        // 列表节假日查询
        queryByPage(this.model).then(res => {
          if (res.respCode == SUCCESS) {
            this.tdhTableData = res.data.list
            this.model.pageNum = res.data.pageNumber
            this.model.pageSize = res.data.pageSize
            this.model.total = res.data.total
            this.queryCalendar();
            loading.close();
          }
        })
      },
      // 日历节假日查询
      queryCalendar() {
        this.tdhModel.cur = this.model.cur
        this.tdhModel.dat = this.model.dat
        queryAll(this.tdhModel).then(res => {
          if (res.respCode == SUCCESS) {
            this.tdhDat = res.data;
            this.searchLoading = false;
          } else {
            this.searchLoading = false;
          }
        }).catch((err) => {
          this.searchLoading = false;
          this.$notify.error("节假日查询失败!");
        });
      },
      // 【按钮点击事件,删除节假日】
      handleClick(itemValue) {
        if (!this.isEditBtn) {
          // 无权限操作
          this.$notify.error("抱歉,您没有该权限!");
          return;
        }
        this.$confirm("是否删除【" + itemValue.curname + "】的节假日?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          let params = {
            inr: itemValue.inr
          }
          deleteById(params).then((res) => {
              this.$notify.success("删除成功!");
              this.onSearch()
            })
            .catch((err) => {
              this.$notify.error("修改失败!");
            });
        }).catch(() => {
          this.$message({
            type: "info",
            message: "取消删除",
          });
        });
      },
      // 新增节假日信息
      addTdh(currentCellData) {
        if (!this.isEditBtn) {
          // 无权限操作
          this.$notify.error("抱歉,您没有该权限!");
          return;
        }
        if (this.model.cur == '') {
          this.$notify.error("请先选择对应币种!");
          return;
        }
        var temp = new Tdh().data;
        temp.cur = this.model.cur;
        this.$confirm("是否新增【" + this.currentSelectCurName + "】节假日?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }).then(() => {
            this.form = new Tdh().data;
            this.form.cur = this.model.cur;
            this.form.dat = currentCellData.day;
            add(this.form)
              .then((res) => {
                if (res.respCode == SUCCESS) {
                  this.$notify.success("新增节假日成功!");
                  this.onDbltdhSearch();
                } else {
                  this.$notify.error(res.respMsg);
                }
              })
              .catch((err) => {
                this.$notify.error("新增节假日失败!");
              });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "取消修改",
            });
          });
      },

      // 文件个数超出
      handleExceed() {
        this.$notify.error(`只允许上传1个文件`);
      },
      // 上传前校检大小
      handleBeforeUpload(file) {
        // 校检文件大小
        const isLt = file.size / 1024 / 1024 < 10;
        if (!isLt) {
          this.$notify.error(`上传文件大小不能超过 10 MB!`);
          return false;
        }
        return true;
      },
      // 删除文件
      handleDelete(index) {
        this.fileList.splice(index, 1);
      },
      // 获取文件名称
      getFileName(name) {
        if (name.lastIndexOf("/") > -1) {
          return name.slice(name.lastIndexOf("/") + 1).toLowerCase();
        } else {
          return "";
        }
      },
      /** 手动提交上传 */
      submitUpload() {
        this.$refs.uploadff.submit()
        this.cancel()
      },
      /** 关闭上传弹框 */
      cancel() {
        this.fileList = [];
        this.dialog = false;
        this.onSearch();
      }
    },
  };
</script>

<style scoped lang="less">
  .table-button-item-list {
    padding: 0;
    margin: 0;
  }

  .table-button-item-list li {
    list-style: none;
    padding: 5px 0;
    text-align: center;
    color: #606266;
    cursor: pointer;
  }

  ::v-deep .el-calendar-day {
		height: 60px;
    padding: 0;
	}
	::v-deep .el-calendar__header {
		padding: 6px 20px;
	}
	::v-deep .el-calendar__body {
		padding: 6px 20px 35px;
	}
	::v-deep .el-calendar-table thead th {
		padding: 6px 0;
	}
	::v-deep .el-form-item {
		margin-bottom: 10px;
	}
	::v-deep .poin-skin .el-table th {
		line-height: 32px;
	}
  .is-selected {
    background: #fffdd0;
    color: orange;
  }

  .hidePoper {
    display: none
  }

  .btn-wrap {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-start;
		margin-top: -2px;
		flex-wrap: wrap;
  }
</style>