yyb
3 天以前 b6a007d417bf5eea80ec807d3f1201e220e5f651
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<template>
  <div>
    <el-dialog
        v-model="isShow"
        title="新增产品"
        width="1200"
        @close="closeModal"
    >
      <div class="table_list" v-loading="tableLoading">
        <el-table :data="tableData"
                  border
                  row-key="id"
                  @selection-change="handleChangeSelection">
          <el-table-column align="center"
                           type="selection"
                           width="55" />
          <el-table-column align="center"
                           label="序号"
                           type="index"
                           width="60" />
                           <el-table-column label="入库单号"
                               prop="inboundBatches"
                               width="150" />
              <el-table-column label="批次号"
                               prop="batchNo"
                               width="150" />
          <el-table-column label="产品大类"
                           prop="productCategory" />
          <el-table-column label="规格型号"
                           prop="specificationModel" />
          <el-table-column label="单位"
                           prop="unit"
                           width="70" />
          <el-table-column label="数量"
                           prop="stockInNum"
                           width="70" />
          <el-table-column label="可退货数量"
                           prop="unQuantity"
                           width="130" />
          <el-table-column label="已退货数量"
                           prop="totalReturnNum"
                           width="130" />
          <!-- <el-table-column label="库存预警数量"
                           prop="warnNum"
                           width="120"
                           show-overflow-tooltip />
          <el-table-column label="税率(%)"
                           prop="taxRate"
                           width="80" /> -->
          <el-table-column label="含税单价(元)"
                           prop="taxInclusiveUnitPrice"
                           :formatter="formattedNumber"
                           width="150" />
          <!-- <el-table-column label="含税总价(元)"
                           prop="taxInclusiveTotalPrice"
                           :formatter="formattedNumber"
                           width="150" />
          <el-table-column label="不含税总价(元)"
                           prop="taxExclusiveTotalPrice"
                           :formatter="formattedNumber"
                           width="150" /> -->
          <el-table-column label="是否质检"
                           prop="isChecked"
                           width="150">
            <template #default="scope">
              <el-tag :type="scope.row.isChecked ? 'success' : 'info'">
                {{ scope.row.isChecked ? '是' : '否' }}
              </el-tag>
            </template>
          </el-table-column>
        </el-table>
      </div>
 
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" :disabled="selectedRows.length === 0" @click="handleSubmit">确认</el-button>
          <el-button @click="closeModal">取消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
 
<script setup>
import {computed, ref, onMounted} from "vue";
import {getPurchaseReturnOrderByPurchaseLedgerId} from "@/api/procurementManagement/purchase_return_order.js";
import {ElMessage} from "element-plus";
 
const props = defineProps({
  visible: {
    type: Boolean,
    required: true,
  },
 
  purchaseLedgerId: {
    type: [Number, String],
    required: true,
  }
});
 
const emit = defineEmits(['update:visible', 'completed']);
 
const isShow = computed({
  get() {
    return props.visible;
  },
  set(val) {
    emit('update:visible', val);
  },
});
 
const tableData = ref([])
const selectedRows = ref([])
const tableLoading = ref(false)
const formattedNumber = (row, column, cellValue) => {
  return parseFloat(cellValue).toFixed(2);
};
 
const handleChangeSelection = (val) => {
  selectedRows.value = val;
}
 
/** 与 New.vue 中采购台账变更时解析 getByPurchaseLedgerId 的规则一致 */
const parseProductRowsFromLedgerResponse = (res) => {
  const payload = res?.data
  let list = []
  if (Array.isArray(payload)) {
    list = payload
  } else if (payload && typeof payload === 'object') {
    const nested =
      payload.purchaseReturnOrderProductsDtos ||
      payload.purchaseReturnOrderProductsDetailVoList
    list = Array.isArray(nested) ? nested : []
    if (list.length && list[0]?.salesLedgerProduct) {
      list = list.map((item) => ({ ...item, ...item.salesLedgerProduct }))
    }
  }
  return list
}
 
const fetchData = () => {
  if (props.purchaseLedgerId === undefined || props.purchaseLedgerId === null || props.purchaseLedgerId === '') {
    tableData.value = []
    return
  }
  tableLoading.value = true
  getPurchaseReturnOrderByPurchaseLedgerId({
    purchaseLedgerId: props.purchaseLedgerId,
  })
    .then((res) => {
      const list = parseProductRowsFromLedgerResponse(res)
      tableData.value = list
    })
    .catch(() => {
      tableData.value = []
    })
    .finally(() => {
      tableLoading.value = false
    })
}
 
const handleSubmit = () => {
  if (selectedRows.value.length === 0) {
    ElMessage.warning("请选择一条产品");
    return;
  }
 
  emit('completed', selectedRows.value);
  closeModal()
}
 
const closeModal = () => {
  isShow.value = false;
};
 
onMounted(() => {
  fetchData()
})
 
</script>