index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <!-- 货物 -->
  2. <template>
  3. <basic-container>
  4. <avue-crud :option="option"
  5. :table-loading="loading"
  6. :data="data"
  7. :page.sync="page"
  8. :permission="permissionList"
  9. id="out-table"
  10. :header-cell-class-name="headerClassName"
  11. :before-open="beforeOpen"
  12. v-model="form"
  13. ref="crud"
  14. @row-update="rowUpdate"
  15. @row-save="rowSave"
  16. @row-del="rowDel"
  17. @search-change="searchChange"
  18. @search-reset="searchReset"
  19. @selection-change="selectionChange"
  20. @current-change="currentChange"
  21. @size-change="sizeChange"
  22. @refresh-change="refreshChange"
  23. @resetColumn="resetColumnTwo('crud', 'option', 'optionBack', 290)"
  24. @saveColumn="saveColumnTwo('crud', 'option', 'optionBack', 290)"
  25. @on-load="onLoad">
  26. <template slot="remarks" slot-scope="scope">
  27. <avue-text-ellipsis :text="scope.row.remarks" :height="30" use-tooltip placement="top">
  28. <small slot="more">...</small>
  29. </avue-text-ellipsis>
  30. </template>
  31. <template slot="menuLeft">
  32. <el-button type="danger"
  33. size="small"
  34. icon="el-icon-delete"
  35. plain
  36. @click="handleDelete">删 除
  37. </el-button>
  38. </template>
  39. <template slot="unitNoForm">
  40. <search-query ref="SearchQuery"
  41. :datalist="unitNoData"
  42. title="计量单位"
  43. :filterable="true"
  44. :clearable="true"
  45. :remote="true"
  46. :forParameter="{key:'id',label:'cnName',value:'cnName'}"
  47. @remoteMethod="getBunitsListfun" @corpChange="corpChange" >
  48. <bunits @selectionChange="selectionBunits"></bunits>
  49. </search-query>
  50. </template>
  51. </avue-crud>
  52. </basic-container>
  53. </template>
  54. <script>
  55. import {bcommodityList, bcommodityDetail, bcommoditySubmit, bcommodityRemove} from "@/api/iosBasicData/bcommodity";
  56. import {mapGetters} from "vuex";
  57. import SearchQuery from '@/components/iosbasic-data/searchquery.vue'
  58. import bunits from '@/views/iosBasicData/bunits/index.vue'
  59. import {getBunitsList} from "@/api/iosBasicData/bunits";
  60. export default {
  61. data() {
  62. return {
  63. // 计算单位请求到的数据
  64. unitNoData:[],
  65. form: {},
  66. query: {},
  67. loading: true,
  68. page: {
  69. pageSize: 10,
  70. currentPage: 1,
  71. total: 0
  72. },
  73. selectionList: [],
  74. option:{},
  75. optionBack: {
  76. height:'auto',
  77. stripe: true,
  78. calcHeight: 30,
  79. labelWidth:100,
  80. tip: false,
  81. searchShow: true,
  82. searchMenuSpan: 6,
  83. border: true,
  84. index: true,
  85. viewBtn: true,
  86. selection: true,
  87. dialogClickModal: false,
  88. column: [
  89. {
  90. label: "HS CODE",
  91. prop: "hsCode",
  92. search: true,
  93. rules: [{
  94. required: true,
  95. message: "请输入HS CODE(The Harmonization System Code)",
  96. trigger: "blur"
  97. }]
  98. },
  99. {
  100. label: "中文名称",
  101. prop: "cnName",
  102. search: true,
  103. rules: [{
  104. required: true,
  105. message: "请输入中文名称",
  106. trigger: "blur"
  107. }]
  108. },
  109. {
  110. label: "英文名称",
  111. prop: "enName",
  112. search: true,
  113. rules: [{
  114. required: true,
  115. message: "请输入英文名称",
  116. trigger: "blur"
  117. }]
  118. },
  119. {
  120. label: "计量单位",
  121. prop: "unitNo",
  122. formslot:true,
  123. type:'select',
  124. clearable:false,
  125. dicData:[],
  126. rules: [{
  127. required: true,
  128. message: "请输入计量单位",
  129. trigger: "blur"
  130. }]
  131. },
  132. {
  133. label: "NCM CODE",
  134. prop: "ncmCode",
  135. width:100,
  136. },
  137. {
  138. label: "版本",
  139. prop: "version",
  140. hide:true,
  141. display:false,
  142. },
  143. {
  144. label: "状态",
  145. prop: "status",
  146. type:'select',
  147. dicData:[{
  148. label:'正常',
  149. value:0
  150. },{
  151. label:'停用',
  152. value:1
  153. }],
  154. },
  155. {
  156. label: "是否已删除(0 否 1是)",
  157. prop: "isDeleted",
  158. hide:true,
  159. display:false,
  160. },
  161. {
  162. label: "主键",
  163. prop: "id",
  164. hide:true,
  165. display:false,
  166. },
  167. {
  168. label: "创建人 Id",
  169. prop: "createUser",
  170. hide:true,
  171. display:false,
  172. },
  173. {
  174. label: "创建人",
  175. prop: "createUserName",
  176. display:false,
  177. },
  178. {
  179. label: "创建部门 Id",
  180. prop: "createDept",
  181. hide:true,
  182. display:false,
  183. },
  184. {
  185. label: "创建部门",
  186. prop: "createDeptName",
  187. display:false,
  188. },
  189. {
  190. label: "创建时间",
  191. prop: "createTime",
  192. width: 160,
  193. display:false,
  194. },
  195. {
  196. label: "修改人 Id",
  197. prop: "updateUser",
  198. hide:true,
  199. display:false,
  200. },
  201. {
  202. label: "修改人",
  203. prop: "updateUserName",
  204. display:false,
  205. },
  206. {
  207. label: "修改时间",
  208. prop: "updateTime",
  209. display:false,
  210. },
  211. {
  212. label: "备注",
  213. prop: "remarks",
  214. type: 'textarea',
  215. width: "180",
  216. slot: true,
  217. span: 24,
  218. minRows: 3,
  219. },
  220. ]
  221. },
  222. data: []
  223. };
  224. },
  225. components:{
  226. SearchQuery,
  227. bunits
  228. },
  229. computed: {
  230. ...mapGetters(["permission"]),
  231. permissionList() {
  232. return {
  233. // addBtn: this.vaildData(this.permission.bcommodity_add, false),
  234. // viewBtn: this.vaildData(this.permission.bcommodity_view, false),
  235. // delBtn: this.vaildData(this.permission.bcommodity_delete, false),
  236. // editBtn: this.vaildData(this.permission.bcommodity_edit, false)
  237. };
  238. },
  239. ids() {
  240. let ids = [];
  241. this.selectionList.forEach(ele => {
  242. ids.push(ele.id);
  243. });
  244. return ids.join(",");
  245. }
  246. },
  247. async created() {
  248. this.option = await this.getColumnData(this.getColumnName(290), this.optionBack);
  249. // 获取计算单位数据
  250. this.getBunitsListfun()
  251. },
  252. methods: {
  253. // 获取计算单位数据
  254. getBunitsListfun(cnName){
  255. getBunitsList(1, 10,{cnName}).then(res=>{
  256. this.unitNoData = res.data.data.records
  257. })
  258. },
  259. // 计量单位选中的回调
  260. corpChange(value){
  261. this.form.unitNo = value
  262. // for(let item of this.unitNoData) {
  263. // if (item.id == value) {
  264. // this.form.unitNo = item.cnName
  265. // }
  266. // }
  267. },
  268. // 表格组件抛出的选择数据
  269. selectionBunits(list){
  270. console.log(list,271)
  271. },
  272. rowSave(row, done, loading) {
  273. bcommoditySubmit(row).then(() => {
  274. this.onLoad(this.page);
  275. this.$message({
  276. type: "success",
  277. message: "操作成功!"
  278. });
  279. done();
  280. }, error => {
  281. loading();
  282. window.console.log(error);
  283. });
  284. },
  285. rowUpdate(row, index, done, loading) {
  286. bcommoditySubmit(row).then(() => {
  287. this.onLoad(this.page);
  288. this.$message({
  289. type: "success",
  290. message: "操作成功!"
  291. });
  292. done();
  293. }, error => {
  294. loading();
  295. console.log(error);
  296. });
  297. },
  298. rowDel(row) {
  299. this.$confirm("确定将选择数据删除?", {
  300. confirmButtonText: "确定",
  301. cancelButtonText: "取消",
  302. type: "warning"
  303. })
  304. .then(() => {
  305. return bcommodityRemove(row.id);
  306. })
  307. .then(() => {
  308. this.onLoad(this.page);
  309. this.$message({
  310. type: "success",
  311. message: "操作成功!"
  312. });
  313. });
  314. },
  315. handleDelete() {
  316. if (this.selectionList.length === 0) {
  317. this.$message.warning("请选择至少一条数据");
  318. return;
  319. }
  320. this.$confirm("确定将选择数据删除?", {
  321. confirmButtonText: "确定",
  322. cancelButtonText: "取消",
  323. type: "warning"
  324. })
  325. .then(() => {
  326. return bcommodityRemove(this.ids);
  327. })
  328. .then(() => {
  329. this.onLoad(this.page);
  330. this.$message({
  331. type: "success",
  332. message: "操作成功!"
  333. });
  334. this.$refs.crud.toggleSelection();
  335. });
  336. },
  337. beforeOpen(done, type) {
  338. if (["edit", "view"].includes(type)) {
  339. bcommodityDetail(this.form.id).then(res => {
  340. this.form = res.data.data;
  341. // 获取插槽数据
  342. this.$nextTick(()=>{
  343. console.log(this.$refs.SearchQuery.selectValue)
  344. this.$refs.SearchQuery.selectValue = this.form.unitNo
  345. })
  346. });
  347. }
  348. done();
  349. },
  350. searchReset() {
  351. this.query = {};
  352. this.onLoad(this.page);
  353. },
  354. searchChange(params, done) {
  355. this.query = params;
  356. this.page.currentPage = 1;
  357. this.onLoad(this.page, params);
  358. done();
  359. },
  360. selectionChange(list) {
  361. this.selectionList = list;
  362. },
  363. selectionClear() {
  364. this.selectionList = [];
  365. this.$refs.crud.toggleSelection();
  366. },
  367. currentChange(currentPage){
  368. this.page.currentPage = currentPage;
  369. },
  370. sizeChange(pageSize){
  371. this.page.pageSize = pageSize;
  372. },
  373. refreshChange() {
  374. this.onLoad(this.page, this.query);
  375. },
  376. onLoad(page, params = {}) {
  377. this.loading = true;
  378. bcommodityList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  379. const data = res.data.data;
  380. this.page.total = data.total;
  381. this.data = data.records;
  382. this.loading = false;
  383. this.selectionClear();
  384. });
  385. },
  386. //自定义列保存
  387. async saveColumnTwo(ref, option, optionBack, code) {
  388. /**
  389. * 已定义全局方法,直接使用,saveColumnData保存列数据方法,参数传值(表格名称,当前表格的option数据)
  390. * 已定义全局方法,直接使用,getColumnName方法用来获取枚举值,参数根据自己定义的code值获取中文名
  391. * 一定要执行异步操作,要等接口成功返回,才能执行下一行代码
  392. */
  393. const inSave = await this.saveColumnData(this.getColumnName(code), this[option]);
  394. if (inSave) {
  395. this.$message.success("保存成功");
  396. //关闭窗口
  397. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  398. }
  399. },
  400. //自定义列重置
  401. async resetColumnTwo(ref, option, optionBack, code) {
  402. this[option] = this[optionBack];
  403. const inSave = await this.delColumnData(this.getColumnName(code), this[optionBack]);
  404. if (inSave) {
  405. this.$message.success("重置成功");
  406. this.$refs[ref].$refs.dialogColumn.columnBox = false;
  407. }
  408. },
  409. // 更改表格颜色
  410. headerClassName(tab){
  411. //颜色间隔
  412. let back = ""
  413. if (tab.columnIndex >= 0 && tab.column.level === 1) {
  414. if (tab.columnIndex % 2 === 0) {
  415. back = "back-one"
  416. } else if (tab.columnIndex % 2 === 1) {
  417. back = "back-two"
  418. }
  419. }
  420. return back;
  421. },
  422. }
  423. };
  424. </script>
  425. <style lang="scss" scoped>
  426. ::v-deep#out-table .back-one {
  427. background: #ecf5ff !important;
  428. }
  429. ::v-deep#out-table .back-two {
  430. background: #ecf5ff !important;
  431. }
  432. /deep/ .el-col-md-8 {
  433. width: 24.33333%;
  434. }
  435. </style>