index.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. <template>
  2. <!-- 修改现货品种 -->
  3. <a-modal class="commonModal addSpotVariety"
  4. title="修改现货品种"
  5. v-if="visible"
  6. v-model:visible="visible"
  7. centered
  8. :maskClosable="maskClosableFlag"
  9. @cancel="cancel"
  10. width="890px">
  11. <template #footer>
  12. <a-button key="submit"
  13. type="primary"
  14. :loading="loading"
  15. @click="submit">完成
  16. </a-button>
  17. </template>
  18. <a-form class="inlineForm"
  19. ref="formRef"
  20. :model="formState"
  21. :rules="rules">
  22. <fieldset class="formFieldSet">
  23. <legend>基本信息</legend>
  24. <a-row :gutter="24">
  25. <a-col :span="12">
  26. <a-form-item label="现货品种名称"
  27. name="deliverygoodsname">
  28. <a-input class="dialogInput"
  29. v-model:value="formState.deliverygoodsname"
  30. style="width: 200px"
  31. placeholder="请输入现货品种名称" />
  32. </a-form-item>
  33. </a-col>
  34. <a-col :span="12">
  35. <a-form-item label="现货品种代码"
  36. name="deliverygoodscode">
  37. <a-input class="dialogInput"
  38. style="width: 200px"
  39. v-model:value="formState.deliverygoodscode"
  40. placeholder="请输入现货品种代码" />
  41. </a-form-item>
  42. </a-col>
  43. </a-row>
  44. <a-row :gutter="24">
  45. <a-col :span="24">
  46. <a-form-item label="单位"
  47. name="unitid">
  48. <a-select class="inlineFormSelect"
  49. style="width: 200px"
  50. v-model:value="formState.unitid"
  51. placeholder="请选择单位">
  52. <a-select-option v-for="item in unitList"
  53. :value="item.enumitemname"
  54. :key="item.autoid">
  55. {{ item.enumdicname }}
  56. </a-select-option>
  57. </a-select>
  58. </a-form-item>
  59. </a-col>
  60. </a-row>
  61. <a-row :gutter="24">
  62. <a-col :span="24">
  63. <a-form-item label="备注"
  64. name="remark">
  65. <a-input class="dialogInput"
  66. v-model:value="formState.remark"
  67. style="width: 588px"
  68. placeholder="请输入备注" />
  69. </a-form-item>
  70. </a-col>
  71. </a-row>
  72. </fieldset>
  73. <fieldset class="formFieldSet">
  74. <legend>品类信息</legend>
  75. <a-row :gutter="24"
  76. class="dialogRowTitle">
  77. <a-col :span="6">
  78. <span>
  79. <span class="red">*</span>
  80. 品类
  81. </span>
  82. </a-col>
  83. <a-col :span="6">
  84. <span>
  85. <span class="red">*</span>
  86. 单位
  87. </span>
  88. </a-col>
  89. <a-col :span="6">
  90. <span>
  91. <span class="red">*</span>
  92. 标仓系数
  93. </span>
  94. </a-col>
  95. <a-col :span="6">
  96. <span>
  97. 操作
  98. </span>
  99. </a-col>
  100. <template v-for="(domain, index) in formState.gldwrstandards"
  101. :key="domain.index + 'domain'">
  102. <a-col :span="6">
  103. <a-form-item :name="['gldwrstandards',index, 'wrstandardname', ]"
  104. :rules="rules.gldwrstandards.wrstandardname">
  105. <a-input class="dialogInput"
  106. v-model:value="domain.wrstandardname"
  107. placeholder="请输入品类"></a-input>
  108. </a-form-item>
  109. </a-col>
  110. <a-col :span="6">
  111. <a-form-item :name="['gldwrstandards',index,'unitid' ]"
  112. :rules="rules.gldwrstandards.unitid">
  113. <a-select class="inlineFormSelect"
  114. v-model:value="domain.unitid"
  115. placeholder="请选择单位">
  116. <a-select-option v-for="item in unitList"
  117. :value="item.enumitemname"
  118. :key="item.autoid">
  119. {{ item.enumdicname }}
  120. </a-select-option>
  121. </a-select>
  122. </a-form-item>
  123. </a-col>
  124. <a-col :span="6">
  125. <a-form-item :name="['gldwrstandards',index,'convertfactor']"
  126. :rules="rules.gldwrstandards.convertfactor">
  127. <a-input-number class="dialogInput"
  128. style="width: 200px"
  129. v-model:value="domain.convertfactor"
  130. placeholder="请输入标仓系数"></a-input-number>
  131. </a-form-item>
  132. </a-col>
  133. <a-col :span="6"
  134. class="tc">
  135. <a-button class="plusBtn"
  136. @click="deleteOne('gldwrstandards', index)"
  137. v-if="index > 0">
  138. <template #icon>
  139. <MinusOutlined />
  140. </template>
  141. </a-button>
  142. <a-button class="minusBtn"
  143. @click="addOne('gldwrstandards')">
  144. <template #icon>
  145. <PlusOutlined />
  146. </template>
  147. </a-button>
  148. </a-col>
  149. </template>
  150. </a-row>
  151. </fieldset>
  152. <fieldset class="formFieldSet">
  153. <legend>品牌信息</legend>
  154. <a-row :gutter="24"
  155. class="dialogRowTitle dialogRowTitle2">
  156. <a-col :span="12">
  157. <span>
  158. <span class="red">*</span>
  159. 品牌
  160. </span>
  161. </a-col>
  162. <a-col :span="12">
  163. <span>
  164. 操作
  165. </span>
  166. </a-col>
  167. <template v-for="(domain, index) in formState.glddgfactoryItems"
  168. :key="domain.index + 'domain'">
  169. <a-col :span="12">
  170. <a-form-item :name="['glddgfactoryItems',index,'dgfactoryitemvalue']"
  171. :rules="rules.glddgfactoryItems.dgfactoryitemvalue">
  172. <a-input class="dialogInput"
  173. v-model:value="domain.dgfactoryitemvalue"
  174. placeholder="请输入品牌"></a-input>
  175. </a-form-item>
  176. </a-col>
  177. <a-col :span="12">
  178. <a-button class="plusBtn"
  179. @click="deleteOne('glddgfactoryItems', index)"
  180. v-if="index > 0">
  181. <template #icon>
  182. <MinusOutlined />
  183. </template>
  184. </a-button>
  185. <a-button class="minusBtn"
  186. @click="addOne('glddgfactoryItems')">
  187. <template #icon>
  188. <PlusOutlined />
  189. </template>
  190. </a-button>
  191. </a-col>
  192. </template>
  193. </a-row>
  194. </fieldset>
  195. <fieldset class="formFieldSet">
  196. <legend>套保品种信息</legend>
  197. <a-row :gutter="24"
  198. class="dialogRowTitle">
  199. <a-col :span="6">
  200. <span>
  201. <span class="red">*</span>
  202. 套保品种
  203. </span>
  204. </a-col>
  205. <a-col :span="6">
  206. <span>
  207. <span class="red">*</span>
  208. 单位
  209. </span>
  210. </a-col>
  211. <a-col :span="6">
  212. <span>
  213. <span class="red">*</span>
  214. 套保系数
  215. </span>
  216. </a-col>
  217. <a-col :span="6">
  218. <span>
  219. 操作
  220. </span>
  221. </a-col>
  222. <template v-for="(domain, index) in formState.wrsconvertdetails"
  223. :key="domain.index + 'domain'">
  224. <a-col :span="6">
  225. <a-form-item :name="['wrsconvertdetails',index,'middlegoodsid']"
  226. :rules="rules.wrsconvertdetails.middlegoodsid">
  227. <a-select class="inlineFormSelect"
  228. @change="middleChange(domain.middlegoodsid, domain)"
  229. v-model:value="domain.middlegoodsid"
  230. placeholder="请选择套保品种">
  231. <a-select-option v-for="item in goodsGroup"
  232. :value="item.goodsgroupid"
  233. :key="item.goodsgroupid">
  234. {{ item.goodsgroupname }}
  235. </a-select-option>
  236. </a-select>
  237. </a-form-item>
  238. </a-col>
  239. <a-col :span="6">
  240. <a-form-item :name="['wrsconvertdetails', index, 'unitidName']">
  241. <a-input class="dialogInput"
  242. readonly
  243. v-model:value="domain.unitidName"
  244. placeholder="选择套保品种后自动填入"></a-input>
  245. </a-form-item>
  246. </a-col>
  247. <a-col :span="6">
  248. <a-form-item :name="['wrsconvertdetails', index, 'convertratio']"
  249. :rules="rules.wrsconvertdetails.convertratio">
  250. <a-input-number class="dialogInput"
  251. style="width: 200px"
  252. v-model:value="domain.convertratio"
  253. placeholder="请输入套保系数"></a-input-number>
  254. </a-form-item>
  255. </a-col>
  256. <a-col :span="6"
  257. class="tc">
  258. <a-button class="plusBtn"
  259. @click="deleteOne('wrsconvertdetails', index)"
  260. v-if="index > 0">
  261. <template #icon>
  262. <MinusOutlined />
  263. </template>
  264. </a-button>
  265. <a-button class="minusBtn"
  266. @click="addOne('wrsconvertdetails')">
  267. <template #icon>
  268. <PlusOutlined />
  269. </template>
  270. </a-button>
  271. </a-col>
  272. </template>
  273. </a-row>
  274. </fieldset>
  275. </a-form>
  276. </a-modal>
  277. </template>
  278. <script lang="ts">
  279. import { defineComponent, PropType, ref, watchEffect } from 'vue';
  280. import { closeModal } from '@/common/setup/modal/index';
  281. import { initData } from '@/common/methods/index';
  282. import { PlusOutlined, MinusOutlined } from '@ant-design/icons-vue';
  283. import { handleFromState, handleGoodsGroup } from './setup';
  284. import { RuleObject } from 'ant-design-vue/es/form/interface';
  285. import { FormState, WRSConvertDetailEx } from './interface';
  286. import { validateCommon } from '@/common/setup/validate';
  287. import { initDG } from '../../list/spot-variety/setup';
  288. import { ErmcpDeliveryGoodsDetailEx } from '@/services/go/ermcp/goodsInfo/interface';
  289. import { mergeTwoObj } from '@/utils/objHandle';
  290. import { getGoodsUnitEnumList } from '@/common/constants/enumsList';
  291. import { requestResultLoadingAndInfo } from '@/common/methods/request/resultInfo';
  292. import { addDeliveryGoodsApply } from '@/services/proto/delivery';
  293. import { DeliveryGoodsApplyReq } from '@/services/proto/delivery/interface';
  294. import { validateAction } from '@/common/setup/form';
  295. interface Obj {
  296. [props: string]: any;
  297. }
  298. /**
  299. * 检验单位
  300. */
  301. const validateUnit = async (rule: RuleObject, value: number) => {
  302. return validateCommon(value, '请选择单位');
  303. };
  304. /**
  305. *
  306. */
  307. const valideteWR = async (rule: RuleObject, value: number) => {
  308. return validateCommon(value, '请选择品类');
  309. };
  310. export default defineComponent({
  311. name: 'modify-custom',
  312. props: {
  313. selctedDeliveryGoods: {
  314. default: initDG,
  315. type: Object as PropType<ErmcpDeliveryGoodsDetailEx>,
  316. },
  317. },
  318. components: {
  319. PlusOutlined,
  320. MinusOutlined,
  321. },
  322. setup(props, context) {
  323. // 控制关闭弹窗
  324. const { visible, cancel } = closeModal('goods_info_spot_normal_modify');
  325. // 下单方法
  326. const loading = ref<boolean>(false);
  327. // 单位列表
  328. const unitList = getGoodsUnitEnumList();
  329. // 表单
  330. const formRef = ref();
  331. const { formState, addOne, deleteOne } = handleFromState();
  332. const rules = {
  333. deliverygoodsname: [{ required: true, message: '请输入现货品种名称', trigger: 'blur' }],
  334. // unitid: [{ required: true, message: '请选择单位', trigger: 'change' }],
  335. unitid: [{ required: true, validator: validateUnit, trigger: 'change' }],
  336. gldwrstandards: {
  337. unitid: { required: true, validator: validateUnit, trigger: 'change' },
  338. wrstandardname: { required: true, message: '请输入品类', trigger: 'blur' },
  339. convertfactor: { required: true, message: '请输入标仓系数', trigger: 'blur', type: 'number' },
  340. },
  341. glddgfactoryItems: {
  342. dgfactoryitemvalue: { required: true, message: '请输入品牌', trigger: 'blur' },
  343. },
  344. wrsconvertdetails: {
  345. middlegoodsid: { required: true, validator: valideteWR, trigger: 'change' },
  346. convertratio: { required: true, message: '请输入套保系数', trigger: 'blur', type: 'number' },
  347. },
  348. };
  349. function submit() {
  350. validateAction<FormState>(formRef, formState).then((param) => {
  351. const unitid = param.unitid === undefined ? 0 : param.unitid;
  352. const reqParam: DeliveryGoodsApplyReq = {
  353. deliverygoodsid: param.deliverygoodsid,
  354. unitid: unitid,
  355. deliverygoodsname: param.deliverygoodsname,
  356. deliverygoodscode: param.deliverygoodscode,
  357. type: 2,
  358. remark: param.remark,
  359. gldwrstandards: param.gldwrstandards.map((value) => {
  360. const gldunitid = value.unitid === undefined ? 0 : value.unitid;
  361. const convertfactors: any = value.convertfactor === null ? 0 : value.convertfactor;
  362. return {
  363. wrstandardid: value.wrstandardid,
  364. wrstandardname: value.wrstandardname,
  365. unitid: gldunitid,
  366. convertfactor: (convertfactors as string) ? Number(convertfactors) : convertfactors,
  367. };
  368. }),
  369. glddgfactoryItems: param.glddgfactoryItems,
  370. wrsconvertdetails: param.wrsconvertdetails.map((value) => {
  371. const middlegoodsid = value.middlegoodsid === undefined ? 0 : value.middlegoodsid;
  372. const convertratio: any = value.convertratio === null ? 0 : value.convertratio;
  373. const wrsunitid = value.unitid === null ? 0 : value.unitid;
  374. return {
  375. middlegoodsid: middlegoodsid,
  376. convertratio: convertratio ? Number(convertratio) : convertratio,
  377. unitid: wrsunitid,
  378. };
  379. }),
  380. };
  381. requestResultLoadingAndInfo(addDeliveryGoodsApply, reqParam, loading, ['修改现货品种成功', '修改现货品种失败:']).then(() => {
  382. cancel();
  383. context.emit('refresh');
  384. });
  385. });
  386. }
  387. const { goodsGroup, getGoodsGroup } = handleGoodsGroup();
  388. /**
  389. * 切换套保品种时候,获取对应的单位
  390. */
  391. function middleChange(id: number, value: WRSConvertDetailEx) {
  392. const obj = goodsGroup.value.find((e) => e.groupcategroyid === id);
  393. if (obj) {
  394. value.unitidName = obj.enumdicname;
  395. value.unitid = obj.goodunitid;
  396. }
  397. }
  398. watchEffect(() => {
  399. if (props.selctedDeliveryGoods.data.deliverygoodsname) {
  400. const { data, gblist, gmlist, mgList } = props.selctedDeliveryGoods;
  401. mergeTwoObj(formState, props.selctedDeliveryGoods);
  402. mergeTwoObj(formState, data);
  403. // 单位
  404. formState.unitid = data.goodsunitid;
  405. // 品类
  406. formState.gldwrstandards = gmlist.map((e) => {
  407. const { wrstandardid, wrstandardname, convertfactor, unitid } = e;
  408. return { wrstandardid, wrstandardname, convertfactor: convertfactor, unitid };
  409. });
  410. // 品牌
  411. formState.glddgfactoryItems = gblist.map((e) => {
  412. const { brandid, brandname } = e;
  413. return { dgfactoryitemid: brandid, dgfactoryitemvalue: brandname };
  414. });
  415. // 套保信息
  416. formState.wrsconvertdetails = mgList.map((e) => {
  417. const { goodsgroupid, goodsunitid, enumdicname } = e.mg;
  418. return {
  419. middlegoodsid: goodsgroupid,
  420. unitid: goodsunitid,
  421. unitidName: enumdicname,
  422. convertratio: e.convertratio,
  423. };
  424. });
  425. }
  426. });
  427. initData(() => {
  428. getGoodsGroup();
  429. });
  430. return {
  431. visible,
  432. cancel,
  433. formRef,
  434. formState,
  435. addOne,
  436. deleteOne,
  437. rules,
  438. unitList,
  439. goodsGroup,
  440. middleChange,
  441. submit,
  442. loading,
  443. maskClosableFlag: false,
  444. };
  445. },
  446. });
  447. </script>
  448. <style lang="less">
  449. .addSpotVariety {
  450. width: 100%;
  451. height: 100%;
  452. // padding: 30px;
  453. .ant-form.inlineForm .ant-row.ant-form-item .ant-form-item-label {
  454. width: 120px !important;
  455. }
  456. .upload {
  457. display: inline-flex;
  458. .ant-btn.uploadBtn {
  459. width: 60px;
  460. height: 30px;
  461. background: @m-blue0;
  462. border: 0;
  463. padding: 0;
  464. text-align: center;
  465. font-size: 14px;
  466. color: @m-white0;
  467. .rounded-corners(3px);
  468. &:hover {
  469. background: rgba(@m-blue0, 0);
  470. color: rgba(@m-white0, 0.8);
  471. }
  472. }
  473. .look {
  474. color: @m-blue0;
  475. font-size: 14px;
  476. margin-left: 10px;
  477. cursor: pointer;
  478. }
  479. }
  480. .red {
  481. color: @m-red1;
  482. }
  483. .ant-btn.minusBtn,
  484. .ant-btn.plusBtn {
  485. width: 26px;
  486. height: 26px;
  487. .inlineflex;
  488. justify-content: center;
  489. background: @m-blue0;
  490. .rounded-corners(3px);
  491. border: 0;
  492. .anticon {
  493. font-size: 12px;
  494. color: @m-white0;
  495. align-self: center;
  496. align-items: center;
  497. }
  498. &:hover,
  499. &:focus {
  500. background: rgba(@m-blue0, 0.8);
  501. .anticon {
  502. color: rgba(@m-white0, 0.8);
  503. }
  504. }
  505. }
  506. .ant-btn.plusBtn {
  507. margin-right: 10px;
  508. background: transparent;
  509. border: 1px solid #3a87f7;
  510. .anticon {
  511. color: @m-blue0;
  512. }
  513. }
  514. .white {
  515. color: @m-white0;
  516. }
  517. .dialogTable {
  518. .ant-table {
  519. .ant-table-content {
  520. .ant-table-body {
  521. table {
  522. tr {
  523. td {
  524. padding: 0;
  525. .ant-input.dialogInput {
  526. height: 34px;
  527. line-height: 34px;
  528. border: 0;
  529. border-radius: 0;
  530. }
  531. .dialogSelect.ant-select-single {
  532. float: left;
  533. margin-right: 0;
  534. .ant-select-selector {
  535. padding: 0 10px;
  536. height: 34px;
  537. background: @m-grey21;
  538. border: 0;
  539. border-radius: 0;
  540. .ant-select-selection-placeholder {
  541. color: @m-grey10;
  542. text-align: left;
  543. }
  544. }
  545. .ant-select-arrow {
  546. color: @m-blue0;
  547. }
  548. }
  549. }
  550. }
  551. }
  552. }
  553. }
  554. }
  555. }
  556. .ant-form.inlineForm {
  557. .ant-row.dialogRowTitle {
  558. .ant-col {
  559. .ant-row.ant-form-item {
  560. .ant-col.ant-form-item-control-wrapper {
  561. width: 100%;
  562. .ant-form-item-control {
  563. .ant-form-item-children {
  564. .ant-input.dialogInput {
  565. border-radius: 0;
  566. margin-top: 1px;
  567. // margin-left: -1px;
  568. // width: calc(100% + 2px);
  569. }
  570. .ant-select.inlineFormSelect {
  571. margin-top: 1px;
  572. .ant-select-selector {
  573. text-align: left;
  574. }
  575. }
  576. }
  577. }
  578. .ant-form-item-control.has-error {
  579. text-align: left;
  580. .ant-form-item-children {
  581. .ant-input.dialogInput {
  582. background: @m-grey21;
  583. }
  584. }
  585. .ant-form-explain {
  586. color: @m-red1;
  587. }
  588. }
  589. }
  590. }
  591. }
  592. .ant-col {
  593. text-align: center;
  594. }
  595. }
  596. .ant-row.dialogRowTitle2 {
  597. .ant-col:nth-child(3),
  598. .ant-col:nth-child(4) {
  599. border-top: 1px solid @m-grey20;
  600. }
  601. }
  602. }
  603. }
  604. </style
  605. >;