index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  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. v-if="permission.priceLibrary_edit"
  151. @click.stop="editOpen(row, index)"
  152. >{{ row.$cellEdit ? "保存" : "修改" }}
  153. </el-button>
  154. <el-button
  155. type="text"
  156. icon="el-icon-delete"
  157. size="small"
  158. v-if="permission.priceLibrary_delete"
  159. @click.stop="rowDel(row, index)"
  160. >删除
  161. </el-button>
  162. </template>
  163. </avue-crud>
  164. <el-dialog
  165. title="导入价格"
  166. append-to-body
  167. :visible.sync="excelBox"
  168. width="555px"
  169. >
  170. <avue-form
  171. :option="excelOption"
  172. v-model="excelForm"
  173. :upload-after="uploadAfter"
  174. class="excelUpload"
  175. />
  176. </el-dialog>
  177. </basic-container>
  178. </div>
  179. </template>
  180. <script>
  181. import option from "./config/mainList.json";
  182. import { getToken } from "@/util/auth";
  183. import {
  184. getList,
  185. remove,
  186. getGoodstype,
  187. submit
  188. } from "@/api/maintenance/priceLibrary";
  189. import { micrometerFormat } from "@/util/validate";
  190. import { orderStateFormat } from "@/enums/order-stauts";
  191. import { taxRateFormat } from "@/enums/tax-rate";
  192. import { purchaseCal } from "@/util/calculate";
  193. import {mapGetters} from "vuex";
  194. import _ from "lodash";
  195. export default {
  196. name: "customerInformation",
  197. data() {
  198. return {
  199. excelOption: {
  200. submitBtn: false,
  201. emptyBtn: false,
  202. column: [
  203. {
  204. label: "导入数据",
  205. prop: "excelFile",
  206. type: "upload",
  207. drag: true,
  208. loadText: "导入数据中,请稍等",
  209. span: 24,
  210. propsHttp: {
  211. res: "data"
  212. },
  213. tip: "请上传 .xls,.xlsx 标准格式文件",
  214. action: "/api/blade-mocha-item/pricebank/importPrice"
  215. }
  216. ]
  217. },
  218. excelBox: false,
  219. excelForm: {},
  220. goodsConfiguration: {
  221. multipleChoices: false,
  222. multiple: false,
  223. collapseTags: false,
  224. placeholder: "请点击右边按钮选择",
  225. dicData: [],
  226. clearable: true
  227. },
  228. configuration: {
  229. multipleChoices: false,
  230. multiple: false,
  231. collapseTags: false,
  232. placeholder: "请点击右边按钮选择",
  233. dicData: [],
  234. clearable: true
  235. },
  236. search: {},
  237. form: {},
  238. option: {},
  239. parentId: 0,
  240. dataList: [],
  241. page: {
  242. pageSize: 10,
  243. currentPage: 1,
  244. total: 0,
  245. pageSizes: [10, 50, 100, 200, 300, 400, 500]
  246. },
  247. detailData: {},
  248. loading: false,
  249. currencyList: []
  250. };
  251. },
  252. async created() {
  253. /**
  254. * 已定义全局方法,直接使用,getColumnData获取列数据,参数传值(表格名称,引入的本地JSON的数据定义的名称)
  255. * 已定义全局方法,直接使用,getColumnName方法用来获取枚举值,参数根据自己定义的code值获取中文名
  256. * 一定要执行异步操作,要等接口成功返回,才能执行下一行代码
  257. */
  258. this.option = await this.getColumnData(this.getColumnName(50), option);
  259. this.getWorkDicts("billType").then(res => {
  260. this.findObject(this.option.column, "billType").dicData = res.data.data;
  261. });
  262. getGoodstype(1, 500).then(res => {
  263. this.findObject(this.option.column, "goodsTypeName").dicData =
  264. res.data.data.records;
  265. });
  266. this.getWorkDicts("price_library_currency").then(res => {
  267. this.currencyList = res.data.data;
  268. });
  269. this.option.height = window.innerHeight - 210;
  270. },
  271. filters: {
  272. orderStateFormat(val) {
  273. return orderStateFormat(val);
  274. },
  275. taxRateFormat(val) {
  276. return taxRateFormat(val);
  277. },
  278. endTimeFormat(time) {
  279. const today = new Date();
  280. const endTime = new Date(time);
  281. const curretMonth = new Date(
  282. today.getFullYear(),
  283. today.getMonth() + 1,
  284. 0
  285. );
  286. const curretMonthDayCount = curretMonth.getDate();
  287. const dateDiff = endTime.getTime() - today.getTime(); //时间差的毫秒数
  288. const dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000)); //计算出相差天数
  289. if (dayDiff < 0) {
  290. time = '<span style="color:red">' + time + "</span>";
  291. } else if (dayDiff >= 0 && dayDiff < curretMonthDayCount) {
  292. time = '<span style="color:#9ACD32">' + time + "</span>";
  293. }
  294. return time;
  295. }
  296. },
  297. methods: {
  298. searchCriteriaSwitch(type) {
  299. if (type) {
  300. this.option.height = this.option.height - 93;
  301. } else {
  302. this.option.height = this.option.height + 93;
  303. }
  304. this.$refs.crud.getTableHeight();
  305. },
  306. cellStyle() {
  307. return "padding:0;height:40px;";
  308. },
  309. priceChange(row) {
  310. row.purchaseAmount = purchaseCal(row.price, row.taxRate, row.coefficient);
  311. },
  312. uploadAfter(res, done, loading, column) {
  313. if (res != "导入成功") {
  314. this.$message.error(res);
  315. }
  316. this.excelBox = false;
  317. this.page.currentPage = 1;
  318. this.onLoad(this.page);
  319. loading();
  320. done();
  321. },
  322. derivation() {
  323. this.$confirm("是否下载模板?", "提示", {
  324. confirmButtonText: "确定",
  325. cancelButtonText: "取消",
  326. type: "warning"
  327. }).then(() => {
  328. window.open(
  329. `/api/blade-mocha-item/pricebank/exportPrice?${
  330. this.website.tokenHeader
  331. }=${getToken()}`
  332. );
  333. });
  334. },
  335. currencyChange(row) {
  336. this.currencyList.forEach(e => {
  337. if (e.dictValue == row.currency) {
  338. row.exchangeRate = e.remark;
  339. }
  340. });
  341. },
  342. //删除列表后面的删除按钮触发触发(row, index, done)
  343. rowDel(row, index, done) {
  344. this.$confirm("确定删除数据?", {
  345. confirmButtonText: "确定",
  346. cancelButtonText: "取消",
  347. type: "warning"
  348. }).then(() => {
  349. remove(row.id).then(res => {
  350. if (res.data.code == 200) {
  351. this.$message({
  352. type: "success",
  353. message: "删除成功!"
  354. });
  355. this.onLoad(this.page, this.search);
  356. }
  357. });
  358. });
  359. },
  360. editOpen(row, index) {
  361. if (row.$cellEdit == true) {
  362. submit({ ...row, tradeType: "CK" }).then(res => {
  363. this.onLoad(this.page, this.search);
  364. this.$set(row, "$cellEdit", false);
  365. });
  366. } else {
  367. this.$set(row, "$cellEdit", true);
  368. }
  369. },
  370. //点击搜索按钮触发
  371. searchChange(params, done) {
  372. if (params.dateValidity) {
  373. params.dateValidityStart = params.dateValidity[0];
  374. params.dateValidityEnd = params.dateValidity[1];
  375. }
  376. delete params.dateValidity;
  377. this.onLoad(this.page, params);
  378. done();
  379. },
  380. currentChange(val) {
  381. this.page.currentPage = val;
  382. },
  383. sizeChange(val) {
  384. this.page.currentPage = 1;
  385. this.page.pageSize = val;
  386. },
  387. onLoad(page, params = {}) {
  388. params = {
  389. ...params,
  390. tradeType: "CK"
  391. };
  392. this.loading = true;
  393. getList(
  394. page.currentPage,
  395. page.pageSize,
  396. Object.assign(params, this.search)
  397. )
  398. .then(res => {
  399. // if (res.data.data.records) {
  400. // res.data.data.records.forEach(e => {
  401. // });
  402. // }
  403. this.dataList = res.data.data.records ? res.data.data.records : [];
  404. this.page.total = res.data.data.total;
  405. })
  406. .finally(() => {
  407. this.loading = false;
  408. });
  409. },
  410. summaryMethod({ columns, data }) {
  411. const sums = [];
  412. if (columns.length > 0) {
  413. columns.forEach((item, index) => {
  414. sums[0] = "合计";
  415. if (item.property == "price" || item.property == "purchaseAmount") {
  416. let priceSum = 0;
  417. let amountSum = 0;
  418. data.forEach(e => {
  419. priceSum = _.add(priceSum, Number(e.price));
  420. amountSum = _.add(amountSum, Number(e.purchaseAmount));
  421. });
  422. //最新价格
  423. if (item.property == "price") {
  424. sums[index] = micrometerFormat(priceSum);
  425. }
  426. //采购价格
  427. if (item.property == "purchaseAmount") {
  428. sums[index] = micrometerFormat(amountSum);
  429. }
  430. }
  431. });
  432. }
  433. return sums;
  434. },
  435. refreshChange() {
  436. this.onLoad(this.page, this.search);
  437. },
  438. async saveColumn() {
  439. const inSave = await this.saveColumnData(
  440. this.getColumnName(50),
  441. this.option
  442. );
  443. if (inSave) {
  444. this.$message.success("保存成功");
  445. //关闭窗口
  446. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  447. }
  448. },
  449. async resetColumn() {
  450. this.option = option;
  451. const inSave = await this.delColumnData(this.getColumnName(50), option);
  452. if (inSave) {
  453. this.$message.success("重置成功");
  454. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  455. }
  456. }
  457. },
  458. computed: {
  459. ...mapGetters(["permission"])
  460. }
  461. };
  462. </script>
  463. <style scoped>
  464. ::v-deep .select-component {
  465. display: flex;
  466. }
  467. .page-crad ::v-deep .basic-container__card {
  468. height: 94.2vh;
  469. }
  470. .excelUpload ::v-deep .el-upload-list {
  471. display: none;
  472. }
  473. </style>