quoteModel.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <BasicModal
  3. v-bind="$attrs"
  4. @register="register"
  5. title="维修报价"
  6. width="700px"
  7. @cancel="clearInfo"
  8. :confirmLoading="loading"
  9. @ok="handleSubmit"
  10. >
  11. <div class="pt-2px pr-3px">
  12. <BasicForm @register="registerForm">
  13. <template #text="{ model, field }">
  14. {{ model[field] }}
  15. </template>
  16. <template #add>
  17. <div>
  18. <Button @click="add" style="margin-left:20px">添加人工</Button>
  19. <Button @click="updataRepairInfo" style="margin-left:20px">重置</Button>
  20. </div>
  21. </template>
  22. <template #del="{ field }">
  23. <Button @click="del(field)">删除</Button>
  24. </template>
  25. <template #delList="{ field }">
  26. <Button @click="del(field)">删除</Button>
  27. </template>
  28. </BasicForm>
  29. <div class="priceCount">
  30. <span>合计:</span>
  31. <div class="label">总价:{{ fileFlow.priceCount || 0 }}元 <Button :preIcon="'outline-refresh'" @click="updataCount"><RedoOutlined /></Button></div>
  32. </div>
  33. </div>
  34. </BasicModal>
  35. </template>
  36. <script lang="ts">
  37. import { defineComponent, h, onMounted, reactive, ref } from 'vue';
  38. import { BasicModal, useModalInner } from '/@/components/Modal';
  39. import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
  40. import { useMessage } from '/@/hooks/web/useMessage';
  41. import { getPriceList, checkRegisterInfo, addOrUpdatePriceList, allList } from '/@/api/spares'
  42. import { useI18n } from '/@/hooks/web/useI18n';
  43. import { uploadApi } from '/@/api/product/index';
  44. import { RedoOutlined, } from '@ant-design/icons-vue';
  45. const { t } = useI18n();
  46. export default defineComponent({
  47. components: { BasicModal, BasicForm, RedoOutlined },
  48. props: {
  49. userData: { type: Object },
  50. },
  51. emits: ['update', 'register'],
  52. setup(props, { emit }) {
  53. const n = ref(1);
  54. const fileFlow = reactive({
  55. file:null,
  56. type:2,//2-普通发票,3-专用发票
  57. count:1,//第一次报价
  58. priceCount:0,//总价
  59. priceLists:[],
  60. priceListsPrice:{}
  61. })
  62. const loading = ref(false)
  63. const { createMessage,createConfirm } = useMessage();
  64. const schemas: FormSchema[] = [
  65. {
  66. field: 'id',
  67. component: 'Input',
  68. show:false,
  69. label: '发票编号',
  70. },
  71. {
  72. field: 'repairId',
  73. component: 'Input',
  74. label: '维修单号',
  75. slot: 'text',
  76. colProps: {
  77. span: 24,
  78. },
  79. },{
  80. field: 'deviceInfo',
  81. component: 'Input',
  82. label: '设备信息',
  83. slot: 'text',
  84. colProps: {
  85. span: 18,
  86. },
  87. },{
  88. field: 'checkResult',
  89. component: 'Input',
  90. label: '检测结果',
  91. slot: 'text',
  92. colProps: {
  93. span: 18,
  94. },
  95. },{
  96. field: '0',
  97. component: 'Input',
  98. label: '报价明细',
  99. labelWidth:0,
  100. colProps: {
  101. span: 24,
  102. },
  103. slot: 'add',
  104. },
  105. ];
  106. const [registerForm, { validate, getFieldsValue, resetFields, setFieldsValue, removeSchemaByFiled, appendSchemaByField, updateSchema }] = useForm({
  107. labelWidth: 100,
  108. labelAlign:'left',
  109. schemas:schemas,
  110. showActionButtonGroup: false,
  111. actionColOptions: {
  112. span: 24,
  113. },
  114. });
  115. onMounted(async () => {
  116. let allListOption = await allList()//获取价格
  117. console.log('allList',allListOption)
  118. fileFlow.priceListsPrice
  119. allListOption.map(ele => {
  120. fileFlow.priceListsPrice[ele.laborCostId] = ele.price
  121. })
  122. });
  123. let addListFunc = () => {};
  124. const [register, { closeModal }] = useModalInner((data) => {
  125. data && onDataReceive(data);
  126. });
  127. async function updataRepairInfo() {
  128. let { repairId } = getFieldsValue()
  129. console.log('20230228171427939',repairId)
  130. const { priceLists, count } = await getPriceList({repairId})//
  131. addPriceItem(priceLists)
  132. clearInfo(true)
  133. setTimeout(() => {
  134. updataCount()
  135. }, 100);
  136. }
  137. async function onDataReceive(data) {
  138. const { priceLists, count } = await getPriceList({repairId:data.repairId})//
  139. addPriceItem(priceLists)
  140. resetFields();
  141. fileFlow.type = data.type
  142. setFieldsValue({
  143. ...data,
  144. deviceInfo:t(`routes.scene.tableType.${data.cameraType}`)+data.cameraSnCode
  145. });
  146. }
  147. function del(field) {
  148. removeSchemaByFiled([`deviceType${field}`, `device_${field}`, `${field}`]);
  149. // n.value--;
  150. }
  151. function add() {
  152. let list = addSchemas(n.value);
  153. list.map(ele => {
  154. appendSchemaByField(ele,'')
  155. })
  156. n.value++
  157. }
  158. function addPriceItem(list){
  159. fileFlow.priceLists = list.reverse()
  160. let priceSchema = [],valueObj = {},count=0
  161. list.map(ele => {
  162. valueObj[`priceList${ele.priceListId}`] = ele.count || 0
  163. valueObj[`priceListText${ele.priceListId}`] = `${ele.name} ${ele.price} 元/次`
  164. count = count + ele.count*ele.price
  165. priceSchema.unshift({
  166. field: 'priceListText' + ele.priceListId,
  167. component: 'InputNumber',
  168. label: ele.type == 0?'备件':'人工',
  169. slot: 'text',
  170. // labelWidth:300,
  171. // subLabel:"数量",
  172. colProps: {
  173. span: 12,
  174. }
  175. },{
  176. field: 'priceList' + ele.priceListId,
  177. label: '数量',//`${ele.type == 0?'备件':'人工'}: ${ele.name} ${ele.price} 元/次`,
  178. // suffix:'数量',
  179. component: 'InputNumber',
  180. defaultValue:ele.count || 0,
  181. // labelWidth:300,
  182. // subLabel:"数量",
  183. colProps: {
  184. span: 12,
  185. },
  186. required: true,
  187. componentProps: {
  188. disabled:ele.status == 1,
  189. min:0,
  190. max:999,
  191. maxLength: 15,
  192. onChange:(val)=>{
  193. setTimeout(() => {
  194. updataCount()
  195. }, 100)
  196. }
  197. },
  198. })
  199. })
  200. fileFlow.priceCount = count
  201. priceSchema.map(item =>{
  202. console.log('priceSchema',item)
  203. appendSchemaByField(item,'')
  204. })
  205. console.log('addPriceItem',valueObj)
  206. setTimeout(()=>{
  207. setFieldsValue(valueObj)
  208. },10)
  209. }
  210. function addSchemas(number){
  211. let parentList: FormSchema[] = [
  212. {
  213. field: 'deviceType' + number,
  214. label: '人工',
  215. component: 'ApiSelect',
  216. colProps: {
  217. span: 12,
  218. },
  219. required: true,
  220. componentProps: {
  221. api: allList,
  222. labelField: 'name',
  223. valueField: 'laborCostId',
  224. showSearch:true,
  225. onChange:(value)=>{
  226. console.log('onchange',value,arguments)
  227. }
  228. },
  229. },
  230. {
  231. field: 'device_' + number,
  232. label: '数量',
  233. component: 'InputNumber',
  234. required: true,
  235. defaultValue: 1,
  236. labelWidth:50,
  237. componentProps: {
  238. max: 999,
  239. min:1,
  240. },
  241. colProps: {
  242. span: 6,
  243. },
  244. },{
  245. field: number.toString(),
  246. component: 'Input',
  247. label: '',
  248. labelWidth:0,
  249. colProps: {
  250. span: 6,
  251. },
  252. slot: 'del',
  253. }
  254. ];
  255. return parentList
  256. }
  257. const handleSubmit = async () => {
  258. const params = await validate();
  259. try {
  260. createConfirm({
  261. iconType: 'warning',
  262. title: () => h('span', '温馨提示'),
  263. content: '确定要提交报价吗?',
  264. onOk: async () => {
  265. loading.value = true
  266. let priceListsparams = []
  267. console.log('addOrUpdatePriceList',params,fileFlow.priceLists)
  268. fileFlow.priceLists.map(ele => {
  269. priceListsparams.push({
  270. type:ele.type,
  271. laborId:ele.laborId,
  272. partId:ele.partId,
  273. count:params[`priceList${ele.priceListId}`]
  274. })
  275. })
  276. for (let index = 1; index < n.value; index++) {
  277. if(params[`device_${index}`]){
  278. priceListsparams.push({
  279. // priceListId:params[`deviceType${index}`],
  280. count:params[`device_${index}`],
  281. laborId:params[`deviceType${index}`],
  282. partId:params[`deviceType${index}`],
  283. type:1,
  284. })
  285. }
  286. }
  287. let res = await addOrUpdatePriceList({
  288. repairId:params.repairId,
  289. priceLists:priceListsparams,
  290. })
  291. console.log('res',res)
  292. createMessage.success(t('common.optSuccess'));
  293. closeModal();
  294. emit('update');
  295. loading.value = false
  296. clearInfo()
  297. },
  298. onCancel: () => {
  299. loading.value = false
  300. }
  301. });
  302. } catch (error) {
  303. loading.value = false
  304. console.log('not passing', error);
  305. }
  306. };
  307. function updataCount(){
  308. let fromData = getFieldsValue() ,count = 0
  309. // fileFlow.priceListsPrice
  310. console.log('fromData',fromData)
  311. fileFlow.priceLists.map(ele => {
  312. count = count + fromData[`priceList${ele.priceListId}`]*ele.price
  313. })
  314. for (let index = 1; index < n.value; index++) {
  315. if(fromData[`deviceType${index}`] && fromData[`device_${index}`]){
  316. let priceId = fromData[`deviceType${index}`]
  317. let fromPrice = fromData[`device_${index}`] * fileFlow.priceListsPrice[priceId]
  318. count = count +fromPrice
  319. }
  320. }
  321. fileFlow.priceCount = count
  322. }
  323. function clearInfo(val){
  324. let indexa = n.value;
  325. fileFlow.priceCount = 0
  326. if(!val){
  327. resetFields()
  328. }
  329. let clearFiled = []
  330. fileFlow.priceLists.map(ele =>{
  331. clearFiled.push(`priceList${ele.priceListId}`,`priceListText${ele.priceListId}`)
  332. })
  333. for (let index = 1; index < indexa; index++) {
  334. clearFiled.push(`deviceType${index}`, `device_${index}`, `${index}`)
  335. }
  336. removeSchemaByFiled(clearFiled);
  337. n.value = 1
  338. }
  339. return {
  340. register,
  341. registerForm,
  342. fileFlow,
  343. handleSubmit,
  344. addListFunc,
  345. resetFields,
  346. loading,
  347. clearInfo,
  348. updataCount,
  349. t,
  350. del,
  351. add,
  352. updataRepairInfo,
  353. };
  354. },
  355. });
  356. </script>
  357. <style lang="less" scoped>
  358. .priceCount{
  359. padding: 20px 180px;
  360. .label{
  361. display: inline-block;
  362. }
  363. }
  364. </style>