index.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. import { ref, reactive, computed, toRefs } from "vue";
  2. import { Table } from "@/hooks/interface";
  3. import { ColumnProps } from "@/components/LjVxeTable/interface";
  4. import { ALLOW_EDIT_STATE } from "@/config/index";
  5. import { SaveMtrlDef, DeleteMtrlDef, BanMtrlDef, getMtrlType } from "@/api/modules/basicinfo";
  6. import { getPriceList } from "@/api/modules/saleprice";
  7. import { ElMessage, ElMessageBox } from "element-plus";
  8. import { transformTreeData } from "@/utils/index";
  9. interface defaultState {
  10. /**
  11. * @description 单据当前状态
  12. */
  13. orderStatus: string;
  14. /**
  15. * @description 列表Ref
  16. */
  17. VxeTableRef: any;
  18. /**
  19. * @description 详情页Ref
  20. */
  21. LjDetailRef: any;
  22. /**
  23. * @description 详情页明细表格Ref
  24. */
  25. VxeTableMxRef: any;
  26. copyFormVisible: boolean;
  27. copyFormOption: any[];
  28. copyFormCol: any;
  29. copyFormValue: any;
  30. priceListEnum: any[];
  31. priceListFormVisiable: boolean;
  32. priceListFormParams: any;
  33. priceListVisiable: boolean;
  34. }
  35. const state = reactive<defaultState>({
  36. orderStatus: "",
  37. VxeTableRef: null,
  38. LjDetailRef: null,
  39. VxeTableMxRef: null,
  40. copyFormVisible: false,
  41. copyFormOption: [
  42. {
  43. field: "price",
  44. title: "单价单位",
  45. datatype: "number",
  46. basicinfo: {
  47. el: "input",
  48. span: 2,
  49. editable: ALLOW_EDIT_STATE
  50. }
  51. },
  52. {
  53. field: "priceunit",
  54. title: "单位",
  55. basicinfo: {
  56. el: "input",
  57. span: 2,
  58. editable: ALLOW_EDIT_STATE
  59. }
  60. },
  61. {
  62. field: "shrinkage",
  63. title: "收缩率",
  64. datatype: "number",
  65. basicinfo: {
  66. el: "input",
  67. span: 2,
  68. editable: ALLOW_EDIT_STATE
  69. }
  70. },
  71. {
  72. field: "thickness",
  73. title: "厚度",
  74. datatype: "number",
  75. basicinfo: {
  76. el: "input",
  77. span: 2,
  78. editable: ALLOW_EDIT_STATE
  79. }
  80. },
  81. {
  82. field: "gram_weight",
  83. title: "克重",
  84. datatype: "number",
  85. basicinfo: {
  86. el: "input",
  87. span: 2,
  88. editable: ALLOW_EDIT_STATE
  89. }
  90. }
  91. ],
  92. copyFormCol: {},
  93. copyFormValue: "",
  94. priceListEnum: [],
  95. priceListFormVisiable: false,
  96. priceListFormParams: {
  97. pricelistid_from: 0 as number,
  98. pricelistid_to: 0 as number,
  99. rate: 1 as number
  100. },
  101. priceListVisiable: false
  102. });
  103. /**
  104. * @description 表格多选数据操作
  105. * @param {String} rowKey 当表格可以多选时,所指定的 id
  106. * */
  107. export const useHooks = (t?: any) => {
  108. // 表格配置项
  109. const columns: ColumnProps<any>[] = [
  110. { type: "checkbox", width: 80, fixed: "left" },
  111. {
  112. field: "fjcnt",
  113. title: "附件",
  114. width: 80,
  115. basicinfo: {
  116. visible: false
  117. }
  118. },
  119. {
  120. field: "name",
  121. title: "物料名称",
  122. basicinfo: {
  123. el: "input",
  124. span: 2,
  125. editable: ALLOW_EDIT_STATE
  126. }
  127. },
  128. {
  129. field: "price",
  130. title: "单价单位",
  131. datatype: "number",
  132. basicinfo: {
  133. visible: false
  134. }
  135. },
  136. {
  137. field: "priceunit",
  138. title: "单位",
  139. basicinfo: {
  140. el: "input",
  141. span: 2,
  142. editable: ALLOW_EDIT_STATE
  143. }
  144. },
  145. {
  146. field: "shrinkage",
  147. title: "收缩率",
  148. datatype: "number",
  149. basicinfo: {
  150. el: "input",
  151. span: 2,
  152. editable: ALLOW_EDIT_STATE
  153. }
  154. },
  155. {
  156. field: "thickness",
  157. title: "厚度",
  158. datatype: "number",
  159. basicinfo: {
  160. el: "input",
  161. span: 2,
  162. editable: ALLOW_EDIT_STATE
  163. }
  164. },
  165. {
  166. field: "gram_weight",
  167. title: "克重",
  168. datatype: "number",
  169. basicinfo: {
  170. el: "input",
  171. span: 2,
  172. editable: ALLOW_EDIT_STATE
  173. }
  174. },
  175. {
  176. field: "if_inputqty",
  177. title: "固定厚度",
  178. datatype: "checkbox",
  179. basicinfo: {
  180. span: 1,
  181. editable: ALLOW_EDIT_STATE,
  182. render: (scope: any) => {
  183. const { column, searchParam } = scope;
  184. return (
  185. <>
  186. <div class="flx-align-center">
  187. <el-checkbox v-model={searchParam[column.field]} true-value={1} false-value={0} />
  188. </div>
  189. </>
  190. );
  191. }
  192. }
  193. },
  194. {
  195. field: "if_subspecs",
  196. title: "主副规格调整",
  197. datatype: "checkbox",
  198. basicinfo: {
  199. span: 1,
  200. editable: ALLOW_EDIT_STATE,
  201. render: (scope: any) => {
  202. const { column, searchParam } = scope;
  203. return (
  204. <>
  205. <div class="flx-align-center">
  206. <el-checkbox v-model={searchParam[column.field]} true-value={1} false-value={0} />
  207. </div>
  208. </>
  209. );
  210. }
  211. }
  212. },
  213. {
  214. field: "if_areaprice",
  215. title: "单价按面积",
  216. datatype: "checkbox",
  217. basicinfo: {
  218. el: "input",
  219. span: 2,
  220. editable: ALLOW_EDIT_STATE
  221. }
  222. },
  223. {
  224. field: "createby",
  225. title: "登记人",
  226. basicinfo: {
  227. visible: false
  228. }
  229. },
  230. {
  231. field: "createtime",
  232. title: "登记时间",
  233. basicinfo: {
  234. visible: false
  235. }
  236. },
  237. {
  238. field: "erp_mtrlcode",
  239. title: "L1物料编码",
  240. basicinfo: {
  241. visible: false
  242. }
  243. },
  244. {
  245. field: "erp_mtrlname",
  246. title: "L1物料名称",
  247. basicinfo: {
  248. visible: false
  249. }
  250. },
  251. {
  252. field: "erp_mtrlmode",
  253. title: "L1物料规格",
  254. basicinfo: {
  255. visible: false
  256. }
  257. },
  258. {
  259. field: "erp_unit",
  260. title: "L1物料单位",
  261. basicinfo: {
  262. visible: false
  263. }
  264. },
  265. {
  266. field: "erp_mtrlengname",
  267. title: "L1英文名称",
  268. basicinfo: {
  269. visible: false
  270. }
  271. },
  272. {
  273. field: "isuse",
  274. title: "有效",
  275. visible: false,
  276. basicinfo: {
  277. editable: ALLOW_EDIT_STATE,
  278. span: 2,
  279. render: (scope: any) => {
  280. const { column, searchParam } = scope;
  281. return (
  282. <>
  283. <div class="flx-align-center">
  284. <el-checkbox v-model={searchParam[column.field]} true-label={1} false-value={0} />
  285. </div>
  286. </>
  287. );
  288. }
  289. }
  290. },
  291. {
  292. field: "lastdate",
  293. title: "有效时间",
  294. visible: false,
  295. basicinfo: {
  296. el: "date-picker",
  297. span: 2,
  298. editable: ALLOW_EDIT_STATE
  299. }
  300. },
  301. {
  302. field: "handtype",
  303. title: "默认类别",
  304. visible: false,
  305. basicinfo: {
  306. el: "tree-select",
  307. span: 2,
  308. editable: ALLOW_EDIT_STATE
  309. },
  310. enum: async () => {
  311. const data = await getMtrlType();
  312. return transformTreeData(data.reList);
  313. },
  314. fieldNames: {
  315. label: "mtrltype",
  316. value: "mtrltypeid",
  317. children: "children"
  318. }
  319. },
  320. {
  321. field: "pricelistid",
  322. title: "价格表",
  323. visible: false,
  324. // limited: true,
  325. enum: async () => {
  326. const data = (await getPriceList()).list;
  327. state.priceListEnum = data;
  328. return { data };
  329. },
  330. basicinfo: {
  331. visible: false
  332. },
  333. search: {
  334. el: "select",
  335. key: "pricelistid",
  336. props: {
  337. clearable: false,
  338. filterable: false,
  339. defaultFirstOption: true,
  340. remote: true
  341. },
  342. defaultValue: 12
  343. },
  344. fieldNames: {
  345. label: "pricelistname",
  346. value: "pricelistid"
  347. }
  348. },
  349. {
  350. field: "dscrp",
  351. title: "备注",
  352. basicinfo: {
  353. el: "input",
  354. span: 4,
  355. editable: ALLOW_EDIT_STATE,
  356. props: { type: "textarea", rows: 5 },
  357. row: 3
  358. }
  359. }
  360. ];
  361. const columns_mx: ColumnProps<any>[] = [
  362. {
  363. field: "pricetype",
  364. title: "单价方式",
  365. filters: [
  366. { label: "直接单价", value: "0" },
  367. { label: "公式单价", value: "1" }
  368. ],
  369. editRender: {
  370. name: "VxeSelect",
  371. options: [
  372. { label: "直接单价", value: "0" },
  373. { label: "公式单价", value: "1" }
  374. ]
  375. }
  376. },
  377. {
  378. field: "price",
  379. title: "单价",
  380. editRender: {
  381. name: "$input",
  382. props: {}
  383. }
  384. },
  385. {
  386. field: "price_formula",
  387. title: "单价公式",
  388. editRender: {
  389. name: "$input",
  390. props: {}
  391. }
  392. },
  393. {
  394. field: "qty_formula",
  395. title: "用量公式",
  396. editRender: {
  397. name: "$input",
  398. props: {}
  399. }
  400. }
  401. ];
  402. // 保存
  403. const fSave = (param: any) => {
  404. return new Promise((resolve, reject) => {
  405. ElMessageBox.confirm("是否确定要保存吗?", "询问", {
  406. confirmButtonText: "是",
  407. cancelButtonText: "否",
  408. type: "warning"
  409. })
  410. .then(() => {
  411. SaveMtrlDef(param).then(() => {
  412. ElMessage.success("保存成功!");
  413. state.VxeTableRef?.refresh();
  414. resolve({});
  415. });
  416. })
  417. .catch(() => {
  418. ElMessage({
  419. type: "info",
  420. message: "操作取消"
  421. });
  422. });
  423. });
  424. };
  425. // 删除
  426. const fDelete = () => {
  427. const checkDate = state.VxeTableRef?.element.getCheckboxRecords();
  428. if (checkDate.length === 0) {
  429. ElMessage.error("请选择要删除的数据!");
  430. return;
  431. }
  432. const delArr = checkDate.map((item: any) => {
  433. return { mtrlid: parseInt(item.mtrlid), name: item.name };
  434. });
  435. ElMessageBox.confirm("是否确定要删除吗?", "询问", {
  436. confirmButtonText: "是",
  437. cancelButtonText: "否",
  438. type: "warning"
  439. })
  440. .then(() => {
  441. DeleteMtrlDef({ list: delArr }).then(() => {
  442. ElMessage.success("删除成功!");
  443. state.VxeTableRef?.refresh();
  444. });
  445. })
  446. .catch(() => {
  447. ElMessage({
  448. type: "info",
  449. message: "操作取消"
  450. });
  451. });
  452. };
  453. // 禁用
  454. const fBan = type => {
  455. const text = type ? "反禁用" : "禁用";
  456. const checkDate = state.VxeTableRef?.element.getCheckboxRecords();
  457. if (checkDate.length === 0) {
  458. ElMessage.error(`请选择要${text}的数据!`);
  459. return;
  460. }
  461. const delArr = checkDate.map((item: any) => {
  462. return { mtrlid: parseInt(item.mtrlid), name: item.name };
  463. });
  464. ElMessageBox.confirm(`是否确定要${text}吗?`, "询问", {
  465. confirmButtonText: "是",
  466. cancelButtonText: "否",
  467. type: "warning"
  468. })
  469. .then(() => {
  470. BanMtrlDef({ list: delArr, type }).then(() => {
  471. ElMessage.success(`${text}成功!`);
  472. state.VxeTableRef?.refresh();
  473. });
  474. })
  475. .catch(() => {
  476. ElMessage({
  477. type: "info",
  478. message: "操作取消"
  479. });
  480. });
  481. };
  482. return {
  483. ...toRefs(state),
  484. columns,
  485. columns_mx,
  486. fSave,
  487. fDelete,
  488. fBan
  489. };
  490. };