You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

331 lines
8.9 KiB

7 months ago
<template>
<view class="add">
<!-- 设备详情信息 -->
<view class="main">
<u--form labelPosition="left" labelAlign="center" :model="form" ref="form1">
<u-form-item label="设备名称" prop="equipName" labelWidth="auto" borderBottom @click="showSb()">
<u--input v-model="form.equipName" border="none" placeholder="请选择设备" readonly></u--input>
<u-icon slot="right" name="arrow-right"></u-icon>
<u-picker :show="showName" :columns="columns" keyName="name" @cancel='showName=false' @confirm='confirm'></u-picker>
</u-form-item>
<u-form-item label="设备编号" prop="equipNo" labelWidth="auto" borderBottom>
<u--input v-model="form.equipNo" border="none" readonly></u--input>
</u-form-item>
<u-form-item label="供应商" prop="supplierName" labelWidth="auto" borderBottom>
<u--input v-model="form.supplierName" border="none" readonly></u--input>
</u-form-item>
<u-form-item label="采购数量" prop="num" labelWidth="auto" borderBottom>
<u--input v-model="form.num" type="number" border="none" placeholder="请输入采购数量"
:readonly="form.id!=null"></u--input>
</u-form-item>
<u-form-item label="采购价格" prop="price" labelWidth="auto" borderBottom>
<u--input v-model="form.price" border="none" type="number" placeholder="请输入采购价格"
:readonly="form.id!=null">
</u--input>
</u-form-item>
<u-form-item label="生产日期" prop="productionTime" labelWidth="auto" @click="scShow = true; " borderBottom
ref="item1" v-if="form.id!=null">
<u--input v-model="form.productionTime" disabled disabledColor="#ffffff" placeholder="请选择生产日期"
border="none"></u--input>
<u-icon slot="right" name="arrow-right"></u-icon>
<u-datetime-picker :show="scShow" v-model="pickerTime" mode="date" :closeOnClickOverlay="true"
@close="scShow = false" @cancel="scShow = false" @confirm="dateConfirm"></u-datetime-picker>
</u-form-item>
<u-form-item label="采购日期" prop="purchaseTime" labelWidth="auto" @click="cgShow = true; " borderBottom
ref="item1" v-if="form.id!=null">
<u--input v-model="form.purchaseTime" disabled disabledColor="#ffffff" placeholder="请选择采购日期"
border="none"></u--input>
<u-icon slot="right" name="arrow-right"></u-icon>
<u-datetime-picker :show="cgShow" v-model="pickerTime" mode="date" :closeOnClickOverlay="true"
@close="cgShow = false" @cancel="cgShow = false" @confirm="date2Confirm"></u-datetime-picker>
</u-form-item>
<u-form-item label="凭证照片" prop="pzImg" labelWidth="auto" borderBottom ref="item1" v-if="form.id!=null">
<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
:maxCount="10" :previewFullImage="true"></u-upload>
</u-form-item>
</u--form>
</view>
<view v-if="form.status!=2 &&form.status!=3">
<view class="submit" v-if='form.id!=null'>
<u-button type="primary" @click="cgEquip" text="采 购 设 备"></u-button>
</view>
<view class="submit" v-else>
<u-button type="primary" @click="submit" text="添 加 记 录"></u-button>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
show: true,
scShow: false,
cgShow: false,
form: {
id: null,
equipNo: null,
equipName: null,
price: null,
supplierId: null,
supplierName: null,
num: null,
// 采购日期
purchaseTime: null,
// 生产日期
productionTime: null,
pzImg: null,
batch: null,
inTime: null,
status: null,
},
pickerTime: Number(new Date()),
showName: false,
deviceList: [],
fileList1: [],
pId: null,
columns: [],
}
},
onLoad: function(options) {
if (options.form) {
let data = JSON.parse(options.form);
this.form = data
this.pId = data.id
this.getVoucherList();
}
},
onShow: function() {
this.getList()
},
created() {},
methods: {
async getVoucherList() {
const {
data: res
} = await this.$http('/app/voucherList', {
pId: this.pId + ''
})
if (res.code) return
for (var i = 0; i < res.data.length; i++) {
this.fileList1.push({
id: res.data[i].id,
url: res.data[i].img
})
}
},
async getList() {
const {
data: res
} = await this.$http('/app/equipList')
if (res.code) return
this.deviceList = res.data
this.columns.push(this.deviceList)
},
confirm(d){
this.form.equipName = d.value[0].name
this.form.equipNo = d.value[0].eno
this.form.supplierId = d.value[0].supplierId
this.form.supplierName = d.value[0].supplierName
this.showName = false;
},
// 采购设备
async cgEquip() {
let flag = true;
if(this.form.purchaseTime==null || this.form.purchaseTime=='' ){
flag = false;
}
if(this.form.productionTime == null || this.form.productionTime==''){
flag = false;
}
if(this.fileList1 == null || this.fileList1.length==0){
flag = false;
}
if(!flag) return uni.showToast({
title: '请补充采购内容',
icon: 'error'
})
let url = [];
for (var i = 0; i < this.fileList1.length; i++) {
url.push(this.fileList1[i].url.slice(this.fileList1[i].url.indexOf("/profile")))
}
this.form.pzImg = url.join(",");
const {
data: res
} = await this.$http('/app/cg', this.form)
if (res.code == 0) {
uni.showToast({
title: '设备采购成功',
icon: 'success'
});
this.reset();
wx.navigateTo({
url: 'purchase_yg',
})
} else {
uni.showToast({
title: "设备采购失败",
icon: 'error'
})
}
},
// 添加采购记录
async submit() {
let flag = true;
if(this.form.equipName==null || this.form.equipName=='' ){
flag = false;
}
if(this.form.num == null || this.form.equipName==''){
flag = false;
}
if(this.form.price == null || this.form.price==''){
flag = false;
}
if(!flag) return uni.showToast({
title: '请补充采购内容',
icon: 'error'
})
const {
data: res
} = await this.$http('/app/addPurchase', this.form)
if (res.code == 0) {
uni.showToast({
title: '添加成功',
icon: 'success'
});
this.reset();
uni.navigateTo({
url: 'purchase_sg',
})
} else {
uni.showToast({
title: "添加失败!",
icon: 'error'
})
}
},
dateConfirm(e) {
const timeFormat = uni.$u.timeFormat
this.scShow = false;
this.form.productionTime = timeFormat(e.value, 'yyyy-mm-dd');
},
date2Confirm(e) {
const timeFormat = uni.$u.timeFormat
this.cgShow = false;
this.form.purchaseTime = timeFormat(e.value, 'yyyy-mm-dd');
},
showSb(){
if(this.form.id){
this.showName = false
}else{
this.showName = true
}
},
reset() {
this.form = {
id: null,
equipNo: null,
equipName: null,
price: null,
supplierId: null,
supplierName: null,
num: null,
// 采购日期
purchaseTime: null,
// 生产日期
productionTime: null,
pzImg: null,
batch: null,
inTime: null,
}
this.fileList1 = []
},
// 删除图片
deletePic(event) {
this[`fileList${event.name}`].splice(event.index, 1)
},
// 新增图片
async afterRead(event) {
// 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
let lists = [].concat(event.file)
let fileListLen = this[`fileList${event.name}`].length
lists.map((item) => {
this[`fileList${event.name}`].push({
...item,
status: 'uploading',
message: '上传中'
})
})
for (let i = 0; i < lists.length; i++) {
const result = await this.uploadFilePromise(lists[i].url)
let item = this[`fileList${event.name}`][fileListLen]
this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
status: 'success',
message: '',
url: result
}))
fileListLen++
}
},
uploadFilePromise(url) {
return new Promise((resolve, reject) => {
let a = uni.uploadFile({
url: this.BASE_URL + '/app/upload', // 仅为示例,非真实的接口地址
filePath: url,
name: 'file',
success: (res) => {
setTimeout(() => {
let data = JSON.parse(res.data)
console.log(data)
resolve(this.BASE_URL + data.fileName)
}, 1000)
}
});
})
},
}
}
</script>
<style lang="scss">
.submit {
margin: 1vh 2.667vw;
}
.add {
background: #f6f6f6;
padding: 2.667vw;
height: 95vh;
.main {
background: #ffffff;
margin-bottom: 2.667vw;
padding: 2vw;
border-radius: 8px;
.u-form-item__body__right {
padding-left: 20vw;
}
.u-button {
border: none !important;
padding: 0 !important;
justify-content: flex-start;
}
}
}
</style>