index.vue 14 KB

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