index.vue 11 KB

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