Browse Source

form表单增加list的单选changeFn事件

cz 1 year ago
parent
commit
8b6310f877

+ 4 - 1
src/components/testForm/index.vue

@@ -257,7 +257,9 @@
             :columns="item.data"
             :columns-field-names="item.fieldNames ? item.fieldNames : onePickerFieldNames"
             @cancel="item.showPicker = false"
-            @confirm="(option) => onConfirmListPicker(option, item)" />
+            @confirm="(option) =>(item.changeFn ? item.changeFn(option, item, currentIndex , currentSonIndex) : onConfirmListPicker(option, item))"
+            />
+            <!-- @confirm="(option) => onConfirmListPicker(option, item)"  -->
         </van-popup>
         <van-popup v-model:show="item.showPicker" round position="bottom" v-if="item.type == 'picker' && item.itemType == 'datePicker'">
           <van-date-picker
@@ -780,6 +782,7 @@ const changeCheckboxGroup = (form, label, data, fieldNames) => {
 defineExpose({
   formDataShowLabelOne,
   formDataListShowLabelOne,
+  btnConfigCopy,
 });
 // onMounted(() => {});
 </script>

+ 15 - 0
src/lang/cnCZ.js

@@ -34,6 +34,21 @@ export function cnCZ() {
       qualityInspectionQuantityCannotBeZero: "质检数量不能为零",
       qualityInspectionQuantityNotBeGreaterThanArrivalNumber: "质检数量加已质检数量不可大于到货数量",
     },
+    inventoryCount: {
+      name: "库存盘点",
+      inventoryTime: "盘点时间",
+      inventoryPerson: "盘点人",
+      inventoryResult: "盘点结果",
+      inventoryWarehouse: "盘点仓库",
+      goodsName: "物品名称",
+      stockNumber: "库存数量",
+      inventoryNumber: "盘点数量",
+      goodsNameCanNotBeEmpty: "物品名称不能为空",
+      inventoryNumberCanNotBeEmpty: "盘点数量不能为空",
+      qualityUnQualifiedCanNotBeEmpty: "质检不合格不能为空",
+      qualityInspectionQuantityCannotBeZero: "质检数量不能为零",
+      qualityInspectionQuantityNotBeGreaterThanArrivalNumber: "质检数量加已质检数量不可大于到货数量",
+    },
   };
 
   return cnCZ;

+ 10 - 0
src/router/jxskRouter.js

@@ -90,6 +90,16 @@ export function jxskRouter() {
       name: "到货质检添加",
       component: () => import("../views/procurementManagement/arrival/add.vue"),
     },
+    {
+      path: 'inventoryCount',
+      name: '库存盘点',
+      component: () => import('../views/purchase-sales/inventory-management/Inventory/index.vue')
+    },
+    {
+      path: 'inventoryCountAdd',
+      name: '库存盘点添加',
+      component: () => import('../views/purchase-sales/inventory-management/Inventory/add.vue')
+    },
   ];
   return jxskRouter;
 }

+ 201 - 0
src/views/purchase-sales/inventory-management/Inventory/add.vue

@@ -0,0 +1,201 @@
+<template>
+  <div class="form">
+    <van-nav-bar
+      :title="$t('inventoryCount.name')"
+      :left-text="$t('common.back')"
+      left-arrow
+      @click-left="onClickLeft"
+    >
+    </van-nav-bar>
+    <testForm
+      v-model="formData.data"
+      :formOption="formOption"
+      :formConfig="formConfig"
+      :rules="rules"
+      @onSubmit="onSubmit"
+      ref="formDom"
+    ></testForm>
+  </div>
+</template>
+
+<script setup>
+import { ref, reactive, getCurrentInstance, onMounted } from "vue";
+import { showSuccessToast, showFailToast } from "vant";
+import { useRoute } from "vue-router";
+import testForm from "@/components/testForm/index.vue";
+const proxy = getCurrentInstance().proxy;
+const route = useRoute();
+const formDom = ref(null);
+const formData = reactive({
+  data: {},
+});
+const rules = {
+  qualifiedCount: [
+    {
+      required: true,
+      message: proxy.t("inventoryCount.qualityQualifiedCanNotBeEmpty"),
+    },
+  ],
+  noQualifiedCount: [
+    {
+      required: true,
+      message: proxy.t("inventoryCount.qualityUnQualifiedCanNotBeEmpty"),
+    },
+  ],
+};
+const formOption = reactive({
+  readonly: false, //用于控制整个表单是否只读
+  disabled: false,
+  labelAlign: "top",
+  scroll: true,
+  labelWidth: "62pk",
+  submitBtnText: proxy.t("common.submit"),
+  btnConfig: {
+    isNeed: true,
+    label: proxy.t("common.details"),
+    prop: "list",
+    plain: true,
+    listConfig: [
+      {
+        type: "picker",
+        label: proxy.t("inventoryCount.goodsName"),
+        prop: "productId",
+        itemType: "onePicker",
+        showPicker: false,
+        readonly: false,
+        fieldNames: {
+          text: "name",
+          value: "id",
+        },
+        data: [],
+        changeFn: function (option, item, index, currentSonIndex) {
+          console.log(option, item, index, currentSonIndex, "ww");
+          formData.data.list[index][item.prop] = option.selectedOptions[0].id;
+          formData.data.list[index][item.prop + "Name"] =
+            option.selectedOptions[0].name;
+          formDom.value.btnConfigCopy.listConfig[
+            currentSonIndex
+          ].showPicker = false;
+        },
+      },
+      {
+        type: "input",
+        itemType: "text",
+        label: proxy.t("inventoryCount.stockNumber"),
+        prop: "quantity",
+        readonly: true,
+      },
+      {
+        type: "input",
+        itemType: "number",
+        label: proxy.t("inventoryCount.inventoryNumber"),
+        prop: "quantity",
+        readonly: false,
+      },
+    ],
+    clickFn: () => {
+      if (formData.data.list && formData.data.list.length > 0) {
+        formData.data.list.push({
+          productId: "",
+          quantity: "",
+          checkQuantity: "",
+        });
+      } else {
+        formData.data.list = [
+          {
+            productId: "",
+            quantity: "",
+            checkQuantity: "",
+          },
+        ];
+      }
+    },
+  },
+});
+const formConfig = reactive([
+  {
+    type: "picker",
+    label: proxy.t("inventoryCount.inventoryWarehouse"),
+    prop: "warehouseId",
+    itemType: "onePicker",
+    showPicker: false,
+    readonly: false,
+    fieldNames: {
+      text: "name",
+      value: "id",
+    },
+    data: [],
+    changeFn: function (option, item, index) {
+      formData.data[item.prop] = option.selectedOptions[0].id;
+      formData.data[item.prop + "Name"] = option.selectedOptions[0].name;
+      formConfig[index].showPicker = false;
+    },
+  },
+]);
+const onClickLeft = () => history.back();
+const productData = ref([]);
+const getDict = () => {
+  proxy.post("/warehouse/page", { pageNum: 1, pageSize: 9999 }).then((res) => {
+    formConfig[0].data = res.data.rows;
+  });
+  proxy
+    .post("/productInfo/page", { pageNum: 1, pageSize: 9999, definition: "" })
+    .then((res) => {
+      formOption.btnConfig.listConfig[0].data = res.data.rows;
+      productData.value = res.data.rows;
+    });
+};
+onMounted(() => {
+  getDict();
+  if (route.query && route.query.id) {
+    proxy.post("/stockCheck/detail", { id: route.query.id }).then((res) => {
+      console.log(res, "aaa");
+    });
+  }
+});
+
+const onSubmit = () => {
+  let data = { ...formData.data };
+  if (Number(data.qualifiedCount) + Number(data.noQualifiedCount) > 0) {
+    if (
+      Number(data.qualifiedCount) +
+        Number(data.noQualifiedCount) +
+        Number(data.sumQualityCount) >
+      Number(data.count)
+    ) {
+      return showFailToast(
+        proxy.t(
+          "inventoryCount.qualityInspectionQuantityNotBeGreaterThanArrivalNumber"
+        )
+      );
+    } else {
+      let obj = {
+        arrivalDetailId: data.arrivalDetailId,
+        qualifiedCount: data.qualifiedCount,
+        noQualifiedCount: data.noQualifiedCount,
+      };
+      delete data.arrivalDetailId;
+      delete data.qualifiedCount;
+      delete data.noQualifiedCount;
+      data.qualityDetailList = [obj];
+      proxy.post("/quality/add", data).then(
+        () => {
+          showSuccessToast(proxy.t("common.operationSuccessful"));
+          setTimeout(() => {
+            onClickLeft();
+          }, 500);
+        },
+        (err) => {
+          return showFailToast(err.message);
+        }
+      );
+    }
+  } else {
+    return showFailToast(
+      proxy.t("inventoryCount.qualityInspectionQuantityCannotBeZero")
+    );
+  }
+};
+</script>
+<style lang="scss" scoped>
+</style>

+ 110 - 0
src/views/purchase-sales/inventory-management/Inventory/index.vue

@@ -0,0 +1,110 @@
+<template>
+  <van-nav-bar
+    :title="$t('inventoryCount.name')"
+    left-text=""
+    left-arrow
+    @click-left="onClickLeft"
+    @click-right="onClickRight"
+  >
+    <template #right> {{ $t("common.add") }} </template>
+  </van-nav-bar>
+  <van-search
+    v-model="req.keyword"
+    :placeholder="$t('common.pleaseEnterKeywords')"
+    @search="onRefresh"
+  />
+  <van-pull-refresh v-model="loading" @refresh="onRefresh">
+    <div class="list">
+      <van-list
+        v-model:loading="loading"
+        :finished="finished"
+        :finished-text="$t('common.noMore')"
+        @load="getList"
+        style="margin-bottom: 60px"
+      >
+        <commonList :data="listData" @onClick="toDtl" :config="listConfig">
+          <template #inventoryResult="{ row }">
+            <div>
+              <span v-if="row.result == 0">正常</span>
+              <span style="color: #d9001b" v-else>异常</span>
+            </div>
+          </template>
+        </commonList>
+      </van-list>
+    </div>
+  </van-pull-refresh>
+</template>
+<script setup>
+import { ref, getCurrentInstance } from "vue";
+import commonList from "@/components/common-list.vue";
+
+const proxy = getCurrentInstance().proxy;
+const onClickLeft = () => proxy.$router.push("/main/working");
+const req = ref({
+  pageNum: 1,
+  keyword: null,
+  dataType: "1",
+});
+const finished = ref(false);
+const onRefresh = () => {
+  req.value.pageNum = 1;
+  finished.value = false;
+  getList("refresh");
+};
+const loading = ref(false);
+const listData = ref([]);
+const getList = (type) => {
+  loading.value = true;
+  proxy
+    .post("/stockCheck/page", req.value)
+    .then((res) => {
+      listData.value =
+        type === "refresh"
+          ? res.data.rows
+          : listData.value.concat(res.data.rows);
+      if (req.value.pageNum * 10 >= res.data.total) {
+        finished.value = true;
+      }
+      req.value.pageNum++;
+      loading.value = false;
+    })
+    .catch(() => {
+      loading.value = false;
+    });
+};
+const toDtl = (row) => {
+  proxy.$router.push({
+    path: "/main/inventoryCountAdd",
+    query: {
+      id: row.id,
+    },
+  });
+};
+const onClickRight = () => {
+  proxy.$router.push({
+    path: "/main/inventoryCountAdd",
+    query: {},
+  });
+};
+const listConfig = ref([
+  {
+    label: proxy.t("inventoryCount.inventoryTime"),
+    prop: "createTime",
+  },
+  {
+    label: proxy.t("inventoryCount.inventoryPerson"),
+    prop: "userName",
+  },
+  {
+    type: "slot",
+    label: proxy.t("inventoryCount.inventoryResult"),
+    slotName: "inventoryResult",
+  },
+]);
+</script>
+
+<style lang="scss" scoped>
+.list {
+  min-height: 70vh;
+}
+</style>