index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. <template>
  2. <div>
  3. <basic-container class="page-crad">
  4. <avue-crud
  5. ref="crud"
  6. :option="option"
  7. :data="dataList"
  8. v-model="form"
  9. :page.sync="page"
  10. :search.sync="search"
  11. @search-change="searchChange"
  12. @current-change="currentChange"
  13. @resetColumn="resetColumn"
  14. @size-change="sizeChange"
  15. @refresh-change="refreshChange"
  16. @on-load="onLoad"
  17. :table-loading="loading"
  18. @saveColumn="saveColumn"
  19. :cell-style="cellStyle"
  20. :summary-method="summaryMethod"
  21. @search-criteria-switch="searchCriteriaSwitch"
  22. >
  23. <template slot="menuLeft">
  24. <el-button
  25. type="primary"
  26. icon="el-icon-plus"
  27. size="small"
  28. @click.stop="excelBox = !excelBox"
  29. >导入</el-button
  30. >
  31. <el-button
  32. type="success"
  33. icon="el-icon-upload2"
  34. size="small"
  35. @click="derivation()"
  36. >下载模板
  37. </el-button>
  38. <el-button type="info" size="small">报表</el-button>
  39. </template>
  40. <template slot="cnameSearch">
  41. <goods-select
  42. v-model="search.cname"
  43. :configuration="goodsConfiguration"
  44. />
  45. </template>
  46. <template slot="priorityReferrer" slot-scope="{ row }">
  47. <el-checkbox
  48. :disabled="!row.$cellEdit"
  49. v-model="row.priorityReferrer"
  50. :true-label="1"
  51. :false-label="0"
  52. />
  53. </template>
  54. <template slot="corpIdSearch">
  55. <crop-select v-model="search.corpId" corpType="GYS"></crop-select>
  56. </template>
  57. <template slot="dateValiditySearch">
  58. <el-date-picker
  59. v-model="search.dateValidity"
  60. type="daterange"
  61. start-placeholder="开始日期"
  62. end-placeholder="结束日期"
  63. format="yyyy-MM-dd"
  64. value-format="yyyy-MM-dd HH:mm:ss"
  65. :default-time="['00:00:00', '23:59:59']"
  66. >
  67. </el-date-picker>
  68. </template>
  69. <template slot-scope="{ row }" slot="corpId">
  70. {{ row.corpName }}
  71. </template>
  72. <template slot-scope="{ row }" slot="grossProfitRate">
  73. {{ row.grossProfitRate ? scope.row.grossProfitRate : 0 }}%
  74. </template>
  75. <template slot-scope="{ row }" slot="status">
  76. {{ row.status | orderStateFormat }}
  77. </template>
  78. <template slot-scope="{ row }" slot="ename">
  79. <el-input
  80. v-if="row.$cellEdit"
  81. v-model="row.ename"
  82. size="small"
  83. ></el-input>
  84. <span v-else>{{ row.ename }}</span>
  85. </template>
  86. <template slot-scope="{ row }" slot="coefficient">
  87. <el-input
  88. v-if="row.$cellEdit"
  89. v-model="row.coefficient"
  90. size="small"
  91. oninput="value=value.replace(/[^0-9.]/g,'').replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3')"
  92. @change="priceChange(row)"
  93. ></el-input>
  94. <span v-else>{{ row.coefficient }}</span>
  95. </template>
  96. <template slot-scope="{ row }" slot="price">
  97. <el-input
  98. v-if="row.$cellEdit"
  99. v-model="row.price"
  100. size="small"
  101. oninput="value=value.replace(/[^0-9.]/g,'').replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3')"
  102. @change="priceChange(row)"
  103. ></el-input>
  104. <span v-else>{{ row.price }}</span>
  105. </template>
  106. <template slot-scope="{ row }" slot="endTime">
  107. <el-date-picker
  108. v-if="row.$cellEdit"
  109. format="yyyy-MM-dd"
  110. value-format="yyyy-MM-dd 00:00:00"
  111. v-model="row.endTime"
  112. type="date"
  113. placeholder="选择日期"
  114. ></el-date-picker>
  115. <span v-else v-html="$options.filters.endTimeFormat(row.endTime)" />
  116. </template>
  117. <template slot-scope="{ row }" slot="currency">
  118. <el-select
  119. size="small"
  120. v-model="row.currency"
  121. placeholder="请选择"
  122. @change="currencyChange(row)"
  123. v-if="row.$cellEdit"
  124. >
  125. <el-option
  126. v-for="item in currencyList"
  127. :key="item.id"
  128. :label="item.dictValue"
  129. :value="item.dictValue"
  130. >
  131. </el-option>
  132. </el-select>
  133. <span v-else>{{ row.currency }}</span>
  134. </template>
  135. <template slot-scope="{ row }" slot="taxRate">
  136. <el-input
  137. v-if="row.$cellEdit"
  138. v-model="row.taxRate"
  139. size="small"
  140. oninput="value=value.replace(/[^0-9.]/g,'').replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3')"
  141. @change="priceChange(row)"
  142. ></el-input>
  143. <span v-else>{{ row.taxRate | taxRateFormat }}</span>
  144. </template>
  145. <template slot-scope="{ row, index }" slot="menu">
  146. <el-button
  147. type="text"
  148. icon="el-icon-edit"
  149. size="small"
  150. @click.stop="editOpen(row, index)"
  151. >{{ row.$cellEdit ? "保存" : "修改" }}
  152. </el-button>
  153. <el-button
  154. type="text"
  155. icon="el-icon-delete"
  156. size="small"
  157. @click.stop="rowDel(row, index)"
  158. >删除
  159. </el-button>
  160. </template>
  161. </avue-crud>
  162. <el-dialog
  163. title="导入价格"
  164. append-to-body
  165. :visible.sync="excelBox"
  166. width="555px"
  167. >
  168. <avue-form
  169. :option="excelOption"
  170. v-model="excelForm"
  171. :upload-after="uploadAfter"
  172. class="excelUpload"
  173. />
  174. </el-dialog>
  175. </basic-container>
  176. </div>
  177. </template>
  178. <script>
  179. import option from "./config/mainList.json";
  180. import { getToken } from "@/util/auth";
  181. import {
  182. getList,
  183. remove,
  184. getGoodstype,
  185. submit
  186. } from "@/api/maintenance/priceLibrary";
  187. import { micrometerFormat } from "@/util/validate";
  188. import { orderStateFormat } from "@/enums/order-stauts";
  189. import { taxRateFormat } from "@/enums/tax-rate";
  190. import { purchaseCal } from "@/util/calculate";
  191. import _ from "lodash";
  192. export default {
  193. name: "customerInformation",
  194. data() {
  195. return {
  196. excelOption: {
  197. submitBtn: false,
  198. emptyBtn: false,
  199. column: [
  200. {
  201. label: "导入数据",
  202. prop: "excelFile",
  203. type: "upload",
  204. drag: true,
  205. loadText: "导入数据中,请稍等",
  206. span: 24,
  207. propsHttp: {
  208. res: "data"
  209. },
  210. tip: "请上传 .xls,.xlsx 标准格式文件",
  211. action: "/api/blade-mocha-item/pricebank/importPrice"
  212. }
  213. ]
  214. },
  215. excelBox: false,
  216. excelForm: {},
  217. goodsConfiguration: {
  218. multipleChoices: false,
  219. multiple: false,
  220. collapseTags: false,
  221. placeholder: "请点击右边按钮选择",
  222. dicData: [],
  223. clearable: true
  224. },
  225. configuration: {
  226. multipleChoices: false,
  227. multiple: false,
  228. collapseTags: false,
  229. placeholder: "请点击右边按钮选择",
  230. dicData: [],
  231. clearable: true
  232. },
  233. search: {},
  234. form: {},
  235. option: {},
  236. parentId: 0,
  237. dataList: [],
  238. page: {
  239. pageSize: 10,
  240. currentPage: 1,
  241. total: 0,
  242. pageSizes: [10, 50, 100, 200, 300, 400, 500]
  243. },
  244. detailData: {},
  245. loading: false,
  246. currencyList: []
  247. };
  248. },
  249. async created() {
  250. /**
  251. * 已定义全局方法,直接使用,getColumnData获取列数据,参数传值(表格名称,引入的本地JSON的数据定义的名称)
  252. * 已定义全局方法,直接使用,getColumnName方法用来获取枚举值,参数根据自己定义的code值获取中文名
  253. * 一定要执行异步操作,要等接口成功返回,才能执行下一行代码
  254. */
  255. this.option = await this.getColumnData(this.getColumnName(50), option);
  256. this.getWorkDicts("billType").then(res => {
  257. this.findObject(this.option.column, "billType").dicData = res.data.data;
  258. });
  259. getGoodstype(1, 500).then(res => {
  260. this.findObject(this.option.column, "goodsTypeName").dicData =
  261. res.data.data.records;
  262. });
  263. this.getWorkDicts("price_library_currency").then(res => {
  264. this.currencyList = res.data.data;
  265. });
  266. this.option.height = window.innerHeight - 210;
  267. },
  268. filters: {
  269. orderStateFormat(val) {
  270. return orderStateFormat(val);
  271. },
  272. taxRateFormat(val) {
  273. return taxRateFormat(val);
  274. },
  275. endTimeFormat(time) {
  276. const today = new Date();
  277. const endTime = new Date(time);
  278. const curretMonth = new Date(
  279. today.getFullYear(),
  280. today.getMonth() + 1,
  281. 0
  282. );
  283. const curretMonthDayCount = curretMonth.getDate();
  284. const dateDiff = endTime.getTime() - today.getTime(); //时间差的毫秒数
  285. const dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000)); //计算出相差天数
  286. if (dayDiff < 0) {
  287. time = '<span style="color:red">' + time + "</span>";
  288. } else if (dayDiff >= 0 && dayDiff < curretMonthDayCount) {
  289. time = '<span style="color:#9ACD32">' + time + "</span>";
  290. }
  291. return time;
  292. }
  293. },
  294. methods: {
  295. searchCriteriaSwitch(type) {
  296. if (type) {
  297. this.option.height = this.option.height - 93;
  298. } else {
  299. this.option.height = this.option.height + 93;
  300. }
  301. this.$refs.crud.getTableHeight();
  302. },
  303. cellStyle() {
  304. return "padding:0;height:40px;";
  305. },
  306. priceChange(row) {
  307. row.purchaseAmount = purchaseCal(row.price, row.taxRate, row.coefficient);
  308. },
  309. uploadAfter(res, done, loading, column) {
  310. if (res != "导入成功") {
  311. this.$message.error(res);
  312. }
  313. this.excelBox = false;
  314. this.page.currentPage = 1;
  315. this.onLoad(this.page);
  316. loading();
  317. done();
  318. },
  319. derivation() {
  320. this.$confirm("是否下载模板?", "提示", {
  321. confirmButtonText: "确定",
  322. cancelButtonText: "取消",
  323. type: "warning"
  324. }).then(() => {
  325. window.open(
  326. `/api/blade-mocha-item/pricebank/exportPrice?${
  327. this.website.tokenHeader
  328. }=${getToken()}`
  329. );
  330. });
  331. },
  332. currencyChange(row) {
  333. this.currencyList.forEach(e => {
  334. if (e.dictValue == row.currency) {
  335. row.exchangeRate = e.remark;
  336. }
  337. });
  338. },
  339. //删除列表后面的删除按钮触发触发(row, index, done)
  340. rowDel(row, index, done) {
  341. this.$confirm("确定删除数据?", {
  342. confirmButtonText: "确定",
  343. cancelButtonText: "取消",
  344. type: "warning"
  345. }).then(() => {
  346. remove(row.id).then(res => {
  347. if (res.data.code == 200) {
  348. this.$message({
  349. type: "success",
  350. message: "删除成功!"
  351. });
  352. this.onLoad(this.page, this.search);
  353. }
  354. });
  355. });
  356. },
  357. editOpen(row, index) {
  358. if (row.$cellEdit == true) {
  359. submit({ ...row, tradeType: "CK" }).then(res => {
  360. this.onLoad(this.page, this.search);
  361. this.$set(row, "$cellEdit", false);
  362. });
  363. } else {
  364. this.$set(row, "$cellEdit", true);
  365. }
  366. },
  367. //点击搜索按钮触发
  368. searchChange(params, done) {
  369. if (params.dateValidity) {
  370. params.dateValidityStart = params.dateValidity[0];
  371. params.dateValidityEnd = params.dateValidity[1];
  372. }
  373. delete params.dateValidity;
  374. this.onLoad(this.page, params);
  375. done();
  376. },
  377. currentChange(val) {
  378. this.page.currentPage = val;
  379. },
  380. sizeChange(val) {
  381. this.page.currentPage = 1;
  382. this.page.pageSize = val;
  383. },
  384. onLoad(page, params = {}) {
  385. params = {
  386. ...params,
  387. tradeType: "CK"
  388. };
  389. this.loading = true;
  390. getList(
  391. page.currentPage,
  392. page.pageSize,
  393. Object.assign(params, this.search)
  394. )
  395. .then(res => {
  396. // if (res.data.data.records) {
  397. // res.data.data.records.forEach(e => {
  398. // });
  399. // }
  400. this.dataList = res.data.data.records ? res.data.data.records : [];
  401. this.page.total = res.data.data.total;
  402. })
  403. .finally(() => {
  404. this.loading = false;
  405. });
  406. },
  407. summaryMethod({ columns, data }) {
  408. const sums = [];
  409. if (columns.length > 0) {
  410. columns.forEach((item, index) => {
  411. sums[0] = "合计";
  412. if (item.property == "price" || item.property == "purchaseAmount") {
  413. let priceSum = 0;
  414. let amountSum = 0;
  415. data.forEach(e => {
  416. priceSum = _.add(priceSum, Number(e.price));
  417. amountSum = _.add(amountSum, Number(e.purchaseAmount));
  418. });
  419. //最新价格
  420. if (item.property == "price") {
  421. sums[index] = micrometerFormat(priceSum);
  422. }
  423. //采购价格
  424. if (item.property == "purchaseAmount") {
  425. sums[index] = micrometerFormat(amountSum);
  426. }
  427. }
  428. });
  429. }
  430. return sums;
  431. },
  432. refreshChange() {
  433. this.onLoad(this.page, this.search);
  434. },
  435. async saveColumn() {
  436. const inSave = await this.saveColumnData(
  437. this.getColumnName(50),
  438. this.option
  439. );
  440. if (inSave) {
  441. this.$message.success("保存成功");
  442. //关闭窗口
  443. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  444. }
  445. },
  446. async resetColumn() {
  447. this.option = option;
  448. const inSave = await this.delColumnData(this.getColumnName(50), option);
  449. if (inSave) {
  450. this.$message.success("重置成功");
  451. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  452. }
  453. }
  454. }
  455. };
  456. </script>
  457. <style scoped>
  458. ::v-deep .select-component {
  459. display: flex;
  460. }
  461. .page-crad ::v-deep .basic-container__card {
  462. height: 94.2vh;
  463. }
  464. .excelUpload ::v-deep .el-upload-list {
  465. display: none;
  466. }
  467. </style>