quoteModel.vue 8.6 KB

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