123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677 |
- import { required, diyRequired } from '@/components/template/rules_verify.js'
- import { getBrandList } from '@/api/miniapp'
- import { getClassifyList } from '@/api/goods'
- import { goodsMaterialList } from '@/api/commercialMaterial.js'
- import { goodsPurchaseItemImportCode, goodsPurchaseDetail } from '@/api/goodsPurchasedStored.js'
- export default {
- data() {
- return {
- brandList: [],
- ClassifyList: [],
- goodsMaterialList: []
- }
- },
- computed: {
- storage_goods() {
- return [
- {
- columnAttributes: {
- label: '*品牌',
- prop: 'brandId',
- propName: 'brandName',
- width: 160
- },
- render: (h, { row, column, index }) => {
- return this.isEditIndex == index ? (
- <div class="redbordererr">
- <el-form-item
- label=""
- lebel-width="0px"
- prop={`items.${index}.${column.columnAttributes.prop}`}
- rules={[diyRequired.bind(this)((rule, value)=>{
- if(this.logs){
- this.logs.push({index:index, errMsg:`${column.columnAttributes.label}不能为空`})
- }
- this?.tishicuowu?.()
- return new Error('必须填写')
- })]}
- >
- <el-select
- value={row[column.columnAttributes.prop]}
- onInput={val => {
- row[column.columnAttributes.prop] = val
- }}
- onChange={val => {
- this.shanchujichu(row, 0)
- if (val) {
- row[column.columnAttributes.propName] = this.brandList.find(item => item.id == val).brandName
- } else {
- row[column.columnAttributes.propName] = ''
- }
- }}
- placeholder="请选择"
- >
- {this.brandList.map((item, index_) => (
- <el-option key={index_} label={item.brandName} value={item.id}></el-option>
- ))}
- </el-select>
- </el-form-item>
- </div>
- ) : (
- <div style="padding:0 6px">{row[column.columnAttributes.propName]}</div>
- )
- }
- },
- {
- columnAttributes: {
- label: '*商品大类',
- prop: 'mainId',
- propName: 'mainName',
- width: 160
- },
- render: (h, { row, column, index }) => {
- return this.isEditIndex == index ? (
- <div class="redbordererr">
- <el-form-item
- label=""
- lebel-width="0px"
- prop={`items.${index}.${column.columnAttributes.prop}`}
- rules={[diyRequired.bind(this)((rule, value)=>{
- if(this.logs){
- this.logs.push({index:index, errMsg:`${column.columnAttributes.label}不能为空`})
- }
- this?.tishicuowu?.()
- return new Error('必须填写')
- })]}
- >
- <el-select
- value={row[column.columnAttributes.prop]}
- onInput={val => {
- row[column.columnAttributes.prop] = val
- }}
- onChange={val => {
- this.shanchujichu(row, 1)
- if (val) {
- row[column.columnAttributes.propName] = this.ClassifyList.find(
- item => item.categoryId == val
- ).name
- } else {
- row[column.columnAttributes.propName] = ''
- }
- }}
- placeholder="请选择"
- >
- {this.ClassifyList.map((item, index_) => (
- <el-option key={index_} label={item.name} value={item.categoryId}></el-option>
- ))}
- </el-select>
- </el-form-item>
- </div>
- ) : (
- <div style="padding:0 6px">{row[column.columnAttributes.propName]}</div>
- )
- }
- },
- {
- columnAttributes: {
- label: '*商品小类',
- prop: 'smallId',
- propName: 'smallName',
- width: 160
- },
- render: (h, { row, column, index }) => {
- return this.isEditIndex == index ? (
- <div class="redbordererr">
- <el-form-item
- label=""
- lebel-width="0px"
- prop={`items.${index}.${column.columnAttributes.prop}`}
- rules={[diyRequired.bind(this)((rule, value)=>{
- if(this.logs){
- this.logs.push({index:index, errMsg:`${column.columnAttributes.label}不能为空`})
- }
- this?.tishicuowu?.()
- return new Error('必须填写')
- })]}
- >
- <el-select
- value={row[column.columnAttributes.prop]}
- onInput={val => {
- row[column.columnAttributes.prop] = val
- }}
- onChange={val => {
- this.shanchujichu(row, 2)
- if (val) {
- row[column.columnAttributes.propName] = (
- this.ClassifyList.find(item => item.categoryId == row.mainId)?.children || []
- ).find(item => item.categoryId == val).name
- } else {
- row[column.columnAttributes.propName] = ''
- }
- }}
- placeholder="请选择"
- >
- {(this.ClassifyList.find(item => item.categoryId == row.mainId)?.children || []).map(
- (item, index_) => (
- <el-option key={index_} label={item.name} value={item.categoryId}></el-option>
- )
- )}
- </el-select>
- </el-form-item>
- </div>
- ) : (
- <div style="padding:0 6px">{row[column.columnAttributes.propName]}</div>
- )
- }
- },
- {
- columnAttributes: {
- label: '*商品名称',
- prop: 'goodsMaterialId',
- propName: 'goodsMaterialName',
- width: 160
- },
- render: (h, { row, column, index }) => {
- return this.isEditIndex == index ? (
- <div class="redbordererr">
- <el-form-item
- label=""
- lebel-width="0px"
- prop={`items.${index}.${column.columnAttributes.prop}`}
- rules={[diyRequired.bind(this)((rule, value)=>{
- if(this.logs){
- this.logs.push({index:index, errMsg:`${column.columnAttributes.label}不能为空`})
- }
- this?.tishicuowu?.()
- return new Error('必须填写')
- })]}
- >
- <el-select
- value={row[column.columnAttributes.prop]}
- onInput={val => {
- row[column.columnAttributes.prop] = val
- }}
- onChange={val => {
- this.shanchujichu(row, 3)
- if (val) {
- var data = this.goodsMaterialList
- .filter(
- item =>
- item.brandId === row.brandId && item.mainId === row.mainId && item.smallId === row.smallId
- )
- .find(item => item.id == val)
- row[column.columnAttributes.propName] = data?.goodsName
- this.getGoodsDetl(data, res => {
- if (this.formDialogType == 0) {
- row['specsName'] = res?.specsName
- row['unit'] = res?.unit
- row['stockQty'] = res?.stockQty
- row['factoryNo'] = res?.factoryNo
- row['insideQty'] =
- res.items
- .filter(item => item.type === 'INSIDE')
- .map(item => item.qty)
- .reduce((accumulator, currentValue) => accumulator + currentValue, 0) * Number(row?.qty)
- row['outQty'] =
- res.items
- .filter(item => item.type === 'OUT')
- .map(item => item.qty)
- .reduce((accumulator, currentValue) => accumulator + currentValue, 0) * Number(row?.qty)
- row['partsQty'] =
- res.items
- .filter(item => item.type === 'PARTS')
- .map(item => item.qty)
- .reduce((accumulator, currentValue) => accumulator + currentValue, 0) * Number(row?.qty)
- }
- })
- } else {
- row[column.columnAttributes.propName] = ''
- row['specsName'] = ''
- row['unit'] = ''
- row['insideQty'] = ''
- row['outQty'] = ''
- row['partsQty'] = ''
- row['stockQty'] = ''
- row['factoryNo'] = ''
- }
- }}
- filterable={true}
- placeholder="请选择"
- >
- {this.goodsMaterialList
- .filter(
- item =>
- item.brandId === row.brandId && item.mainId === row.mainId && item.smallId === row.smallId
- )
- .map((item, index_) => (
- <el-option key={index_} label={item.goodsName} value={item.id}></el-option>
- ))}
- </el-select>
- </el-form-item>
- </div>
- ) : (
- <div style="padding:0 6px">{row[column.columnAttributes.propName]}</div>
- )
- }
- },
- {
- columnAttributes: {
- label: '厂物料编码',
- prop: 'factoryNo',
- width: 120
- }
- },
- {
- columnAttributes: {
- label: '规格型号',
- prop: 'specsName',
- width: 120
- }
- },
- {
- columnAttributes: {
- label: '单位',
- prop: 'unit'
- },
- render: (h, { row, column, index }) => {
- return <div style="padding:0 6px">{{ C: '整套', I: '单个' }[row[column.columnAttributes.prop]] || ''}</div>
- }
- },
- {
- columnAttributes: {
- label: '*采购数量',
- prop: 'qty',
- width: 160
- },
- render: (h, { row, column, index }) => {
- return this.isEditIndex == index ? (
- <div class="redbordererr">
- <el-form-item
- label=""
- lebel-width="0px"
- prop={`items.${index}.${column.columnAttributes.prop}`}
- rules={[diyRequired.bind(this)((rule, value)=>{
- if(this.logs){
- this.logs.push({index:index, errMsg:`${column.columnAttributes.label}不能为空`})
- }
- this?.tishicuowu?.()
- return new Error('必须填写')
- })]}
- >
- <el-input
- value={row[column.columnAttributes.prop]}
- onInput={val => {
- row[column.columnAttributes.prop] = val <= 0 ? 0 : Number(val)
- this.getGoodsDetl(
- this.goodsMaterialList
- .filter(
- item =>
- item.brandId === row.brandId && item.mainId === row.mainId && item.smallId === row.smallId
- )
- .find(item => item.id == row.goodsMaterialId),
- res => {
- if (this.formDialogType == 0) {
- row['insideQty'] =
- res.items
- .filter(item => item.type === 'INSIDE')
- .map(item => item.qty)
- .reduce((accumulator, currentValue) => accumulator + currentValue, 0) *
- row[column.columnAttributes.prop]
- row['outQty'] =
- res.items
- .filter(item => item.type === 'OUT')
- .map(item => item.qty)
- .reduce((accumulator, currentValue) => accumulator + currentValue, 0) *
- row[column.columnAttributes.prop]
- row['partsQty'] =
- res.items
- .filter(item => item.type === 'PARTS')
- .map(item => item.qty)
- .reduce((accumulator, currentValue) => accumulator + currentValue, 0) *
- row[column.columnAttributes.prop]
- }
- }
- )
- }}
- type="number"
- placeholder="请输入"
- ></el-input>
- </el-form-item>
- </div>
- ) : (
- <div style="padding:0 6px">{row[column.columnAttributes.prop]}</div>
- )
- }
- },
- {
- columnAttributes: {
- label: '内机数量',
- prop: 'insideQty'
- }
- },
- {
- columnAttributes: {
- label: '外机数量',
- prop: 'outQty'
- }
- },
- {
- columnAttributes: {
- label: '配件数量',
- prop: 'partsQty'
- }
- },
- {
- columnAttributes: {
- label: '导入内机条码数量',
- prop: 'insideCodeQty',
- width: 120
- }
- },
- {
- columnAttributes: {
- label: '导入外机条码数量',
- prop: 'outCodeQty',
- width: 120
- }
- },
- {
- columnAttributes: {
- label: '导入配件条码数量',
- prop: 'partsCodeQty',
- width: 120
- }
- },
- {
- columnAttributes: {
- label: '*采购价格',
- prop: 'price',
- width: 160
- },
- render: (h, { row, column, index }) => {
- return this.isEditIndex == index ? (
- <div class="redbordererr">
- <el-form-item
- label=""
- lebel-width="0px"
- prop={`items.${index}.${column.columnAttributes.prop}`}
- rules={[diyRequired.bind(this)((rule, value)=>{
- if(this.logs){
- this.logs.push({index:index, errMsg:`${column.columnAttributes.label}不能为空`})
- }
- this?.tishicuowu?.()
- return new Error('必须填写')
- })]}
- >
- <el-input
- value={row[column.columnAttributes.prop]}
- onInput={val => {
- row[column.columnAttributes.prop] = val
- }}
- type="number"
- placeholder="请输入"
- ></el-input>
- </el-form-item>
- </div>
- ) : (
- <div style="padding:0 6px">{row[column.columnAttributes.prop]}</div>
- )
- }
- },
- {
- columnAttributes: {
- label: '采购金额',
- prop: 'amount',
- width: 160
- },
- render: (h, { row, column, index }) => {
- return <div style="padding:0 6px">{Number(row['qty']) * Number(row['price'])}</div>
- }
- },
- {
- columnAttributes: {
- label: '库存数量',
- prop: 'stockQty'
- }
- },
- ...(() => {
- if (this.formDialogType < 2 && !~['WAIT', 'OK', 'FAIL'].indexOf(this.formData.status)) {
- return [
- {
- columnAttributes: {
- label: '操作',
- fixed: 'right',
- width: 140
- },
- render: (h, { row, column, index }) => {
- return (
- <div style="padding:0 6px" class="operation-btns">
- {[
- this.isEditIndex == index ? (
- <el-button
- type="text"
- onClick={() => {
- this.$refs.formRef.validateField(
- this.getVfyKey(this.isEditIndex),
- (valid, invalidFields, errLabels) => {
- if (valid && this.eidtItems()) {
- this.isEditIndex = -1
- }
- }
- )
- }}
- >
- 保存
- </el-button>
- ) : null,
- this.isEditIndex == -1 ? (
- <el-button
- type="text"
- onClick={() => {
- this.isEditIndex = index
- }}
- >
- 编辑
- </el-button>
- ) : null,
- <el-button
- type="text"
- onClick={() => {
- this.delGoodsInfo(row, index)
- }}
- >
- 删除
- </el-button>
- ]}
- </div>
- )
- }
- }
- ]
- } else if (this.formDialogType < 2 && !!~[].indexOf(this.formData.status) && this.joinCode) {
- return [
- {
- columnAttributes: {
- label: '操作',
- fixed: 'right',
- width: 140
- },
- render: (h, { row, column, index }) => {
- return (
- <div style="padding:0 6px" class="operation-btns">
- {this.importButton(goodsPurchaseItemImportCode, '导入条码', { purchaseItemId: row.id }, () => { }, () => {
- if (this.formData.id) {
- // 更新表单信息
- goodsPurchaseDetail({ id: this.formData.id }).then(res => {
- Object.assign(this.formData, res.data, {
- fileUrl: res.data.fileUrl ? [{ url: res.data.fileUrl }] : [],
- items: res.data.items.map(item => ({ ...item, details: {} }))
- })
- })
- }
- })}
- </div>
- )
- }
- }
- ]
- }
- return []
- })()
- ]
- }
- },
- methods: {
- getBaseList() {
- getBrandList({
- status: true
- }).then(res => {
- this.brandList = res.data
- })
- getClassifyList({
- type: 2,
- status: true
- }).then(res => {
- this.ClassifyList = res.data
- })
- goodsMaterialList({
- pageNum: 1,
- pageSize: -1,
- params: []
- }).then(res => {
- this.goodsMaterialList = res.data.records
- .filter(item => item.isVirtyual !== 'YES' && item.state == 'ON')
- .map(item => ({ ...item, details: {} }))
- })
- },
- shanchujichu(row, num) {
- if (num <= 0) {
- }
- if (num <= 1) {
- row.smallId = ''
- row.smallName = ''
- }
- if (num <= 2) {
- row.goodsMaterialId = ''
- row.goodsMaterialName = ''
- row.specsName = ''
- row.unit = ''
- row.insideQty = ''
- row.outQty = ''
- row.partsQty = ''
- row.stockQty = ''
- row.factoryNo = ''
- }
- },
- getVfyKey(index, bool = true) {
- return [
- ...(() => {
- if (bool) {
- return [`items`]
- }
- return []
- })(),
- ...(() => {
- if (index > -1) {
- return [
- `items.${index}.brandId`,
- `items.${index}.mainId`,
- `items.${index}.smallId`,
- `items.${index}.goodsMaterialId`,
- `items.${index}.qty`,
- `items.${index}.price`
- ]
- }
- return []
- })()
- ]
- },
- eidtItems() {
- try {
- this.formData.items.map((item, index) => {
- this.formData.items.map((item2, index2) => {
- if (
- index !== index2 &&
- `${item.brandId}_${item.mainId}_${item.smallId}_${item.goodsMaterialId}` ==
- `${item2.brandId}_${item2.mainId}_${item2.smallId}_${item2.goodsMaterialId}`
- ) {
- throw new Error('')
- }
- })
- })
- } catch (error) {
- this.$message.warning('重复')
- return false
- }
- return true
- },
- // 添加商品信息
- addGoodsInfo() {
- if (this.isEditIndex > -1) {
- this.$refs.formRef.validateField(this.getVfyKey(this.isEditIndex), (valid, invalidFields, errLabels) => {
- if (valid && this.eidtItems()) {
- this.formData.items.unshift({
- brandId: '',
- brandName: '',
- mainId: '',
- mainName: '',
- smallId: '',
- smallName: '',
- goodsMaterialId: '',
- goodsMaterialName: '',
- specsName: '',
- unit: '',
- qty: '',
- insideQty: '',
- outQty: '',
- partsQty: '',
- insideCodeQty: '',
- outCodeQty: '',
- partsCodeQty: '',
- price: '',
- amount: '',
- stockQty: '',
- factoryNo: "",
- })
- this.isEditIndex = 0
- }
- })
- } else if (this.eidtItems()) {
- this.formData.items.unshift({
- brandId: '',
- brandName: '',
- mainId: '',
- mainName: '',
- smallId: '',
- smallName: '',
- goodsMaterialId: '',
- goodsMaterialName: '',
- specsName: '',
- unit: '',
- qty: '',
- insideQty: '',
- outQty: '',
- partsQty: '',
- insideCodeQty: '',
- outCodeQty: '',
- partsCodeQty: '',
- price: '',
- amount: '',
- stockQty: '',
- factoryNo: ''
- })
- this.isEditIndex = 0
- }
- },
- delGoodsInfo(row, index) {
- if (index > this.isEditIndex) {
- this.formData?.items?.splice(index, 1)
- } else if (index == this.isEditIndex) {
- this.formData?.items?.splice(index, 1)
- this.isEditIndex = -1
- }
- }
- }
- }
|