index.vue 23 KB

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