123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 |
- 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 { SaveMtrlDef, DeleteMtrlDef, BanMtrlDef, getMtrlType } from "@/api/modules/basicinfo";
- import { getPriceList } from "@/api/modules/saleprice";
- import { ElMessage, ElMessageBox } from "element-plus";
- import { transformTreeData } from "@/utils/index";
- interface defaultState {
- /**
- * @description 单据当前状态
- */
- orderStatus: string;
- /**
- * @description 列表Ref
- */
- VxeTableRef: any;
- /**
- * @description 详情页Ref
- */
- LjDetailRef: any;
- /**
- * @description 详情页明细表格Ref
- */
- VxeTableMxRef: any;
- copyFormVisible: boolean;
- copyFormOption: any[];
- copyFormCol: any;
- copyFormValue: any;
- priceListEnum: any[];
- priceListFormVisiable: boolean;
- priceListFormParams: any;
- priceListVisiable: boolean;
- }
- const state = reactive<defaultState>({
- orderStatus: "",
- VxeTableRef: null,
- LjDetailRef: null,
- VxeTableMxRef: null,
- copyFormVisible: false,
- copyFormOption: [
- {
- field: "price",
- title: "单价单位",
- datatype: "number",
- basicinfo: {
- el: "input",
- span: 2,
- editable: ALLOW_EDIT_STATE
- }
- },
- {
- field: "priceunit",
- title: "单位",
- basicinfo: {
- el: "input",
- span: 2,
- editable: ALLOW_EDIT_STATE
- }
- },
- {
- field: "shrinkage",
- title: "收缩率",
- datatype: "number",
- basicinfo: {
- el: "input",
- span: 2,
- editable: ALLOW_EDIT_STATE
- }
- },
- {
- field: "thickness",
- title: "厚度",
- datatype: "number",
- basicinfo: {
- el: "input",
- span: 2,
- editable: ALLOW_EDIT_STATE
- }
- },
- {
- field: "gram_weight",
- title: "克重",
- datatype: "number",
- basicinfo: {
- el: "input",
- span: 2,
- editable: ALLOW_EDIT_STATE
- }
- }
- ],
- copyFormCol: {},
- copyFormValue: "",
- priceListEnum: [],
- priceListFormVisiable: false,
- priceListFormParams: {
- pricelistid_from: 0 as number,
- pricelistid_to: 0 as number,
- rate: 1 as number
- },
- priceListVisiable: false
- });
- /**
- * @description 表格多选数据操作
- * @param {String} rowKey 当表格可以多选时,所指定的 id
- * */
- export const useHooks = (t?: any) => {
- // 表格配置项
- const columns: ColumnProps<any>[] = [
- { type: "checkbox", width: 80, fixed: "left" },
- {
- field: "fjcnt",
- title: "附件",
- width: 80,
- basicinfo: {
- visible: false
- }
- },
- {
- field: "name",
- title: "物料名称",
- basicinfo: {
- el: "input",
- span: 2,
- editable: ALLOW_EDIT_STATE
- }
- },
- {
- field: "price",
- title: "单价单位",
- datatype: "number",
- basicinfo: {
- visible: false
- }
- },
- {
- field: "priceunit",
- title: "单位",
- basicinfo: {
- el: "input",
- span: 2,
- editable: ALLOW_EDIT_STATE
- }
- },
- {
- field: "shrinkage",
- title: "收缩率",
- datatype: "number",
- basicinfo: {
- el: "input",
- span: 2,
- editable: ALLOW_EDIT_STATE
- }
- },
- {
- field: "thickness",
- title: "厚度",
- datatype: "number",
- basicinfo: {
- el: "input",
- span: 2,
- editable: ALLOW_EDIT_STATE
- }
- },
- {
- field: "gram_weight",
- title: "克重",
- datatype: "number",
- basicinfo: {
- el: "input",
- span: 2,
- editable: ALLOW_EDIT_STATE
- }
- },
- {
- field: "if_inputqty",
- title: "固定厚度",
- datatype: "checkbox",
- basicinfo: {
- span: 1,
- editable: ALLOW_EDIT_STATE,
- render: (scope: any) => {
- const { column, searchParam } = scope;
- return (
- <>
- <div class="flx-align-center">
- <el-checkbox v-model={searchParam[column.field]} true-value={1} false-value={0} />
- </div>
- </>
- );
- }
- }
- },
- {
- field: "if_subspecs",
- title: "主副规格调整",
- datatype: "checkbox",
- basicinfo: {
- span: 1,
- editable: ALLOW_EDIT_STATE,
- render: (scope: any) => {
- const { column, searchParam } = scope;
- return (
- <>
- <div class="flx-align-center">
- <el-checkbox v-model={searchParam[column.field]} true-value={1} false-value={0} />
- </div>
- </>
- );
- }
- }
- },
- {
- field: "if_areaprice",
- title: "单价按面积",
- datatype: "checkbox",
- basicinfo: {
- el: "input",
- span: 2,
- editable: ALLOW_EDIT_STATE
- }
- },
- {
- field: "createby",
- title: "登记人",
- basicinfo: {
- visible: false
- }
- },
- {
- field: "createtime",
- title: "登记时间",
- basicinfo: {
- visible: false
- }
- },
- {
- field: "erp_mtrlcode",
- title: "L1物料编码",
- basicinfo: {
- visible: false
- }
- },
- {
- field: "erp_mtrlname",
- title: "L1物料名称",
- basicinfo: {
- visible: false
- }
- },
- {
- field: "erp_mtrlmode",
- title: "L1物料规格",
- basicinfo: {
- visible: false
- }
- },
- {
- field: "erp_unit",
- title: "L1物料单位",
- basicinfo: {
- visible: false
- }
- },
- {
- field: "erp_mtrlengname",
- title: "L1英文名称",
- basicinfo: {
- visible: false
- }
- },
- {
- field: "isuse",
- title: "有效",
- visible: false,
- basicinfo: {
- editable: ALLOW_EDIT_STATE,
- span: 2,
- render: (scope: any) => {
- const { column, searchParam } = scope;
- return (
- <>
- <div class="flx-align-center">
- <el-checkbox v-model={searchParam[column.field]} true-label={1} false-value={0} />
- </div>
- </>
- );
- }
- }
- },
- {
- field: "lastdate",
- title: "有效时间",
- visible: false,
- basicinfo: {
- el: "date-picker",
- span: 2,
- editable: ALLOW_EDIT_STATE
- }
- },
- {
- field: "handtype",
- title: "默认类别",
- visible: false,
- basicinfo: {
- el: "tree-select",
- span: 2,
- editable: ALLOW_EDIT_STATE
- },
- enum: async () => {
- const data = await getMtrlType();
- return transformTreeData(data.reList);
- },
- fieldNames: {
- label: "mtrltype",
- value: "mtrltypeid",
- children: "children"
- }
- },
- {
- field: "pricelistid",
- title: "价格表",
- visible: false,
- // limited: true,
- enum: async () => {
- const data = (await getPriceList()).list;
- state.priceListEnum = data;
- return { data };
- },
- basicinfo: {
- visible: false
- },
- search: {
- el: "select",
- key: "pricelistid",
- props: {
- clearable: false,
- filterable: false,
- defaultFirstOption: true,
- remote: true
- },
- defaultValue: 12
- },
- fieldNames: {
- label: "pricelistname",
- value: "pricelistid"
- }
- },
- {
- field: "dscrp",
- title: "备注",
- basicinfo: {
- el: "input",
- span: 4,
- editable: ALLOW_EDIT_STATE,
- props: { type: "textarea", rows: 5 },
- row: 3
- }
- }
- ];
- const columns_mx: ColumnProps<any>[] = [
- {
- field: "pricetype",
- title: "单价方式",
- filters: [
- { label: "直接单价", value: "0" },
- { label: "公式单价", value: "1" }
- ],
- editRender: {
- name: "VxeSelect",
- options: [
- { label: "直接单价", value: "0" },
- { label: "公式单价", value: "1" }
- ]
- }
- },
- {
- field: "price",
- title: "单价",
- editRender: {
- name: "$input",
- props: {}
- }
- },
- {
- field: "price_formula",
- title: "单价公式",
- editRender: {
- name: "$input",
- props: {}
- }
- },
- {
- field: "qty_formula",
- title: "用量公式",
- editRender: {
- name: "$input",
- props: {}
- }
- }
- ];
- // 保存
- const fSave = (param: any) => {
- return new Promise((resolve, reject) => {
- ElMessageBox.confirm("是否确定要保存吗?", "询问", {
- confirmButtonText: "是",
- cancelButtonText: "否",
- type: "warning"
- })
- .then(() => {
- SaveMtrlDef(param).then(() => {
- ElMessage.success("保存成功!");
- state.VxeTableRef?.refresh();
- resolve({});
- });
- })
- .catch(() => {
- ElMessage({
- type: "info",
- message: "操作取消"
- });
- });
- });
- };
- // 删除
- const fDelete = () => {
- const checkDate = state.VxeTableRef?.element.getCheckboxRecords();
- if (checkDate.length === 0) {
- ElMessage.error("请选择要删除的数据!");
- return;
- }
- const delArr = checkDate.map((item: any) => {
- return { mtrlid: parseInt(item.mtrlid), name: item.name };
- });
- ElMessageBox.confirm("是否确定要删除吗?", "询问", {
- confirmButtonText: "是",
- cancelButtonText: "否",
- type: "warning"
- })
- .then(() => {
- DeleteMtrlDef({ list: delArr }).then(() => {
- ElMessage.success("删除成功!");
- state.VxeTableRef?.refresh();
- });
- })
- .catch(() => {
- ElMessage({
- type: "info",
- message: "操作取消"
- });
- });
- };
- // 禁用
- const fBan = type => {
- const text = type ? "反禁用" : "禁用";
- const checkDate = state.VxeTableRef?.element.getCheckboxRecords();
- if (checkDate.length === 0) {
- ElMessage.error(`请选择要${text}的数据!`);
- return;
- }
- const delArr = checkDate.map((item: any) => {
- return { mtrlid: parseInt(item.mtrlid), name: item.name };
- });
- ElMessageBox.confirm(`是否确定要${text}吗?`, "询问", {
- confirmButtonText: "是",
- cancelButtonText: "否",
- type: "warning"
- })
- .then(() => {
- BanMtrlDef({ list: delArr, type }).then(() => {
- ElMessage.success(`${text}成功!`);
- state.VxeTableRef?.refresh();
- });
- })
- .catch(() => {
- ElMessage({
- type: "info",
- message: "操作取消"
- });
- });
- };
- return {
- ...toRefs(state),
- columns,
- columns_mx,
- fSave,
- fDelete,
- fBan
- };
- };
|