zuozhengqing
2023-12-06 84d9de8968ea6675ecb57fa7c59a7bf2fede8f4d
src/views/purchaseManage/purchase/index.vue
@@ -1,62 +1,81 @@
<template>
  <div class="rightContent">
    <div class="content-box" v-loading="tableLoading">
      <div class="supplier-search">
        <SearchCommonView
          ref="searchCommonView"
          :inputSelect="false"
          placeholder="可输入供应商,物料,采购单等搜索"
          @searchClick="searchClick"
          @resetClick="resetClick"
  <div class="purchase"  v-loading="tableLoading">
    <div class="filter">
      <div class="filter-card">
        <CommonSearch
            :show-add="true"
            add-title="新建"
            @addCommonClick="addBtnClick"
            :show-download="false"
            :amount-view="false"
            :show-action-btn="false"
            :placeholder="'请输入供应商名称/物料名称/采购单名称'"
            @searchClick="onFilterSearch"
        />
        <div class="add-view">
          <el-button type="primary" size="mini" @click="addBtnClick">新建</el-button>
        </div>
      </div>
      <template>
        <TableCommonView
          class="content-table"
          ref="tableListRef"
          :table-list="tableList"
          @selCommonClick="selCommonClick"
        >
          <template slot="tableButton">
            <el-table-column label="状态" width="120">
              <template slot-scope="scope">
                {{ getpurchaseStatus(scope.row.status) }}
              </template>
            </el-table-column>
            <el-table-column label="操作" width="120" fixed="right">
              <template slot-scope="scope">
                <el-button type="text" size="small" @click="editClick(scope.row)" style="margin-right: 5px"
    </div>
    <div class="body">
      <div class="body-card">
        <div class="list-view">
          <TableCommonView
              ref="tableListRef"
              :table-list="tableList"
              @selCommonClick="selCommonClick"
              @selTableCol="selTableCol"
          >
            <template slot="tableButton">
              <el-table-column  label="状态" width="120">
                <template slot-scope="scope">
                  {{ getpurchaseStatus(scope.row.status) }}
                </template>
              </el-table-column>
              <el-table-column label="操作" width="220" fixed="right">
                <template slot-scope="scope">
                  <el-button v-if="scope.row.status===1" type="text" size="small" @click="btnConfirm(scope.row)" style="margin-right: 5px"
                  >确认</el-button
                  >
                  <el-button v-if="scope.row.status===1" type="text" size="small" @click="btnEdit(scope.row)" style="margin-right: 5px"
                  >编辑</el-button
                >
                <el-button @click="submitClick(scope.row)" type="text" size="small">提交</el-button>
              </template>
            </el-table-column>
          </template>
        </TableCommonView>
                  >
                  <el-button type="text" size="small" @click="btnLook(scope.row)" style="margin-right: 5px"
                  >查看</el-button
                  >
                  <el-button v-if="scope.row.status===1" type="text" size="small" @click="btnCancel(scope.row)" style="margin-right: 5px"
                  >取消</el-button
                  >
                  <!-- <el-button v-if="scope.row.status===1" type="text" size="small" @click="btnDelete(scope.row)" style="margin-right: 5px"
                  >删除</el-button
                  > -->
                  <!-- <el-button v-if="scope.row.status< 4" @click="submitClick(scope.row)" type="text" size="small">提交</el-button> -->
                </template>
              </el-table-column>
            </template>
          </TableCommonView>
        </div>
        <div class="btn-pager">
          <PagerView class="page" :pager-options="pagerOptions" v-on="pagerEvents" />
        </div>
      </template>
      </div>
    </div>
    <!-- 新建/编辑销售线索 -->
    <!-- <AddSalesLeadDialog v-if="editSalesLeadConfig.visible" :edit-rightContent-config="editSalesLeadConfig" /> -->
    <!-- 详情 -->
    <DetailSupplier v-if="commonDetail.visible" :common-detail="commonDetail" />
    <!-- 新建/编辑 -->
    <AddPurchase v-if="editConfig.visible" :edit-common-config="editConfig" />
    <AddPurchase ref="addDialog" v-if="editConfig.visible" :edit-common-config="editConfig" />
  </div>
</template>
<script>
import pageMixin from "@/components/makepager/pager/mixin/pageMixin"
import { getPurchaseList, getPurchaseInfo, submitPurchase } from "@/api/purchaseManage/purchase"
import { getPurchaseList, getPurchaseInfo, submitPurchase,deletePurchase } from "@/api/purchaseManage/purchase"
import DetailSupplier from "@/views/purchaseManage/purchase/DetailSupplier"
import AddPurchase from "@/views/purchaseManage/purchase/components/AddPurchase"
import { getDataByType } from "@/api/data"
import { getSupplierList } from "@/api/supplierManage/supplier"
import { getDataByType } from "@/api/data";
export default {
  name: "SupplierManage",
  props: {},
@@ -65,6 +84,7 @@
  computed: {},
  data() {
    return {
      purchaseStatusList:getDataByType('purchaseStatus'),
      tableLoading: false,
      tableList: {}, // 列表
      selValueList: [],
@@ -77,14 +97,55 @@
      editConfig: {
        visible: false,
        title: "创建",
        infomation: {}
        isDisabled:false,
        detailEnter:false,
        infomation: {
          supplierList:[]
        }
      },
      purchaseStatusList: getDataByType("purchaseStatus")
      tableColumn: [
        { label: "单据类型", prop: "orderType", min: 130 },
        { label: "采购单号", prop: "number", min: 150, isCommonClick: true ,default:true},
        { label: "采购单名称", prop: "name", min: 130, isCommonClick: true },
        { label: "供应商名称", prop: "supplierName", min: 130 },
        { label: "采购数量", prop: "quantity", min: 130 },
        { label: "收货仓库", prop: "warehouse", min: 130 },
        { label: "经办人", prop: "handledBy", min: 130 },
        { label: "制单人", prop: "creator", min: 130 }
      ],
      showCol: ['采购单号', '采购单名称', '单据类型', '供应商名称', '采购数量', '收货仓库','经办人','制单人'],
      pagerOptions:{
        pageSize:15,
        currPage:1,
      },
    }
  },
  created() {
    console.log(this.$route.params,"路由参数")
    if(this.$route.params.supplierId){
      this.editConfig.visible = true
      this.editConfig.infomation = {
        productList: [],
        purchaseTypeId: "",
        supplierId: this.$route.params.supplierId||'',
        supplierName: this.$route.params.supplierName||'',
        orderSource: "手动创建",
        name: "",
        contact: "",
        phone: "",
        signingDate: "",
        deliveryDate: "",
        remark: "",
        wholeDiscountType: null,
        wholeDiscount: 0,
        priceAdjustmentType: null,
        priceAdjustment: 0,
        realTotalPrice: 0
      }
    }
    this.setTable()
    this.getData()
    this.getSupplierData()
  },
  methods: {
    getpurchaseStatus(val) {
@@ -98,52 +159,74 @@
        return "--"
      }
    },
    setColumnVisible(showCol){
      return  this.tableColumn.map(ele=>{
        return {
          ...ele,
          isShowColumn:showCol.includes(ele.label)
        }
      })
    },
    setTable() {
      this.tableList = {
        tableInfomation: [],
        selectIndex: true,
        tableColumn: [
          { label: "采购单号", prop: "number", min: 150, isCommonClick: true },
          { label: "采购单名称", prop: "name", min: 130, isCommonClick: true },
          { label: "单据类型", prop: "orderType", min: 130 },
          { label: "供应商名称", prop: "contact", min: 130 },
          { label: "采购数量", prop: "quantity", min: 130 },
          { label: "收货仓库", prop: "warehouse", min: 130 },
          { label: "经办人", prop: "handledBy", min: 130 },
          { label: "制单人", prop: "creator", min: 130 }
        ]
        showcol: this.showCol,
        allcol: [],
        tableColumn:this.setColumnVisible(this.showCol)
      }
      this.tableList.allcol = this.tableList.tableColumn.filter(ele=>!ele.default).map(ele=>ele.label);
    },
    selTableCol(val) {
      this.showcol = val;
      this.tableList.tableColumn = this.setColumnVisible(val);
    },
    // 请求数据
    async getData() {
      await getPurchaseList({
        keyword: this.search,
        keyword: this.search||'',
        page: this.pagerOptions.currPage,
        pageSize: this.pagerOptions.pageSize
      })
        .then((res) => {
          if (res.data.code === 200) {
            const list = res.data.data.list
            this.tableList.tableInfomation = list || []
            this.pagerOptions.totalCount = res.data.data.total
          }
        })
        .catch((err) => {
          console.log(err)
        })
      .then((res) => {
        if (res.code === 200) {
          let list = res.data.list
          list.map((item)=>{
            item.supplierName=item.supplier.name
          })
          this.tableList.tableInfomation = list || []
          this.pagerOptions.totalCount = res.data.total
        }
      })
      .catch((err) => {
        console.log(err)
      })
    },
    // 获取供应商数据
    async getSupplierData() {
      await getSupplierList({
        // [val]: content,
        status:1,
        page:1,
        pageSize: 10
      })
      .then((res) => {
        if (res.data.code == 200) {
          this.editConfig.infomation.supplierList=res.data.data.list
        }
      })
    },
    // 搜索
    searchClick(val, content) {
      console.log(val, content)
      this.search = content
      this.getData()
    },
    resetClick() {
      this.search = ""
    onFilterSearch(searchText){
      this.search = searchText ?? ''
      this.pagerOptions.currPage = 1
      this.getData()
    },
    // 新建
    addBtnClick() {
      this.editConfig.detailEnter=false
      this.editConfig.isDisabled=false
      // this.editRow = {};
      // this.$refs.add.islook = true;
      this.editConfig.visible = true
@@ -169,13 +252,18 @@
    },
    // 编辑
    editClick(row) {
    btnEdit(row) {
      this.editConfig.detailEnter=false
      this.editConfig.isDisabled=false
      this.tableLoading = true
      getPurchaseInfo({ id: row.ID }).then((res) => {
        if (res.code == 200) {
          this.tableLoading = false
          this.editConfig.visible = true
          this.editConfig.title = "编辑"
          res.data.productList.map((item,index)=>{
            item.productIndex=index
          })
          this.editConfig.infomation = {
            productList: res.data.productList,
            supplierName: res.data.purchase.supplier.name,
@@ -192,32 +280,105 @@
      // this.$refs.add.islook = true;
    },
    // 确认发货
    submitClick(row) {
      this.$confirm("是否提交?", "提示", {
    btnConfirm(row) {
      let string='是否提交?'
      if(!row.supplierName){
        string='您有必填字段未录入,请检查数据完整性。'
      }
      this.$confirm(string, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          console.log("dddd")
          submitPurchase({ id: row.ID }).then((response) => {
          if(!row.supplierName){
            this.btnEdit(row)
          }else{
            submitPurchase({ id: row.ID,status:2 }).then((response) => {
              if (response.code === 200) {
                this.$message.success("提交成功")
                this.getData()
              } else {
                this.$message.warning("提交失败")
              }
            })
          }
        },(e)=>{
          console.error(e)
        })
    },
    // 取消
    btnCancel(row){
      this.$confirm("是否取消?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
      .then(() => {
        submitPurchase({ id: row.ID,status:5 }).then((response) => {
          if (response.code === 200) {
            this.$message.success("已取消")
            this.getData()
          } else {
            // this.$message.warning("提交失败")
          }
        })
      },(e)=>{
        console.error(e)
      })
    },
    // 删除
    btnDelete(row){
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deletePurchase({ id: row.ID }).then((response) => {
            if (response.code === 200) {
              this.$message.success("提交成功")
              this.$message.success("删除成功")
              this.getData()
            } else {
              this.$message.warning("提交失败")
              this.$message.warning("删除失败")
            }
          })
        })
        .catch(() => {})
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
    },
    // 详情
    selCommonClick(row) {
      console.log(row)
    // 查看
    btnLook(row){
      this.editConfig.detailEnter=true
      this.editConfig.isDisabled=true
      this.tableLoading = true
      getPurchaseInfo({ id: row.ID }).then((res) => {
        if (res.code == 200) {
          this.tableLoading = false
          this.editConfig.visible = true
          this.editConfig.title = "查看"
          this.editConfig.infomation = {
            productList: res.data.productList,
            supplierName: res.data.purchase.supplier.name,
            ...res.data.purchase
          }
        } else {
          this.$message.error(res.msg ? res.msg + "," : "" + "获取信息失败!")
        }
      })
      setTimeout(() => {
        this.tableLoading = false
      }, 3000)
    },
    // 详情
    selCommonClick(row) {
      this.tableLoading = true
      getPurchaseInfo({ id: row.ID }).then((res) => {
        if (res.code == 200) {
          console.log(res,"产品详情")
          this.tableLoading = false
          this.commonDetail.visible = true
          this.commonDetail.infomation = {
@@ -238,41 +399,40 @@
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.rightContent {
  width: 100%;
  height: calc(100% - 10px);
  .content-box {
    height: 100%;
    .supplier-search {
.purchase{
  height: 100%;
  overflow: hidden;
  background-color: transparent;
  .filter{
    height: 80px;
    display: flex;
    align-items: center;
    padding: 12px 20px 0 20px;
    &-card{
      height: 80px;
      display: flex;
      align-items: center;
      .add-view {
        margin-left: auto;
        margin-right: 20px;
      }
    }
    .content-table {
      // height:calc(100% - 60px - 42px);
    }
    .btn-pager {
      display: flex;
      // background: #fff;
      .page {
        margin-left: auto;
      }
      box-sizing: border-box;
      padding: 10px 20px;
      flex: 1;
      border-radius: 12px;
      background-color: #fff;
    }
  }
  .bottom {
    .product-search {
      display: flex;
      align-items: center;
      .search {
        margin-left: auto;
      }
      .add-view {
        margin-left: 20px;
        margin-right: 20px;
      }
  .body{
    box-sizing: border-box;
    padding: 10px 20px;
    border-radius: 12px;
    height: calc(100% - 92px);
    &-card {
      background-color: #fff;
      border-radius: 12px;
      height: 100%;
      overflow: hidden;
    }
    .list-view {
      height: calc(100% - 60px);
      overflow: hidden;
    }
    .btn-pager {
      display: flex;