haoyahui
2023-11-13 6843b10472482b305b5580cc2f5cdbb97fb9a203
admin-web/src/views/stock/accessStock/outbound/edit.vue
@@ -6,14 +6,14 @@
          <el-col :span="12">
            <el-form-item label="出库仓库" prop="warehouseId">
              <el-select v-model="formData.warehouseId" placeholder="请选择" style="width: 100%">
                <el-option v-for="item in warehouses" :key="item.id" :label="item.warehouseName" :value="item.id" />
                <el-option v-for="item in warehouseOptions" :key="item.id" :label="item.warehouseName" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出库时间" prop="procureTime">
            <el-form-item label="出库时间" prop="dealTime">
              <el-date-picker
                v-model="formData.procureTime"
                v-model="formData.dealTime"
                type="datetime"
                value="yyyy-MM-dd HH:mm:ss"
                value-format="yyyyMMddHHmmss"
@@ -25,18 +25,18 @@
          </el-col>
        </el-row>
        <el-row :gutter="24" class="headerHeight">
          <el-col :span="12">
          <el-col :span="24">
            <el-form-item label="出库手续" prop="procureDoc">
              <upload :settings="uploadSettings" @on-change="uploadChange"></upload>
              <upload ref="uploadRef" :settings="uploadSettings" @on-change="uploadChange"></upload>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="goods-card" v-for="(goodsItem, goodsIndex) in formData.procureGoods" :key="goodsIndex">
        <div class="goods-card" v-for="(goodsItem, goodsIndex) in formData.goods" :key="goodsIndex">
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item
                label="物品分类"
                :prop="`procureGoods[${goodsIndex}].baseCategoryIds`"
                :prop="`goods[${goodsIndex}].baseCategoryIds`"
                :rules="{
                  required: true,
                  message: '请选择',
@@ -55,7 +55,7 @@
            <el-col :span="12">
              <el-form-item
                label="物品名称"
                :prop="`procureGoods[${goodsIndex}].baseGoodsTemplateId`"
                :prop="`goods[${goodsIndex}].baseGoodsTemplateId`"
                :rules="{
                  required: true,
                  message: '请选择',
@@ -84,7 +84,7 @@
            <el-col :span="12">
              <el-form-item
                label="规格型号"
                :prop="`procureGoods[${goodsIndex}].modelsIds`"
                :prop="`goods[${goodsIndex}].modelsIds`"
                :rules="{
                  required: true,
                  message: '请选择',
@@ -138,7 +138,7 @@
          </el-table>
          <div class="btn-group">
            <el-button
              v-if="formData.procureGoods.length > 1"
              v-if="formData.goods.length > 1"
              name="移除"
              type="danger"
              plain
@@ -147,7 +147,7 @@
              >移除</el-button
            >
            <el-button
              v-if="formData.procureGoods.length - 1 == goodsIndex"
              v-if="formData.goods.length - 1 == goodsIndex"
              name="新增物品"
              type="primary"
              plain
@@ -168,12 +168,13 @@
<script>
import {
  goodsTemplate,
  procureAdd,
  procureEdit,
  selectTenantWarehouse,
  goodsModel,
  procureDetail,
} from '@/api/stock/procure/purchaseOrder';
  selectTenantWarehouse,
} from '@/api/baseSetting/finsystenant';
import {
  outputAdd,
  outputSelectNumber
} from '@/api/stock/accessStock';
import { getTree } from '@/api/foudation/classification';
import MyButton from '@/components/myButton/myButton';
import winMd from '@/components/win/win-md';
@@ -192,35 +193,21 @@
  },
  data() {
    return {
      visible: false,
      loading: false,
      buyTypeOptions: [
        {
          label: '集采',
          value: '1',
        },
        {
          label: '自采',
          value: '2',
        },
      ],
      warehouses: [], // 出库仓库列表
      warehouseOptions: [], // 出库仓库列表
      categoryOptions: [], // 物品分类列表
      modelList: [], //型号列表
      formData: {
        warehouseId: '', // 出库仓库id
        procureTime: '', // 出库时间
        buyType: '2', // 出库方式(1:集采;2=自采)
        procureGoods: [],
        dealTime: '', // 出库时间
        procureDoc: '',
        goods: [],
      },
      goodsItem: {
        whFormProcureId: '', // 出库单ID
        baseCategoryIds: '', // 分类编号数组
        baseCategoryId: '', // 分类编号
        baseGoodsTemplateId: '', // 物品模版编号
        goodsTemplateName: '', // 物品模版名称
        supplier: '', // 供应商
        sort: '', // 显示顺序
        goodsOptions: [], // 物品列表select
        modelsOptions: [], //规格型号select
        models: [], // 物品名称
@@ -228,18 +215,16 @@
      },
      modelsItem: {
        baseGoodsModelsId: '', // 规格型号编号
        price: 0, // 单价(出库需要,调拨不需要)
        worehouseCount: 0,
        counts: 0, // 操作数量
        supplier: '', // 供应商
        unit: null, //单位
      },
      rules: {
        warehouseId: [{ required: true, message: '请选择', trigger: 'change' }],
        procureTime: [{ required: true, message: '请选择', trigger: 'change' }],
        dealTime: [{ required: true, message: '请选择', trigger: 'change' }],
        buyType: [{ required: true, message: '请选择', trigger: 'change' }],
        // procureDoc: [{ required: true, message: '请上传', trigger: 'change' }],
        procureDoc: [{ required: true, message: '请上传', trigger: 'change' }],
        baseCategoryIds: [{ required: true, message: '请选择', trigger: 'change' }],
        baseGoodsTemplateId: [{ required: true, message: '请选择', trigger: 'change' }],
        modelsIds: [{ required: true, message: '请选择', trigger: 'change' }],
@@ -248,13 +233,13 @@
      uploadSettings: {
        title: '上传',
        max: 20, // 最大大小,单位M
        num: 2, // 支持上传图片个数
        num: 10, // 支持上传图片个数
        accept: '.jpg,.png', // 限制格式
        tip: '', // 提示 默认:`只能上传${this.defaultSettings.num}个${this.defaultSettings.accept}文件,且不超过${this.defaultSettings.max}kb`
        uploadUrl: getUploadUrl(), // 上传路径
        multiple: true, // 是否支持批量上传
        disabled: false, // 是否禁用
        type: 'text', // text/picture
        type: 'picture', // text/picture
      },
    };
  },
@@ -269,39 +254,17 @@
      // 获取物品分类列表
      const treeRes = await getTree();
      this.categoryOptions = this.removeEmptyChildren(treeRes);
      if (this.setting.id) {
        const detail = await procureDetail({ id: this.setting.id });
        this.formData = Object.assign(this.formData, detail);
        this.$set(this.formData, 'buyType', this.formData.buyType.toString());
        this.formData.procureTime = this.formData.procureTime.toString();
        this.formData.procureGoods.map((item, index) => {
          // 根据子集ID拼接物品分类列表
          let pIds = this.findParentIds(this.categoryOptions, item.baseCategoryId);
          pIds = pIds.reverse();
          item.baseCategoryIds = [...pIds, item.baseCategoryId];
          this.$set(
            this.formData.procureGoods[index],
            'modelsIds',
            item.models.map((v) => v.baseGoodsModelsId),
          );
          this.getgoodsTemplate(item.baseCategoryId, index);
          this.getgoodsModel(item.baseGoodsTemplateId, index);
          return item;
        });
      } else {
        this.formData.procureGoods.push(JSON.parse(JSON.stringify(this.goodsItem)));
      }
      this.visible = true;
      this.formData.goods.push(JSON.parse(JSON.stringify(this.goodsItem)));
    },
    // 获取出库仓库列表
    getWarehouseList() {
      selectTenantWarehouse()
        .then((res) => {
          this.warehouses = res;
          if (this.warehouses.length && !this.formData.warehouseId) {
          this.warehouseOptions = res;
          if (this.warehouseOptions.length && !this.formData.warehouseId) {
            // 默认选中第一个仓库
            this.formData.warehouseId = this.warehouses[0].id;
            this.formData.warehouseId = this.warehouseOptions[0].id;
          }
        })
        .catch((err) => {
@@ -324,7 +287,7 @@
    getgoodsTemplate(id, index) {
      goodsTemplate({ categoryId: id || '' }).then((res) => {
        if (index || index == 0) {
          this.$set(this.formData.procureGoods[index], 'goodsOptions', res);
          this.$set(this.formData.goods[index], 'goodsOptions', res);
        } else {
          this.goodsTemplatelAll = res;
        }
@@ -335,7 +298,7 @@
    getgoodsModel(id, index) {
      goodsModel({ goodsTemplatesId: id || '' }).then((res) => {
        if (index || index == 0) {
          this.$set(this.formData.procureGoods[index], 'modelsOptions', res);
          this.$set(this.formData.goods[index], 'modelsOptions', res);
        } else {
          this.goodsModelAll = res;
        }
@@ -362,67 +325,70 @@
    // 物品分类选择
    categoryChange(e, index) {
      this.formData.procureGoods[index].goodsOptions = [];
      this.formData.procureGoods[index].baseGoodsTemplateId = '';
      this.formData.procureGoods[index].goodsTemplateName = '';
      this.formData.procureGoods[index].modelsOptions = [];
      this.formData.procureGoods[index].modelsIds = [];
      this.formData.procureGoods[index].models = [];
      this.formData.goods[index].goodsOptions = [];
      this.formData.goods[index].baseGoodsTemplateId = '';
      this.formData.goods[index].goodsTemplateName = '';
      this.formData.goods[index].modelsOptions = [];
      this.formData.goods[index].modelsIds = [];
      this.formData.goods[index].models = [];
      this.formData.procureGoods[index].baseCategoryId = e[e.length - 1];
      this.formData.goods[index].baseCategoryId = e[e.length - 1];
      // 根据选中分类请求物品名称列表
      this.getgoodsTemplate(e[e.length - 1], index);
    },
    // 物品名称列表
    goodsTemplateChange(e, index) {
      this.formData.procureGoods[index].modelsOptions = [];
      this.formData.procureGoods[index].modelsIds = [];
      this.formData.procureGoods[index].models = [];
      this.formData.goods[index].modelsOptions = [];
      this.formData.goods[index].modelsIds = [];
      this.formData.goods[index].models = [];
      this.formData.procureGoods[index].goodsTemplateName = this.getGoodsTemplateName(e);
      this.formData.goods[index].goodsTemplateName = this.getGoodsTemplateName(e);
      // 根据选中物品名称id获取规格型号列表
      this.getgoodsModel(e, index);
    },
    // 规格型号选择
    modelChange(e, index) {
      let arr = [...this.formData.procureGoods[index].models];
    async modelChange(e, index) {
      let arr = [...this.formData.goods[index].models];
      let str = JSON.stringify(arr);
      e.forEach((item) => {
      for(let item of e) {
        if (str.indexOf(item) == -1) {
          let temp = this.goodsModelAll.find((v) => v.id == item);
          arr.push({ ...this.modelsItem, baseGoodsModelsId: item, unit: temp.unit });
          // 获取库存
          let num = await outputSelectNumber({warehouseId:this.formData.warehouseId,baseGoodsModelsId:item})
          arr.push({ ...this.modelsItem, baseGoodsModelsId: item, unit: temp.unit,worehouseCount: num});
        }
      });
      this.formData.procureGoods[index].models = arr;
      }
      this.formData.goods[index].models = arr;
    },
    // 规格型号移除
    modelRemoveTag(e, index) {
      let arr = this.formData.procureGoods[index].models;
      let arr = this.formData.goods[index].models;
      let delIndex = arr.findIndex((v) => v.baseGoodsModelsId == e);
      this.formData.procureGoods[index].models.splice(delIndex, 1);
      this.formData.goods[index].models.splice(delIndex, 1);
    },
    // 上传
    uploadChange(e) {
      console.log('uploadChange', e);
    uploadChange() {
      let arr = this.$refs.uploadRef.fileList
      this.formData.procureDoc = JSON.stringify(arr)
    },
    // 点击新增物品
    addGoods() {
      this.formData.procureGoods.push(JSON.parse(JSON.stringify(this.goodsItem)));
      this.formData.goods.push(JSON.parse(JSON.stringify(this.goodsItem)));
    },
    // 点击移除
    removeGoods(index) {
      this.formData.procureGoods.splice(index, 1);
      this.formData.goods.splice(index, 1);
    },
    // 出库数量校验
    countsChange(e, goodsIndex,index) {
      const curItem = this.formData.procureGoods[goodsIndex].models[index]
      const curItem = this.formData.goods[goodsIndex].models[index]
      const worehouseCount = curItem.worehouseCount
      if (e > worehouseCount) {
        this.$message.warning('数额超过现有库存');
@@ -435,19 +401,7 @@
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          console.log('this.formData', this.formData);
          if (this.setting.id) {
            procureAdd(this.formData)
              .then((res) => {
                this.$message.success('保存成功!');
                this.close();
                this.$emit('search');
              })
              .catch((err) => {
                console.log('create err', err);
                this.$message.error('保存失败');
              });
          } else {
            procureEdit(this.formData)
            outputAdd(this.formData)
              .then((res) => {
                this.$message.success('保存成功!');
                this.close();
@@ -457,7 +411,6 @@
                console.log('edit err', err);
                this.$message.error('保存失败');
              });
          }
        } else {
          this.$message.error('校验未通过,请检查。');
        }
@@ -467,8 +420,8 @@
    close() {
      this.formData = {
        warehouseId: '', // 出库仓库id
        procureTime: '', // 出库时间
        procureGoods: [],
        dealTime: '', // 出库时间
        goods: [],
      };
      this.$emit('close');
    },