123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853 |
- <template>
- <div class="user">
- <div class="tree">
- <treeList title="物料分类" submitType="2" :data="treeListData" v-model="sourceList.pagination.productClassifyId" @change="treeChange"
- @changeTreeList="getTreeList">
- </treeList>
- </div>
- <div class="content">
- <byTable :source="sourceList.data" :tableHeight="tableHeight" :pagination="sourceList.pagination" :config="config" :loading="loading"
- highlight-current-row :selectConfig="selectConfig" :action-list="[
- {
- text: '添加物料',
- action: () => openModal('add'),
- disabled: false,
- },
- ]" @get-list="getList">
- <template #pic="{ item }">
- <div v-if="item.fileList.length > 0">
- <img :src="item.fileList[0].fileUrl" class="pic" @click="handleClickFile(item.fileList[0])" />
- </div>
- <div v-else></div>
- </template>
- <template #name="{ item }">
- <div>
- <span class="el-click">{{ item.name }}</span>
- </div>
- </template>
- <template #size="{ item }">
- <div v-if="item['length'] && item.width && item.height">
- <span>{{ item['length'] }}</span>*
- <span>{{ item.width }}</span>*
- <span>{{ item.height }}</span>
- </div>
- <div v-else></div>
- </template>
- <template #price="{ item }">
- <div v-if="item.price">
- <span>{{ item.currency }} {{ moneyFormat(item.price ,2)}}</span>
- </div>
- <div v-else></div>
- </template>
- <template #costPrice="{ item }">
- <div v-if="item.costPrice">
- <span>{{ item.currency }} {{ moneyFormat(item.costPrice ,2)}}</span>
- </div>
- <div v-else></div>
- </template>
- </byTable>
- </div>
- <el-dialog :title="modalType == 'add' ? '添加物料' : '编辑物料'" v-model="dialogVisible" width="80%" destroy-on-close>
- <div class="public_height_dialog">
- <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="formDom" v-loading="submitLoading">
- <template #size>
- <div style="width: 100%">
- <el-form-item label="尺寸" class="margin-b-0 wid100" required>
- <el-row>
- <el-col :span="8">
- <el-form-item prop="length" label-width="0px" class="margin-b-0 wid100">
- <el-input-number v-model="formData.data.length" placeholder="请输入" style="width: 100%" :precision="2" :controls="false" :min="0"
- onmousewheel="return false;" />
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item prop="width" label-width="0px" class="margin-b-0 wid100">
- <el-input-number v-model="formData.data.width" placeholder="请输入" style="width: 100%" :precision="2" :controls="false" :min="0"
- onmousewheel="return false;" />
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item prop="height" label-width="0px" class="margin-b-0 wid100">
- <el-input-number v-model="formData.data.height" placeholder="请输入" style="width: 100%" :precision="2" :controls="false" :min="0"
- onmousewheel="return false;" />
- </el-form-item>
- </el-col>
- </el-row>
- </el-form-item>
- </div>
- </template>
- </byForm>
- </div>
- <template #footer>
- <el-button @click="dialogVisible = false" size="defualt" v-debounce>取 消</el-button>
- <el-button type="primary" @click="submitForm()" size="defualt" :loading="submitLoading" v-debounce>
- 确 定
- </el-button>
- </template>
- </el-dialog>
- <el-dialog :title="'关联产品'" v-model="openAssociationProduct" width="70%" destroy-on-close>
- <div>
- <!-- class="public_height_dialog" -->
- <!-- <el-table :data="associationProductData" style="width: 100%;">
- <el-table-column label="产品图片" width="80">
- <template #default="{ row }">
- <div v-if="row.fileUrl">
- <img :src="row.fileUrl" class="pic" @click="openImg(row.fileUrl)" />
- </div>
- </template>
- </el-table-column>
- <el-table-column prop="name" label="产品名称" min-width="130" />
- <el-table-column prop="customCode" label="产品编码" width="180" />
- <el-table-column label="规格尺寸 (cm)" width="130">
- <template #default="{ row, $index }">
- <div style="width: 100%">
- {{row['length']}} * {{row.width}} * {{row.height}}
- </div>
- </template>
- </el-table-column>
- <el-table-column prop="color" label="颜色" width="150" />
- </el-table> -->
- <byTable :source="associationData.data" :pagination="associationData.pagination" :config="associationConfig" :loading="loading"
- highlight-current-row :selectConfig="[]" :action-list="[]" @get-list="getAssociationList">
- <template #pic="{ item }">
- <div v-if="item.fileUrl">
- <img :src="item.fileUrl" class="pic" @click="openImg(item.fileUrl)" />
- </div>
- <div v-else></div>
- </template>
- <template #size="{ item }">
- <div v-if="item['length'] && item.width && item.height">
- <span>{{ item['length'] }}</span>*
- <span>{{ item.width }}</span>*
- <span>{{ item.height }}</span>
- </div>
- <div v-else></div>
- </template>
- </byTable>
- </div>
- <!-- <template #footer>
- <el-button @click="openAssociationProduct = false" size="defualt" v-debounce>关 闭</el-button>
- </template> -->
- </el-dialog>
- </div>
- </template>
- <script setup>
- import byTable from "@/components/byTable/index";
- import byForm from "@/components/byForm/index";
- import treeList from "@/components/product/treeList";
- const { proxy } = getCurrentInstance();
- const currencyData = computed(
- () => proxy.useUserStore().allDict["account_currency"]
- );
- const materialUnitData = computed(
- () => proxy.useUserStore().allDict["material_unit"]
- );
- const colorLayerData = computed(
- () => proxy.useUserStore().allDict["color_layer"]
- );
- const backLinesData = computed(
- () => proxy.useUserStore().allDict["back_lines"]
- );
- const frontLinesData = computed(
- () => proxy.useUserStore().allDict["front_lines"]
- );
- const tableHeight = ref(0);
- const getTableHeight = () => {
- tableHeight.value = window.innerHeight - 245;
- };
- getTableHeight();
- window.addEventListener("resize", () => {
- getTableHeight();
- });
- const loading = ref(false);
- const submitLoading = ref(false);
- const sourceList = ref({
- data: [],
- pagination: {
- total: 3,
- pageNum: 1,
- pageSize: 10,
- type: "",
- productClassifyId: "",
- keyword: "",
- definition: "2",
- },
- });
- const dialogVisible = ref(false);
- const modalType = ref("add");
- const treeData = ref([]);
- const rules = ref({
- productClassifyId: [
- { required: true, message: "请选择物料分类", trigger: "change" },
- ],
- name: [{ required: true, message: "请输入物料名称", trigger: "blur" }],
- customCode: [{ required: true, message: "请输入物料编码", trigger: "blur" }],
- length: [{ required: true, message: "请输入长 (cm)", trigger: "blur" }],
- width: [{ required: true, message: "请输入宽 (cm)", trigger: "blur" }],
- height: [{ required: true, message: "请输入高 (cm)", trigger: "blur" }],
- price: [{ required: true, message: "请输入销售价", trigger: "blur" }],
- });
- const selectConfig = computed(() => []);
- const config = computed(() => {
- return [
- {
- attrs: {
- label: "图片",
- slot: "pic",
- align: "center",
- width: 80,
- },
- },
- {
- attrs: {
- label: "物料分类",
- prop: "classifyName",
- "min-width": 200,
- },
- },
- {
- attrs: {
- label: "物料编码",
- prop: "customCode",
- width: 190,
- },
- },
- {
- attrs: {
- label: "物料名称",
- slot: "name",
- "min-width": 300,
- },
- },
- {
- attrs: {
- label: "安全库存",
- prop: "stockThreshold",
- width: 100,
- },
- },
- // {
- // attrs: {
- // label: "物料材质",
- // prop: "material",
- // width: 120,
- // },
- // },
- // {
- // attrs: {
- // label: "物料型号",
- // prop: "spec",
- // width: 120,
- // },
- // },
- {
- attrs: {
- label: "单位",
- prop: "unit",
- width: 80,
- },
- // render(val) {
- // return proxy.dictKeyValue(val, materialUnitData.value);
- // },
- },
- {
- attrs: {
- label: "尺寸",
- slot: "size",
- width: 130,
- },
- },
- {
- attrs: {
- label: "净重",
- prop: "netWeight",
- width: 100,
- },
- render(val) {
- if (val) {
- return val + " kg";
- }
- },
- },
- {
- attrs: {
- label: "成本价",
- prop: "costPrice",
- width: 100,
- },
- render(val) {
- return proxy.moneyFormat(val, 2);
- },
- },
- {
- attrs: {
- label: "销售价",
- prop: "price",
- width: 100,
- },
- render(val) {
- return proxy.moneyFormat(val, 2);
- },
- },
- {
- attrs: {
- label: "操作",
- width: "180",
- align: "center",
- fixed: "right",
- },
- renderHTML(row) {
- return [
- {
- attrs: {
- label: "产品反查",
- type: "primary",
- text: true,
- },
- el: "button",
- click() {
- getAssociationProduct(row);
- },
- },
- {
- attrs: {
- label: "修改",
- type: "primary",
- text: true,
- },
- el: "button",
- click() {
- getDtl(row);
- },
- },
- {
- attrs: {
- label: "删除",
- type: "danger",
- text: true,
- },
- el: "button",
- click() {
- proxy
- .msgConfirm()
- .then((res) => {
- proxy
- .post("/productInfo/delete", {
- id: row.id,
- })
- .then((res) => {
- proxy.msgTip("删除成功", 1);
- getList();
- });
- })
- .catch((err) => {});
- },
- },
- ];
- },
- },
- ];
- });
- const formData = reactive({
- data: {},
- });
- const formOption = reactive({
- inline: true,
- labelWidth: 100,
- itemWidth: 100,
- });
- const formDom = ref(null);
- const treeListData = ref([]);
- function findNodeById(treeData, nodeId) {
- // 遍历当前层级的所有节点
- for (let i = 0; i < treeData.length; i++) {
- let node = treeData[i];
- // 如果当前节点的 ID 匹配目标节点的 ID,则返回当前节点
- if (node.id === nodeId) {
- return node;
- }
- // 如果当前节点有子节点,则递归调用当前函数继续查找子节点
- if (node.children && node.children.length > 0) {
- let foundNode = findNodeById(node.children, nodeId);
- // 如果在子节点中找到了目标节点,则返回找到的节点
- if (foundNode) {
- return foundNode;
- }
- }
- }
- // 如果遍历完所有节点仍未找到目标节点,则返回 null
- return null;
- }
- const isShowLabel = ref(false);
- const formConfig = computed(() => {
- return [
- {
- type: "title1",
- title: "基本信息",
- },
- {
- type: "treeSelect",
- prop: "productClassifyId",
- label: "物料分类",
- data: treeData.value,
- itemWidth: 100,
- disabled: false,
- fn: (val) => {
- changeProductClassifyId(val);
- },
- },
- {
- type: "input",
- prop: "name",
- label: "物料名称",
- itemWidth: 50,
- disabled: false,
- },
- {
- type: "input",
- prop: "customCode",
- label: "物料编码",
- itemWidth: 50,
- disabled: false,
- },
- {
- type: "uploadImg",
- // limit: 1,
- // listType: "picture-card",
- // accept: ".gif, .jpeg, .jpg, .png",
- imgProp: "imageUrl",
- prop: "fileList",
- label: "物料缩略图",
- isShow: !isSpecial.value,
- },
- {
- type: "title1",
- title: "材质特征",
- isShow: !isSpecial.value,
- },
- {
- type: "input",
- prop: "material",
- label: "材质",
- itemWidth: 50,
- isShow: !isSpecial.value,
- },
- {
- type: "input",
- prop: "spec",
- label: "型号",
- itemWidth: 50,
- isShow: !isSpecial.value,
- },
- {
- type: "select",
- prop: "frontalTexture",
- label: "正面纹路",
- data: frontLinesData.value,
- itemWidth: 50,
- isShow: !isSpecial.value,
- },
- {
- type: "select",
- prop: "reverseTexture",
- label: "背面纹路",
- data: backLinesData.value,
- itemWidth: 50,
- isShow: !isSpecial.value,
- },
- {
- type: "input",
- prop: "unit",
- label: "单位",
- // data: materialUnitData.value,
- itemWidth: 50,
- isShow: !isSpecial.value,
- },
- // {
- // type: "select",
- // prop: "unit",
- // label: "单位",
- // data: materialUnitData.value,
- // itemWidth: 50,
- // },
- {
- type: "select",
- prop: "colorLayer",
- label: "色层",
- data: colorLayerData.value,
- itemWidth: 50,
- isShow: !isSpecial.value,
- },
- // {
- // type: "input",
- // prop: "remark",
- // label: "备注",
- // itemType: "textarea",
- // },
- {
- type: "title1",
- title: "规格",
- isShow: !isSpecial.value,
- },
- {
- type: "input",
- prop: "color",
- label: "颜色",
- itemWidth: 50,
- isShow: !isSpecial.value,
- },
- {
- type: "number",
- prop: "stockThreshold",
- label: "安全库存",
- precision: 0,
- min: 0,
- controls: false,
- itemWidth: 50,
- isShow: !isSpecial.value,
- },
- {
- type: "number",
- prop: "costPrice",
- label: "成本价" + (isShowLabel.value ? "(cm²)" : ""),
- precision: 2,
- min: 0.01,
- controls: false,
- itemWidth: 50,
- isShow: !isSpecial.value,
- },
- // {
- // type: "selectInput",
- // prop: "costPrice",
- // selectProp: "costCurrency",
- // label: "成本价",
- // itemWidth: 50,
- // disabledSelect: true,
- // data: currencyData.value,
- // },
- {
- type: "number",
- prop: "price",
- label: "销售价" + (isShowLabel.value ? "(cm²)" : ""),
- precision: 2,
- min: 0.01,
- controls: false,
- itemWidth: 50,
- isShow: !isSpecial.value,
- },
- {
- type: "number",
- prop: "price",
- label: "销售价(cm²)",
- precision: 2,
- min: 0.01,
- controls: false,
- itemWidth: 50,
- isShow: isSpecial.value,
- },
- // {
- // type: "selectInput",
- // prop: "price",
- // selectProp: "currency",
- // label: "销售价",
- // itemWidth: 50,
- // disabledSelect: true,
- // data: currencyData.value,
- // },
- {
- type: "slot",
- slotName: "size",
- prop: "size",
- label: "",
- itemWidth: 50,
- disabled: false,
- isShow: !isSpecial.value,
- },
- {
- type: "number",
- prop: "netWeight",
- label: "净重(kg)",
- precision: 2,
- min: 0,
- controls: false,
- itemWidth: 50,
- isShow: !isSpecial.value,
- },
- ];
- });
- const getList = async (req) => {
- sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
- loading.value = true;
- proxy.post("/productInfo/page", sourceList.value.pagination).then((res) => {
- sourceList.value.data = res.rows.map((x) => ({ ...x, fileList: [] }));
- sourceList.value.pagination.total = res.total;
- setTimeout(() => {
- loading.value = false;
- }, 200);
- const productIdList = res.rows.map((x) => x.id);
- // 请求文件数据并回显
- if (productIdList.length > 0) {
- proxy.getFile(productIdList, sourceList.value.data, "id");
- }
- });
- };
- const treeChange = (e) => {
- if (e.id != undefined) {
- sourceList.value.pagination.productClassifyId = e.id;
- getList({ productClassifyId: e.id });
- }
- };
- const isSpecial = ref(false);
- const openModal = () => {
- isSpecial.value = false;
- dialogVisible.value = true;
- modalType.value = "add";
- formData.data = {
- definition: "2",
- fileList: [],
- };
- // if (currencyData.value && currencyData.value.length > 0) {
- // formData.data.currency = currencyData.value[0].dictKey;
- // formData.data.costCurrency = currencyData.value[0].dictKey;
- // }
- };
- const submitForm = () => {
- formDom.value.handleSubmit((valid) => {
- if (!isSpecial.value) {
- if (!formData.data.fileList.length > 0) {
- return proxy.msgTip("请上传图片", 2);
- }
- }
- submitLoading.value = true;
- proxy.post("/productInfo/" + modalType.value, formData.data).then(
- (res) => {
- proxy.msgTip("操作成功", 1);
- dialogVisible.value = false;
- submitLoading.value = false;
- getList();
- },
- (err) => {
- submitLoading.value = false;
- }
- );
- });
- };
- const getTreeList = () => {
- proxy
- .post("/productClassify/tree", { parentId: "", name: "", definition: "2" })
- .then((message) => {
- message = message.map((x) => ({ ...x, id: x.id + "" }));
- treeListData.value = [
- {
- id: "",
- label: "全部",
- parentId: "",
- children: message,
- },
- ];
- treeData.value = message;
- });
- };
- const changeProductClassifyId = (val) => {
- let current = findNodeById(treeData.value, val);
- if (current) {
- // 判断是否是无属性原材料
- if (current.id == 110) {
- isSpecial.value = true;
- } else {
- if (current.parentIdSet) {
- // 判断父级id是否包含无属性原材料
- isSpecial.value = current.parentIdSet.includes("110");
- } else {
- // 不是无属性原材料
- isSpecial.value = false;
- }
- }
- if (isSpecial.value == true) {
- for (const key in formData.data) {
- if (
- ["id", "name", "customCode", "price", "productClassifyId"].includes(
- key
- )
- ) {
- } else {
- delete formData.data[key];
- }
- }
- }
- if (current.id == 100) {
- isShowLabel.value = true;
- } else {
- if (current.parentIdSet) {
- isShowLabel.value = current.parentIdSet.includes("100");
- } else {
- isShowLabel.value = false;
- }
- }
- }
- };
- const getDtl = (row) => {
- modalType.value = "edit";
- proxy.post("/productInfo/detail", { id: row.id }).then((res) => {
- formData.data = res;
- changeProductClassifyId(res.productClassifyId);
- formData.data.fileList = row.fileList.map((x) => ({
- ...x,
- url: x.fileUrl,
- name: x.fileName,
- }));
- if (formData.data.fileList.length > 0) {
- formData.data.imageUrl = formData.data.fileList[0].fileUrl;
- }
- dialogVisible.value = true;
- });
- };
- // const getDtlOne = (row) => {
- // modalType.value = "add";
- // proxy.post("/productInfo/detail", { id: row.id }).then((res) => {
- // fileList.value = [];
- // fileListCopy.value = [];
- // res.type = res.type + "";
- // res.definition = "2";
- // delete res.id;
- // formData.data = res;
- // dialogVisible.value = true;
- // });
- // };
- const handleClickFile = (file) => {
- window.open(file.fileUrl, "_blank");
- };
- getTreeList();
- getList();
- const associationConfig = computed(() => {
- return [
- {
- attrs: {
- label: "产品图片",
- slot: "pic",
- align: "center",
- width: 80,
- },
- },
- {
- attrs: {
- label: "产品编码",
- prop: "customCode",
- width: 190,
- },
- },
- {
- attrs: {
- label: "产品名称",
- prop: "name",
- "min-width": 300,
- },
- },
- {
- attrs: {
- label: "尺寸",
- slot: "size",
- width: 130,
- },
- },
- {
- attrs: {
- label: "产品颜色",
- prop: "color",
- width: 160,
- },
- },
- ];
- });
- const associationData = ref({
- data: [],
- pagination: {
- pageNum: 1,
- pageSize: 10,
- total: 3,
- },
- });
- const openAssociationProduct = ref(false);
- const getAssociationList = (req = {}) => {
- associationData.value.pagination = {
- ...associationData.value.pagination,
- ...req,
- };
- proxy
- .post(
- "/productInfo/getProductByMaterialId",
- associationData.value.pagination
- )
- .then((res) => {
- associationData.value.data = res.rows;
- associationData.value.pagination.total = res.total;
- let productIds = associationData.value.data.map((x) => x.id);
- if (productIds && productIds.length > 0) {
- proxy.getFileData({
- businessIdList: productIds,
- data: associationData.value.data,
- att: "id",
- businessType: "0",
- fileAtt: "fileList",
- filePathAtt: "fileUrl",
- });
- }
- });
- };
- const getAssociationProduct = (row) => {
- openAssociationProduct.value = true;
- associationData.value.pagination = {
- pageNum: 1,
- pageSize: 10,
- total: 3,
- materialId: row.id,
- };
- getAssociationList();
- };
- </script>
- <style lang="scss" scoped>
- .user {
- padding: 10px;
- display: flex;
- justify-content: space-between;
- .tree {
- width: 300px;
- }
- .content {
- width: calc(100% - 310px);
- }
- }
- .pic {
- object-fit: contain;
- width: 50px;
- height: 50px;
- cursor: pointer;
- vertical-align: middle;
- }
- </style>
|