zuozhengqing
2023-12-06 84d9de8968ea6675ecb57fa7c59a7bf2fede8f4d
src/views/purchaseManage/purchase/components/AddPurchase.vue
@@ -27,9 +27,11 @@
                <el-form-item
                  label="采购类型"
                  prop="purchaseTypeId"
                  class="form-item float_left"
                  class="float_left"
                  style="width:100%;"
                >
                  <el-select
                    :disabled="editConfig.isDisabled"
                    placeholder="请选择采购类型"
                    v-model="editConfig.infomation.purchaseTypeId"
                    clearable
@@ -43,6 +45,7 @@
                    ></el-option>
                  </el-select>
                  <i
                    v-if="!editConfig.isDisabled"
                    class="el-icon-setting margin_left_10px cursor_pointer"
                    style="font-size: 20px; color: #333"
                    @click="handleShow"
@@ -54,11 +57,12 @@
                <el-form-item label="供应商名称" prop="supplierName">
                  <div class="custom-name">
                    <el-autocomplete
                      :disabled="editConfig.isDisabled"
                      style="width: calc(100% - 40px)"
                      v-model="editConfig.infomation.supplierName"
                      :fetch-suggestions="
                        (queryString, callback) => {
                          querySearchAsync(queryString, callback, 'client');
                          querySearchAsync(queryString, callback, 'supplier');
                        }
                      "
                      value-key="name"
@@ -66,6 +70,7 @@
                      @select="handleSelectClient('client', $event)"
                    ></el-autocomplete>
                    <div
                      v-if="!editConfig.isDisabled"
                      class="common-select-btn"
                      @click="selClientClick('client')"
                    >
@@ -79,7 +84,8 @@
                      class="common-select-btn"
                      @click="clearupClient('client')"
                    >
                      <i class="el-icon-remove-outline" title="清除"></i>
                      <i class="el-icon-remove-outline"
                      v-if="!editConfig.isDisabled" title="清除"></i>
                    </div>
                  </div>
                </el-form-item>
@@ -96,6 +102,7 @@
              <el-col :span="12">
                <el-form-item label="采购单名称" prop="name">
                  <el-input
                    :disabled="editConfig.isDisabled"
                    v-model="editConfig.infomation.name"
                    placeholder="请填写"
                    clearable
@@ -105,6 +112,7 @@
              <el-col :span="12">
                <el-form-item label="供应商联系人" prop="contact">
                  <el-input
                    :disabled="editConfig.isDisabled"
                    v-model="editConfig.infomation.contact"
                    placeholder="请填写"
                    clearable
@@ -114,8 +122,11 @@
              <el-col :span="12">
                <el-form-item label="联系电话" prop="phone">
                  <el-input
                    :disabled="editConfig.isDisabled"
                    v-model="editConfig.infomation.phone"
                    placeholder="请填写"
                    maxlength="11"
                    show-word-limit
                    clearable
                  ></el-input>
                </el-form-item>
@@ -123,6 +134,7 @@
              <el-col :span="12">
                <el-form-item label="签约日期" prop="signingDate">
                  <el-date-picker
                    :disabled="editConfig.isDisabled"
                    v-model="editConfig.infomation.signingDate"
                    style="width: 100%"
                    type="date"
@@ -136,6 +148,7 @@
              <el-col :span="12">
                <el-form-item label="交付日期" prop="deliveryDate">
                  <el-date-picker
                    :disabled="editConfig.isDisabled"
                    v-model="editConfig.infomation.deliveryDate"
                    style="width: 100%"
                    type="date"
@@ -149,6 +162,7 @@
              <el-col :span="24">
                <el-form-item label="备注信息" prop="remark">
                  <el-input
                    :disabled="editConfig.isDisabled"
                    type="textarea"
                    :autosize="{ minRows: 3, maxRows: 4 }"
                    maxlength="500"
@@ -163,6 +177,7 @@
          <div class="basic-info-title" style="display: flex">产品信息</div>
          <div class="product-view">
            <CommonFormTableView
              :detailEnter=editCommonConfig.detailEnter
              :show-summary="showSummary"
              :recalculateShow="false"
              :product-table-list="productTableList"
@@ -172,6 +187,8 @@
              @addProductClick="addProductClick"
              @emptyProductClick="emptyProductClick"
              @clearupProduct="clearupProduct"
              @rowClick="rowClick"
              @handleProduct="handleProduct"
            />
          </div>
          <div class="table-bottom">
@@ -181,6 +198,7 @@
                  <el-select
                    v-model="editConfig.infomation.wholeDiscountType"
                    placeholder="请选择"
                    :disabled="editConfig.isDisabled"
                    filterable
                    @change="getTotal"
                  >
@@ -194,7 +212,7 @@
                  <el-input
                    v-model="editConfig.infomation.wholeDiscount"
                    size="mini"
                    :disabled="editConfig.infomation.wholeDiscountType?false:true"
                    :disabled="editConfig.isDisabled"
                    @change="getTotal"
                    placeholder="请填写"
                  ></el-input>
@@ -205,6 +223,7 @@
              <div class="table-bottom-l">
                <el-form-item label="调整" prop="member_id">
                  <el-select
                    :disabled="editConfig.isDisabled"
                    v-model="editConfig.infomation.priceAdjustmentType"
                    placeholder="请选择"
                    filterable
@@ -218,9 +237,9 @@
              <div class="table-bottom-r">
                <el-form-item label="" prop="member_id">
                  <el-input
                    :disabled="editConfig.isDisabled"
                    v-model="editConfig.infomation.priceAdjustment"
                    size="mini"
                    :disabled="editConfig.infomation.priceAdjustmentType?false:true"
                    @change="getTotal"
                    placeholder="请填写"
                  ></el-input>
@@ -236,10 +255,10 @@
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" size="small" @click="editConfig.visible = false">保并提交审批</el-button> -->
        <el-button type="primary" size="small" @click="saveClick('form')"
        <el-button type="primary" v-if="this.editConfig.title != '查看'" size="small" @click="saveClick('form')"
          >保存</el-button
        >
        <el-button size="small" @click="editConfig.visible = false"
        <el-button size="small" v-if="this.editConfig.title != '查看'" @click="editConfig.visible = false"
          >取消</el-button
        >
      </div>
@@ -264,6 +283,7 @@
<script>
import CommonFormTableView from "@/components/makepager/CommonFormTableView";
import BomDialog from "@/components/makepager/BomDialog";
import { getProductList } from "@/api/productManage/product"
import {
  addPurchase,
@@ -273,6 +293,7 @@
} from "@/api/purchaseManage/purchase";
import SelectSupplierDialog from "@/views/purchaseManage/purchase/components/SelectSupplierDialog";
// import { formToJSON } from "axios";
export default {
  name: "QuotationDialog",
  components: { SelectSupplierDialog, CommonFormTableView,BomDialog },
@@ -281,6 +302,7 @@
      type: Object,
      default: () => {
        return {
          detailEnter:true,
          visible: false,
          title: "创建",
          infomation: {},
@@ -344,7 +366,8 @@
      },
      supplierId: this.editCommonConfig.infomation.supplierId,
      tableData: [],
      productId: 1,
      productIndex: 0,
      productId:'',
      isNoProduct: true,
      clientList: [],
      plcBrandList:[],
@@ -353,12 +376,18 @@
      },
      total:0,
      totalTwo:0,
      productListIdx:0,
      lacks:[],
    };
  },
  created() {
    this.handleGetBomKindDictList();
    this.$store.dispatch("getSupplier")
  },
  computed: {
    supplierList() {
      return this.$store.state.getSupplierName.supplierList
    }
  },
  watch:{
    'editCommonConfig.visible':{
@@ -432,8 +461,12 @@
    },
    handleConfirmSave(data) {
      console.log(data,'data')
      data.forEach(ele=>{
        delete ele.created_at
      })
      savePurchaseType(data).then((res) => {
        if (res.code == 200) {
        if (res.code === 200) {
          this.$message({
            message: "操作成功!",
            type: "success",
@@ -441,6 +474,12 @@
          this.$refs.editDialog.editDialogVisible = false;
          this.handleGetBomKindDictList(true);
        }
      },(err)=>{
        console.error(err)
        this.$message({
          message: "操作失败!",
          type: "warning",
        });
      });
    },
    validatorPhone(rule, value, callback) {
@@ -480,24 +519,93 @@
            this.$message.error("产品名称不能为空");
          } else {
            const params = this.saveParams();
            console.log(params);
            //新建
            if (this.editConfig.title === "创建") {
              addPurchase(params).then((res) => {
                console.log(res);
                this.editConfig.visible = false;
                if (res.code === 200) {
                  this.$message.success("添加成功");
                  this.$parent.getData();
              this.lacks=[]
              this.tableData.forEach((item)=>{
                if(this.productTableList.tableProductList.map(obj => obj.number).includes(item.number)) {
                    console.log(`${item.name} 在数组中存在`);
                } else {
                  this.lacks.push(item.name)
                }
              });
              })
              if(this.lacks.length>0){
                this.$confirm(`当前供应商不能提供您选择的产品:${this.lacks},    是否继续创建采购单?`, '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                }).then(() => {
                  console.log("确定创建")
                  //创建采购单
                  addPurchase(params).then((res) => {
                    this.editConfig.visible = false;
                    if (res.code === 200) {
                      this.$message.success("创建成功");
                      this.$parent.getData();
                    }
                  });
                }).catch(() => {
                  console.log("取消创建")
                });
              }else{
                addPurchase(params).then((res) => {
                  this.editConfig.visible = false;
                  if (res.code === 200) {
                    this.$message.success("创建成功");
                    this.$parent.getData();
                  }
                });
              }
            } else {
              updatePurchase(params).then((res) => {
                this.editConfig.visible = false;
                if (res.code === 200) {
                  this.$message.success("编辑成功");
                  this.$parent.getData();
              // 编辑
              getProductList({
                supplierId:this.editConfig.infomation.supplierId,
                page:1,
                pageSize:100
              }).then((res)=>{
                if(res.code===200){
                  this.lacks=[]
                  // 编辑前先看看当前供应商对应的产品列表
                  this.productTableList.tableProductList = res.data.list
                  //当前产品是否在当前供应商下存在
                  this.tableData.forEach((item)=>{
                    if(this.productTableList.tableProductList.map(obj => obj.number).includes(item.number)) {
                      console.log(`${item.name} 在数组中存在`);
                    } else {
                      this.lacks.push(item.name)
                    }
                  })
                  // 不存在的产品信息
                  if(this.lacks.length>0){
                    this.$confirm(`当前供应商不能提供您选择的产品:${this.lacks},    是否继续更新采购单?`, '提示', {
                      confirmButtonText: '确定',
                      cancelButtonText: '取消',
                      type: 'warning'
                    }).then(() => {
                      console.log("确定更新")
                      //更新采购单
                      updatePurchase(params).then((res) => {
                        this.editConfig.visible = false;
                        if (res.code === 200) {
                          this.$message.success("更新成功");
                          this.$parent.getData();
                        }
                      });
                    }).catch(() => {
                      console.log("取消更新")
                    });
                  }else {
                    updatePurchase(params).then((res) => {
                      this.editConfig.visible = false;
                      if (res.code === 200) {
                        this.$message.success("更新成功");
                        this.$parent.getData();
                      }
                    });
                  }
                }
              });
              })
            }
          }
        } else {
@@ -518,7 +626,7 @@
      let params = {
        productList:this.tableData,
        purchase:{
          supplierId:this.supplierId||0,
          supplierId:data.supplierId,
          signingDate:data.signingDate||'',
          remark:data.remark,
          orderSource:data.orderSource||'',
@@ -533,6 +641,8 @@
          priceAdjustment:data.priceAdjustment?Number(data.priceAdjustment):0,
          realTotalPrice:this.total?Number(this.total):0,
          totalPrice:this.totalTwo?Number(this.totalTwo):0,
          status:data.status,
          quantity:data.quantity, // 采购数量
        }
      };
      if(data.ID){
@@ -545,9 +655,10 @@
    },
    // 选择客户相关方法
    querySearchAsync(queryString, cb, value) {
      this.productTableList.tableProductList=[]
      var restaurants = [];
      if (value === "client") {
        restaurants = this.clientList;
      if (value === "supplier") {
        restaurants = this.supplierList;
      } 
      var results = queryString
        ? restaurants.filter(this.createStateFilter(queryString))
@@ -561,20 +672,41 @@
        );
      };
    },
    handleSelectClient(value, item) {
      console.log(value);
    // 选择供应商
    async handleSelectClient(value, item) {
      this.productTableList.supplierId=item.ID
      if (value === "client") {
        this.supplierId = item.id;
        this.editConfig.infomation.supplierId=item.ID
      }
      await getProductList({
        supplierId:item.ID,
        page:1,
        pageSize:100
      }).then((res)=>{
        if(res.code===200){
          this.productTableList.tableProductList = res.data.list
          console.log(this.productTableList.tableProductList,"pop")
        }
      })
    },
    selClientClick() {
      this.editSelectSupplierConfig.editVisible = true;
    },
    selClient(row) {
    async selClient(row) {
      await getProductList({
        supplierId:row.ID,
        page:1,
        pageSize:100
      }).then((res)=>{
        if(res.code===200){
          this.productTableList.tableProductList = res.data.list
        }
      })
      this.$set(this.editConfig.infomation,'supplierName',row.name)
      this.editConfig.infomation.contact = row.contact;
      this.editConfig.infomation.phone = row.phone;
      this.supplierId = row.ID;
      this.editConfig.infomation.supplierId = row.ID;
    },
    // 清除已选择用户
    clearupClient(value) {
@@ -591,14 +723,21 @@
      ) {
        this.tableData = [
          {
            purchaseId:0,
            productId: this.productId,
            id: 0,
            productIndex:this.productIndex,
            amount: 0,
            desc: "",
            name: "",
            number: "",
            price: 0,
            total: 0,
            remark:'',
            unit:'',
            purchasePrice:'',
            deliveryTime:"",
            shippingDuration:"",
            specifications:"",
            modelNumber:"",
          },
        ];
      } else {
@@ -608,7 +747,10 @@
        // });
      }
      this.productTableList = {
        tableProductList:[],
        supplierId:undefined,
        tableData: this.tableData,
        disabled:this.editConfig.isDisabled,
        tableColumn: [
          {
            label: "产品名称",
@@ -616,19 +758,21 @@
            min: 180,
            productName: true,
            isRequird: true,
            disabled:this.editConfig.isDisabled,
          },
          { label: "产品编号", prop: "number", min: 150,},
          { label: "计量单位", prop: "unit" },
          { label: "规格型号", prop: "specifications" },
          { label: "数量", prop: "amount", inputNumber: true, isRequird: true },
          { label: "规格型号", prop: "specifications",},
          { label: "数量", prop: "amount", inputNumber: true,disabled:this.editConfig.isDisabled, },
          {
            label: "采购单价",
            prop: "price",
            inputFloat: true,
            isRequird: true,
            disabled:this.editConfig.isDisabled,
          },
          { label: "价税合计", prop: "total", inputFloat: true,disabled:true,multiply:true, },
          { label: "描述", prop: "remark", input: true },
          { label: "价税合计", prop: "total", inputFloat: true,disabled:this.editConfig.isDisabled,multiply:true, },
          { label: "描述", prop: "remark", input: true,disabled:this.editConfig.isDisabled},
        ],
      };
      this.toal=this.editConfig.infomation.realTotalPrice
@@ -636,13 +780,18 @@
    },
    // 产品列表输入
    inputContent(val, prop, row) {
      this.productId = row.productId;
      // this.productId = row.productId;
      this.productIndex=row.productIndex;
      let num=0
      this.tableData.map((item) => {
        if (item.productId === row.productId) {
        num+=item.amount
        if (item.productIndex === row.productIndex) {
          item[prop] = val;
        }
      });
      if(prop==="amount"){
        this.editConfig.infomation.quantity=num
      }
    },
    getSummaries(total){
      this.totalTwo= JSON.parse(JSON.stringify(total));
@@ -670,9 +819,10 @@
    },
    // 产品新增
    addProductClick() {
      this.productId++;
      this.productIndex++;
      this.tableData.push({
        productId: this.productId,
        productIndex: this.productIndex,
        productId:'',
        id: 0,
        amount: 0,
        desc: "",
@@ -685,12 +835,13 @@
    },
    //  产品清空
    emptyProductClick() {
      this.productId = 1;
      this.productIndex = 1;
      this.tableData = [
        {
          productId: this.productId,
          productId: '',
          productIndex:this.productIndex,
          id: 0,
          amount: 0,
          amount: "0",
          desc: "",
          name: "",
          number: "",
@@ -704,6 +855,16 @@
      this.tableData = data;
      this.productTableList.tableData = this.tableData;
    },
    //选择行
    rowClick(row){
      console.log(row,"xuanze")
      this.productListIdx=row.productIndex
    },
    //选中产品
    handleProduct(item){
      this.tableData[this.productListIdx].productId=item.ID
      console.log(item,"选中产品",this.tableData)
    }
  },
};
</script>