index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. <template>
  2. <div class="my-container">
  3. <div class="bill-main" v-show="isShow==='home'" key="index">
  4. <module-view :propConfig="config" ref="moduleView" @pagination="getDataList" @search="getDataList"
  5. @resert="onRefresh" @detail="openEdit" @onRefresh="onRefresh">
  6. </module-view>
  7. </div>
  8. <!-- 新增/编辑弹窗 -->
  9. <div class="detail" v-show="isShow==='detail'" key="index2">
  10. <by-tool :propConfig="toolConfig" @clickHandle="insideTools" />
  11. <div class="box-shadow" style="height: 100%;">
  12. <by-table :propConfig="skuConfig" @onChangeRow="getInputValue" ref="addFormId"></by-table>
  13. </div>
  14. </div>
  15. </div>
  16. </template>
  17. <script lang="ts">
  18. import { Component, Prop, Vue, Watch } from "vue-property-decorator";
  19. import api from "@/api/currency";
  20. import ForTab from "@/components/ForTab/index.vue";
  21. @Component({ components: { ForTab } })
  22. export default class Sku extends Vue {
  23. // 右边
  24. isShow : any = 'home'
  25. timeNum = 0;
  26. calculateCount = 0;
  27. baseInfo : any = ''
  28. timer : any = null
  29. toolConfig = {
  30. tools: {
  31. return: true,
  32. save: true,
  33. },
  34. customTools: [
  35. {
  36. name: '同步WMS', icon: 'el-icon-top', audit: [''], event: {
  37. click: () => {
  38. (this as any).syncSystem2()
  39. }
  40. }
  41. },
  42. ]
  43. }
  44. skuConfig : any = {
  45. attr: {
  46. size: 'mini',
  47. align: 'left',
  48. editRules: {
  49. skuTitle: [
  50. { required: true, message: '请输入标题'}
  51. ],
  52. skuCode: [
  53. { required: true, message: '请输入物料编码'}
  54. ],
  55. barCode: [
  56. { required: true, message: '请输入69码-商品条码'}
  57. ]
  58. }
  59. },
  60. columns: [
  61. {
  62. width: '200px',
  63. title: '标题(必填项)',
  64. field: 'skuTitle',
  65. component: 'by-input',
  66. compConfig: {
  67. attr: {
  68. size: 'mini',
  69. placeholder: ' '
  70. },
  71. }
  72. },
  73. {
  74. width: '200px',
  75. title: '副标题',
  76. field: 'skuSubtitle',
  77. component: 'by-input',
  78. compConfig: {
  79. attr: {
  80. size: 'mini',
  81. placeholder: ' '
  82. },
  83. }
  84. },
  85. {
  86. width: '140px',
  87. title: '物料编码(必填项)',
  88. field: 'skuCode',
  89. component: 'by-input',
  90. compConfig: {
  91. attr: {
  92. size: 'mini',
  93. placeholder: ' '
  94. },
  95. }
  96. },
  97. {
  98. width: '110px',
  99. title: '69码-商品条码(必填项)',
  100. field: 'barCode',
  101. component: 'by-input',
  102. compConfig: {
  103. attr: {
  104. size: 'mini',
  105. placeholder: ' '
  106. },
  107. }
  108. },
  109. {
  110. width: '140px',
  111. title: '财务编号',
  112. field: 'financialCode',
  113. component: 'by-input',
  114. compConfig: {
  115. attr: {
  116. size: 'mini',
  117. placeholder: ' '
  118. },
  119. }
  120. },
  121. {
  122. width: '90px',
  123. title: '价格',
  124. field: 'price',
  125. component: 'by-input',
  126. compConfig: {
  127. attr: {
  128. size: 'mini',
  129. placeholder: ' ',
  130. type: "number",
  131. defaultValue: 0,
  132. min: 0
  133. },
  134. }
  135. },
  136. {
  137. width: '90px',
  138. title: '单位',
  139. field: 'unit',
  140. component: 'by-input',
  141. compConfig: {
  142. attr: {
  143. size: 'mini',
  144. placeholder: ' ',
  145. },
  146. }
  147. },
  148. {
  149. width: '90px',
  150. title: '单位编码',
  151. field: 'unitCode',
  152. component: 'by-input',
  153. compConfig: {
  154. attr: {
  155. size: 'mini',
  156. placeholder: ' ',
  157. },
  158. }
  159. },
  160. {
  161. width: '110px',
  162. title: '保质期(天)',
  163. field: 'shelfLife',
  164. component: 'by-input',
  165. compConfig: {
  166. attr: {
  167. size: 'mini',
  168. placeholder: ' ',
  169. type: "integer",
  170. min: 0
  171. },
  172. }
  173. },
  174. {
  175. width: '90px',
  176. title: '重量/g',
  177. field: 'weight',
  178. component: 'by-input',
  179. compConfig: {
  180. attr: {
  181. size: 'mini',
  182. placeholder: ' ',
  183. type: "number",
  184. min: 0
  185. },
  186. }
  187. },
  188. {
  189. width: '90px',
  190. title: '长/cm',
  191. field: 'length',
  192. component: 'by-input',
  193. compConfig: {
  194. attr: {
  195. size: 'mini',
  196. placeholder: ' ',
  197. type: "number",
  198. min: 0
  199. },
  200. }
  201. },
  202. {
  203. width: '90px',
  204. title: '宽/cm',
  205. field: 'width',
  206. component: 'by-input',
  207. compConfig: {
  208. attr: {
  209. size: 'mini',
  210. placeholder: ' ',
  211. type: "number",
  212. min: 0
  213. },
  214. }
  215. },
  216. {
  217. width: '90px',
  218. title: '高/cm',
  219. field: 'height',
  220. component: 'by-input',
  221. compConfig: {
  222. attr: {
  223. size: 'mini',
  224. placeholder: ' ',
  225. type: "number",
  226. min: 0
  227. },
  228. }
  229. },
  230. {
  231. // width: '90px',
  232. title: '体积/cm³',
  233. field: 'volume',
  234. },
  235. ]
  236. }
  237. config : any = {
  238. search: {
  239. attr: {
  240. size: 'mini',
  241. },
  242. columns: [
  243. [
  244. {
  245. span: 6,
  246. label: '物料编码',
  247. prop: 'skuCode',
  248. component: 'by-input',
  249. labelWidth: '70px',
  250. compConfig: {
  251. attr: {
  252. placeholder: '请输入物料编码',
  253. clearable: true
  254. }
  255. }
  256. },
  257. {
  258. span: 6,
  259. label: '财务编号',
  260. prop: 'accountingCode',
  261. component: 'by-input',
  262. compConfig: {
  263. attr: {
  264. placeholder: '请输入财务编号',
  265. clearable: true
  266. }
  267. }
  268. },
  269. {
  270. span: 6,
  271. label: '69码-商品条码',
  272. prop: 'barCode',
  273. labelWidth: '110px',
  274. component: 'by-input',
  275. compConfig: {
  276. attr: {
  277. placeholder: '69码-商品条码',
  278. clearable: true
  279. }
  280. }
  281. },
  282. ],
  283. ]
  284. },
  285. tool: {
  286. tools: {
  287. search: true,
  288. refresh: true,
  289. },
  290. customTools: [
  291. {
  292. name: '同步WMS', icon: 'el-icon-top', audit: [''], event: {
  293. click: () => {
  294. (this as any).syncSystem()
  295. }
  296. }
  297. },
  298. ]
  299. },
  300. table: {
  301. attr: {
  302. size: 'mini',
  303. align: 'left',
  304. height: '620',
  305. checkbox: true,
  306. triggerRowCheck:'row'
  307. },
  308. columns: [
  309. {
  310. width: '200px',
  311. title: '标题',
  312. field: 'skuTitle',
  313. isDetail: true,
  314. fixed: 'left'
  315. },
  316. {
  317. width: '200px',
  318. title: '副标题',
  319. field: 'skuSubtitle',
  320. },
  321. {
  322. width: '140px',
  323. title: '物料编码',
  324. field: 'skuCode',
  325. },
  326. {
  327. width: '140px',
  328. title: '69码-商品条码',
  329. field: 'barCode',
  330. },
  331. {
  332. width: '140px',
  333. title: '财务编号',
  334. field: 'financialCode',
  335. },
  336. {
  337. width: '80px',
  338. title: '价格',
  339. field: 'price',
  340. },
  341. {
  342. width: '80px',
  343. title: '单位',
  344. field: 'unit',
  345. },
  346. {
  347. width: '80px',
  348. title: '单位编码',
  349. field: 'unitCode',
  350. },
  351. {
  352. width: '100px',
  353. title: '保质期(天)',
  354. field: 'shelfLife',
  355. },
  356. {
  357. width: '80px',
  358. title: '重量/g',
  359. field: 'weight',
  360. },
  361. {
  362. width: '80px',
  363. title: '长/cm',
  364. field: 'length',
  365. },
  366. {
  367. width: '80px',
  368. title: '宽/cm',
  369. field: 'width',
  370. },
  371. {
  372. width: '80px',
  373. title: '高/cm',
  374. field: 'height',
  375. },
  376. {
  377. width: '90px',
  378. title: '体积/cm³',
  379. field: 'volume',
  380. },
  381. {
  382. width: 70,
  383. title: '操作',
  384. action: true,
  385. plugins: [{
  386. icon: 'el-icon-edit',
  387. name: '编辑',
  388. audit: '',
  389. event: {
  390. click: (item : any) => {
  391. (this as any).openEdit(item)
  392. }
  393. }
  394. }]
  395. },
  396. ]
  397. },
  398. }
  399. mounted() {
  400. this.timer = setInterval(() => {
  401. this.getDataList();
  402. this.initTable();
  403. }, 300)
  404. }
  405. // 计算高度
  406. initTable() {
  407. if (!this.$refs.moduleView) {
  408. this.calculateCount++;
  409. if (this.calculateCount > 5) return;
  410. setTimeout(() => {
  411. this.initTable()
  412. }, 500)
  413. return
  414. }
  415. let tableId : any = (this as any).$refs.moduleView.tableID;
  416. this.config.table.attr.height = window.innerHeight - 320;
  417. (this as any).$refs.moduleView.$refs[tableId].recalculate();
  418. }
  419. // 同步财务系统
  420. syncSystem() {
  421. let selectData = (this as any).$refs.moduleView.getSelectData();
  422. if (selectData.length > 0) {
  423. // if (selectData.length > 1) return this.$message.warning('只能同步一条数据');
  424. // if (selectData[0].financialCode) return this.$message.warning('此数据已同步WMS');
  425. this.$confirm('确定同步WMS吗', '注意', {
  426. confirmButtonText: '确定',
  427. cancelButtonText: '取消',
  428. type: 'warning',
  429. center: true
  430. }).then(() => {
  431. let ids = '';
  432. selectData.map((v : any) => {
  433. ids += v.id + ','
  434. })
  435. ids = ids.slice(0, ids.length - 1);
  436. let loading = this.$loading({ target: '.main-container' });
  437. api.WMSPushProducts({ ids: ids }).then((res : any) => {
  438. if (res.code === 200) {
  439. this.$message.success('同步WMS成功');
  440. loading.close();
  441. } else loading.close();
  442. }).catch(() => loading.close());
  443. }).catch(() => this.$message.info('已取消同步WMS'));
  444. } else this.$message.warning('请选择同步数据');
  445. }
  446. syncSystem2() {
  447. this.$confirm('确定同步WMS吗', '注意', {
  448. confirmButtonText: '确定',
  449. cancelButtonText: '取消',
  450. type: 'warning',
  451. center: true
  452. }).then(() => {
  453. let loading = this.$loading({ target: '.main-container' });
  454. api.WMSPushProducts({ ids: this.baseInfo.id }).then((res : any) => {
  455. if (res.code === 200) {
  456. this.$message.success('同步WMS成功');
  457. loading.close();
  458. } else loading.close();
  459. }).catch(() => loading.close());
  460. }).catch(() => this.$message.info('已取消同步WMS'));
  461. }
  462. // 保存
  463. doFormData() {
  464. let data : any = (this as any).$refs.addFormId.getValue();
  465. (this.$refs.addFormId as any).validate();
  466. if (!data[0].skuTitle) return this.$message.warning('物料标题不能为空');
  467. if (!data[0].skuCode) return this.$message.warning('物料编号不能为空');
  468. if (!data[0].barCode) return this.$message.warning('物料属性的69码-商品条码需必填');
  469. if (!/^\d{1,32}$/.test(data[0].barCode)){
  470. return this.$message.warning('69码-商品条码为数字,最大32位');
  471. }
  472. api.updateList(data[0], 'maindataMaterialSku').then((res : any) => {
  473. if (res.code === 200) {
  474. this.$message.success('编辑成功');
  475. this.isShow = 'home';
  476. this.getDataList();
  477. } else this.$message.error(res.msg);
  478. }).catch(() => {});
  479. }
  480. // 获取列表数据
  481. getDataList() {
  482. if (!this.$refs.moduleView) {
  483. if (this.timeNum > 5) {
  484. clearInterval(this.timer)
  485. }
  486. this.timeNum++;
  487. return
  488. }
  489. clearInterval(this.timer)
  490. let query = (this.$refs.moduleView as any).getQuery();
  491. // console.log('表单字段 ==> ', query);
  492. this.getPageList(query)
  493. }
  494. getPageList(query : any) {
  495. let loading = this.$loading({ target: '.main-container' });
  496. api.pageList(query, 'maindataMaterialSku').then((res : any) => {
  497. loading.close();
  498. if (res.code === 200) {
  499. res.data.records.map((v : any, i : any) => {
  500. if(v.volume&&v.weight!='0.00'&&v.weight!=0&&v.weight!='0'){
  501. v.weight = parseFloat(v.weight).toFixed(2)
  502. }
  503. if(v.volume&&v.volume!='0.00'&&v.volume!=0&&v.volume!='0'){
  504. v.volume = parseFloat(v.volume).toFixed(2)
  505. }
  506. });
  507. (this.$refs.moduleView as any).setTableValue(res.data.records);
  508. let page = {
  509. pageNo: res.data.current, //当前页
  510. pageSize: res.data.size, //每页条数
  511. total: res.data.total //总条数
  512. };
  513. (this.$refs.moduleView as any).setPage(page);
  514. } else this.$message.error(res.msg);
  515. }).catch(() => loading.close());
  516. }
  517. // 打开编辑
  518. openEdit(e : any) {
  519. let loading = this.$loading({ target: '.main-container' });
  520. api.single({ id: e.id }, 'maindataMaterialSku').then((res : any) => {
  521. if (res.code === 200) {
  522. this.baseInfo = res.data;
  523. this.isShow = 'detail';
  524. loading.close();
  525. if(res.data.volume&&res.data.volume!='0.00'&&res.data.volume!=0&&res.data.volume!='0'){
  526. res.data.volume = parseFloat(res.data.volume).toFixed(2)
  527. }
  528. setTimeout(() => { (this as any).$refs.addFormId.setValue([res.data]) }, 0);
  529. } else loading.close();
  530. }).catch(() => loading.close());
  531. }
  532. // 监听表格数据
  533. getInputValue(e : any) {
  534. // console.log('监听表格 ==> ', e);
  535. if (e.length && e.width && e.height) {
  536. e.volume = (e.length * e.width * e.height).toFixed(2);
  537. }
  538. }
  539. // 内页工具栏方法
  540. insideTools(e : any) {
  541. if (e === 'onReturn') this.isShow = 'home';
  542. if (e === 'onSave') this.doFormData();
  543. }
  544. // 刷新/重置
  545. onRefresh() {
  546. (this as any).$refs.moduleView.clearSearch();
  547. this.getDataList();
  548. }
  549. }
  550. </script>
  551. <style lang="scss" scoped>
  552. .my-container {
  553. width: 100%;
  554. box-sizing: border-box;
  555. display: flex;
  556. padding: 16px;
  557. height: 100%;
  558. .bill-left {
  559. position: relative;
  560. border-right: solid #EEE 1px;
  561. flex-shrink: 0;
  562. .bill-tab {
  563. width: 150px;
  564. height: 100%;
  565. transition: all .5s;
  566. overflow: hidden;
  567. }
  568. .tab-title {
  569. font-size: 16px;
  570. padding-bottom: 16px;
  571. width: 200px;
  572. }
  573. }
  574. .bill-main {
  575. width: 100%;
  576. box-sizing: border-box;
  577. position: relative;
  578. height: 100%;
  579. overflow-y: hidden;
  580. }
  581. .detail {
  582. width: 100%;
  583. padding: 16px;
  584. .box-shadow {
  585. box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
  586. padding: 20px;
  587. border-radius: 4px;
  588. border: 1px solid #e6ebf5;
  589. background-color: #fff;
  590. overflow: hidden;
  591. color: #303133;
  592. -webkit-transition: .3s;
  593. transition: .3s;
  594. margin-top: 20px;
  595. }
  596. }
  597. }
  598. </style>