index.tsx 11 KB

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