index.vue 14 KB

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