123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- <template>
- <BasicModal
- v-bind="$attrs"
- @register="register"
- title="维修报价"
- width="700px"
- @cancel="clearInfo"
- :confirmLoading="loading"
- @ok="handleSubmit"
- >
- <div class="pt-2px pr-3px">
- <BasicForm @register="registerForm">
- <template #text="{ model, field }">
- {{ model[field] }}
- </template>
- <template #add>
- <Button @click="add" style="margin-left:20px">添加人工</Button>
- </template>
- <template #del="{ field }">
- <Button @click="del(field)">删除</Button>
- </template>
- </BasicForm>
- <div class="priceCount">
- <Button @click="updataCount">更新总价</Button>
- <div class="label" v-if="fileFlow.priceCount">总价:{{ fileFlow.priceCount }}</div>
- </div>
- </div>
- </BasicModal>
- </template>
- <script lang="ts">
- import { defineComponent, h, onMounted, reactive, ref } from 'vue';
- import { BasicModal, useModalInner } from '/@/components/Modal';
- import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
- import { useMessage } from '/@/hooks/web/useMessage';
- import { getPriceList, checkRegisterInfo, addOrUpdatePriceList, allList } from '/@/api/spares'
- import { useI18n } from '/@/hooks/web/useI18n';
- import { uploadApi } from '/@/api/product/index';
- const { t } = useI18n();
- export default defineComponent({
- components: { BasicModal, BasicForm },
- props: {
- userData: { type: Object },
- },
- emits: ['update', 'register'],
- setup(props, { emit }) {
- const n = ref(1);
- const fileFlow = reactive({
- file:null,
- type:2,//2-普通发票,3-专用发票
- count:1,//第一次报价
- priceCount:0,//总价
- priceLists:[],
- priceListsPrice:{}
- })
- const loading = ref(false)
- const { createMessage,createConfirm } = useMessage();
- const schemas: FormSchema[] = [
- {
- field: 'id',
- component: 'Input',
- show:false,
- label: '发票编号',
- },
- {
- field: 'repairId',
- component: 'Input',
- label: '维修单号',
- slot: 'text',
- colProps: {
- span: 24,
- },
- },{
- field: 'deviceInfo',
- component: 'Input',
- label: '设备信息',
- slot: 'text',
- colProps: {
- span: 18,
- },
- },{
- field: 'noteContent',
- component: 'Input',
- label: '检测结果',
- slot: 'text',
- colProps: {
- span: 18,
- },
- },{
- field: '0',
- component: 'Input',
- label: '第一次报价',
- labelWidth:0,
- colProps: {
- span: 24,
- },
- slot: 'add',
- },
- ];
- const [registerForm, { validate, getFieldsValue, resetFields, setFieldsValue, removeSchemaByFiled, appendSchemaByField, updateSchema }] = useForm({
- labelWidth: 180,
- schemas:schemas,
- showActionButtonGroup: false,
- actionColOptions: {
- span: 24,
- },
- });
- onMounted(async () => {
- let allListOption = await allList()//获取价格
- console.log('allList',allListOption)
- fileFlow.priceListsPrice
- allListOption.map(ele => {
- fileFlow.priceListsPrice[ele.laborCostId] = ele.price
- })
- });
- let addListFunc = () => {};
- const [register, { closeModal }] = useModalInner((data) => {
- data && onDataReceive(data);
- });
- async function onDataReceive(data) {
- const { priceLists, count } = await getPriceList({repairId:data.repairId})//
- updateSchema({
- field:'0',
- label:`第${count || 1}次报价`,
- })
- addPriceItem(priceLists)
- resetFields();
- fileFlow.type = data.type
- setFieldsValue({
- ...data,
- deviceInfo:t(`routes.scene.tableType.${data.cameraType}`)+data.cameraSnCode
- });
- }
- function del(field) {
- removeSchemaByFiled([`deviceType${field}`, `device_${field}`, `${field}`]);
- n.value--;
- }
- function add() {
- let list = addSchemas(n.value);
- list.map(ele => {
- appendSchemaByField(ele,'')
- })
- n.value++
- }
- function addPriceItem(list){
- fileFlow.priceLists = list
- let priceSchema = []
- let valueObj = {}
- list.map(ele => {
- valueObj[`priceList${ele.priceListId}`] = ele.count || 1
- priceSchema.unshift({
- field: 'priceList' + ele.priceListId,
- label: ele.name+'次数',
- component: 'InputNumber',
- defaultValue:ele.count || 1,
- suffix:ele.price+"元/次",
- colProps: {
- span: 13,
- },
- required: true,
- componentProps: {
- disabled:ele.status == 1,
- min:1,
- max:999,
- maxLength: 15,
- },
- })
- })
- priceSchema.map(item =>{
- console.log('priceSchema',item)
- appendSchemaByField(item,'')
- })
- setTimeout(()=>{
- setFieldsValue(valueObj)
- },100)
- }
- function addSchemas(number){
- let parentList: FormSchema[] = [
- {
- field: 'deviceType' + number,
- label: '人工费'+ number,
- component: 'ApiSelect',
- colProps: {
- span: 12,
- },
- required: true,
- componentProps: {
- api: allList,
- labelField: 'name',
- valueField: 'laborCostId',
- showSearch:true,
- onChange:(value)=>{
- console.log('onchange',value,arguments)
- }
- },
- },
- {
- field: 'device_' + number,
- label: '数量',
- component: 'InputNumber',
- required: true,
- defaultValue: 1,
- labelWidth:50,
- componentProps: {
- max: 999,
- min:1,
- },
- colProps: {
- span: 6,
- },
- },{
- field: number.toString(),
- component: 'Input',
- label: '',
- labelWidth:0,
- colProps: {
- span: 6,
- },
- slot: 'del',
- }
- ];
- return parentList
- }
- const handleSubmit = async () => {
- loading.value = true
- try {
- createConfirm({
- iconType: 'warning',
- title: () => h('span', '温馨提示'),
- content: '确定要提交检测报告吗?',
- onOk: async () => {
- const params = await validate();
- await cameraIn(params)
- createMessage.success(t('common.optSuccess'));
- closeModal();
- emit('update');
- loading.value = false
- clearInfo()
- },
- });
- } catch (error) {
- loading.value = false
- console.log('not passing', error);
- }
- };
- function updataCount(){
- let fromData = getFieldsValue() ,count = 0
- fileFlow.priceListsPrice
- fileFlow.priceLists.map(ele => {
- count = count + fromData[`priceList${ele.priceListId}`]*ele.price
- })
- for (let index = 1; index < n.value; index++) {
- if(fromData[`deviceType${index}`] && fromData[`device_${index}`]){
- let priceId = fromData[`deviceType${index}`]
- let fromPrice = fromData[`device_${index}`] * fileFlow.priceListsPrice[priceId]
- count = count +fromPrice
- }
- }
- fileFlow.priceCount = count
- console.log('fromData',fromData)
- }
- function clearInfo(){
- let indexa = n.value;
- fileFlow.priceCount = 0
- resetFields()
- let clearFiled = []
- fileFlow.priceLists.map(ele =>{
- clearFiled.push(`priceList${ele.priceListId}`)
- })
- for (let index = 1; index < indexa; index++) {
- clearFiled.push(`deviceType${index}`, `device_${index}`, `${index}`)
- }
- removeSchemaByFiled(clearFiled);
- n.value = 1
- }
- return {
- register,
- registerForm,
- fileFlow,
- handleSubmit,
- addListFunc,
- resetFields,
- loading,
- clearInfo,
- updataCount,
- t,
- del,
- add,
- };
- },
- });
- </script>
- <style lang="less" scoped>
- .priceCount{
- padding: 20px 180px;
- .label{
- display: inline-block;
- }
- }
- </style>
|