123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- import { ref, reactive, computed, toRefs } from "vue";
- import { Table } from "@/hooks/interface";
- import { ColumnProps } from "@/components/LjVxeTable/interface";
- import { ALLOW_EDIT_STATE } from "@/config/index";
- import { SaveMattressExtra, DeleteMattressExtra } from "@/api/modules/basicinfo";
- import { ElMessage, ElMessageBox } from "element-plus";
- import { numCheck } from "@/utils/rules/index";
- import { isArray } from "@/utils/is";
- interface defaultState {
- /**
- * @description 单据当前状态
- */
- orderStatus: string;
- /**
- * @description 列表Ref
- */
- VxeTableRef: any;
- /**
- * @description 详情页Ref
- */
- LjDetailRef: any;
- /**
- * @description 是否有包边
- */
- ifEdge: boolean;
- }
- const state = reactive<defaultState>({
- orderStatus: "",
- VxeTableRef: null,
- LjDetailRef: null,
- ifEdge: false
- });
- /**
- * @description 表格多选数据操作
- * @param {String} rowKey 当表格可以多选时,所指定的 id
- * */
- export const useHooks = (t?: any) => {
- // 表格配置项
- const columns: ColumnProps<any>[] = [
- { type: "checkbox", width: 80, fixed: "left" },
- // {
- // field: "areaname",
- // title: "分区名称",
- // basicinfo: {
- // el: "input",
- // span: 4,
- // editable: ALLOW_EDIT_STATE
- // }
- // },
- {
- field: "extraid",
- title: "项目类型",
- basicinfo: {
- el: "select",
- span: 4,
- editable: ALLOW_EDIT_STATE,
- rules: [{ required: true, message: "请输入项目类型", trigger: "blur" }]
- }
- },
- {
- field: "extramxname",
- title: "项目名称",
- basicinfo: {
- el: "input",
- span: 4,
- editable: ALLOW_EDIT_STATE
- }
- },
- {
- field: "price",
- title: "金额",
- basicinfo: {
- el: "input",
- props: {
- type: "number"
- },
- span: 4,
- editable: ALLOW_EDIT_STATE
- }
- },
- {
- field: "qty",
- title: "数量",
- basicinfo: {
- el: "input",
- props: {
- type: "number"
- },
- span: 4,
- editable: ALLOW_EDIT_STATE
- }
- },
- {
- field: "dscrp",
- title: "备注",
- basicinfo: {
- el: "input",
- span: 4,
- editable: ALLOW_EDIT_STATE
- }
- },
- {
- field: "inuse",
- title: "禁用",
- basicinfo: {
- el: "checkbox",
- span: 1,
- editable: ALLOW_EDIT_STATE
- }
- },
- {
- field: "inputtype",
- title: "录入类型",
- enum: [
- {
- label: "选择",
- value: 0
- },
- {
- label: "录入",
- value: 1
- },
- {
- label: "带出",
- value: 2
- },
- {
- label: "选择物料",
- value: 3
- }
- ],
- basicinfo: {
- el: "select",
- span: 1,
- editable: ALLOW_EDIT_STATE
- }
- },
- {
- field: "ifinit",
- title: "自动导入",
- basicinfo: {
- el: "checkbox",
- span: 1,
- editable: ALLOW_EDIT_STATE
- }
- }
- ];
- // 保存
- const fSave = (param: any) => {
- return new Promise((resolve, reject) => {
- ElMessageBox.confirm("是否确定要保存吗?", "询问", {
- confirmButtonText: "是",
- cancelButtonText: "否",
- type: "warning"
- })
- .then(() => {
- SaveMattressExtra(param).then(() => {
- ElMessage.success("保存成功!");
- state.VxeTableRef?.refresh();
- resolve({});
- });
- })
- .catch(() => {
- ElMessage({
- type: "info",
- message: "操作取消"
- });
- });
- });
- };
- // 删除
- const fDelete = (data?: any) => {
- console.log("fDelete data :>> ", data);
- let delArr = [];
- if (isArray(data) && data.length > 0) {
- delArr = data.map((item: any) => {
- return { extramxid: parseInt(item.extramxid) };
- });
- } else {
- const checkDate = state.VxeTableRef?.element.getCheckboxRecords();
- if (checkDate.length === 0) {
- ElMessage.error("请选择要删除的数据!");
- return;
- }
- delArr = checkDate.map((item: any) => {
- return { extramxid: parseInt(item.extramxid) };
- });
- }
- ElMessageBox.confirm("是否确定要删除吗?", "询问", {
- confirmButtonText: "是",
- cancelButtonText: "否",
- type: "warning"
- })
- .then(() => {
- DeleteMattressExtra({ list: delArr }).then(() => {
- ElMessage.success("删除成功!");
- state.VxeTableRef?.refresh();
- });
- })
- .catch(() => {
- ElMessage({
- type: "info",
- message: "操作取消"
- });
- });
- };
- return {
- ...toRefs(state),
- columns,
- fSave,
- fDelete
- };
- };
|