confirmPriceModal.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <template>
  2. <BasicModal
  3. v-bind="$attrs"
  4. @register="register"
  5. title="确认报价"
  6. width="600px"
  7. @cancel="clearInfo"
  8. :confirmLoading="loading"
  9. @ok="handleApi"
  10. >
  11. <!-- <template #footer>
  12. <div style="text-align: center">
  13. <a-button type="primary" danger @click="handleCancel">取消维修</a-button>
  14. <a-button type="primary" @click="handleSubmit">确认维修</a-button>
  15. </div>
  16. </template> -->
  17. <div class="pt-2px pr-3px">
  18. <BasicForm @register="registerForm">
  19. <template #text="{ model, field }">
  20. {{ model[field] }}
  21. </template>
  22. </BasicForm>
  23. <div class="priceCount">
  24. <span>合计:</span>
  25. <div class="label">{{ fileFlow.priceCount || 0 }}元 </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, confirmRepair, allList } from '/@/api/spares';
  36. import { useI18n } from '/@/hooks/web/useI18n';
  37. import { RedoOutlined } from '@ant-design/icons-vue';
  38. const { t } = useI18n();
  39. export default defineComponent({
  40. components: { BasicModal, BasicForm, RedoOutlined },
  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. {
  74. field: 'warrantyExpirationDateText',
  75. component: 'Input',
  76. slot: 'text',
  77. label: '保修届满日期',
  78. },
  79. {
  80. field: 'deviceInfo',
  81. component: 'Input',
  82. label: '设备信息',
  83. slot: 'text',
  84. colProps: {
  85. span: 18,
  86. },
  87. },
  88. {
  89. field: 'checkResult',
  90. component: 'Input',
  91. label: '检测结果',
  92. slot: 'text',
  93. colProps: {
  94. span: 18,
  95. },
  96. },
  97. {
  98. field: 'confirm',
  99. component: 'RadioGroup',
  100. label: '维修意向',
  101. defaultValue: 0,
  102. componentProps: {
  103. options: [
  104. {
  105. label: '确认维修',
  106. value: 0,
  107. },
  108. {
  109. label: '取消维修',
  110. value: 1,
  111. },
  112. ],
  113. onChange: (val) => {
  114. console.log('ifShow',val)
  115. updateSchema({
  116. field: 'remark',
  117. required: val.target.value == 1,
  118. ifShow: val.target.value == 1,
  119. })
  120. },
  121. },
  122. colProps: {
  123. span: 22,
  124. },
  125. },
  126. {
  127. field: 'remark',
  128. component: 'InputTextArea',
  129. ifShow: false,
  130. required: false,
  131. label: '取消原因',
  132. componentProps: {
  133. maxLength: 500,
  134. rows: 4,
  135. placeholder: '请填写取消原因',
  136. },
  137. colProps: {
  138. span: 18,
  139. },
  140. },
  141. ];
  142. const [
  143. registerForm,
  144. {
  145. validate,
  146. getFieldsValue,
  147. resetFields,
  148. setFieldsValue,
  149. removeSchemaByFiled,
  150. appendSchemaByField,
  151. updateSchema,
  152. },
  153. ] = useForm({
  154. labelWidth: 100,
  155. labelAlign: 'left',
  156. schemas: schemas,
  157. showActionButtonGroup: false,
  158. actionColOptions: {
  159. span: 24,
  160. },
  161. });
  162. onMounted(async () => {
  163. let allListOption = await allList(); //获取价格
  164. fileFlow.priceListsPrice;
  165. allListOption.map((ele) => {
  166. fileFlow.priceListsPrice[ele.laborCostId] = ele.price;
  167. });
  168. });
  169. let addListFunc = () => {};
  170. const [register, { closeModal }] = useModalInner((data) => {
  171. data && onDataReceive(data);
  172. });
  173. async function updataRepairInfo() {
  174. let { repairId } = getFieldsValue();
  175. console.log('20230228171427939', repairId);
  176. const { priceLists } = await getPriceList({ repairId }); //
  177. addPriceItem(priceLists);
  178. clearInfo(true);
  179. setTimeout(() => {
  180. updataCount();
  181. }, 100);
  182. }
  183. async function onDataReceive(data) {
  184. const { priceLists } = await getPriceList({ repairId: data.repairId }); //
  185. addPriceItem(priceLists);
  186. resetFields();
  187. fileFlow.type = data.type;
  188. updateSchema({
  189. field: 'remark',
  190. required: false,
  191. ifShow: false,
  192. })
  193. setFieldsValue({
  194. ...data,
  195. remark: '',
  196. warrantyExpirationDateText: data.warrantyDate + '(' + t(`routes.spares.warrantyType.${data.warrantyType}`) + ')',
  197. deviceInfo: t(`routes.scene.tableType.${data.cameraType}`) + data.cameraSnCode,
  198. });
  199. }
  200. function del(field) {
  201. removeSchemaByFiled([`deviceType${field}`, `device_${field}`, `${field}`]);
  202. // n.value--;
  203. }
  204. function add() {
  205. let list = addSchemas(n.value);
  206. list.map((ele) => {
  207. appendSchemaByField(ele, '');
  208. });
  209. n.value++;
  210. }
  211. function addPriceItem(list) {
  212. fileFlow.priceLists = list.reverse();
  213. let priceSchema = [],
  214. valueObj = {},
  215. count = 0;
  216. list.map((ele) => {
  217. if (ele.count == 0) {
  218. return;
  219. }
  220. let price = ele.discount == 1 ? ele.priceDiscount : ele.price;
  221. valueObj[`priceList${ele.priceListId}`] = ele.count || 0;
  222. valueObj[`remark${ele.priceListId}`] = ele.remark || 0;
  223. valueObj[`priceListText${ele.priceListId}`] = `${ele.name} ${price} 元${
  224. ele.type == 0 ? '/' + ele.partUnit : ''
  225. }`;
  226. count = count + ele.count * price;
  227. priceSchema.unshift(
  228. {
  229. field: 'priceListText' + ele.priceListId,
  230. component: 'InputNumber',
  231. label: ele.type == 0 ? '备件' : ele.type == 2 ? '明细' : ele.type == 3 ? '减免' : '人工',
  232. slot: 'text',
  233. // labelWidth:300,
  234. // subLabel:"数量",
  235. colProps: {
  236. span: 18,
  237. },
  238. },
  239. {
  240. field: 'priceList' + ele.priceListId,
  241. label: '数量', //`${ele.type == 0?'备件':'人工'}: ${ele.name} ${ele.price} 元/次`,
  242. // suffix:'数量',
  243. component: 'InputNumber',
  244. slot: 'text',
  245. defaultValue: ele.count || 0,
  246. // labelWidth:300,
  247. // subLabel:"数量",
  248. colProps: {
  249. span: 6,
  250. },
  251. required: true,
  252. componentProps: {
  253. disabled: ele.status == 1,
  254. min: 0,
  255. max: 999,
  256. maxLength: 15,
  257. onChange: (_) => {
  258. setTimeout(() => {
  259. updataCount();
  260. }, 100);
  261. },
  262. },
  263. },
  264. {
  265. field: 'remark' + ele.priceListId,
  266. label: '备注',
  267. component: 'InputNumber',
  268. ifShow: ele.type == 2 || ele.type == 3,
  269. slot: 'text',
  270. colProps: {
  271. span: 18,
  272. },
  273. },
  274. );
  275. });
  276. fileFlow.priceCount = count.toFixed(2);
  277. priceSchema.map((item) => {
  278. console.log('priceSchema', item);
  279. appendSchemaByField(item, '');
  280. });
  281. console.log('addPriceItem', valueObj);
  282. setTimeout(() => {
  283. setFieldsValue(valueObj);
  284. }, 10);
  285. }
  286. function addSchemas(number) {
  287. let parentList: FormSchema[] = [
  288. {
  289. field: 'deviceType' + number,
  290. label: '人工',
  291. component: 'ApiSelect',
  292. colProps: {
  293. span: 12,
  294. },
  295. required: true,
  296. componentProps: {
  297. api: allList,
  298. labelField: 'name',
  299. valueField: 'laborCostId',
  300. showSearch: true,
  301. onChange: (value) => {
  302. console.log('onchange', value, arguments);
  303. },
  304. },
  305. },
  306. {
  307. field: 'device_' + number,
  308. label: '数量',
  309. component: 'InputNumber',
  310. required: true,
  311. defaultValue: 1,
  312. labelWidth: 50,
  313. componentProps: {
  314. max: 999,
  315. min: 1,
  316. },
  317. colProps: {
  318. span: 6,
  319. },
  320. },
  321. {
  322. field: number.toString(),
  323. component: 'Input',
  324. label: '',
  325. labelWidth: 0,
  326. colProps: {
  327. span: 6,
  328. },
  329. slot: 'del',
  330. },
  331. ];
  332. return parentList;
  333. }
  334. const handleCancel = async (val) => {
  335. console.log('handleCancel', val, arguments);
  336. handleApi(true);
  337. };
  338. const handleApi = async () => {
  339. const params = await validate();
  340. let val = params.confirm == 1;
  341. try {
  342. createConfirm({
  343. iconType: 'warning',
  344. title: () => h('span', '温馨提示'),
  345. content: val ? '确定取消维修吗' : '确定报价并开始维修吗?',
  346. onOk: async () => {
  347. loading.value = true;
  348. let res = await confirmRepair({
  349. repairId: params.repairId,
  350. remark: params.remark,
  351. confirm: val ? 1 : 0,
  352. });
  353. console.log('res', res);
  354. createMessage.success(t('common.optSuccess'));
  355. closeModal();
  356. emit('update');
  357. loading.value = false;
  358. clearInfo(false);
  359. },
  360. onCancel: () => {
  361. loading.value = false;
  362. },
  363. });
  364. } catch (error) {
  365. loading.value = false;
  366. console.log('not passing', error);
  367. }
  368. };
  369. const handleSubmit = async () => {
  370. handleApi(false);
  371. };
  372. function updataCount() {
  373. let fromData = getFieldsValue(),
  374. count = 0;
  375. // fileFlow.priceListsPrice
  376. console.log('fromData', fromData);
  377. fileFlow.priceLists.map((ele) => {
  378. count = count + fromData[`priceList${ele.priceListId}`] * ele.price;
  379. });
  380. for (let index = 1; index < n.value; index++) {
  381. if (fromData[`deviceType${index}`] && fromData[`device_${index}`]) {
  382. let priceId = fromData[`deviceType${index}`];
  383. let fromPrice = fromData[`device_${index}`] * fileFlow.priceListsPrice[priceId];
  384. count = count + fromPrice;
  385. }
  386. }
  387. fileFlow.priceCount = count.toFixed(2);
  388. }
  389. function clearInfo(val) {
  390. fileFlow.priceCount = 0;
  391. if (!val) {
  392. resetFields();
  393. }
  394. let clearFiled = [];
  395. fileFlow.priceLists.map((ele) => {
  396. clearFiled.push(`priceList${ele.priceListId}`, `priceListText${ele.priceListId}`,`remark${ele.priceListId}`);
  397. });
  398. removeSchemaByFiled(clearFiled);
  399. n.value = 1;
  400. }
  401. return {
  402. register,
  403. registerForm,
  404. fileFlow,
  405. handleSubmit,
  406. handleCancel,
  407. addListFunc,
  408. resetFields,
  409. loading,
  410. clearInfo,
  411. updataCount,
  412. handleApi,
  413. t,
  414. del,
  415. add,
  416. updataRepairInfo,
  417. };
  418. },
  419. });
  420. </script>
  421. <style lang="less" scoped>
  422. .priceCount {
  423. line-height: 32px;
  424. .label {
  425. display: inline-block;
  426. }
  427. }
  428. </style>