checkModel.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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 myRadioGroup">
  12. <BasicForm @register="registerForm">
  13. <template #text="{ model, field }">
  14. {{ model[field] }}
  15. </template>
  16. <template #add>
  17. <Button @click="add">添加备件</Button>
  18. </template>
  19. <template #del="{ field }">
  20. <Button @click="del(field)">删除</Button>
  21. </template>
  22. </BasicForm>
  23. <div class="tips" style="padding:0 100px">
  24. <p>说明</p>
  25. <p>1、保内维修,直接进入待备料或维修中</p>
  26. <p>2、保外维修,由售后人员进行报价确认后再备料维修</p>
  27. </div>
  28. </div>
  29. </BasicModal>
  30. </template>
  31. <script lang="ts">
  32. import { defineComponent, h, onMounted, reactive, ref } from 'vue';
  33. import { BasicModal, useModalInner } from '/@/components/Modal';
  34. import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
  35. import { useMessage } from '/@/hooks/web/useMessage';
  36. import { partAllList, faultAllList, checkRegister } from '/@/api/spares';
  37. import { useI18n } from '/@/hooks/web/useI18n';
  38. import { uploadApi } from '/@/api/product/index';
  39. const { t } = useI18n();
  40. export default defineComponent({
  41. components: { BasicModal, BasicForm },
  42. props: {
  43. userData: { type: Object },
  44. },
  45. emits: ['update', 'register'],
  46. setup(props, { emit }) {
  47. const n = ref(1);
  48. const fileFlow = reactive({
  49. file: null,
  50. cameraType: 0,
  51. type: 2, //2-普通发票,3-专用发票
  52. faultList: [],
  53. });
  54. const loading = ref(false);
  55. const { createMessage, createConfirm } = useMessage();
  56. let schemas: FormSchema[] = [
  57. {
  58. field: 'repairId',
  59. component: 'Input',
  60. label: '维修单号',
  61. slot: 'text',
  62. colProps: {
  63. span: 24,
  64. },
  65. },
  66. {
  67. field: 'deviceInfo',
  68. component: 'Input',
  69. label: '设备信息',
  70. slot: 'text',
  71. colProps: {
  72. span: 18,
  73. },
  74. },
  75. {
  76. field: 'warrantyExpirationDateText',
  77. component: 'Input',
  78. slot: 'text',
  79. label: '保修届满日期',
  80. },
  81. {
  82. field: 'faultIds',
  83. component: 'CheckboxGroup',
  84. label: '故障类型',
  85. required: true,
  86. componentProps: {
  87. options: fileFlow.faultList,
  88. maxLength: 50,
  89. },
  90. colProps: {
  91. span: 18,
  92. },
  93. },
  94. {
  95. field: 'defineDamage',
  96. component: 'RadioGroup',
  97. label: '定损结论',
  98. helpMessage:'保修期内人为损坏将转为保修外',
  99. defaultValue: 0,
  100. componentProps: {
  101. options: [
  102. {
  103. label: '非人为损坏',
  104. value: 0,
  105. },
  106. {
  107. label: '人为损坏',
  108. value: 1,
  109. },
  110. ],
  111. },
  112. colProps: {
  113. span: 22,
  114. },
  115. },
  116. {
  117. field: 'checkResult',
  118. component: 'InputTextArea',
  119. label: '检测结果',
  120. required: true,
  121. componentProps: {
  122. maxLength: 500,
  123. rows: 3,
  124. placeholder: '请描述检测后的具体故障情况。',
  125. },
  126. colProps: {
  127. span: 18,
  128. },
  129. },
  130. {
  131. field: 'checkImg',
  132. component: 'Upload',
  133. label: '相关图片',
  134. rules: [{ required: false, message: t('common.uploadMessge') }],
  135. itemProps: {
  136. validateTrigger: 'blur',
  137. },
  138. componentProps: {
  139. api: uploadApi,
  140. maxNumber: 5,
  141. maxSize: 1000,
  142. accept: ['jpeg', 'jpg', 'png'],
  143. },
  144. colProps: {
  145. span: 12,
  146. },
  147. },
  148. {
  149. field: '0',
  150. component: 'Input',
  151. label: '所需备件',
  152. colProps: {
  153. span: 18,
  154. },
  155. slot: 'add',
  156. },
  157. ];
  158. const [
  159. registerForm,
  160. {
  161. validate,
  162. resetFields,
  163. setFieldsValue,
  164. removeSchemaByFiled,
  165. appendSchemaByField,
  166. updateSchema,
  167. },
  168. ] = useForm({
  169. labelWidth: 100,
  170. schemas: schemas,
  171. showActionButtonGroup: false,
  172. actionColOptions: {
  173. span: 24,
  174. },
  175. });
  176. onMounted(() => {});
  177. getFaultList();
  178. let addListFunc = () => {};
  179. const [register, { closeModal }] = useModalInner((data) => {
  180. data && onDataReceive(data);
  181. });
  182. async function getFaultList() {
  183. const res = await faultAllList({});
  184. fileFlow.faultList = res.map((item) => {
  185. return {
  186. ...item,
  187. label: item.faultMsg,
  188. value: item.faultId,
  189. };
  190. });
  191. }
  192. function onDataReceive(data) {
  193. resetFields();
  194. updateSchema([{
  195. field: 'faultIds',
  196. componentProps: {
  197. options: fileFlow.faultList,
  198. },
  199. },{
  200. field: 'damage',
  201. ifShow: data.warrantyType == 0,
  202. }]);
  203. fileFlow.type = data.type;
  204. fileFlow.cameraType = data.cameraType;
  205. setFieldsValue({
  206. ...data,
  207. warrantyExpirationDateText: `${data.warrantyDate} (${data.warrantyType==0?'保内维修':data.warrantyType==1?'保内转保外':'保外维修'})`,
  208. deviceInfo: t(`routes.scene.tableType.${data.cameraType}`) + data.cameraSnCode,
  209. });
  210. }
  211. function del(field) {
  212. removeSchemaByFiled([`partId${field}`, `partCount${field}`, `${field}`]);
  213. // n.value--;
  214. }
  215. function add() {
  216. let list = addSchemas(n.value);
  217. list.map((ele) => {
  218. appendSchemaByField(ele, '');
  219. });
  220. n.value++;
  221. }
  222. function addSchemas(number) {
  223. let parentList: FormSchema[] = [
  224. {
  225. field: 'partId' + number,
  226. label: '备件' + number,
  227. component: 'ApiSelect',
  228. colProps: {
  229. span: 12,
  230. },
  231. required: true,
  232. componentProps: {
  233. maxLength: 15,
  234. style:'width: 220px',
  235. api: partAllList,
  236. labelField: 'partName',
  237. valueField: 'partId',
  238. params: {
  239. cameraType: fileFlow.cameraType,
  240. },
  241. showSearch: true,
  242. optionFilterProp: 'label',
  243. },
  244. },
  245. {
  246. field: 'partCount' + number,
  247. label: '数量',
  248. component: 'InputNumber',
  249. required: true,
  250. defaultValue: 1,
  251. labelWidth: 50,
  252. componentProps: {
  253. max: 999,
  254. min: 1,
  255. },
  256. colProps: {
  257. span: 6,
  258. },
  259. },
  260. {
  261. field: number.toString(),
  262. component: 'Input',
  263. label: '',
  264. labelWidth: 0,
  265. colProps: {
  266. span: 6,
  267. },
  268. slot: 'del',
  269. },
  270. ];
  271. return parentList;
  272. }
  273. function clearInfo(val){
  274. if(!val){
  275. resetFields()
  276. }
  277. let clearFiled = []
  278. for (let index = 1; index < n.value; index++) {
  279. clearFiled.push(`partId${index}`,`partCount${index}`,`${index}`)
  280. }
  281. removeSchemaByFiled(clearFiled);
  282. n.value = 1
  283. }
  284. const handleSubmit = async () => {
  285. loading.value = true;
  286. try {
  287. // createConfirm({
  288. // iconType: 'warning',
  289. // title: () => h('span', '温馨提示'),
  290. // content: '确定要提交检测报告吗?',
  291. // onOk: async () => {
  292. const params = await validate();
  293. let partList = [];
  294. for (let s = 1; s <= n.value; s++) {
  295. console.log('params', params, partList);
  296. if (params[`partId${s}`]) {
  297. partList.push({
  298. partId: params[`partId${s}`],
  299. partCount: params[`partCount${s}`],
  300. type:0,
  301. });
  302. }
  303. }
  304. console.log('params', params, partList);
  305. await checkRegister({
  306. ...params,
  307. partList,
  308. })
  309. clearInfo(false)
  310. loading.value = false;
  311. createMessage.success(t('common.optSuccess'));
  312. closeModal();
  313. emit('update');
  314. } catch (error) {
  315. loading.value = false;
  316. console.log('not passing', error);
  317. }
  318. };
  319. return {
  320. register,
  321. registerForm,
  322. fileFlow,
  323. handleSubmit,
  324. addListFunc,
  325. resetFields,
  326. loading,
  327. clearInfo,
  328. t,
  329. del,
  330. add,
  331. };
  332. },
  333. });
  334. </script>
  335. <style lang="less">
  336. .myRadioGroup{
  337. .ant-checkbox-group{
  338. overflow-y: auto;
  339. height: 90px;
  340. }
  341. }
  342. </style>