index.tsx 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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 { SaveDept, DeleteDept, AuditDept } from "@/api/modules/saleprice";
  6. import { ElMessage, ElMessageBox } from "element-plus";
  7. interface defaultState {
  8. /**
  9. * @description 单据当前状态
  10. */
  11. orderStatus: string;
  12. /**
  13. * @description 列表Ref
  14. */
  15. VxeTableRef: any;
  16. /**
  17. * @description 详情页Ref
  18. */
  19. LjDetailRef: any;
  20. }
  21. const state = reactive<defaultState>({
  22. orderStatus: "",
  23. VxeTableRef: null,
  24. LjDetailRef: null
  25. });
  26. /**
  27. * @description 表格多选数据操作
  28. * @param {String} rowKey 当表格可以多选时,所指定的 id
  29. * */
  30. export const useHooks = (t?: any) => {
  31. // 表格配置项
  32. const columns: ColumnProps<any>[] = [
  33. { type: "checkbox", width: 80, fixed: "left" },
  34. {
  35. field: "deptname",
  36. title: "部门名称",
  37. basicinfo: {
  38. el: "input",
  39. span: 2,
  40. editable: ALLOW_EDIT_STATE,
  41. rules: [{ required: true }]
  42. }
  43. },
  44. {
  45. field: "pricelistid",
  46. title: "价格表",
  47. basicinfo: {
  48. el: "select",
  49. span: 2,
  50. editable: ALLOW_EDIT_STATE,
  51. rules: [{ required: true }],
  52. defaultValue: 0
  53. }
  54. },
  55. {
  56. field: "springtypeid",
  57. title: "弹簧分类",
  58. basicinfo: {
  59. el: "select",
  60. span: 1,
  61. editable: ALLOW_EDIT_STATE,
  62. defaultValue: 0,
  63. rules: [{ required: true }]
  64. }
  65. },
  66. {
  67. field: "moneyrate",
  68. title: "汇率",
  69. basicinfo: {
  70. el: "input",
  71. span: 1,
  72. editable: ALLOW_EDIT_STATE,
  73. props: {
  74. placeholder: "请输入汇率"
  75. },
  76. rules: [{ required: true, pattern: new RegExp(/^\d+(\.\d+)?$/), message: "汇率不能为0", trigger: "change" }]
  77. }
  78. },
  79. {
  80. field: "profitrate",
  81. title: "利润率",
  82. basicinfo: {
  83. el: "input",
  84. span: 1,
  85. editable: ALLOW_EDIT_STATE,
  86. props: {
  87. placeholder: "请输入利润率"
  88. },
  89. rules: [{ required: true, pattern: new RegExp(/^\d+(\.\d+)?$/), message: "利润率不能为0", trigger: "change" }]
  90. }
  91. },
  92. {
  93. field: "discount",
  94. title: "折扣率",
  95. basicinfo: {
  96. el: "input",
  97. span: 1,
  98. editable: ALLOW_EDIT_STATE,
  99. props: {
  100. placeholder: "请输入折扣率"
  101. },
  102. rules: [{ required: true, pattern: new RegExp(/^\d+(\.\d+)?$/), message: "折扣率不能为0", trigger: "change" }]
  103. }
  104. },
  105. {
  106. field: "if_rate_auto",
  107. title: "是否自动读取汇率",
  108. datatype: "checkbox",
  109. basicinfo: {
  110. el: "switch",
  111. editable: ALLOW_EDIT_STATE
  112. }
  113. },
  114. {
  115. field: "createtime",
  116. title: "建立时间",
  117. basicinfo: {
  118. visible: false
  119. }
  120. },
  121. {
  122. field: "modemp",
  123. title: "修改人",
  124. basicinfo: {
  125. visible: false
  126. }
  127. },
  128. {
  129. field: "moddate",
  130. title: "修改时间",
  131. basicinfo: {
  132. visible: false
  133. }
  134. },
  135. {
  136. field: "auditemp",
  137. title: "审核人",
  138. basicinfo: {
  139. visible: false
  140. }
  141. },
  142. {
  143. field: "audidate",
  144. title: "审核时间",
  145. basicinfo: {
  146. visible: false
  147. }
  148. },
  149. {
  150. field: "manage_amt",
  151. title: "部门管理费",
  152. basicinfo: {
  153. el: "input",
  154. editable: ALLOW_EDIT_STATE,
  155. span: 1,
  156. props: {
  157. placeholder: "请输入部门管理费"
  158. }
  159. // rules: [{ trigger: "change" }]
  160. }
  161. },
  162. {
  163. field: "mtrltype",
  164. title: "默认物料类别",
  165. basicinfo: {
  166. el: "tree-select",
  167. span: 2,
  168. editable: ALLOW_EDIT_STATE
  169. }
  170. },
  171. {
  172. field: "managerate",
  173. title: "管理费用点",
  174. basicinfo: {
  175. el: "input",
  176. props: {
  177. type: "number"
  178. },
  179. span: 2,
  180. editable: ALLOW_EDIT_STATE
  181. }
  182. },
  183. {
  184. field: "com_profitrate",
  185. title: "公司利润率",
  186. basicinfo: {
  187. el: "input",
  188. props: {
  189. type: "number"
  190. },
  191. span: 2,
  192. editable: ALLOW_EDIT_STATE
  193. }
  194. },
  195. {
  196. field: "dannum1_rate",
  197. title: "散单利润浮动",
  198. basicinfo: {
  199. el: "input",
  200. props: {
  201. type: "number"
  202. },
  203. span: 2,
  204. editable: ALLOW_EDIT_STATE
  205. }
  206. },
  207. {
  208. field: "dannum2_rate",
  209. title: "标准利润浮动",
  210. basicinfo: {
  211. el: "input",
  212. props: {
  213. type: "number"
  214. },
  215. span: 2,
  216. editable: ALLOW_EDIT_STATE
  217. }
  218. },
  219. {
  220. field: "dannum3_rate",
  221. title: "大单利润浮动",
  222. basicinfo: {
  223. el: "input",
  224. props: {
  225. type: "number"
  226. },
  227. span: 2,
  228. editable: ALLOW_EDIT_STATE
  229. }
  230. },
  231. {
  232. field: "dannum4_rate",
  233. title: "小单利润浮动",
  234. basicinfo: {
  235. el: "input",
  236. props: {
  237. type: "number"
  238. },
  239. span: 2,
  240. editable: ALLOW_EDIT_STATE
  241. }
  242. },
  243. {
  244. field: "taxes_rate",
  245. title: "非报关产品税金补偿",
  246. basicinfo: {
  247. el: "input",
  248. props: {
  249. type: "number"
  250. },
  251. span: 2,
  252. editable: ALLOW_EDIT_STATE
  253. }
  254. }
  255. ];
  256. // 保存
  257. const fSave = (param: any) => {
  258. return new Promise((resolve, reject) => {
  259. ElMessageBox.confirm("是否确定要保存吗?", "询问", {
  260. confirmButtonText: "是",
  261. cancelButtonText: "否",
  262. type: "warning"
  263. })
  264. .then(() => {
  265. SaveDept(param).then(() => {
  266. ElMessage.success("保存成功!");
  267. state.VxeTableRef?.refresh();
  268. resolve({});
  269. });
  270. })
  271. .catch(() => {
  272. ElMessage({
  273. type: "info",
  274. message: "操作取消"
  275. });
  276. });
  277. });
  278. };
  279. // 删除
  280. const fDelete = () => {
  281. const checkDate = state.VxeTableRef?.element.getCheckboxRecords();
  282. if (checkDate.length === 0) {
  283. ElMessage.error("请选择要删除的数据!");
  284. return;
  285. }
  286. const delArr = checkDate.map((item: any) => {
  287. return { deptid: parseInt(item.deptid), deptname: item.deptname };
  288. });
  289. ElMessageBox.confirm("是否确定要删除吗?", "询问", {
  290. confirmButtonText: "是",
  291. cancelButtonText: "否",
  292. type: "warning"
  293. })
  294. .then(() => {
  295. DeleteDept({ list: delArr }).then(() => {
  296. ElMessage.success("删除成功!");
  297. state.VxeTableRef?.refresh();
  298. });
  299. })
  300. .catch(() => {
  301. ElMessage({
  302. type: "info",
  303. message: "操作取消"
  304. });
  305. });
  306. };
  307. // 审核
  308. const fAudit = type => {
  309. let operate = "审核";
  310. switch (type) {
  311. case 1:
  312. operate = "撤审";
  313. break;
  314. case 2:
  315. operate = "反禁用";
  316. break;
  317. case 3:
  318. operate = "禁用";
  319. break;
  320. default:
  321. operate = "审核";
  322. break;
  323. }
  324. const checkDate = state.VxeTableRef?.element.getCheckboxRecords();
  325. if (checkDate.length === 0) {
  326. ElMessage.error(`请选择要${operate}的数据!`);
  327. return;
  328. }
  329. const delArr = checkDate.map((item: any) => {
  330. return { deptid: parseInt(item.deptid) };
  331. });
  332. ElMessageBox.confirm(`是否确定要${operate}吗?`, "询问", {
  333. confirmButtonText: "是",
  334. cancelButtonText: "否",
  335. type: "warning"
  336. })
  337. .then(() => {
  338. AuditDept({ list: delArr, type }).then(() => {
  339. ElMessage.success(`${operate}成功!`);
  340. state.VxeTableRef?.refresh();
  341. });
  342. })
  343. .catch(() => {
  344. ElMessage({
  345. type: "info",
  346. message: "操作取消"
  347. });
  348. });
  349. };
  350. return {
  351. ...toRefs(state),
  352. columns,
  353. fSave,
  354. fDelete,
  355. fAudit
  356. };
  357. };