123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470 |
- <template>
- <div>
- <basic-container class="page-crad">
- <avue-crud
- ref="crud"
- :option="option"
- :data="dataList"
- v-model="form"
- :page.sync="page"
- :search.sync="search"
- @search-change="searchChange"
- @current-change="currentChange"
- @resetColumn="resetColumn"
- @size-change="sizeChange"
- @refresh-change="refreshChange"
- @on-load="onLoad"
- :table-loading="loading"
- @saveColumn="saveColumn"
- :cell-style="cellStyle"
- :summary-method="summaryMethod"
- @search-criteria-switch="searchCriteriaSwitch"
- >
- <template slot="menuLeft">
- <el-button
- type="primary"
- icon="el-icon-plus"
- size="small"
- @click.stop="excelBox = !excelBox"
- >导入</el-button
- >
- <el-button
- type="success"
- icon="el-icon-upload2"
- size="small"
- @click="derivation()"
- >下载模板
- </el-button>
- <el-button type="info" size="small">报表</el-button>
- </template>
- <template slot="cnameSearch">
- <goods-select
- v-model="search.cname"
- :configuration="goodsConfiguration"
- />
- </template>
- <template slot="priorityReferrer" slot-scope="{ row }">
- <el-checkbox
- :disabled="!row.$cellEdit"
- v-model="row.priorityReferrer"
- :true-label="1"
- :false-label="0"
- />
- </template>
- <template slot="corpIdSearch">
- <crop-select v-model="search.corpId" corpType="GYS"></crop-select>
- </template>
- <template slot="dateValiditySearch">
- <el-date-picker
- v-model="search.dateValidity"
- type="daterange"
- start-placeholder="开始日期"
- end-placeholder="结束日期"
- format="yyyy-MM-dd"
- value-format="yyyy-MM-dd HH:mm:ss"
- :default-time="['00:00:00', '23:59:59']"
- >
- </el-date-picker>
- </template>
- <template slot-scope="{ row }" slot="corpId">
- {{ row.corpName }}
- </template>
- <template slot-scope="{ row }" slot="grossProfitRate">
- {{ row.grossProfitRate ? scope.row.grossProfitRate : 0 }}%
- </template>
- <template slot-scope="{ row }" slot="status">
- {{ row.status | orderStateFormat }}
- </template>
- <template slot-scope="{ row }" slot="ename">
- <el-input
- v-if="row.$cellEdit"
- v-model="row.ename"
- size="small"
- ></el-input>
- <span v-else>{{ row.ename }}</span>
- </template>
- <template slot-scope="{ row }" slot="coefficient">
- <el-input
- v-if="row.$cellEdit"
- v-model="row.coefficient"
- size="small"
- oninput="value=value.replace(/[^0-9.]/g,'').replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3')"
- @change="priceChange(row)"
- ></el-input>
- <span v-else>{{ row.coefficient }}</span>
- </template>
- <template slot-scope="{ row }" slot="price">
- <el-input
- v-if="row.$cellEdit"
- v-model="row.price"
- size="small"
- oninput="value=value.replace(/[^0-9.]/g,'').replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3')"
- @change="priceChange(row)"
- ></el-input>
- <span v-else>{{ row.price }}</span>
- </template>
- <template slot-scope="{ row }" slot="endTime">
- <el-date-picker
- v-if="row.$cellEdit"
- format="yyyy-MM-dd"
- value-format="yyyy-MM-dd 00:00:00"
- v-model="row.endTime"
- type="date"
- placeholder="选择日期"
- ></el-date-picker>
- <span v-else v-html="$options.filters.endTimeFormat(row.endTime)" />
- </template>
- <template slot-scope="{ row }" slot="currency">
- <el-select
- size="small"
- v-model="row.currency"
- placeholder="请选择"
- @change="currencyChange(row)"
- v-if="row.$cellEdit"
- >
- <el-option
- v-for="item in currencyList"
- :key="item.id"
- :label="item.dictValue"
- :value="item.dictValue"
- >
- </el-option>
- </el-select>
- <span v-else>{{ row.currency }}</span>
- </template>
- <template slot-scope="{ row }" slot="taxRate">
- <el-input
- v-if="row.$cellEdit"
- v-model="row.taxRate"
- size="small"
- oninput="value=value.replace(/[^0-9.]/g,'').replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3')"
- @change="priceChange(row)"
- ></el-input>
- <span v-else>{{ row.taxRate | taxRateFormat }}</span>
- </template>
- <template slot-scope="{ row, index }" slot="menu">
- <el-button
- type="text"
- icon="el-icon-edit"
- size="small"
- @click.stop="editOpen(row, index)"
- >{{ row.$cellEdit ? "保存" : "修改" }}
- </el-button>
- <el-button
- type="text"
- icon="el-icon-delete"
- size="small"
- @click.stop="rowDel(row, index)"
- >删除
- </el-button>
- </template>
- </avue-crud>
- <el-dialog
- title="导入价格"
- append-to-body
- :visible.sync="excelBox"
- width="555px"
- >
- <avue-form
- :option="excelOption"
- v-model="excelForm"
- :upload-after="uploadAfter"
- class="excelUpload"
- />
- </el-dialog>
- </basic-container>
- </div>
- </template>
- <script>
- import option from "./config/mainList.json";
- import { getToken } from "@/util/auth";
- import {
- getList,
- remove,
- getGoodstype,
- submit
- } from "@/api/maintenance/priceLibrary";
- import { micrometerFormat } from "@/util/validate";
- import { orderStateFormat } from "@/enums/order-stauts";
- import { taxRateFormat } from "@/enums/tax-rate";
- import { purchaseCal } from "@/util/calculate";
- import _ from "lodash";
- export default {
- name: "customerInformation",
- data() {
- return {
- excelOption: {
- submitBtn: false,
- emptyBtn: false,
- column: [
- {
- label: "导入数据",
- prop: "excelFile",
- type: "upload",
- drag: true,
- loadText: "导入数据中,请稍等",
- span: 24,
- propsHttp: {
- res: "data"
- },
- tip: "请上传 .xls,.xlsx 标准格式文件",
- action: "/api/blade-mocha-item/pricebank/importPrice"
- }
- ]
- },
- excelBox: false,
- excelForm: {},
- goodsConfiguration: {
- multipleChoices: false,
- multiple: false,
- collapseTags: false,
- placeholder: "请点击右边按钮选择",
- dicData: [],
- clearable: true
- },
- configuration: {
- multipleChoices: false,
- multiple: false,
- collapseTags: false,
- placeholder: "请点击右边按钮选择",
- dicData: [],
- clearable: true
- },
- search: {},
- form: {},
- option: {},
- parentId: 0,
- dataList: [],
- page: {
- pageSize: 10,
- currentPage: 1,
- total: 0,
- pageSizes: [10, 50, 100, 200, 300, 400, 500]
- },
- detailData: {},
- loading: false,
- currencyList: []
- };
- },
- async created() {
- /**
- * 已定义全局方法,直接使用,getColumnData获取列数据,参数传值(表格名称,引入的本地JSON的数据定义的名称)
- * 已定义全局方法,直接使用,getColumnName方法用来获取枚举值,参数根据自己定义的code值获取中文名
- * 一定要执行异步操作,要等接口成功返回,才能执行下一行代码
- */
- this.option = await this.getColumnData(this.getColumnName(50), option);
- this.getWorkDicts("billType").then(res => {
- this.findObject(this.option.column, "billType").dicData = res.data.data;
- });
- getGoodstype(1, 500).then(res => {
- this.findObject(this.option.column, "goodsTypeName").dicData =
- res.data.data.records;
- });
- this.getWorkDicts("price_library_currency").then(res => {
- this.currencyList = res.data.data;
- });
- this.option.height = window.innerHeight - 210;
- },
- filters: {
- orderStateFormat(val) {
- return orderStateFormat(val);
- },
- taxRateFormat(val) {
- return taxRateFormat(val);
- },
- endTimeFormat(time) {
- const today = new Date();
- const endTime = new Date(time);
- const curretMonth = new Date(
- today.getFullYear(),
- today.getMonth() + 1,
- 0
- );
- const curretMonthDayCount = curretMonth.getDate();
- const dateDiff = endTime.getTime() - today.getTime(); //时间差的毫秒数
- const dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000)); //计算出相差天数
- if (dayDiff < 0) {
- time = '<span style="color:red">' + time + "</span>";
- } else if (dayDiff >= 0 && dayDiff < curretMonthDayCount) {
- time = '<span style="color:#9ACD32">' + time + "</span>";
- }
- return time;
- }
- },
- methods: {
- searchCriteriaSwitch(type) {
- if (type) {
- this.option.height = this.option.height - 93;
- } else {
- this.option.height = this.option.height + 93;
- }
- this.$refs.crud.getTableHeight();
- },
- cellStyle() {
- return "padding:0;height:40px;";
- },
- priceChange(row) {
- row.purchaseAmount = purchaseCal(row.price, row.taxRate, row.coefficient);
- },
- uploadAfter(res, done, loading, column) {
- if (res != "导入成功") {
- this.$message.error(res);
- }
- this.excelBox = false;
- this.page.currentPage = 1;
- this.onLoad(this.page);
- loading();
- done();
- },
- derivation() {
- this.$confirm("是否下载模板?", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning"
- }).then(() => {
- window.open(
- `/api/blade-mocha-item/pricebank/exportPrice?${
- this.website.tokenHeader
- }=${getToken()}`
- );
- });
- },
- currencyChange(row) {
- this.currencyList.forEach(e => {
- if (e.dictValue == row.currency) {
- row.exchangeRate = e.remark;
- }
- });
- },
- //删除列表后面的删除按钮触发触发(row, index, done)
- rowDel(row, index, done) {
- this.$confirm("确定删除数据?", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning"
- }).then(() => {
- remove(row.id).then(res => {
- if (res.data.code == 200) {
- this.$message({
- type: "success",
- message: "删除成功!"
- });
- this.onLoad(this.page, this.search);
- }
- });
- });
- },
- editOpen(row, index) {
- if (row.$cellEdit == true) {
- submit({ ...row, tradeType: "CK" }).then(res => {
- this.onLoad(this.page, this.search);
- this.$set(row, "$cellEdit", false);
- });
- } else {
- this.$set(row, "$cellEdit", true);
- }
- },
- //点击搜索按钮触发
- searchChange(params, done) {
- if (params.dateValidity) {
- params.dateValidityStart = params.dateValidity[0];
- params.dateValidityEnd = params.dateValidity[1];
- }
- delete params.dateValidity;
- this.onLoad(this.page, params);
- done();
- },
- currentChange(val) {
- this.page.currentPage = val;
- },
- sizeChange(val) {
- this.page.currentPage = 1;
- this.page.pageSize = val;
- },
- onLoad(page, params = {}) {
- params = {
- ...params,
- tradeType: "CK"
- };
- this.loading = true;
- getList(
- page.currentPage,
- page.pageSize,
- Object.assign(params, this.search)
- )
- .then(res => {
- // if (res.data.data.records) {
- // res.data.data.records.forEach(e => {
- // });
- // }
- this.dataList = res.data.data.records ? res.data.data.records : [];
- this.page.total = res.data.data.total;
- })
- .finally(() => {
- this.loading = false;
- });
- },
- summaryMethod({ columns, data }) {
- const sums = [];
- if (columns.length > 0) {
- columns.forEach((item, index) => {
- sums[0] = "合计";
- if (item.property == "price" || item.property == "purchaseAmount") {
- let priceSum = 0;
- let amountSum = 0;
- data.forEach(e => {
- priceSum = _.add(priceSum, Number(e.price));
- amountSum = _.add(amountSum, Number(e.purchaseAmount));
- });
- //最新价格
- if (item.property == "price") {
- sums[index] = micrometerFormat(priceSum);
- }
- //采购价格
- if (item.property == "purchaseAmount") {
- sums[index] = micrometerFormat(amountSum);
- }
- }
- });
- }
- return sums;
- },
- refreshChange() {
- this.onLoad(this.page, this.search);
- },
- async saveColumn() {
- const inSave = await this.saveColumnData(
- this.getColumnName(50),
- this.option
- );
- if (inSave) {
- this.$message.success("保存成功");
- //关闭窗口
- this.$refs.crud.$refs.dialogColumn.columnBox = false;
- }
- },
- async resetColumn() {
- this.option = option;
- const inSave = await this.delColumnData(this.getColumnName(50), option);
- if (inSave) {
- this.$message.success("重置成功");
- this.$refs.crud.$refs.dialogColumn.columnBox = false;
- }
- }
- }
- };
- </script>
- <style scoped>
- ::v-deep .select-component {
- display: flex;
- }
- .page-crad ::v-deep .basic-container__card {
- height: 94.2vh;
- }
- .excelUpload ::v-deep .el-upload-list {
- display: none;
- }
- </style>
|