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.
247 lines
7.2 KiB
247 lines
7.2 KiB
<template>
|
|
<view class="v-pages">
|
|
<!-- 页面 产品 -->
|
|
<view class="v-pages-product">
|
|
<view class="v-product-name">{{formData.productName}}</view>
|
|
<view class="v-product-code m-t-small"><text
|
|
class="iconfont icon-code m-r-small"></text>{{formData.traceabilityProduct}}</view>
|
|
</view>
|
|
|
|
<!-- 页面 表单 -->
|
|
<view class="v-form v-container" style="margin-top:-40px; padding-bottom:50px;">
|
|
<uni-forms :modelValue="formData" ref="formRef" :label-width="120" :rules="formRules">
|
|
<view class="v-form-item">
|
|
<uni-forms-item label="客户名称" name="customId" required>
|
|
<picker @change="ClientChange" :value="CurrenSalesType" :range="ClientPickerList">
|
|
<view class="uni-input" v-if="ClientPickerList[CurrenClient]">
|
|
{{ClientPickerList[CurrenClient]}}
|
|
</view>
|
|
<view v-else class="placeholder">请选择客户名称</view>
|
|
<uni-icons type="down" size="14" class="v-icon"></uni-icons>
|
|
</picker>
|
|
</uni-forms-item>
|
|
<uni-forms-item label="客户地址" name="customAddress">
|
|
<input v-model="formData.customAddress" placeholder="请输入客户地址" />
|
|
</uni-forms-item>
|
|
<uni-forms-item label="联 系 人" name="contacts">
|
|
<input v-model="formData.contacts" placeholder="请输入联系人" />
|
|
</uni-forms-item>
|
|
<uni-forms-item label="联系电话" name="phone">
|
|
<input v-model="formData.phone" placeholder="请输入联系电话" />
|
|
</uni-forms-item>
|
|
<uni-forms-item label="销售类型" name="salesType" required>
|
|
<picker @change="SalesTypeChange" :value="CurrenSalesType" :range="SalesTypePickerList">
|
|
<view class="uni-input" v-if="SalesTypePickerList[CurrenSalesType]">
|
|
{{SalesTypePickerList[CurrenSalesType]}}
|
|
</view>
|
|
<view v-else class="placeholder">请选择销售类型</view>
|
|
<uni-icons type="down" size="14" class="v-icon"></uni-icons>
|
|
</picker>
|
|
</uni-forms-item>
|
|
<uni-forms-item label="销售数量(公斤)" name="salesNumber" required>
|
|
<input v-model="formData.salesNumber" placeholder="请输入销售数量" type="digit"
|
|
@blur="handlerInput($event,index)">
|
|
</input>
|
|
</uni-forms-item>
|
|
<uni-forms-item label="销售金额(元)" name="salesVolume">
|
|
<input v-model="formData.salesVolume" placeholder="请输入销售金额" type="digit"
|
|
@blur="handlerInput1($event,index)">
|
|
</input>
|
|
</uni-forms-item>
|
|
</view>
|
|
|
|
<!-- 页面 提交 -->
|
|
<view class="sticky fixedBottom"><button class="v-primary-btn large" @click="submitForm()">保存</button>
|
|
</view>
|
|
</uni-forms>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import * as ProductApi from "@/api/traceability/product"
|
|
import * as customApi from "@/api/traceability/custom"
|
|
import * as SaleRecordApi from '@/api/traceability/salerecord'
|
|
import {
|
|
getDictDatas,
|
|
DICT_TYPE
|
|
} from '@/utils/dict';
|
|
export default {
|
|
data() {
|
|
return {
|
|
ProductID: null,
|
|
CurrenClient: -1, //当前客户
|
|
ClientPickerList: [], //客户列表
|
|
ClientList: [], //客户选择列表
|
|
|
|
CurrenSalesType: 0, //当前销售类型
|
|
SalesTypePickerList: [], //销售类型列表
|
|
SalesTypeList: [], //销售类型选择列表
|
|
|
|
formData: {
|
|
id: undefined,
|
|
productId: undefined,
|
|
productName: undefined,
|
|
traceabilityProduct: undefined,
|
|
customId: undefined,
|
|
customAddress: undefined,
|
|
contacts: undefined,
|
|
phone: undefined,
|
|
salesType: 1,
|
|
salesNumber: undefined,
|
|
salesVolume: undefined
|
|
},
|
|
// 表单校验
|
|
formRules: {
|
|
customId: {
|
|
rules: [{
|
|
required: true,
|
|
errorMessage: '客户不能为空'
|
|
}]
|
|
},
|
|
customAddress: {
|
|
rules: [{
|
|
required: true,
|
|
errorMessage: '客户地址不能为空'
|
|
}]
|
|
},
|
|
contacts: {
|
|
rules: [{
|
|
required: true,
|
|
errorMessage: '联系人不能为空'
|
|
}]
|
|
},
|
|
phone: {
|
|
rules: [{
|
|
required: true,
|
|
errorMessage: '联系电话不能为空'
|
|
}]
|
|
},
|
|
salesType: {
|
|
rules: [{
|
|
required: true,
|
|
errorMessage: '销售类型不能为空'
|
|
}]
|
|
},
|
|
salesNumber: {
|
|
rules: [{
|
|
required: true,
|
|
errorMessage: '销售数量不能为空'
|
|
}]
|
|
}
|
|
},
|
|
|
|
}
|
|
},
|
|
onLoad(options) {
|
|
// 获取当前ID号
|
|
this.ProductID = JSON.parse(JSON.stringify(options.id))
|
|
// 获取页面
|
|
this.initialize(this.ProductID)
|
|
},
|
|
onReady() {
|
|
// 设置自定义表单校验规则,必须在节点渲染完毕后执行
|
|
this.$refs.formRef.setRules(this.formRules)
|
|
},
|
|
methods: {
|
|
// 页面初始化
|
|
async initialize(id) {
|
|
try {
|
|
this.getAllClient()
|
|
this.getSalesType()
|
|
/** 获取溯源产品 信息 */
|
|
const res = await ProductApi.getAllTraceableProducts(id)
|
|
this.formData.productId = id
|
|
this.formData.productName = res.data[0].processingName
|
|
this.formData.traceabilityProduct = res.data[0].traceabilityProduct
|
|
} finally {}
|
|
},
|
|
|
|
/** 提交按钮 */
|
|
async submitForm() {
|
|
// 校验主表
|
|
try {
|
|
this.formData.salesType = this.SalesTypeList[this.CurrenSalesType].value
|
|
await this.$refs['formRef'].validate()
|
|
const data = this.formData
|
|
await SaleRecordApi.createSaleRecord(data)
|
|
uni.showToast({
|
|
title: `保存成功`,
|
|
icon: 'success',
|
|
duration: 2000,
|
|
complete: function() {
|
|
uni.setStorageSync( 'canRefresh', 'true');
|
|
setTimeout(function() {
|
|
uni.navigateBack({
|
|
delta: 1
|
|
})
|
|
}, 2000);
|
|
}
|
|
})
|
|
} catch (err) {
|
|
console.log("验证未通过")
|
|
} finally {}
|
|
},
|
|
|
|
// 获得客户列表
|
|
async getAllClient() {
|
|
try {
|
|
const res = await customApi.getAllClient()
|
|
let newData = res.data
|
|
this.ClientList = newData
|
|
this.ClientPickerList = newData.map(item => {
|
|
return item.logisticsName
|
|
})
|
|
} finally {}
|
|
},
|
|
|
|
// 选择客户
|
|
ClientChange(e) {
|
|
this.CurrenClient = e.detail.value
|
|
this.formData.customId = this.ClientList[this.CurrenClient].id
|
|
this.formData.customAddress = this.ClientList[this.CurrenClient].address
|
|
this.formData.contacts = this.ClientList[this.CurrenClient].logisticsLeader
|
|
this.formData.phone = this.ClientList[this.CurrenClient].logisticsPhone
|
|
},
|
|
|
|
//获取销售类型列表
|
|
getSalesType() {
|
|
//销售类型 数据字典查询
|
|
let newData = this.getDictDatas(DICT_TYPE.SALES_TYPE);
|
|
this.SalesTypeList = newData
|
|
this.SalesTypePickerList = newData.map((item) => {
|
|
return item.label
|
|
})
|
|
},
|
|
// 选择销售类型
|
|
SalesTypeChange(e) {
|
|
this.CurrenSalesType = e.detail.value
|
|
},
|
|
|
|
// 格式化小数两位
|
|
handlerInput(event, index) {
|
|
this.$nextTick(() => {
|
|
const num = parseFloat(event.target.value).toFixed(2)
|
|
if (isNaN(num)) {
|
|
this.formData.salesNumber = undefined
|
|
} else {
|
|
this.formData.salesNumber = num
|
|
}
|
|
this.$forceUpdate()
|
|
})
|
|
},
|
|
|
|
// 格式化小数两位
|
|
handlerInput1(event, index) {
|
|
this.$nextTick(() => {
|
|
const num = parseFloat(event.target.value).toFixed(2)
|
|
this.$forceUpdate()
|
|
this.formData.salesVolume = num
|
|
})
|
|
},
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
</style>
|
|
|