image.pngimage.png
    子组件:

    1. <template>
    2. <div class="product-base-info-form">
    3. <a-form-model
    4. ref="productBaseInfoRef"
    5. :model="form"
    6. :rules="rules"
    7. labelAlign="left"
    8. :label-col="labelCol"
    9. :wrapper-col="wrapperCol"
    10. :colon="false"
    11. >
    12. <!-- 在frameId为容器的情况下 -->
    13. <div v-if="frameId === STOCK_FRAME_TYPE.CONTAINER" :gutter="12">
    14. <div v-if="!disabled">
    15. <a-form-model-item
    16. prop="icon"
    17. :label-col="labelColItem"
    18. :wrapper-col="{ span: 4 }"
    19. >
    20. <a-select v-model="form.icon" placeholder="图标">
    21. <a-select-option
    22. :key="index"
    23. :value="item"
    24. v-for="(item, index) in productIcons"
    25. >
    26. <!-- <a-icon :type="item" style="font-size: 16px" /> -->
    27. <svg-icon :icon-class="item" :style="{ fontSize: '16px' }" />
    28. </a-select-option>
    29. </a-select>
    30. </a-form-model-item>
    31. <section class="column-item">
    32. <p class="lable">产品名称</p>
    33. <a-form-model-item
    34. class="right"
    35. prop="name"
    36. :label-col="labelColItem"
    37. :wrapper-col="{ span: 8 }"
    38. >
    39. <a-input v-model="form.name" placeholder="名称"></a-input>
    40. </a-form-model-item>
    41. </section>
    42. <section class="column-item">
    43. <p class="lable">编码(Prefix)</p>
    44. <a-form-model-item
    45. class="right"
    46. prop="prefix"
    47. :label-col="labelColItem"
    48. :wrapper-col="{ span: 8 }"
    49. >
    50. <a-input v-model="form.prefix" placeholder="prefix"></a-input>
    51. </a-form-model-item>
    52. </section>
    53. </div>
    54. <a-form-model-item label="容器单位" prop="unitId">
    55. <span v-if="disabled">
    56. {{ unitOptions.filter(item => item.id == form.unitId)[0].unitName }}
    57. </span>
    58. <a-select
    59. v-else
    60. @dropdownVisibleChange="dropdownVisibleChange"
    61. v-model="form.unitId"
    62. placeholder="请选择"
    63. >
    64. <a-select-option
    65. :key="item.id"
    66. :value="item.id"
    67. v-for="item in unitOptions"
    68. >
    69. {{ item.unitName }}
    70. </a-select-option>
    71. <template v-slot:notFoundContent v-if="spinning">
    72. <a-spin :spinning="spinning"></a-spin>
    73. </template>
    74. </a-select>
    75. </a-form-model-item>
    76. <a-form-model-item label="上限容量" prop="capacity">
    77. <span v-if="disabled">{{ form.capacity }}</span>
    78. <a-input v-else v-model="form.capacity"></a-input>
    79. </a-form-model-item>
    80. </div>
    81. <!-- 在frameId不为容器的情况下 -->
    82. <!-- frameId !== STOCK_FRAME_TYPE.CONTAINER -->
    83. <!-- 可编辑状态 -->
    84. <div v-else>
    85. <div v-if="!disabled">
    86. <a-form-model-item
    87. prop="icon"
    88. :label-col="labelColItem"
    89. :wrapper-col="{ span: 6 }"
    90. label="图标"
    91. >
    92. <a-select v-model="form.icon" placeholder="图标">
    93. <a-select-option
    94. :key="index"
    95. :value="item"
    96. v-for="(item, index) in productIcons"
    97. >
    98. <!-- <a-icon :type="item" style="font-size: 16px" /> -->
    99. <svg-icon :icon-class="item" :style="{ fontSize: '16px' }" />
    100. </a-select-option>
    101. </a-select>
    102. </a-form-model-item>
    103. <a-form-model-item
    104. class="right"
    105. prop="name"
    106. :label-col="labelColItem"
    107. :wrapper-col="{ span: 8 }"
    108. label="产品名称"
    109. >
    110. <a-input v-model="form.name" placeholder="名称"></a-input>
    111. </a-form-model-item>
    112. <a-form-model-item
    113. class="right"
    114. prop="prefix"
    115. :label-col="labelColItem"
    116. :wrapper-col="{ span: 8 }"
    117. label="编码(Prefix)"
    118. >
    119. <a-input v-model="form.prefix" placeholder="prefix"></a-input>
    120. </a-form-model-item>
    121. </div>
    122. </div>
    123. <!-- <div class="custom-fields"> -->
    124. <!-- 动态字段 -->
    125. <a-form-model-item
    126. v-for="item in productValues" // 动态字段
    127. :label="item.paramName"
    128. :prop="item.id"
    129. :key="item.id"
    130. :label-col="labelColItem"
    131. :wrapper-col="wrapperColItem"
    132. >
    133. <div
    134. v-if="
    135. paramTypeColumn.text === item.paramType ||
    136. paramTypeColumn.integer === item.paramType ||
    137. paramTypeColumn.float === item.paramType
    138. "
    139. >
    140. <template v-if="disabled">
    141. <span v-if="item.isMultipleValue === 2">{{
    142. form[item.id][0]
    143. }}</span>
    144. <a-tag v-else :key="index" v-for="(ele, index) in form[item.id]">
    145. {{ ele }}
    146. </a-tag>
    147. </template>
    148. <template v-else>
    149. <a-input
    150. v-if="item.isMultipleValue === 2"
    151. v-model="form[item.id][0]"
    152. ></a-input>
    153. <a-select
    154. v-else
    155. v-model="form[item.id]"
    156. :dropdownStyle="{ display: 'none' }"
    157. :dropdownMenuStyle="{ display: 'none' }"
    158. mode="tags"
    159. ></a-select>
    160. </template>
    161. </div>
    162. <div v-else-if="paramTypeColumn.textArea === item.paramType">
    163. <span v-if="disabled">{{ form[item.id][0] }}</span>
    164. <a-input
    165. v-else
    166. :auto-size="{ minRows: 3, maxRows: 5 }"
    167. v-model="form[item.id][0]"
    168. type="textarea"
    169. ></a-input>
    170. </div>
    171. <div v-else-if="paramTypeColumn.radioSelect === item.paramType">
    172. <span v-if="disabled">{{ form[item.id][0] }}</span>
    173. <a-select v-else v-model="form[item.id][0]">
    174. <a-select-option
    175. :key="element"
    176. v-for="element in item.preDefinedValues"
    177. >
    178. {{ element }}
    179. </a-select-option>
    180. </a-select>
    181. </div>
    182. <div v-else-if="paramTypeColumn.multiSelect === item.paramType">
    183. <div v-if="disabled">
    184. <a-tag :key="index" v-for="(ele, index) in form[item.id]">
    185. {{ ele }}
    186. </a-tag>
    187. </div>
    188. <a-select v-else mode="multiple" v-model="form[item.id]">
    189. <a-select-option
    190. :key="element"
    191. v-for="element in item.preDefinedValues"
    192. >
    193. {{ element }}
    194. </a-select-option>
    195. </a-select>
    196. </div>
    197. <div v-else-if="paramTypeColumn.time === item.paramType">
    198. <span v-if="disabled">{{
    199. item.paramValues[0] &&
    200. moment(item.paramValues[0]).format('YYYY-MM-DD HH:mm:ss')
    201. }}</span>
    202. <a-date-picker
    203. v-else
    204. v-model="item.paramValues[0]"
    205. :showTime="true"
    206. ></a-date-picker>
    207. </div>
    208. <div v-else-if="paramTypeColumn.link === item.paramType">
    209. <!-- <span>产品链接类型。。。</span> -->
    210. <!-- 展示产品链接 -->
    211. <div v-if="disabled">
    212. <div class="link-item-box">
    213. <li
    214. class="link-type"
    215. :key="ele.referenceId"
    216. v-for="ele in item.paramValues"
    217. @click="showProductLinkDetail(ele)"
    218. >
    219. <a-icon type="link" />{{ ele.referenceName }}
    220. </li>
    221. </div>
    222. </div>
    223. <div v-else>
    224. <a-button @click="selectProduct(item.paramValues)" size="small"
    225. ><a-icon type="fullscreen" />选择产品</a-button
    226. >
    227. <div class="link-item-box">
    228. <li
    229. class="link-type"
    230. :key="ele.referenceId"
    231. v-for="ele in item.paramValues"
    232. @click="showProductLinkDetail(ele)"
    233. >
    234. <a-icon type="link" /> {{ ele.referenceName }}
    235. </li>
    236. </div>
    237. </div>
    238. </div>
    239. <div v-else-if="paramTypeColumn.cycle === item.paramType">
    240. <div v-if="disabled">
    241. <span
    242. v-if="item.paramValues[0].value && item.paramValues[0].cycleType"
    243. >{{
    244. `${item.paramValues[0].value} ${
    245. CycleTypeInfo[item.paramValues[0].cycleType]
    246. }`
    247. }}</span
    248. >
    249. </div>
    250. <!-- 周期 -->
    251. <CycleTypeCom
    252. v-else
    253. :info="item.paramValues[0]"
    254. style="width: 260px"
    255. />
    256. </div>
    257. <div v-else-if="paramTypeColumn.container === item.paramType">
    258. <!-- 选择的关联容器 -->
    259. <span v-if="disabled">
    260. <!-- {{ item.paramValues[0] ? item.paramValues[0].containerName : '' }} -->
    261. <!-- {{ form[item.id][0] ? form[item.id][0].containerName : '' }} -->
    262. {{ form[item.id][0].containerName }}
    263. </span>
    264. <a-select v-else v-model="form[item.id][0].containerName" show-search>
    265. <!-- 关联容器列表 -->
    266. <a-select-option
    267. :key="element.id"
    268. v-for="element in ContainerOptions"
    269. :value="element.name"
    270. >
    271. {{ element.name }}
    272. </a-select-option>
    273. </a-select>
    274. </div>
    275. </a-form-model-item>
    276. <!-- </div> -->
    277. </a-form-model>
    278. <product-link-modal ref="productLinkModalRef"></product-link-modal>
    279. <product-base-info-modal
    280. ref="productBaseInfoModalRef"
    281. ></product-base-info-modal>
    282. </div>
    283. </template>
    284. <script>
    285. import moment from 'moment'
    286. import { queryStockSchemasDetail } from '@/api/material/locationSetting'
    287. import {
    288. handleMaterialValidateCodePlus,
    289. validateInteger,
    290. validateFloat,
    291. validateFloatNumber,
    292. validateArrRequired
    293. } from '@/common/inspectFunction'
    294. import {
    295. paramTypeColumn,
    296. productIcons,
    297. STOCK_FRAME_TYPE,
    298. VOLUME_TYPE_UNIT,
    299. CycleTypeInfo
    300. } from '@/common/global'
    301. import { getFullUnitInfo } from '@/api/system/unit'
    302. import ProductBaseInfoModal from './ProductBaseInfoModal'
    303. import ProductLinkModal from './ProductLinkModal'
    304. import CycleTypeCom from './fieldRuleSetting/CycleTypeCom'
    305. export default {
    306. props: {
    307. productValues: {
    308. type: Array,
    309. default() {
    310. return []
    311. }
    312. },
    313. productSelfInfo: {
    314. type: Object,
    315. default() {
    316. return {}
    317. }
    318. },
    319. icons: {
    320. type: Array,
    321. default() {
    322. return []
    323. }
    324. },
    325. frameId: {
    326. type: String,
    327. default() {
    328. return ''
    329. }
    330. }
    331. },
    332. components: {
    333. ProductBaseInfoModal,
    334. ProductLinkModal,
    335. CycleTypeCom
    336. },
    337. data() {
    338. return {
    339. CycleTypeInfo,
    340. productIcons: this.icons,
    341. labelCol: { span: 8 },
    342. wrapperCol: { span: 12 },
    343. labelColItem: { span: 8 },
    344. wrapperColItem: { span: 12 },
    345. paramTypeColumn: Object.freeze(paramTypeColumn),
    346. baseInfo: {
    347. prefix: '',
    348. name: '',
    349. icon: '',
    350. unitId: undefined,
    351. capacity: undefined,
    352. version: undefined
    353. },
    354. form: {
    355. prefix: '',
    356. name: '',
    357. icon: '',
    358. unitId: undefined,
    359. capacity: '',
    360. version: undefined
    361. },
    362. showForm: {},
    363. rules: {
    364. prefix: [
    365. { required: true, message: '请填写编号', trigger: 'blur' },
    366. {
    367. min: 1,
    368. max: 32,
    369. message: '编号长度在1-32个字符之间',
    370. trigger: 'change'
    371. },
    372. {
    373. validator: this.handleMaterialValidateCodePlus,
    374. message: '编号格式不正确',
    375. trigger: 'change'
    376. }
    377. ],
    378. unitId: [{ required: true, message: '请填写单位', trigger: 'blur' }],
    379. capacity: [
    380. {
    381. validator: this.validateFloatNumber,
    382. message: '容量格式不正确',
    383. trigger: 'change'
    384. }
    385. ],
    386. name: [
    387. { required: true, message: '必填', trigger: 'change' },
    388. {
    389. min: 1,
    390. max: 32,
    391. message: '名称长度在1-32个字符之间',
    392. trigger: 'change'
    393. }
    394. ]
    395. },
    396. disabled: true,
    397. // 后端需要的paramType
    398. paramTypeObj: {},
    399. STOCK_FRAME_TYPE: Object.freeze(STOCK_FRAME_TYPE),
    400. unitOptions: [],
    401. ContainerOptions: [],
    402. // tmpContainerId: '',
    403. spinning: true,
    404. checkContainer: false
    405. }
    406. },
    407. methods: {
    408. moment,
    409. // 下拉菜单触发的回调
    410. dropdownVisibleChange(open) {
    411. // this.spinning = true
    412. open && _.isEmpty(this.unitOptions) && this.getFullUnitInfo()
    413. },
    414. /**
    415. * 获取数据库预选单位
    416. */
    417. async getFullUnitInfo() {
    418. this.spinning = true
    419. const res = await getFullUnitInfo({
    420. artifacts: [VOLUME_TYPE_UNIT],
    421. pageSize: -1
    422. }).finally(() => {
    423. this.spinning = false
    424. })
    425. if (res.code === '200') {
    426. this.unitOptions = res.data
    427. }
    428. },
    429. /**
    430. * 获取数据库容器
    431. */
    432. async getFullContainerInfo() {
    433. this.ContainerOptions = []
    434. const res = await queryStockSchemasDetail({
    435. stockFrameId: '3',
    436. pageSize: -1
    437. })
    438. if (res.code === '200') {
    439. this.ContainerOptions = res.data.result
    440. // return res.data.result
    441. }
    442. },
    443. /**
    444. * 自定义编码规则
    445. */
    446. handleMaterialValidateCodePlus,
    447. /**
    448. * 整数自定义验证
    449. */
    450. validateInteger,
    451. /**
    452. * 浮点数自定义验证
    453. */
    454. validateFloat,
    455. validateFloatNumber,
    456. validateArrRequired,
    457. /**
    458. * 验证表单数据规则是否匹配
    459. */
    460. validateFormData() {
    461. let flag = false
    462. this.$refs.productBaseInfoRef.validate(valid => {
    463. flag = valid
    464. })
    465. return flag
    466. },
    467. /**
    468. * 选择产品
    469. */
    470. selectProduct(paramValues) {
    471. this.$refs.productLinkModalRef.openSelectProductInfoModal(paramValues)
    472. },
    473. /**
    474. * 展示产品详情
    475. */
    476. showProductLinkDetail(item) {
    477. this.$refs.productBaseInfoModalRef.openProductInfoModal({
    478. id: item.referenceId
    479. })
    480. },
    481. /**
    482. * 父组件会调用它来传输产品基本信息和产品种类自定义字段
    483. */
    484. async getFullData(callback) {
    485. if (!this.validateFormData()) {
    486. return
    487. // callback(false)
    488. }
    489. // const target = _.cloneDeep(this.form)
    490. const target = _.cloneDeep(this.showForm)
    491. let targetArr = []
    492. // {...this.baseInfo} = target
    493. Object.keys(this.baseInfo).forEach(key => {
    494. this.baseInfo[key] = target[key]
    495. delete target[key]
    496. })
    497. Object.keys(target).forEach(key => {
    498. targetArr.push({
    499. id: key,
    500. paramValues: target[key],
    501. paramType: this.paramTypeObj[key]
    502. })
    503. })
    504. await callback({ ...this.baseInfo, productValues: targetArr })
    505. },
    506. /**
    507. * 改变为可以编辑的状态
    508. */
    509. changeIsShowStatus() {
    510. this.disabled = false
    511. },
    512. /**
    513. * 改变为不可编辑的状态
    514. */
    515. changeNoShowStatus() {
    516. this.disabled = true
    517. },
    518. /**
    519. * 清除 form 表单 多余信息
    520. */
    521. resetFormInfo() {
    522. this.$refs.productBaseInfoRef &&
    523. this.$refs.productBaseInfoRef.resetFields &&
    524. this.$refs.productBaseInfoRef.resetFields()
    525. const baseInfoKeys = Object.keys(this.baseInfo)
    526. Object.keys(this.form)
    527. .filter(item => {
    528. return !baseInfoKeys.includes(item)
    529. })
    530. .forEach(key => {
    531. delete this.form[key]
    532. })
    533. }
    534. },
    535. created() {
    536. this.frameId === STOCK_FRAME_TYPE.CONTAINER &&
    537. this.dropdownVisibleChange(true)
    538. },
    539. watch: {
    540. productValues: {
    541. // 切换产品后动态字段信息变化后清除表单动态字段信息给动态字段赋值新的信息并添加到
    542. // form中并在rules中添加新的验证规则。
    543. handler(newProductValues) {
    544. // console.log(newProductValues);
    545. // this.tmpContainerId = ''
    546. this.resetFormInfo()
    547. this.getFullContainerInfo()
    548. newProductValues.forEach(element => {
    549. this.paramTypeObj[element.id] = element.paramType
    550. this.$set(this.form, element.id, element.paramValues || [])
    551. // 给预设容器默认值防止v-model取不到值
    552. if (element.paramType === this.paramTypeColumn.container) {
    553. if (!this.form[element.id][0]) {
    554. this.$set(this.form, element.id, [{
    555. containerId: '',
    556. containerName: ''
    557. }])
    558. }
    559. }
    560. // 控制位置容器数没有值预设容器不必填
    561. if (element.fieldName === "位置容器数") {
    562. this.checkContainer = true
    563. }
    564. // 必填项
    565. if (element.isRequired === 1) {
    566. const requiredInfo = [
    567. { validator: this.validateArrRequired, trigger: 'change' },
    568. { required: true, message: '必填', trigger: 'change' }
    569. ]
    570. !this.rules[element.id] &&
    571. this.$set(this.rules, element.id, requiredInfo)
    572. if (
    573. this.rules[element.id] &&
    574. this.rules[element.id].findIndex(item => item.required) < 0
    575. ) {
    576. this.rules[element.id].push(...requiredInfo)
    577. }
    578. // this.rules[element.id] = [{ required: true, message: '必填', trigger: 'change' }]
    579. }
    580. // 整数
    581. if (element.paramType === this.paramTypeColumn.integer) {
    582. !this.rules[element.id] &&
    583. this.$set(this.rules, element.id, [
    584. { validator: this.validateInteger }
    585. ])
    586. this.rules[element.id] &&
    587. this.rules[element.id].push({
    588. validator: this.validateInteger
    589. })
    590. }
    591. // 浮点数
    592. if (element.paramType === this.paramTypeColumn.float) {
    593. !this.rules[element.id] &&
    594. this.$set(this.rules, element.id, [
    595. { validator: this.validateFloat }
    596. ])
    597. this.rules[element.id] &&
    598. this.rules[element.id].push({
    599. validator: this.validateFloat
    600. })
    601. }
    602. // 覆盖预设容器的规则
    603. if (this.checkContainer && element.paramType === this.paramTypeColumn.container) {
    604. this.rules[element.id] &&
    605. this.$set(this.rules, element.id, [])
    606. // this.rules[element.id] &&
    607. // this.rules[element.id].push([])
    608. this.checkContainer = false
    609. }
    610. })
    611. },
    612. immediate: true
    613. },
    614. productSelfInfo: {
    615. // 切换产品后给表单基本信息新值
    616. handler(newProductSelfInfo) {
    617. this.form.name = newProductSelfInfo.name
    618. this.form.prefix = newProductSelfInfo.prefix
    619. this.form.icon = newProductSelfInfo.icon
    620. this.form.unitId = newProductSelfInfo.unitId
    621. this.form.capacity = newProductSelfInfo.capacity
    622. this.form.version = newProductSelfInfo.version
    623. },
    624. immediate: true,
    625. deep: true
    626. },
    627. frameId: {
    628. handler(newFramaId) {
    629. newFramaId === STOCK_FRAME_TYPE.CONTAINER &&
    630. this.dropdownVisibleChange(true)
    631. },
    632. immediate: true
    633. },
    634. disabled: {
    635. handler(newDisabled) {
    636. this.showForm = _.cloneDeep(this.form);
    637. console.log(this.showForm);
    638. if (newDisabled) {
    639. // 如果是非编辑状态
    640. } else {
    641. // 如果是编辑状态
    642. }
    643. },
    644. immediate: true
    645. }
    646. }
    647. }
    648. </script>
    649. <style lang="scss" scoped>
    650. .product-base-info-form {
    651. .link-item-box {
    652. .link-type {
    653. margin: 0 2px;
    654. display: inline-block;
    655. }
    656. }
    657. & > .columns {
    658. display: flex;
    659. flex-flow: column;
    660. section.column-item {
    661. display: flex;
    662. flex-flow: row wrap;
    663. justify-content: space-between;
    664. align-items: center;
    665. p.lable {
    666. flex-grow: 1;
    667. color: #8c8c8c;
    668. font-size: 14px;
    669. user-select: none;
    670. }
    671. .right {
    672. width: 304px;
    673. }
    674. }
    675. }
    676. }
    677. .custom-fields,
    678. .columns {
    679. margin-right: 25px;
    680. ::v-deep div.ant-row.ant-form-item {
    681. display: flex !important;
    682. flex-flow: row wrap;
    683. justify-content: space-between;
    684. align-items: center;
    685. }
    686. ::v-deep div.ant-col.ant-col-8.ant-form-item-label.ant-form-item-label-left {
    687. background-color: red;
    688. flex-grow: 1;
    689. color: #8c8c8c;
    690. font-size: 14px;
    691. user-select: none;
    692. }
    693. ::v-deep .ant-col.ant-col-12.ant-form-item-control-wrapper {
    694. width: 304px;
    695. input.ant-input {
    696. width: 304px;
    697. }
    698. }
    699. }
    700. </style>

    父组件:
    image.png

    1. <!-- TODO -->
    2. <template>
    3. <div class="product-info-detail-right">
    4. <!-- 具体产品详细信息 -->
    5. <a-spin :spinning="isLoading">
    6. <a-col :span="10">
    7. <div class="product-info-content">
    8. <div class="product-info-content-head">
    9. <a-space>
    10. <span
    11. ><!-- <a-icon :type="productSelfInfo.icon" /> -->
    12. <svg-icon :icon-class="productSelfInfo.icon" />
    13. {{ productSelfInfo.name }}</span
    14. >
    15. <span
    16. :style="{
    17. fontWeight: 'normal',
    18. fontSize: '12px',
    19. color: '#bfbfbf',
    20. }"
    21. >PREFIX: {{ productSelfInfo.prefix }}</span
    22. >
    23. </a-space>
    24. <div>
    25. <a-button
    26. v-if="operatorName[1] === 'edit'"
    27. @click="(e) => changeCradStatus(1, e)"
    28. size="small"
    29. icon="edit"
    30. />
    31. </div>
    32. </div>
    33. <div
    34. :class="
    35. operatorName[1] === 'ok'
    36. ? 'product-info-content-card'
    37. : 'product-info-content-card rquired-no-star'
    38. "
    39. >
    40. <product-base-info-form
    41. ref="productBaseInfoFormRef"
    42. :productSelfInfo="productSelfInfo"
    43. :productValues="frameParams"
    44. :icons="schemaIcons"
    45. :frameId="frameId"
    46. ></product-base-info-form>
    47. <div class="product-info-content-card-footer">
    48. <a-space v-if="operatorName[1] === 'ok'">
    49. <a-button size="small" @click="(e) => backCradEditStatus(1, e)"
    50. >取消</a-button
    51. >
    52. <a-button
    53. type="primary"
    54. size="small"
    55. @click="(e) => changeCradStatus(1, e)"
    56. >提交</a-button
    57. >
    58. </a-space>
    59. </div>
    60. </div>
    61. <div class="product-info-content-card">
    62. <div class="product-info-content-card-header">
    63. <span>附加信息</span>
    64. <div>
    65. <a-button
    66. v-if="operatorName[2] === 'edit'"
    67. @click="(e) => changeCradStatus(2, e)"
    68. size="small"
    69. icon="edit"
    70. />
    71. </div>
    72. </div>
    73. <a-descriptions
    74. v-if="operatorName[2] === 'edit'"
    75. :column="1"
    76. size="small"
    77. bordered
    78. >
    79. <a-descriptions-item
    80. :label="item.paramName"
    81. :key="item.id"
    82. v-for="item in customFields"
    83. >
    84. <span class="info-value">{{ item.paramValue }}</span>
    85. </a-descriptions-item>
    86. </a-descriptions>
    87. <div v-show="operatorName[2] === 'ok'">
    88. <a-alert message="进入编辑状态,暂未保存更新" banner />
    89. <product-custom-fields
    90. ref="productCustomFieldsRef"
    91. @getData="getSchemaFieldsData"
    92. :customFields="customFields"
    93. ></product-custom-fields>
    94. <div class="product-info-content-card-footer">
    95. <a-space>
    96. <a-button
    97. size="small"
    98. @click="(e) => backCradEditStatus(2, e)"
    99. >取消</a-button
    100. >
    101. <a-button
    102. type="primary"
    103. size="small"
    104. @click="(e) => changeCradStatus(2, e)"
    105. >提交</a-button
    106. >
    107. </a-space>
    108. </div>
    109. </div>
    110. </div>
    111. </div>
    112. </a-col>
    113. <a-col :span="14">
    114. <div>
    115. <a-tabs
    116. :default-active-key="titleKey"
    117. @change="(key) => onTabChange(key, 'titleKey')"
    118. size="small"
    119. >
    120. <a-tab-pane key="1" tab="相关库位">
    121. <batch-info-table-list
    122. :parentId="productInfoId"
    123. ></batch-info-table-list>
    124. </a-tab-pane>
    125. <a-tab-pane key="2" tab="库位设置" force-render>
    126. <div class="bmy-tab-pane-content">
    127. <storage-location
    128. ref="storageLocationRef"
    129. @getData="getStorageLocationFieldsData"
    130. :customFields="storageFields"
    131. :showMode="showMode.productKey"
    132. >
    133. </storage-location>
    134. <div class="product-info-content-card-footer">
    135. <a-space>
    136. <a-button
    137. type="primary"
    138. size="small"
    139. @click="(e) => changeCradStatus(3, e)"
    140. >提交</a-button
    141. >
    142. </a-space>
    143. </div>
    144. </div>
    145. </a-tab-pane>
    146. </a-tabs>
    147. </div>
    148. </a-col>
    149. </a-spin>
    150. </div>
    151. </template>
    152. <script>
    153. import { schemaIcons } from "@/common/global";
    154. import {
    155. queryStockFramesDetailBySchemaId,
    156. updateStockSchema,
    157. updateStockSchemaFields,
    158. } from "@/api/material/locationSetting";
    159. import ProductCustomFields from "@/views/materialcenter/productManagement/components/ProductCustomFields";
    160. import ProductBaseInfoForm from "@/views/materialcenter/productManagement/components/ProductBaseInfoForm";
    161. import BatchInfoTableList from "./StockInstanceTable";
    162. import { CUSTOM_FIELD_SHOW_MODE } from "@/views/materialcenter/productManagement/components/comm/constValues";
    163. export default {
    164. props: {
    165. productInfo: {
    166. type: Object,
    167. default() {
    168. return {};
    169. },
    170. },
    171. getLeftStockFrameOrSchema: Function,
    172. },
    173. components: {
    174. ProductCustomFields,
    175. StorageLocation: ProductCustomFields,
    176. ProductBaseInfoForm,
    177. BatchInfoTableList,
    178. },
    179. data() {
    180. return {
    181. schemaIcons: Object.freeze(schemaIcons), // icon 图标
    182. operatorName: {
    183. 1: "edit",
    184. 2: "edit",
    185. },
    186. isLoading: false,
    187. productInfoId: "",
    188. productSelfInfo: {
    189. name: "",
    190. prefix: "",
    191. icon: "",
    192. capacity: undefined,
    193. unitId: undefined,
    194. version: undefined,
    195. },
    196. customFields: [],
    197. frameParams: [],
    198. tabListTitle: [
    199. {
    200. key: "1",
    201. tab: "元件字段",
    202. },
    203. {
    204. key: "2",
    205. tab: "库位字段",
    206. },
    207. ],
    208. titleKey: "1",
    209. showMode: Object.freeze(CUSTOM_FIELD_SHOW_MODE),
    210. schemaCustomFieldsData: {},
    211. storageFieldsData: {},
    212. storageFields: [],
    213. frameId: "",
    214. };
    215. },
    216. methods: {
    217. /**
    218. * 切换 元件/库位字段卡片视图
    219. */
    220. onTabChange(key, type) {
    221. this[type] = key;
    222. },
    223. /**
    224. * 改变卡片状态,会让子组件切换状态
    225. */
    226. changeCradStatus(key, e) {
    227. if (key === 3) {
    228. this.editBaseInfoOrFields(key);
    229. return;
    230. }
    231. if (this.operatorName[key] === "edit") {
    232. this.operatorName[key] = "ok";
    233. // 会让子组件切换状态
    234. key === 1 ? this.$refs.productBaseInfoFormRef.changeIsShowStatus() : "";
    235. } else {
    236. // this.operatorName[key] = 'edit'
    237. // 编辑基本信息/编辑产品字段
    238. this.editBaseInfoOrFields(key);
    239. }
    240. },
    241. /**
    242. * 调用编辑基本信息/产品字段
    243. * key 1.基本信息 2.产品字段 3.库位/批次字段
    244. */
    245. editBaseInfoOrFields(key) {
    246. switch (key) {
    247. case 1:
    248. //切换卡片时调用
    249. this.editProductBaseInfo();
    250. break;
    251. case 3:
    252. case 2:
    253. this.editProductFields();
    254. break;
    255. default:
    256. break;
    257. }
    258. },
    259. /**
    260. * 编辑产品字段 确认时
    261. */
    262. editProductFields() {
    263. this.$refs.productCustomFieldsRef.getData();
    264. this.$refs.storageLocationRef.getData();
    265. this.updateProductFields({
    266. id: this.productInfoId,
    267. customParams: this.schemaCustomFieldsData,
    268. stockParams: this.storageFieldsData,
    269. });
    270. },
    271. /**
    272. * 编辑产品基本信息
    273. */
    274. editProductBaseInfo() {
    275. this.$refs.productBaseInfoFormRef.getFullData((data) => {
    276. data.frameParams = data.productValues;
    277. delete data.productValues;
    278. data &&
    279. this.updateProductInfo({
    280. stockFrameId: this.frameId,
    281. id: this.productInfoId,
    282. ...data,
    283. });
    284. });
    285. },
    286. /**
    287. * 更新产品基本信息 含产品种类字段的 values
    288. * fixme 这个函数到底是干嘛的。。。。
    289. */
    290. // 编辑状态确认时更新信息
    291. async updateProductInfo(data) {
    292. const res = await updateStockSchema(data);
    293. if (res.code === "200") {
    294. this.productSelfInfo.version = res.data.version;
    295. this.productSelfInfo.name = this.$refs.productBaseInfoFormRef.form.name;
    296. this.productSelfInfo.prefix =this.$refs.productBaseInfoFormRef.form.prefix;
    297. this.productSelfInfo.icon = this.$refs.productBaseInfoFormRef.form.icon;
    298. this.operatorName[1] = "edit";
    299. this.$refs.productBaseInfoFormRef.changeNoShowStatus();
    300. // this.$emit('updateProductName')
    301. // 更新库位元件名称 => 手动调用接口
    302. this.getLeftStockFrameOrSchema();
    303. }
    304. },
    305. /**
    306. * 更新产品自定义字段
    307. */
    308. async updateProductFields(data) {
    309. const res = await updateStockSchemaFields(data);
    310. if (res.code === "200") {
    311. this.operatorName[2] = "edit";
    312. // 发起请求
    313. this.getFullProductInfoDetail({ id: this.productInfoId });
    314. }
    315. },
    316. /**
    317. * 从编辑状态返回
    318. */
    319. backCradEditStatus(key, e) {
    320. if (this.operatorName[key] === "ok") {
    321. this.operatorName[key] = "edit";
    322. key === 1 ? this.$refs.productBaseInfoFormRef.changeNoShowStatus() : "";
    323. }
    324. },
    325. /**
    326. * 获取产品字段属性数据
    327. */
    328. getSchemaFieldsData(data, deletingFieldIds) {
    329. // 产品字段 修改是否编辑
    330. // this.updateProductFields({
    331. // id: this.productInfoId,
    332. // params: data,
    333. // deletingFieldIds,
    334. // })
    335. this.schemaCustomFieldsData = {
    336. params: data,
    337. deletingFieldIds,
    338. };
    339. },
    340. /**
    341. * 获取库位字段信息
    342. */
    343. getStorageLocationFieldsData(data, deletingFieldIds) {
    344. this.storageFieldsData = {
    345. params: data,
    346. deletingFieldIds,
    347. };
    348. },
    349. /**
    350. * 获取产品信息详情
    351. */
    352. async getFullProductInfoDetail(data) {
    353. this.isLoading = true;
    354. const res = await queryStockFramesDetailBySchemaId(data).finally(() => {
    355. this.isLoading = false;
    356. });
    357. if (res.code === "200") {
    358. this.customFields = res.data.customParams;
    359. this.frameId = res.data.frameId;
    360. this.frameParams = res.data.frameParams;
    361. this.storageFields = res.data.stockParams;
    362. Object.keys(this.productSelfInfo).forEach((key) => {
    363. this.productSelfInfo[key] = res.data[key];
    364. });
    365. // 深克隆 => productBaseInfoForm 组件监听
    366. this.productSelfInfo = _.cloneDeep(this.productSelfInfo);
    367. }
    368. },
    369. resetCartView() {
    370. this.operatorName = {
    371. 1: "edit",
    372. 2: "edit",
    373. };
    374. this.$refs.productBaseInfoFormRef &&
    375. this.$refs.productBaseInfoFormRef.changeNoShowStatus &&
    376. this.$refs.productBaseInfoFormRef.changeNoShowStatus();
    377. },
    378. },
    379. watch: {
    380. "productInfo.id": {
    381. handler(newVal) {
    382. this.productInfoId = newVal;
    383. this.resetCartView();
    384. this.getFullProductInfoDetail({ id: newVal });
    385. },
    386. immediate: true,
    387. },
    388. },
    389. };
    390. </script>
    391. <style lang="scss" scoped>
    392. .product-info-detail-right {
    393. height: 100%;
    394. // background-color: red;
    395. padding: 16px;
    396. .forbidden {
    397. pointer-events: none;
    398. }
    399. .product-fields {
    400. height: 350px;
    401. overflow-y: scroll;
    402. }
    403. .product-forbidden {
    404. cursor: not-allowed;
    405. }
    406. .batch-info {
    407. height: 500px;
    408. overflow-y: scroll;
    409. }
    410. .product-fields::-webkit-scrollbar {
    411. display: none;
    412. }
    413. }
    414. .product-info-detail-right {
    415. height: 100%;
    416. // background-color: red;
    417. padding: 16px;
    418. .forbidden {
    419. pointer-events: none;
    420. }
    421. .product-fields {
    422. height: 350px;
    423. overflow-y: scroll;
    424. ::v-deep.ant-card-head {
    425. border: none;
    426. }
    427. }
    428. .product-forbidden {
    429. cursor: not-allowed;
    430. }
    431. .batch-info {
    432. height: 500px;
    433. overflow-y: scroll;
    434. }
    435. .product-fields::-webkit-scrollbar {
    436. display: none;
    437. }
    438. }
    439. .product-info-content {
    440. height: calc(100vh - 48px);
    441. overflow-y: auto;
    442. margin-right: 8px;
    443. padding-right: 8px;
    444. border-right: 1px solid #f0f0f0;
    445. .product-info-content-head {
    446. display: flex;
    447. justify-content: space-between;
    448. padding: 0 8px 8px 0;
    449. span {
    450. font-size: 16px;
    451. font-weight: 700;
    452. }
    453. }
    454. .product-info-content-card {
    455. padding: 24px 8px 8px 24px;
    456. .product-info-content-card-header {
    457. display: flex;
    458. justify-content: space-between;
    459. margin-bottom: 8px;
    460. span {
    461. color: #8c8c8c;
    462. font-weight: 500;
    463. }
    464. }
    465. }
    466. .info-value {
    467. color: #262626;
    468. }
    469. ::v-deep.ant-form-item {
    470. margin-bottom: 8px;
    471. color: rgba(0, 0, 0, 0.85);
    472. }
    473. ::v-deep.ant-form-item-label-left {
    474. label {
    475. color: #8c8c8c;
    476. font-weight: 500;
    477. }
    478. }
    479. .rquired-no-star {
    480. ::v-deep.ant-form-item-required::before {
    481. content: none;
    482. }
    483. }
    484. }
    485. .product-info-content-card-footer {
    486. display: flex;
    487. justify-content: flex-end;
    488. }
    489. .bmy-tab-pane-content {
    490. padding: 8px 24px;
    491. }
    492. </style>
    1. <!-- TODO -->
    2. <template>
    3. <div class="product-info-detail-right">
    4. <!-- 具体产品详细信息 -->
    5. <a-spin :spinning="isLoading">
    6. <a-col :span="10">
    7. <div class="product-info-content">
    8. <div class="product-info-content-head">
    9. <a-space>
    10. <span
    11. ><!-- <a-icon :type="productSelfInfo.icon" /> -->
    12. <svg-icon :icon-class="productSelfInfo.icon" />
    13. {{ productSelfInfo.name }}</span
    14. >
    15. <span
    16. :style="{
    17. fontWeight: 'normal',
    18. fontSize: '12px',
    19. color: '#bfbfbf',
    20. }"
    21. >PREFIX: {{ productSelfInfo.prefix }}</span
    22. >
    23. </a-space>
    24. <div>
    25. <a-button
    26. v-if="operatorName[1] === 'edit'"
    27. @click="(e) => changeCradStatus(1, e)"
    28. size="small"
    29. icon="edit"
    30. />
    31. </div>
    32. </div>
    33. <div
    34. :class="
    35. operatorName[1] === 'ok'
    36. ? 'product-info-content-card'
    37. : 'product-info-content-card rquired-no-star'
    38. "
    39. >
    40. <product-base-info-form
    41. ref="productBaseInfoFormRef"
    42. :productSelfInfo="productSelfInfo"
    43. :productValues="frameParams"
    44. :icons="schemaIcons"
    45. :frameId="frameId"
    46. ></product-base-info-form>
    47. <div class="product-info-content-card-footer">
    48. <a-space v-if="operatorName[1] === 'ok'">
    49. <a-button size="small" @click="(e) => backCradEditStatus(1, e)"
    50. >取消</a-button
    51. >
    52. <a-button
    53. type="primary"
    54. size="small"
    55. @click="(e) => changeCradStatus(1, e)"
    56. >提交</a-button
    57. >
    58. </a-space>
    59. </div>
    60. </div>
    61. <div class="product-info-content-card">
    62. <div class="product-info-content-card-header">
    63. <span>附加信息</span>
    64. <div>
    65. <a-button
    66. v-if="operatorName[2] === 'edit'"
    67. @click="(e) => changeCradStatus(2, e)"
    68. size="small"
    69. icon="edit"
    70. />
    71. </div>
    72. </div>
    73. <a-descriptions
    74. v-if="operatorName[2] === 'edit'"
    75. :column="1"
    76. size="small"
    77. bordered
    78. >
    79. <a-descriptions-item
    80. :label="item.paramName"
    81. :key="item.id"
    82. v-for="item in customFields"
    83. >
    84. <span class="info-value">{{ item.paramValue }}</span>
    85. </a-descriptions-item>
    86. </a-descriptions>
    87. <div v-show="operatorName[2] === 'ok'">
    88. <a-alert message="进入编辑状态,暂未保存更新" banner />
    89. <product-custom-fields
    90. ref="productCustomFieldsRef"
    91. @getData="getSchemaFieldsData"
    92. :customFields="customFields"
    93. ></product-custom-fields>
    94. <div class="product-info-content-card-footer">
    95. <a-space>
    96. <a-button
    97. size="small"
    98. @click="(e) => backCradEditStatus(2, e)"
    99. >取消</a-button
    100. >
    101. <a-button
    102. type="primary"
    103. size="small"
    104. @click="(e) => changeCradStatus(2, e)"
    105. >提交</a-button
    106. >
    107. </a-space>
    108. </div>
    109. </div>
    110. </div>
    111. </div>
    112. </a-col>
    113. <a-col :span="14">
    114. <div>
    115. <a-tabs
    116. :default-active-key="titleKey"
    117. @change="(key) => onTabChange(key, 'titleKey')"
    118. size="small"
    119. >
    120. <a-tab-pane key="1" tab="相关库位">
    121. <batch-info-table-list
    122. :parentId="productInfoId"
    123. ></batch-info-table-list>
    124. </a-tab-pane>
    125. <a-tab-pane key="2" tab="库位设置" force-render>
    126. <div class="bmy-tab-pane-content">
    127. <storage-location
    128. ref="storageLocationRef"
    129. @getData="getStorageLocationFieldsData"
    130. :customFields="storageFields"
    131. :showMode="showMode.productKey"
    132. >
    133. </storage-location>
    134. <div class="product-info-content-card-footer">
    135. <a-space>
    136. <a-button
    137. type="primary"
    138. size="small"
    139. @click="(e) => changeCradStatus(3, e)"
    140. >提交</a-button
    141. >
    142. </a-space>
    143. </div>
    144. </div>
    145. </a-tab-pane>
    146. </a-tabs>
    147. </div>
    148. </a-col>
    149. <!-- <a-row :gutter="16">
    150. <a-col :span="12">
    151. <a-card
    152. class="card product-fields"
    153. title="基本信息"
    154. :class="{ 'product-forbidden': operatorName[1] === 'edit' }"
    155. >
    156. <a slot="extra" @click="(e) => changeCradStatus(1, e)">{{
    157. operatorName[1] === "edit" ? "编辑" : "确认"
    158. }}</a>
    159. <product-base-info-form
    160. ref="productBaseInfoFormRef"
    161. :productSelfInfo="productSelfInfo"
    162. :productValues="frameParams"
    163. :icons="schemaIcons"
    164. :frameId="frameId"
    165. :class="{ forbidden: operatorName[1] === 'edit' }"
    166. ></product-base-info-form>
    167. </a-card>
    168. </a-col>
    169. <a-col :span="12">
    170. <a-card
    171. class="card product-fields"
    172. :class="{ 'product-forbidden': operatorName[2] === 'edit' }"
    173. :tab-list="tabListTitle"
    174. :active-tab-key="titleKey"
    175. @tabChange="(key) => onTabChange(key, 'titleKey')"
    176. >
    177. <a
    178. class="link-button"
    179. slot="tabBarExtraContent"
    180. @click="(e) => changeCradStatus(2, e)"
    181. >{{ operatorName[2] === "edit" ? "编辑" : "确认" }}</a
    182. >
    183. <a-alert
    184. v-if="operatorName[2] === 'ok'"
    185. message="进入编辑状态,暂未保存更新"
    186. banner
    187. />
    188. <product-custom-fields
    189. v-show="titleKey === '1'"
    190. ref="productCustomFieldsRef"
    191. @getData="getSchemaFieldsData"
    192. :customFields="customFields"
    193. :class="{ forbidden: operatorName[2] === 'edit' }"
    194. ></product-custom-fields>
    195. <storage-location
    196. v-show="titleKey === '2'"
    197. ref="storageLocationRef"
    198. @getData="getStorageLocationFieldsData"
    199. :class="{ forbidden: operatorName[2] === 'edit' }"
    200. :customFields="storageFields"
    201. :showMode="showMode.productKey"
    202. >
    203. </storage-location>
    204. </a-card>
    205. </a-col>
    206. </a-row>
    207. <a-row style="margin-top: 16px">
    208. <a-col :span="24">
    209. <a-card class="card batch-info" title="相关库位"> </a-card>
    210. </a-col>
    211. </a-row> -->
    212. </a-spin>
    213. </div>
    214. </template>
    215. <script>
    216. import { schemaIcons } from "@/common/global";
    217. import {
    218. queryStockFramesDetailBySchemaId,
    219. updateStockSchema,
    220. updateStockSchemaFields,
    221. } from "@/api/material/locationSetting";
    222. import ProductCustomFields from "@/views/materialcenter/productManagement/components/ProductCustomFields";
    223. import ProductBaseInfoForm from "@/views/materialcenter/productManagement/components/ProductBaseInfoForm";
    224. import BatchInfoTableList from "./StockInstanceTable";
    225. import { CUSTOM_FIELD_SHOW_MODE } from "@/views/materialcenter/productManagement/components/comm/constValues";
    226. export default {
    227. props: {
    228. productInfo: {
    229. type: Object,
    230. default() {
    231. return {};
    232. },
    233. },
    234. getLeftStockFrameOrSchema: Function,
    235. },
    236. components: {
    237. ProductCustomFields,
    238. StorageLocation: ProductCustomFields,
    239. ProductBaseInfoForm,
    240. BatchInfoTableList,
    241. },
    242. data() {
    243. return {
    244. schemaIcons: Object.freeze(schemaIcons), // icon 图标
    245. operatorName: {
    246. 1: "edit",
    247. 2: "edit",
    248. },
    249. isLoading: false,
    250. productInfoId: "",
    251. productSelfInfo: {
    252. name: "",
    253. prefix: "",
    254. icon: "",
    255. capacity: undefined,
    256. unitId: undefined,
    257. version: undefined,
    258. },
    259. customFields: [],
    260. frameParams: [],
    261. tabListTitle: [
    262. {
    263. key: "1",
    264. tab: "元件字段",
    265. },
    266. {
    267. key: "2",
    268. tab: "库位字段",
    269. },
    270. ],
    271. titleKey: "1",
    272. showMode: Object.freeze(CUSTOM_FIELD_SHOW_MODE),
    273. schemaCustomFieldsData: {},
    274. storageFieldsData: {},
    275. storageFields: [],
    276. frameId: "",
    277. };
    278. },
    279. methods: {
    280. /**
    281. * 切换 元件/库位字段卡片视图
    282. */
    283. onTabChange(key, type) {
    284. this[type] = key;
    285. },
    286. /**
    287. * 改变卡片状态
    288. */
    289. changeCradStatus(key, e) {
    290. if (key === 3) {
    291. this.editBaseInfoOrFields(key);
    292. return;
    293. }
    294. if (this.operatorName[key] === "edit") {
    295. this.operatorName[key] = "ok";
    296. key === 1 ? this.$refs.productBaseInfoFormRef.changeIsShowStatus() : "";
    297. } else {
    298. // this.operatorName[key] = 'edit'
    299. // 编辑基本信息/编辑产品字段
    300. this.editBaseInfoOrFields(key);
    301. }
    302. },
    303. /**
    304. * 调用编辑基本信息/产品字段
    305. * key 1.基本信息 2.产品字段 3.库位/批次字段
    306. */
    307. editBaseInfoOrFields(key) {
    308. switch (key) {
    309. case 1:
    310. this.editProductBaseInfo();
    311. break;
    312. case 3:
    313. case 2:
    314. this.editProductFields();
    315. break;
    316. default:
    317. break;
    318. }
    319. },
    320. /**
    321. * 编辑产品字段 确认时
    322. */
    323. editProductFields() {
    324. this.$refs.productCustomFieldsRef.getData();
    325. this.$refs.storageLocationRef.getData();
    326. this.updateProductFields({
    327. id: this.productInfoId,
    328. customParams: this.schemaCustomFieldsData,
    329. stockParams: this.storageFieldsData,
    330. });
    331. },
    332. /**
    333. * 编辑产品基本信息
    334. */
    335. editProductBaseInfo() {
    336. this.$refs.productBaseInfoFormRef.getFullData(async (data) => {
    337. data.frameParams = data.productValues;
    338. delete data.productValues;
    339. data &&
    340. await this.updateProductInfo({
    341. stockFrameId: this.frameId,
    342. id: this.productInfoId,
    343. ...data,
    344. });
    345. });
    346. },
    347. /**
    348. * 更新产品基本信息 含产品种类字段的 values
    349. * fixme 这个函数到底是干嘛的。。。。
    350. */
    351. async updateProductInfo(data) {
    352. const res = await updateStockSchema(data);
    353. if (res.code === "200") {
    354. this.productSelfInfo.version = res.data.version;
    355. this.productSelfInfo.name = this.$refs.productBaseInfoFormRef.form.name;
    356. this.productSelfInfo.prefix =this.$refs.productBaseInfoFormRef.form.prefix;
    357. this.productSelfInfo.icon = this.$refs.productBaseInfoFormRef.form.icon;
    358. this.operatorName[1] = "edit";
    359. this.$refs.productBaseInfoFormRef.changeNoShowStatus();
    360. // this.$emit('updateProductName')
    361. // 更新库位元件名称 => 手动调用接口
    362. this.getLeftStockFrameOrSchema();
    363. }
    364. },
    365. /**
    366. * 更新产品自定义字段
    367. */
    368. async updateProductFields(data) {
    369. const res = await updateStockSchemaFields(data);
    370. if (res.code === "200") {
    371. this.operatorName[2] = "edit";
    372. // 发起请求
    373. this.getFullProductInfoDetail({ id: this.productInfoId });
    374. }
    375. },
    376. /**
    377. * 从编辑状态返回
    378. */
    379. backCradEditStatus(key, e) {
    380. if (this.operatorName[key] === "ok") {
    381. this.operatorName[key] = "edit";
    382. key === 1 ? this.$refs.productBaseInfoFormRef.changeNoShowStatus() : "";
    383. }
    384. },
    385. /**
    386. * 获取产品字段属性数据
    387. */
    388. getSchemaFieldsData(data, deletingFieldIds) {
    389. // 产品字段 修改是否编辑
    390. // this.updateProductFields({
    391. // id: this.productInfoId,
    392. // params: data,
    393. // deletingFieldIds,
    394. // })
    395. this.schemaCustomFieldsData = {
    396. params: data,
    397. deletingFieldIds,
    398. };
    399. },
    400. /**
    401. * 获取库位字段信息
    402. */
    403. getStorageLocationFieldsData(data, deletingFieldIds) {
    404. this.storageFieldsData = {
    405. params: data,
    406. deletingFieldIds,
    407. };
    408. },
    409. /**
    410. * 获取产品信息详情
    411. */
    412. async getFullProductInfoDetail(data) {
    413. this.isLoading = true;
    414. const res = await queryStockFramesDetailBySchemaId(data).finally(() => {
    415. this.isLoading = false;
    416. });
    417. if (res.code === "200") {
    418. this.customFields = res.data.customParams;
    419. this.frameId = res.data.frameId;
    420. this.frameParams = res.data.frameParams;
    421. this.storageFields = res.data.stockParams;
    422. Object.keys(this.productSelfInfo).forEach((key) => {
    423. this.productSelfInfo[key] = res.data[key];
    424. });
    425. // 深克隆 => productBaseInfoForm 组件监听
    426. this.productSelfInfo = _.cloneDeep(this.productSelfInfo);
    427. }
    428. },
    429. resetCartView() {
    430. this.operatorName = {
    431. 1: "edit",
    432. 2: "edit",
    433. };
    434. this.$refs.productBaseInfoFormRef &&
    435. this.$refs.productBaseInfoFormRef.changeNoShowStatus &&
    436. this.$refs.productBaseInfoFormRef.changeNoShowStatus();
    437. },
    438. },
    439. watch: {
    440. "productInfo.id": {
    441. handler(newVal) {
    442. this.productInfoId = newVal;
    443. this.resetCartView();
    444. this.getFullProductInfoDetail({ id: newVal });
    445. },
    446. immediate: true,
    447. },
    448. },
    449. };
    450. </script>
    451. <style lang="scss" scoped>
    452. .product-info-detail-right {
    453. height: 100%;
    454. // background-color: red;
    455. padding: 16px;
    456. .forbidden {
    457. pointer-events: none;
    458. }
    459. .product-fields {
    460. height: 350px;
    461. overflow-y: scroll;
    462. }
    463. .product-forbidden {
    464. cursor: not-allowed;
    465. }
    466. .batch-info {
    467. height: 500px;
    468. overflow-y: scroll;
    469. }
    470. .product-fields::-webkit-scrollbar {
    471. display: none;
    472. }
    473. }
    474. .product-info-detail-right {
    475. height: 100%;
    476. // background-color: red;
    477. padding: 16px;
    478. .forbidden {
    479. pointer-events: none;
    480. }
    481. .product-fields {
    482. height: 350px;
    483. overflow-y: scroll;
    484. ::v-deep.ant-card-head {
    485. border: none;
    486. }
    487. }
    488. .product-forbidden {
    489. cursor: not-allowed;
    490. }
    491. .batch-info {
    492. height: 500px;
    493. overflow-y: scroll;
    494. }
    495. .product-fields::-webkit-scrollbar {
    496. display: none;
    497. }
    498. }
    499. .product-info-content {
    500. height: calc(100vh - 48px);
    501. overflow-y: auto;
    502. margin-right: 8px;
    503. padding-right: 8px;
    504. border-right: 1px solid #f0f0f0;
    505. .product-info-content-head {
    506. display: flex;
    507. justify-content: space-between;
    508. padding: 0 8px 8px 0;
    509. span {
    510. font-size: 16px;
    511. font-weight: 700;
    512. }
    513. }
    514. .product-info-content-card {
    515. padding: 24px 8px 8px 24px;
    516. .product-info-content-card-header {
    517. display: flex;
    518. justify-content: space-between;
    519. margin-bottom: 8px;
    520. span {
    521. color: #8c8c8c;
    522. font-weight: 500;
    523. }
    524. }
    525. }
    526. .info-value {
    527. color: #262626;
    528. }
    529. ::v-deep.ant-form-item {
    530. margin-bottom: 8px;
    531. color: rgba(0, 0, 0, 0.85);
    532. }
    533. ::v-deep.ant-form-item-label-left {
    534. label {
    535. color: #8c8c8c;
    536. font-weight: 500;
    537. }
    538. }
    539. .rquired-no-star {
    540. ::v-deep.ant-form-item-required::before {
    541. content: none;
    542. }
    543. }
    544. }
    545. .product-info-content-card-footer {
    546. display: flex;
    547. justify-content: flex-end;
    548. }
    549. .bmy-tab-pane-content {
    550. padding: 8px 24px;
    551. }
    552. </style>
    1. <template>
    2. <a-modal
    3. v-if="visible"
    4. :title="title"
    5. :visible="visible"
    6. @ok="handleOk"
    7. @cancel="handleCancel"
    8. :width="800"
    9. :height="900"
    10. :destoryOnClose="true"
    11. :bodyStyle="{ padding: '0px 10px', minHeight: '500px' }"
    12. >
    13. <a-tabs default-active-key="1">
    14. <a-tab-pane key="1" tab="基本信息" style="padding-left: 10px">
    15. <a-row>
    16. <a-form-model
    17. ref="createBatchInfoRef"
    18. :model="form"
    19. :labelCol="{ span: 10 }"
    20. :wrapperCol="{ span: 14 }"
    21. :rules="rules"
    22. >
    23. <a-row :gutter="16">
    24. <a-col :span="12">
    25. <a-form-model-item label="种类" prop="frameName">
    26. <a-input disabled v-model="form.frameName"></a-input>
    27. </a-form-model-item>
    28. </a-col>
    29. <a-col :span="12">
    30. <a-form-model-item label="图标" prop="icon">
    31. <a-select v-model="form.icon">
    32. <a-select-option
    33. :value="item"
    34. :key="index"
    35. v-for="(item, index) in schemaIcons"
    36. >
    37. <!-- <a-icon :type="item" style="font-size: 16px" /> -->
    38. <svg-icon
    39. :icon-class="item"
    40. :style="{ fontSize: '16px' }"
    41. />
    42. </a-select-option>
    43. </a-select>
    44. </a-form-model-item>
    45. </a-col>
    46. <a-col :span="12">
    47. <a-form-model-item label="编码" prop="prefix">
    48. <a-input v-model="form.prefix"></a-input>
    49. </a-form-model-item>
    50. </a-col>
    51. <a-col :span="12">
    52. <a-form-model-item label="元件名称" prop="name">
    53. <a-input v-model="form.name"></a-input>
    54. </a-form-model-item>
    55. </a-col>
    56. <a-col :span="12" v-if="CONTAINER_TYPE === stockFrameInfo.id">
    57. <a-form-model-item label="单位" prop="unitId">
    58. <a-select
    59. @dropdownVisibleChange="dropdownVisibleChange"
    60. v-model="form.unitId"
    61. placeholder="请选择"
    62. >
    63. <a-select-option
    64. :key="item.id"
    65. :value="item.id"
    66. v-for="item in unitOptions"
    67. >
    68. {{ item.unitName }}
    69. </a-select-option>
    70. <template v-slot:notFoundContent v-if="spinning">
    71. <a-spin :spinning="spinning"></a-spin>
    72. </template>
    73. </a-select>
    74. </a-form-model-item>
    75. </a-col>
    76. <a-col :span="12" v-if="CONTAINER_TYPE === stockFrameInfo.id">
    77. <a-form-model-item label="容量" prop="capacity">
    78. <a-input v-model="form.capacity"></a-input>
    79. </a-form-model-item>
    80. </a-col>
    81. <a-col
    82. :key="item.id"
    83. :span="12"
    84. v-for="item in stockFrameAttribute"
    85. >
    86. <template v-if="item.paramType !== paramTypeColumn.container">
    87. <a-form-model-item :label="item.paramName" :prop="item.id">
    88. <template
    89. v-if="
    90. paramTypeColumn.text === item.paramType ||
    91. paramTypeColumn.integer === item.paramType ||
    92. paramTypeColumn.float === item.paramType
    93. "
    94. >
    95. <a-input
    96. v-if="item.isMultipleValue === 2"
    97. v-model="form[item.id][0]"
    98. ></a-input>
    99. <a-select
    100. v-else
    101. v-model="form[item.id]"
    102. :dropdownStyle="{ display: 'none' }"
    103. :dropdownMenuStyle="{ display: 'none' }"
    104. mode="tags"
    105. ></a-select>
    106. </template>
    107. <template
    108. v-else-if="paramTypeColumn.textArea === item.paramType"
    109. >
    110. <a-input
    111. :auto-size="{ minRows: 3, maxRows: 5 }"
    112. class="default-input"
    113. v-model="form[item.id][0]"
    114. type="textarea"
    115. ></a-input>
    116. </template>
    117. <template
    118. v-else-if="paramTypeColumn.radioSelect === item.paramType"
    119. >
    120. <a-select v-model="form[item.id][0]">
    121. <a-select-option
    122. :key="element"
    123. v-for="element in item.preDefinedValues"
    124. >
    125. {{ element }}
    126. </a-select-option>
    127. </a-select>
    128. </template>
    129. <template
    130. v-else-if="paramTypeColumn.multiSelect === item.paramType"
    131. >
    132. <a-select mode="multiple" v-model="form[item.id]">
    133. <a-select-option
    134. :key="element"
    135. v-for="element in item.preDefinedValues"
    136. >
    137. {{ element }}
    138. </a-select-option>
    139. </a-select>
    140. </template>
    141. <template v-else-if="paramTypeColumn.time === item.paramType">
    142. <a-date-picker
    143. v-model="item.paramValues[0]"
    144. :showTime="true"
    145. ></a-date-picker>
    146. </template>
    147. <template v-else-if="paramTypeColumn.link === item.paramType">
    148. <span
    149. class="link-type"
    150. :key="ele.referenceId"
    151. v-for="ele in item.paramValues"
    152. @click="showProductLinkDetail(ele)"
    153. ><a-icon type="link" /> {{ ele.referenceName }}</span
    154. >
    155. </template>
    156. <!-- <template
    157. v-else-if="paramTypeColumn.container === item.paramType && isShowContainerType"
    158. >
    159. <a-select
    160. allowClear
    161. @dropdownVisibleChange="dropdownVisibleChange2"
    162. @change="
    163. id => {
    164. handleChangeContainer(id, form[item.id])
    165. }
    166. "
    167. >
    168. <a-select-option
    169. :key="element.id"
    170. v-for="element in ContainerOptions"
    171. :value="element.id"
    172. >
    173. {{ element.name }}
    174. </a-select-option>
    175. <template v-slot:notFoundContent v-if="spinning">
    176. <a-spin :spinning="spinning"></a-spin>
    177. </template>
    178. </a-select>
    179. </template> -->
    180. </a-form-model-item>
    181. </template>
    182. <template v-else-if="
    183. (item.paramType === paramTypeColumn.container && isShowContainerType) ||
    184. (item.paramType === paramTypeColumn.container && stockFrameInfo.name === '盒') ||
    185. (item.paramType === paramTypeColumn.container && stockFrameInfo.name === '板')
    186. ">
    187. <a-form-model-item :label="item.paramName" :prop="item.id">
    188. <a-select
    189. allowClear
    190. @dropdownVisibleChange="dropdownVisibleChange2"
    191. @change="
    192. id => {
    193. handleChangeContainer(id, form[item.id])
    194. }
    195. "
    196. >
    197. <a-select-option
    198. :key="element.id"
    199. v-for="element in ContainerOptions"
    200. :value="element.id"
    201. >
    202. {{ element.name }}
    203. </a-select-option>
    204. <template v-slot:notFoundContent v-if="spinning">
    205. <a-spin :spinning="spinning"></a-spin>
    206. </template>
    207. </a-select>
    208. </a-form-model-item>
    209. </template>
    210. </a-col>
    211. </a-row>
    212. </a-form-model>
    213. </a-row>
    214. <span>元件字段:</span>
    215. <custom-fields
    216. @getData="getCustomFieldsData"
    217. ref="customFieldsRef"
    218. ></custom-fields>
    219. <span>库位字段:</span>
    220. <storage-fields
    221. ref="storageFieldsRef"
    222. @getData="getStorageLocationFieldsData"
    223. :showMode="showMode.productKey"
    224. >
    225. </storage-fields>
    226. </a-tab-pane>
    227. <a-tab-pane
    228. key="2"
    229. tab="规则设置"
    230. style="padding-left: 10px"
    231. ></a-tab-pane>
    232. </a-tabs>
    233. </a-modal>
    234. </template>
    235. <script>
    236. import {
    237. queryStockFrameFields,
    238. saveStockSchema,
    239. queryStockSchemasDetail
    240. } from '@/api/material/locationSetting'
    241. import { getFullUnitInfo } from '@/api/system/unit'
    242. import {
    243. handleValidateCodePlus,
    244. validateInteger,
    245. validateFloat,
    246. validateFloatNumber,
    247. validateArrRequired
    248. } from '@/common/inspectFunction'
    249. import { paramTypeColumn, schemaIcons, VOLUME_TYPE_UNIT } from '@/common/global'
    250. import CustomFields from '@/views/materialcenter/productManagement/components/ProductCustomFields'
    251. import { CUSTOM_FIELD_SHOW_MODE } from '@/views/materialcenter/productManagement/components/comm/constValues'
    252. const CONTAINER_TYPE = '3'
    253. // const CONTAINER_TYPE_HE = '2'
    254. // const CONTAINER_TYPE_BAN = '4'
    255. export default {
    256. components: {
    257. CustomFields,
    258. StorageFields: CustomFields
    259. },
    260. props: {
    261. leftSuccess: Function,
    262. schemaRightSuccess: Function
    263. },
    264. data() {
    265. return {
    266. schemaIcons: Object.freeze(schemaIcons),
    267. source: '',
    268. stockFrameInfo: {},
    269. visible: false,
    270. title: '新建元件',
    271. paramTypeColumn: Object.freeze(paramTypeColumn),
    272. baseInfo: {
    273. frameName: '',
    274. icon: '',
    275. prefix: '',
    276. name: '',
    277. unitId: undefined,
    278. capacity: undefined
    279. },
    280. form: {
    281. frameName: '',
    282. icon: '',
    283. prefix: '',
    284. name: '',
    285. unitId: undefined,
    286. capacity: undefined
    287. },
    288. rules: {
    289. prefix: [
    290. {
    291. min: 1,
    292. max: 64,
    293. required: true,
    294. message: '编码的长度在1~64位之间',
    295. trigger: 'change'
    296. },
    297. {
    298. validator: this.handleValidateCodePlus,
    299. message: '编号格式不正确',
    300. trigger: 'change'
    301. }
    302. ],
    303. name: [
    304. {
    305. min: 1,
    306. max: 32,
    307. required: true,
    308. message: '元件名称的长度在1~32位之间',
    309. trigger: 'change'
    310. }
    311. ],
    312. capacity: [
    313. {
    314. validator: this.validateFloatNumber
    315. },
    316. {
    317. required: true,
    318. message: '容量为必填',
    319. trigger: 'blur'
    320. }
    321. ],
    322. unitId: [
    323. {
    324. required: true,
    325. message: '请填写单位',
    326. trigger: 'blur'
    327. }
    328. ]
    329. },
    330. stockFrameAttribute: [],
    331. // 后端需要的paramType
    332. paramTypeObj: {},
    333. showMode: Object.freeze(CUSTOM_FIELD_SHOW_MODE),
    334. customFieldsData: [],
    335. storageFieldData: [],
    336. unitOptions: [], // 单位选项
    337. CONTAINER_TYPE,
    338. // CONTAINER_TYPE_HE,
    339. // CONTAINER_TYPE_BAN,
    340. spinning: true,
    341. ContainerOptions: [], //容器选项
    342. tempContainer: '',
    343. checkContainer: false,
    344. isShowContainerType: false,
    345. }
    346. },
    347. methods: {
    348. dropdownVisibleChange(open) {
    349. // this.spinning = true
    350. open && _.isEmpty(this.unitOptions) && this.getFullUnitInfo()
    351. },
    352. /**
    353. * 获取数据库预选单位
    354. */
    355. async getFullUnitInfo() {
    356. this.spinning = true
    357. const res = await getFullUnitInfo({
    358. artifacts: [VOLUME_TYPE_UNIT],
    359. pageSize: -1
    360. }).finally(() => {
    361. this.spinning = false
    362. })
    363. if (res.code === '200') {
    364. this.unitOptions = res.data
    365. }
    366. },
    367. dropdownVisibleChange2(open) {
    368. open && _.isEmpty(this.ContainerOptions) && this.getFullContainerInfo()
    369. },
    370. /**
    371. * 获取数据库容器
    372. */
    373. async getFullContainerInfo() {
    374. this.spinning = true
    375. const res = await queryStockSchemasDetail({
    376. stockFrameId: '3',
    377. pageSize: -1
    378. }).finally(() => {
    379. this.spinning = false
    380. })
    381. if (res.code === '200') {
    382. this.ContainerOptions = res.data.result
    383. }
    384. },
    385. /**
    386. * 自定义编码规则
    387. */
    388. handleValidateCodePlus,
    389. /**
    390. * 整数自定义验证
    391. */
    392. validateInteger,
    393. /**
    394. * 浮点数自定义验证
    395. */
    396. validateFloat,
    397. validateFloatNumber,
    398. /**
    399. * 后端给的值是数组
    400. * 自定义必填
    401. */
    402. validateArrRequired,
    403. /**
    404. * 动态表单校验
    405. */
    406. dynamicValidate(element) {
    407. // 必填项
    408. // console.log(element);
    409. // 位置容器数没有值预设容器不必填
    410. // if (element.fieldName === "位置容器数") {
    411. // this.checkContainer = true
    412. // }
    413. if (element.isRequired === 1) {
    414. const requiredInfo = [
    415. { validator: this.validateArrRequired, trigger: 'change' },
    416. { required: true, message: '必填', trigger: 'change' }
    417. ]
    418. !this.rules[element.id] &&
    419. this.$set(this.rules, element.id, requiredInfo)
    420. if (
    421. this.rules[element.id] &&
    422. this.rules[element.id].findIndex(item => item.required) < 0
    423. ) {
    424. this.rules[element.id].push(...requiredInfo)
    425. }
    426. // this.rules[element.id] = [{ required: true, message: '必填', trigger: 'change' }]
    427. }
    428. // 整数
    429. if (element.paramType === this.paramTypeColumn.integer) {
    430. !this.rules[element.id] &&
    431. this.$set(this.rules, element.id, [
    432. { validator: this.validateInteger }
    433. ])
    434. this.rules[element.id] &&
    435. this.rules[element.id].push({
    436. validator: this.validateInteger
    437. })
    438. }
    439. // 浮点数
    440. if (element.paramType === this.paramTypeColumn.float) {
    441. !this.rules[element.id] &&
    442. this.$set(this.rules, element.id, [{ validator: this.validateFloat }])
    443. this.rules[element.id] &&
    444. this.rules[element.id].push({
    445. validator: this.validateFloat
    446. })
    447. }
    448. // if (this.checkContainer && element.paramType === this.paramTypeColumn.container) {
    449. // this.rules[element.id] &&
    450. // this.$set(this.rules, element.id, [])
    451. // // this.rules[element.id] &&
    452. // // this.rules[element.id].push([])
    453. // this.checkContainer = false
    454. // }
    455. },
    456. /**
    457. * 获取自定义字段数据
    458. */
    459. getCustomFieldsData(data) {
    460. this.customFieldsData = data
    461. },
    462. /**
    463. * 获取元件为库位设置的字段信息
    464. */
    465. getStorageLocationFieldsData(data) {
    466. this.storageFieldData = data
    467. },
    468. /**
    469. * 保存库位元件
    470. */
    471. async saveStockSchema(data) {
    472. const res = await saveStockSchema(data)
    473. if (res.code === '200') {
    474. this.judgeCallback()
    475. this.handleCancel()
    476. }
    477. },
    478. /**
    479. * 判断需要执行的回调
    480. */
    481. judgeCallback() {
    482. switch (this.source) {
    483. case 'storageComponentLeft':
    484. this.leftSuccess(this.stockFrameInfo)
    485. break
    486. case 'storageSchemaListRight':
    487. this.schemaRightSuccess()
    488. break
    489. default:
    490. break
    491. }
    492. },
    493. /**
    494. * 获取自定义字段和设置字段的数据
    495. */
    496. getCustomFieldsDataAndSettingData() {
    497. this.$refs.customFieldsRef.getData()
    498. this.$refs.storageFieldsRef.getData()
    499. },
    500. /**
    501. * 获取种类字段数据
    502. */
    503. getFrameParams() {
    504. let targetArr = []
    505. const target = _.cloneDeep(this.form)
    506. Object.keys(this.baseInfo).forEach(key => {
    507. this.baseInfo[key] = target[key]
    508. delete target[key]
    509. })
    510. Object.keys(target).forEach(key => {
    511. targetArr.push({
    512. id: key,
    513. paramValues: target[key],
    514. paramType: this.paramTypeObj[key]
    515. })
    516. })
    517. // console.log(targetArr);
    518. return targetArr
    519. },
    520. /**
    521. * TODO
    522. * 模态框确定
    523. */
    524. handleOk() {
    525. this.$refs.createBatchInfoRef.validate(valid => {
    526. if (valid) {
    527. this.getCustomFieldsDataAndSettingData()
    528. const frameParams = this.getFrameParams()
    529. this.saveStockSchema({
    530. ...this.baseInfo,
    531. frameParams: frameParams,
    532. customParams: {
    533. params: this.customFieldsData
    534. },
    535. stockParams: {
    536. params: this.storageFieldData
    537. },
    538. stockFrameId: this.stockFrameInfo.id
    539. })
    540. }
    541. })
    542. },
    543. /**
    544. * 模态框取消
    545. */
    546. handleCancel() {
    547. this.visible = false
    548. this.$refs.createBatchInfoRef.resetFields()
    549. this.isShowContainerType = false
    550. this.form = {
    551. frameName: '',
    552. icon: '',
    553. prefix: '',
    554. name: '',
    555. unitId: undefined,
    556. capacity: undefined
    557. }
    558. this.stockFrameAttribute = []
    559. },
    560. /**
    561. * 根据库位种类id获取库位种类属性信息
    562. */
    563. async queryStockFrameFields(data) {
    564. const res = await queryStockFrameFields(data)
    565. if (res.code === '200') {
    566. this.stockFrameAttribute = res.data
    567. this.stockFrameAttribute.forEach(element => {
    568. this.paramTypeObj[element.id] = element.paramType
    569. this.$set(this.form, element.id, element.paramValues || [])
    570. // 校验规则
    571. this.dynamicValidate(element)
    572. // console.log(this.form);
    573. })
    574. }
    575. },
    576. /**
    577. * 打开模态框
    578. */
    579. openCreateStockShemaModal(data, source) {
    580. this.tempContainer = ''
    581. this.source = source || ''
    582. this.visible = true
    583. this.stockFrameInfo = data
    584. this.form.frameName = this.stockFrameInfo.name
    585. this.queryStockFrameFields({ id: this.stockFrameInfo.id })
    586. },
    587. /**
    588. * 改变预选容器
    589. */
    590. handleChangeContainer(id, target) { // 这里改回去
    591. if (id) {
    592. const findContainer = this.ContainerOptions.find(v => v.id === id)
    593. this.tempContainer = id
    594. const { id: containerId, name: containerName } = findContainer
    595. target[0] = { containerId, containerName }
    596. } else {
    597. target[0] = {containerId: null, containerName: ""}
    598. // target = []
    599. }
    600. }
    601. },
    602. watch: {
    603. form: {
    604. handler() {
    605. // Object.keys()
    606. const targetId = this.stockFrameAttribute.find(item => item.paramName === '位置容器数')?.id
    607. // console.log(targetId, this.form[targetId]?.length > 0 && this.form[targetId][0] !== '')
    608. ;(this.form[targetId]?.length > 0 && this.form[targetId][0] !== '') ? (this.isShowContainerType = true) : (this.isShowContainerType = false)
    609. },
    610. deep: true,
    611. }
    612. },
    613. }
    614. </script>
    615. <style lang="scss" scoped></style>
    <template>
      <div class="product-base-info-form">
        <!-- {{ copyForm }} -- {{ form }} -- {{ disabled }} -->
        <!-- {{ showForm }} -->
        <a-form-model
          ref="productBaseInfoRef"
          :model="showForm"
          :rules="rules"
          labelAlign="left"
          :label-col="labelCol"
          :wrapper-col="wrapperCol"
          :colon="false"
        >
          如果STOCK_FRAME_TYPE是容器
          <div v-if="frameId === STOCK_FRAME_TYPE.CONTAINER" :gutter="12">
            <div v-if="!disabled">
              <a-form-model-item
                prop="icon"
                :label-col="labelColItem"
                :wrapper-col="{ span: 4 }"
              >
                <a-select v-model="showForm.icon" placeholder="图标">
                  <a-select-option
                    :key="index"
                    :value="item"
                    v-for="(item, index) in productIcons"
                  >
                    <!-- <a-icon :type="item" style="font-size: 16px" /> -->
                    <svg-icon :icon-class="item" :style="{ fontSize: '16px' }" />
                  </a-select-option>
                </a-select>
              </a-form-model-item>
    
              <section class="column-item">
                <p class="lable">产品名称</p>
                <a-form-model-item
                  class="right"
                  prop="name"
                  :label-col="labelColItem"
                  :wrapper-col="{ span: 8 }"
                >
                  <a-input v-model="showForm.name" placeholder="名称"></a-input>
                </a-form-model-item>
              </section>
    
              <section class="column-item">
                <p class="lable">编码(Prefix)</p>
                <a-form-model-item
                  class="right"
                  prop="prefix"
                  :label-col="labelColItem"
                  :wrapper-col="{ span: 8 }"
                >
                  <a-input v-model="showForm.prefix" placeholder="prefix"></a-input>
                </a-form-model-item>
              </section>
            </div>
            <a-form-model-item label="容器单位" prop="unitId">
              <span v-if="disabled">
                {{ unitOptions.filter(item => item.id == showForm.unitId)[0].unitName }}
              </span>
              <a-select
                v-else
                @dropdownVisibleChange="dropdownVisibleChange"
                v-model="showForm.unitId"
                placeholder="请选择"
              >
                <a-select-option
                  :key="item.id"
                  :value="item.id"
                  v-for="item in unitOptions"
                >
                  {{ item.unitName }}
                </a-select-option>
                <template v-slot:notFoundContent v-if="spinning">
                  <a-spin :spinning="spinning"></a-spin>
                </template>
              </a-select>
            </a-form-model-item>
            <a-form-model-item label="上限容量" prop="capacity">
              <span v-if="disabled">{{ showForm.capacity }}</span>
              <a-input v-else v-model="showForm.capacity"></a-input>
            </a-form-model-item>
          </div>
          <!-- frameId !== STOCK_FRAME_TYPE.CONTAINER -->
          <!-- 可编辑状态 -->
          如果STOCK_FRAME_TYPE不是容器,是盒板位置
          <div v-else>
            如果是编辑状态才显示图标、产品名称、编码
            <div v-if="!disabled">
              <a-form-model-item
                prop="icon"
                :label-col="labelColItem"
                :wrapper-col="{ span: 6 }"
                label="图标"
              >
                <a-select v-model="showForm.icon" placeholder="图标">
                  <a-select-option
                    :key="index"
                    :value="item"
                    v-for="(item, index) in productIcons"
                  >
                    <!-- <a-icon :type="item" style="font-size: 16px" /> -->
                    <svg-icon :icon-class="item" :style="{ fontSize: '16px' }" />
                  </a-select-option>
                </a-select>
              </a-form-model-item>
              <a-form-model-item
                class="right"
                prop="name"
                :label-col="labelColItem"
                :wrapper-col="{ span: 8 }"
                label="产品名称"
              >
                <a-input v-model="showForm.name" placeholder="名称"></a-input>
              </a-form-model-item>
              <a-form-model-item
                class="right"
                prop="prefix"
                :label-col="labelColItem"
                :wrapper-col="{ span: 8 }"
                label="编码(Prefix)"
              >
                <a-input v-model="showForm.prefix" placeholder="prefix"></a-input>
              </a-form-model-item>
            </div>
          </div>
    
          动态字段
          <a-form-model-item
            v-for="item in productValues"
            :label="item.paramName"
            :prop="item.id"
            :key="item.id"
            :label-col="labelColItem"
            :wrapper-col="wrapperColItem"
          >
            <!-- 不是容器的渲染在这里 -->
            <template v-if="item.paramType !== paramTypeColumn.container">
              <div v-if="paramTypeColumn.text === item.paramType || paramTypeColumn.integer === item.paramType || paramTypeColumn.float === item.paramType">
                <template v-if="disabled">
                  <span v-if="item.isMultipleValue === 2">{{
                    showForm[item.id][0]
                  }}</span>
                  <a-tag v-else :key="index" v-for="(ele, index) in showForm[item.id]">
                    {{ ele }}
                  </a-tag>
                </template>
                <template v-else>
                  <a-input
                    v-if="item.isMultipleValue === 2"
                    v-model="showForm[item.id][0]"
                  ></a-input>
                  <a-select
                    v-else
                    v-model="showForm[item.id]"
                    :dropdownStyle="{ display: 'none' }"
                    :dropdownMenuStyle="{ display: 'none' }"
                    mode="tags"
                  ></a-select>
                </template>
              </div>
              <div v-else-if="paramTypeColumn.textArea === item.paramType">
                <span v-if="disabled">{{ showForm[item.id][0] }}</span>
                <a-input
                  v-else
                  :auto-size="{ minRows: 3, maxRows: 5 }"
                  v-model="showForm[item.id][0]"
                  type="textarea"
                ></a-input>
              </div>
              <div v-else-if="paramTypeColumn.radioSelect === item.paramType">
                <span v-if="disabled">{{ showForm[item.id][0] }}</span>
                <a-select v-else v-model="showForm[item.id][0]">
                  <a-select-option
                    :key="element"
                    v-for="element in item.preDefinedValues"
                  >
                    {{ element }}
                  </a-select-option>
                </a-select>
              </div>
              <div v-else-if="paramTypeColumn.multiSelect === item.paramType">
                <div v-if="disabled">
                  <a-tag :key="index" v-for="(ele, index) in showForm[item.id]">
                    {{ ele }}
                  </a-tag>
                </div>
                <a-select v-else mode="multiple" v-model="showForm[item.id]">
                  <a-select-option
                    :key="element"
                    v-for="element in item.preDefinedValues"
                  >
                    {{ element }}
                  </a-select-option>
                </a-select>
              </div>
              <div v-else-if="paramTypeColumn.time === item.paramType">
                <span v-if="disabled">{{
                  item.paramValues[0] &&
                    moment(item.paramValues[0]).format('YYYY-MM-DD HH:mm:ss')
                }}</span>
                <a-date-picker
                  v-else
                  v-model="item.paramValues[0]"
                  :showTime="true"
                ></a-date-picker>
              </div>
              <div v-else-if="paramTypeColumn.link === item.paramType">
                <!-- <span>产品链接类型。。。</span> -->
                <!-- 展示产品链接 -->
                <div v-if="disabled">
                  <div class="link-item-box">
                    <li
                      class="link-type"
                      :key="ele.referenceId"
                      v-for="ele in item.paramValues"
                      @click="showProductLinkDetail(ele)"
                    >
                      <a-icon type="link" />{{ ele.referenceName }}
                    </li>
                  </div>
                </div>
                <div v-else>
                  <a-button @click="selectProduct(item.paramValues)" size="small"
                    ><a-icon type="fullscreen" />选择产品</a-button
                  >
                  <div class="link-item-box">
                    <li
                      class="link-type"
                      :key="ele.referenceId"
                      v-for="ele in item.paramValues"
                      @click="showProductLinkDetail(ele)"
                    >
                      <a-icon type="link" /> {{ ele.referenceName }}
                    </li>
                  </div>
                </div>
              </div>
              <div v-else-if="paramTypeColumn.cycle === item.paramType">
                <div v-if="disabled">
                  <span
                    v-if="item.paramValues[0].value && item.paramValues[0].cycleType"
                    >{{
                      `${item.paramValues[0].value} ${
                        CycleTypeInfo[item.paramValues[0].cycleType]
                      }`
                    }}</span
                  >
                </div>
                <!-- 周期 -->
                <CycleTypeCom
                  v-else
                  :info="item.paramValues[0]"
                  style="width: 260px"
                />
              </div>
            </template>
    
            <!-- 是容器的单独渲染在这里,且isShowContainerType为真 -->
            <template v-else-if="item.paramType === paramTypeColumn.container && isShowContainerType">
    
                <!-- 选择的关联容器 -->
                <span v-if="disabled">
                  {{ showForm[item.id][0].containerName }}
                </span>
                  <a-select v-else :default-value="showForm[item.id][0].containerId" @change="(id) => handleChangeContainer(id, showForm[item.id])" show-search>
                    <!-- 关联容器列表 -->
                    <a-select-option
                      :key="element.id"
                      v-for="element in ContainerOptions"
                      :value="element.id"
                    >
                      {{ element.name }}
                    </a-select-option>
                    <template v-slot:notFoundContent v-if="spinning">
                      <a-spin :spinning="spinning"></a-spin>
                    </template>
                  </a-select>
    
            </template>
    
    
          </a-form-model-item>
          <!-- </div> -->
        </a-form-model>
        <product-link-modal ref="productLinkModalRef"></product-link-modal>
        <product-base-info-modal
          ref="productBaseInfoModalRef"
        ></product-base-info-modal>
      </div>
    </template>
    
    <script>
    import moment from 'moment'
    import { queryStockSchemasDetail } from '@/api/material/locationSetting'
    import {
      handleMaterialValidateCodePlus,
      validateInteger,
      validateFloat,
      validateFloatNumber,
      validateArrRequired
    } from '@/common/inspectFunction'
    import {
      paramTypeColumn,
      productIcons,
      STOCK_FRAME_TYPE,
      VOLUME_TYPE_UNIT,
      CycleTypeInfo
    } from '@/common/global'
    
    import { getFullUnitInfo } from '@/api/system/unit'
    
    import ProductBaseInfoModal from './ProductBaseInfoModal'
    import ProductLinkModal from './ProductLinkModal'
    import CycleTypeCom from './fieldRuleSetting/CycleTypeCom'
    
    export default {
      props: {
        productValues: {
          type: Array,
          default() {
            return []
          }
        },
        productSelfInfo: {
          type: Object,
          default() {
            return {}
          }
        },
        icons: {
          type: Array,
          default() {
            return []
          }
        },
        frameId: {
          type: String,
          default() {
            return ''
          }
        }
      },
      components: {
        ProductBaseInfoModal,
        ProductLinkModal,
        CycleTypeCom
      },
      data() {
        return {
          CycleTypeInfo,
          productIcons: this.icons,
          labelCol: { span: 8 },
          wrapperCol: { span: 12 },
          labelColItem: { span: 8 },
          wrapperColItem: { span: 12 },
          paramTypeColumn: Object.freeze(paramTypeColumn),
          baseInfo: {
            prefix: '',
            name: '',
            icon: '',
            unitId: undefined,
            capacity: undefined,
            version: undefined
          },
          form: {
            prefix: '',
            name: '',
            icon: '',
            unitId: undefined,
            capacity: '',
            version: undefined
          },
          showForm: {},
          rules: {
            prefix: [
              { required: true, message: '请填写编号', trigger: 'blur' },
              {
                min: 1,
                max: 32,
                message: '编号长度在1-32个字符之间',
                trigger: 'change'
              },
              {
                validator: this.handleMaterialValidateCodePlus,
                message: '编号格式不正确',
                trigger: 'change'
              }
            ],
            unitId: [{ required: true, message: '请填写单位', trigger: 'blur' }],
            capacity: [
              {
                validator: this.validateFloatNumber,
                message: '容量格式不正确',
                trigger: 'change'
              }
            ],
            name: [
              { required: true, message: '必填', trigger: 'change' },
              {
                min: 1,
                max: 32,
                message: '名称长度在1-32个字符之间',
                trigger: 'change'
              }
            ]
          },
          disabled: true,
          // 后端需要的paramType
          paramTypeObj: {},
          STOCK_FRAME_TYPE: Object.freeze(STOCK_FRAME_TYPE),
          unitOptions: [],
          ContainerOptions: [],
          // tmpContainerId: '',
          spinning: true,
          checkContainer: false,
          isShowContainerType: false,
        }
      },
      methods: {
        moment,
        dropdownVisibleChange(open) {
          // this.spinning = true
          open && _.isEmpty(this.unitOptions) && this.getFullUnitInfo()
        },
        /**
         * 获取数据库预选单位
         */
        async getFullUnitInfo() {
          this.spinning = true
          const res = await getFullUnitInfo({
            artifacts: [VOLUME_TYPE_UNIT],
            pageSize: -1
          }).finally(() => {
            this.spinning = false
          })
          if (res.code === '200') {
            this.unitOptions = res.data
          }
        },
        /**
         * 获取数据库容器
         */
        async getFullContainerInfo() {
          this.ContainerOptions = []
          this.spinning = true
          const res = await queryStockSchemasDetail({
            stockFrameId: '3',
            pageSize: -1
          }).finally(() => {
            this.spinning = false
          })
          if (res.code === '200') {
            this.ContainerOptions = res.data.result
            // return res.data.result
          }
        },
        /**
         * 自定义编码规则
         */
        handleMaterialValidateCodePlus,
        /**
         * 整数自定义验证
         */
        validateInteger,
        /**
         * 浮点数自定义验证
         */
        validateFloat,
        validateFloatNumber,
    
        validateArrRequired,
    
        /**
         * 验证表单数据规则是否匹配
         */
        validateFormData() {
          let flag = false
          this.$refs.productBaseInfoRef.validate(valid => {
            flag = valid
          })
          return flag
        },
        /**
         * 选择产品
         */
        selectProduct(paramValues) {
          this.$refs.productLinkModalRef.openSelectProductInfoModal(paramValues)
        },
        /**
         * 展示产品详情
         */
        showProductLinkDetail(item) {
          this.$refs.productBaseInfoModalRef.openProductInfoModal({
            id: item.referenceId
          })
        },
        /**
         * 传输产品基本信息和产品种类自定义字段
         */
        async getFullData(callback) {
          if (!this.validateFormData()) {
            return
            // callback(false)
          }
          const target = _.cloneDeep(this.showForm)
          let targetArr = []
          // {...this.baseInfo} = target
          Object.keys(this.baseInfo).forEach(key => {
            this.baseInfo[key] = target[key]
            delete target[key]
          })
          // console.log(target);
          Object.keys(target).forEach(key => {
            targetArr.push({
              id: key,
              paramValues: target[key],
              paramType: this.paramTypeObj[key]
            })
          })
          const _form = { ..._.cloneDeep(this.showForm), version: this.showForm.version + 1 }
          await callback({ ...this.baseInfo, productValues: targetArr })
          this.form = _form
          // this.changeNoShowStatus()
        },
        /**
         * 改变为可以编辑的状态
         */
        changeIsShowStatus() {
          this.disabled = false
        },
        /**
         * 改变为不可编辑的状态
         */
        changeNoShowStatus() {
          this.disabled = true
        },
        /**
         * 清除 form 表单 多余信息
         */
        resetFormInfo() {
          this.$refs.productBaseInfoRef &&
            this.$refs.productBaseInfoRef.resetFields &&
            this.$refs.productBaseInfoRef.resetFields()
          const baseInfoKeys = Object.keys(this.baseInfo)
          Object.keys(this.form)
            .filter(item => {
              return !baseInfoKeys.includes(item)
            })
            .forEach(key => {
              delete this.form[key]
            })
        },
    
        /**
         * 改变 container
         */
        handleChangeContainer(id, target) {
          const findContainer = this.ContainerOptions.find(v => v.id === id)
          this.tempContainer = id
          const { id: containerId, name: containerName } = findContainer
          target[0] = { containerId, containerName }
        }
      },
      created() {
        this.frameId === STOCK_FRAME_TYPE.CONTAINER &&
          this.dropdownVisibleChange(true)
      },
      watch: {
        productValues: {
          handler(newProductValues) {
            // console.log(newProductValues);
            // this.tmpContainerId = ''
            this.resetFormInfo()
            this.getFullContainerInfo()
            newProductValues.forEach(element => {
              this.paramTypeObj[element.id] = element.paramType
              this.$set(this.form, element.id, element.paramValues || [])
              // 给预设容器默认值防止v-model取不到值  !删掉
              if (element.paramType === this.paramTypeColumn.container) {
                if (!this.form[element.id][0]) {
                    this.$set(this.form, element.id, [{
                    containerId: '',
                    containerName: ''
                  }])
                }
              }
              // 控制位置容器数没有值预设容器不必填  !删掉
              if (element.fieldName === "位置容器数") {
                this.checkContainer = true
              }
              // 必填项
              if (element.isRequired === 1) {
                const requiredInfo = [
                  { validator: this.validateArrRequired, trigger: 'change' },
                  { required: true, message: '必填', trigger: 'change' }
                ]
                !this.rules[element.id] &&
                  this.$set(this.rules, element.id, requiredInfo)
                if (
                  this.rules[element.id] &&
                  this.rules[element.id].findIndex(item => item.required) < 0
                ) {
                  this.rules[element.id].push(...requiredInfo)
                }
                // this.rules[element.id] = [{ required: true, message: '必填', trigger: 'change' }]
              }
              // 整数
              if (element.paramType === this.paramTypeColumn.integer) {
                !this.rules[element.id] &&
                  this.$set(this.rules, element.id, [
                    { validator: this.validateInteger }
                  ])
                this.rules[element.id] &&
                  this.rules[element.id].push({
                    validator: this.validateInteger
                  })
              }
              // 浮点数
              if (element.paramType === this.paramTypeColumn.float) {
                !this.rules[element.id] &&
                  this.$set(this.rules, element.id, [
                    { validator: this.validateFloat }
                  ])
                this.rules[element.id] &&
                  this.rules[element.id].push({
                    validator: this.validateFloat
                  })
              }
              // 覆盖预设容器的规则    !删掉
              if (this.checkContainer && element.paramType === this.paramTypeColumn.container) {
                this.rules[element.id] &&
                  this.$set(this.rules, element.id, [])
                // this.rules[element.id] &&
                //   this.rules[element.id].push([])
                this.checkContainer = false
              }
            })
          },
          immediate: true
        },
        productSelfInfo: {
          handler(newProductSelfInfo) {
            this.form.name = newProductSelfInfo.name
            this.form.prefix = newProductSelfInfo.prefix
            this.form.icon = newProductSelfInfo.icon
            this.form.unitId = newProductSelfInfo.unitId
            this.form.capacity = newProductSelfInfo.capacity
            this.form.version = newProductSelfInfo.version
          },
          immediate: true,
          deep: true
        },
        frameId: {
          handler(newFramaId) {
            newFramaId === STOCK_FRAME_TYPE.CONTAINER &&
              this.dropdownVisibleChange(true)
          },
          immediate: true
        },
        disabled: {
          handler(newDisabled) {
            this.showForm = this.disabled ? this.form : this.copyForm
            if (newDisabled) {
              this.showForm = this.form
              this.copyForm = _.cloneDeep(this.form)
            } else {
              this.showForm = _.cloneDeep(this.copyForm)
            }
          }
        },
        form: {
          handler() {
            this.copyForm = _.cloneDeep(this.form)
            this.showForm = _.cloneDeep(this.form)
            const targetId = this.productValues.find(item => item.paramName === '位置容器数')?.id
            // console.log(targetId, this.form[targetId]?.length > 0 && this.form[targetId][0] !== '')
            ;(this.form[targetId]?.length > 0  && this.form[targetId][0] !== '') ? (this.isShowContainerType = true) : (this.isShowContainerType = false)
          },
          deep: true,
          immediate: true
        }
      }
    }
    </script>
    
    <style lang="scss" scoped>
    .product-base-info-form {
      .link-item-box {
        .link-type {
          margin: 0 2px;
          display: inline-block;
        }
      }
      & > .columns {
        display: flex;
        flex-flow: column;
        section.column-item {
          display: flex;
          flex-flow: row wrap;
          justify-content: space-between;
          align-items: center;
          p.lable {
            flex-grow: 1;
            color: #8c8c8c;
            font-size: 14px;
            user-select: none;
          }
          .right {
            width: 304px;
          }
        }
      }
    }
    .custom-fields,
    .columns {
      margin-right: 25px;
      ::v-deep div.ant-row.ant-form-item {
        display: flex !important;
        flex-flow: row wrap;
        justify-content: space-between;
        align-items: center;
      }
      ::v-deep div.ant-col.ant-col-8.ant-form-item-label.ant-form-item-label-left {
        background-color: red;
        flex-grow: 1;
        color: #8c8c8c;
        font-size: 14px;
        user-select: none;
      }
      ::v-deep .ant-col.ant-col-12.ant-form-item-control-wrapper {
        width: 304px;
        input.ant-input {
          width: 304px;
        }
      }
    }
    </style>
    
    <template>
      <div class="product-base-info-form">
        <!-- {{ copyForm }} -- {{ form }} -- {{ disabled }} -->
        <!-- {{ showForm }} -->
        <a-form-model
          ref="productBaseInfoRef"
          :model="showForm"
          :rules="rules"
          labelAlign="left"
          :label-col="labelCol"
          :wrapper-col="wrapperCol"
          :colon="false"
        >
          <div v-if="frameId === STOCK_FRAME_TYPE.CONTAINER" :gutter="12">
            <div v-if="!disabled">
              <a-form-model-item
                prop="icon"
                :label-col="labelColItem"
                :wrapper-col="{ span: 4 }"
              >
                <a-select v-model="showForm.icon" placeholder="图标">
                  <a-select-option
                    :key="index"
                    :value="item"
                    v-for="(item, index) in productIcons"
                  >
                    <!-- <a-icon :type="item" style="font-size: 16px" /> -->
                    <svg-icon :icon-class="item" :style="{ fontSize: '16px' }" />
                  </a-select-option>
                </a-select>
              </a-form-model-item>
    
              <section class="column-item">
                <p class="lable">产品名称</p>
                <a-form-model-item
                  class="right"
                  prop="name"
                  :label-col="labelColItem"
                  :wrapper-col="{ span: 8 }"
                >
                  <a-input v-model="showForm.name" placeholder="名称"></a-input>
                </a-form-model-item>
              </section>
    
              <section class="column-item">
                <p class="lable">编码(Prefix)</p>
                <a-form-model-item
                  class="right"
                  prop="prefix"
                  :label-col="labelColItem"
                  :wrapper-col="{ span: 8 }"
                >
                  <a-input v-model="showForm.prefix" placeholder="prefix"></a-input>
                </a-form-model-item>
              </section>
            </div>
            <a-form-model-item label="容器单位" prop="unitId">
              <span v-if="disabled">
                {{ unitOptions.filter(item => item.id == showForm.unitId)[0].unitName }}
              </span>
              <a-select
                v-else
                @dropdownVisibleChange="dropdownVisibleChange"
                v-model="showForm.unitId"
                placeholder="请选择"
              >
                <a-select-option
                  :key="item.id"
                  :value="item.id"
                  v-for="item in unitOptions"
                >
                  {{ item.unitName }}
                </a-select-option>
                <template v-slot:notFoundContent v-if="spinning">
                  <a-spin :spinning="spinning"></a-spin>
                </template>
              </a-select>
            </a-form-model-item>
            <a-form-model-item label="上限容量" prop="capacity">
              <span v-if="disabled">{{ showForm.capacity }}</span>
              <a-input v-else v-model="showForm.capacity"></a-input>
            </a-form-model-item>
          </div>
          <!-- frameId !== STOCK_FRAME_TYPE.CONTAINER -->
          <!-- 可编辑状态 -->
          <div v-else>
            <div v-if="!disabled">
              <a-form-model-item
                prop="icon"
                :label-col="labelColItem"
                :wrapper-col="{ span: 6 }"
                label="图标"
              >
                <a-select v-model="showForm.icon" placeholder="图标">
                  <a-select-option
                    :key="index"
                    :value="item"
                    v-for="(item, index) in productIcons"
                  >
                    <!-- <a-icon :type="item" style="font-size: 16px" /> -->
                    <svg-icon :icon-class="item" :style="{ fontSize: '16px' }" />
                  </a-select-option>
                </a-select>
              </a-form-model-item>
              <a-form-model-item
                class="right"
                prop="name"
                :label-col="labelColItem"
                :wrapper-col="{ span: 8 }"
                label="产品名称"
              >
                <a-input v-model="showForm.name" placeholder="名称"></a-input>
              </a-form-model-item>
              <a-form-model-item
                class="right"
                prop="prefix"
                :label-col="labelColItem"
                :wrapper-col="{ span: 8 }"
                label="编码(Prefix)"
              >
                <a-input v-model="showForm.prefix" placeholder="prefix"></a-input>
              </a-form-model-item>
            </div>
          </div>
          <!-- <div class="custom-fields"> -->
          <a-form-model-item
            v-for="item in productValues"
            :label="item.paramName"
            :prop="item.id"
            :key="item.id"
            :label-col="labelColItem"
            :wrapper-col="wrapperColItem"
          >
    
            <!-- 不是容器的渲染在这里 -->
            <template v-if="item.paramType !== paramTypeColumn.container">
              <div
                v-if="
                  paramTypeColumn.text === item.paramType ||
                    paramTypeColumn.integer === item.paramType ||
                    paramTypeColumn.float === item.paramType
                "
              >
                <template v-if="disabled">
                  <span v-if="item.isMultipleValue === 2">{{
                    showForm[item.id][0]
                  }}</span>
                  <a-tag v-else :key="index" v-for="(ele, index) in showForm[item.id]">
                    {{ ele }}
                  </a-tag>
                </template>
                <template v-else>
                  <a-input
                    v-if="item.isMultipleValue === 2"
                    v-model="showForm[item.id][0]"
                  ></a-input>
                  <a-select
                    v-else
                    v-model="showForm[item.id]"
                    :dropdownStyle="{ display: 'none' }"
                    :dropdownMenuStyle="{ display: 'none' }"
                    mode="tags"
                  ></a-select>
                </template>
              </div>
              <div v-else-if="paramTypeColumn.textArea === item.paramType">
                <span v-if="disabled">{{ showForm[item.id][0] }}</span>
                <a-input
                  v-else
                  :auto-size="{ minRows: 3, maxRows: 5 }"
                  v-model="showForm[item.id][0]"
                  type="textarea"
                ></a-input>
              </div>
              <div v-else-if="paramTypeColumn.radioSelect === item.paramType">
                <span v-if="disabled">{{ showForm[item.id][0] }}</span>
                <a-select v-else v-model="showForm[item.id][0]">
                  <a-select-option
                    :key="element"
                    v-for="element in item.preDefinedValues"
                  >
                    {{ element }}
                  </a-select-option>
                </a-select>
              </div>
              <div v-else-if="paramTypeColumn.multiSelect === item.paramType">
                <div v-if="disabled">
                  <a-tag :key="index" v-for="(ele, index) in showForm[item.id]">
                    {{ ele }}
                  </a-tag>
                </div>
                <a-select v-else mode="multiple" v-model="showForm[item.id]">
                  <a-select-option
                    :key="element"
                    v-for="element in item.preDefinedValues"
                  >
                    {{ element }}
                  </a-select-option>
                </a-select>
              </div>
              <div v-else-if="paramTypeColumn.time === item.paramType">
                <span v-if="disabled">{{
                  item.paramValues[0] &&
                    moment(item.paramValues[0]).format('YYYY-MM-DD HH:mm:ss')
                }}</span>
                <a-date-picker
                  v-else
                  v-model="item.paramValues[0]"
                  :showTime="true"
                ></a-date-picker>
              </div>
              <div v-else-if="paramTypeColumn.link === item.paramType">
                <!-- <span>产品链接类型。。。</span> -->
                <!-- 展示产品链接 -->
                <div v-if="disabled">
                  <div class="link-item-box">
                    <li
                      class="link-type"
                      :key="ele.referenceId"
                      v-for="ele in item.paramValues"
                      @click="showProductLinkDetail(ele)"
                    >
                      <a-icon type="link" />{{ ele.referenceName }}
                    </li>
                  </div>
                </div>
                <div v-else>
                  <a-button @click="selectProduct(item.paramValues)" size="small"
                    ><a-icon type="fullscreen" />选择产品</a-button
                  >
                  <div class="link-item-box">
                    <li
                      class="link-type"
                      :key="ele.referenceId"
                      v-for="ele in item.paramValues"
                      @click="showProductLinkDetail(ele)"
                    >
                      <a-icon type="link" /> {{ ele.referenceName }}
                    </li>
                  </div>
                </div>
              </div>
              <div v-else-if="paramTypeColumn.cycle === item.paramType">
                <div v-if="disabled">
                  <span
                    v-if="item.paramValues[0].value && item.paramValues[0].cycleType"
                    >{{
                      `${item.paramValues[0].value} ${
                        CycleTypeInfo[item.paramValues[0].cycleType]
                      }`
                    }}</span
                  >
                </div>
                <!-- 周期 -->
                <CycleTypeCom
                  v-else
                  :info="item.paramValues[0]"
                  style="width: 260px"
                />
              </div>
            </template>
    
            <template v-else-if="
              (item.paramType === paramTypeColumn.container && isShowContainerType) ||
              (item.paramType === paramTypeColumn.container && frameId === STOCK_FRAME_TYPE.BOX) ||
              (item.paramType === paramTypeColumn.container && frameId === STOCK_FRAME_TYPE.PLATE)
            ">
              <!-- 选择的关联容器 -->
              <span v-if="disabled">
                {{ showForm[item.id][0].containerName }}
              </span>
              <a-select v-else :default-value="showForm[item.id][0].containerId" @change="(id) => handleChangeContainer(id, showForm[item.id])" show-search>
                <!-- 关联容器列表 -->
                <a-select-option
                  :key="element.id"
                  v-for="element in ContainerOptions"
                  :value="element.id"
                >
                  {{ element.name }}
                </a-select-option>
                <template v-slot:notFoundContent v-if="spinning">
                  <a-spin :spinning="spinning"></a-spin>
                </template>
              </a-select>
            </template>
    
          </a-form-model-item>
          <!-- </div> -->
        </a-form-model>
        <product-link-modal ref="productLinkModalRef"></product-link-modal>
        <product-base-info-modal
          ref="productBaseInfoModalRef"
        ></product-base-info-modal>
      </div>
    </template>
    
    <script>
    import moment from 'moment'
    import { queryStockSchemasDetail } from '@/api/material/locationSetting'
    import {
      handleMaterialValidateCodePlus,
      validateInteger,
      validateFloat,
      validateFloatNumber,
      validateArrRequired
    } from '@/common/inspectFunction'
    import {
      paramTypeColumn,
      productIcons,
      STOCK_FRAME_TYPE,
      VOLUME_TYPE_UNIT,
      CycleTypeInfo
    } from '@/common/global'
    
    import { getFullUnitInfo } from '@/api/system/unit'
    
    import ProductBaseInfoModal from './ProductBaseInfoModal'
    import ProductLinkModal from './ProductLinkModal'
    import CycleTypeCom from './fieldRuleSetting/CycleTypeCom'
    
    export default {
      props: {
        productValues: {
          type: Array,
          default() {
            return []
          }
        },
        productSelfInfo: {
          type: Object,
          default() {
            return {}
          }
        },
        icons: {
          type: Array,
          default() {
            return []
          }
        },
        frameId: {
          type: String,
          default() {
            return ''
          }
        }
      },
      components: {
        ProductBaseInfoModal,
        ProductLinkModal,
        CycleTypeCom
      },
      data() {
        return {
          CycleTypeInfo,
          productIcons: this.icons,
          labelCol: { span: 8 },
          wrapperCol: { span: 12 },
          labelColItem: { span: 8 },
          wrapperColItem: { span: 12 },
          paramTypeColumn: Object.freeze(paramTypeColumn),
          baseInfo: {
            prefix: '',
            name: '',
            icon: '',
            unitId: undefined,
            capacity: undefined,
            version: undefined
          },
          form: {
            prefix: '',
            name: '',
            icon: '',
            unitId: undefined,
            capacity: '',
            version: undefined
          },
          showForm: {},
          rules: {
            prefix: [
              { required: true, message: '请填写编号', trigger: 'blur' },
              {
                min: 1,
                max: 32,
                message: '编号长度在1-32个字符之间',
                trigger: 'change'
              },
              {
                validator: this.handleMaterialValidateCodePlus,
                message: '编号格式不正确',
                trigger: 'change'
              }
            ],
            unitId: [{ required: true, message: '请填写单位', trigger: 'blur' }],
            capacity: [
              {
                validator: this.validateFloatNumber,
                message: '容量格式不正确',
                trigger: 'change'
              }
            ],
            name: [
              { required: true, message: '必填', trigger: 'change' },
              {
                min: 1,
                max: 32,
                message: '名称长度在1-32个字符之间',
                trigger: 'change'
              }
            ]
          },
          disabled: true,
          // 后端需要的paramType
          paramTypeObj: {},
          STOCK_FRAME_TYPE: Object.freeze(STOCK_FRAME_TYPE),
          unitOptions: [],
          ContainerOptions: [],
          // tmpContainerId: '',
          spinning: true,
          // checkContainer: false,
          isShowContainerType: false,
        }
      },
      methods: {
        moment,
        dropdownVisibleChange(open) {
          // this.spinning = true
          open && _.isEmpty(this.unitOptions) && this.getFullUnitInfo()
        },
        /**
         * 获取数据库预选单位
         */
        async getFullUnitInfo() {
          this.spinning = true
          const res = await getFullUnitInfo({
            artifacts: [VOLUME_TYPE_UNIT],
            pageSize: -1
          }).finally(() => {
            this.spinning = false
          })
          if (res.code === '200') {
            this.unitOptions = res.data
          }
        },
        /**
         * 获取数据库容器
         */
        async getFullContainerInfo() {
          this.ContainerOptions = []
          this.spinning = true
          const res = await queryStockSchemasDetail({
            stockFrameId: '3',
            pageSize: -1
          }).finally(() => {
            this.spinning = false
          })
          if (res.code === '200') {
            this.ContainerOptions = res.data.result
            // return res.data.result
          }
        },
        /**
         * 自定义编码规则
         */
        handleMaterialValidateCodePlus,
        /**
         * 整数自定义验证
         */
        validateInteger,
        /**
         * 浮点数自定义验证
         */
        validateFloat,
        validateFloatNumber,
    
        validateArrRequired,
    
        /**
         * 验证表单数据规则是否匹配
         */
        validateFormData() {
          let flag = false
          this.$refs.productBaseInfoRef.validate(valid => {
            flag = valid
          })
          return flag
        },
        /**
         * 选择产品
         */
        selectProduct(paramValues) {
          this.$refs.productLinkModalRef.openSelectProductInfoModal(paramValues)
        },
        /**
         * 展示产品详情
         */
        showProductLinkDetail(item) {
          this.$refs.productBaseInfoModalRef.openProductInfoModal({
            id: item.referenceId
          })
        },
        /**
         * 传输产品基本信息和产品种类自定义字段
         */
        async getFullData(callback) {
          if (!this.validateFormData()) {
            return
            // callback(false)
          }
          const target = _.cloneDeep(this.showForm)
          let targetArr = []
          // {...this.baseInfo} = target
          Object.keys(this.baseInfo).forEach(key => {
            this.baseInfo[key] = target[key]
            delete target[key]
          })
          // console.log(target);
          Object.keys(target).forEach(key => {
            targetArr.push({
              id: key,
              paramValues: target[key],
              paramType: this.paramTypeObj[key]
            })
          })
          const _form = { ..._.cloneDeep(this.showForm), version: this.showForm.version + 1 }
          await callback({ ...this.baseInfo, productValues: targetArr })
          this.form = _form
          // this.changeNoShowStatus()
        },
        /**
         * 改变为可以编辑的状态
         */
        changeIsShowStatus() {
          this.disabled = false
        },
        /**
         * 改变为不可编辑的状态
         */
        changeNoShowStatus() {
          this.disabled = true
        },
        /**
         * 清除 form 表单 多余信息
         */
        resetFormInfo() {
          this.$refs.productBaseInfoRef &&
            this.$refs.productBaseInfoRef.resetFields &&
            this.$refs.productBaseInfoRef.resetFields()
          const baseInfoKeys = Object.keys(this.baseInfo)
          Object.keys(this.form)
            .filter(item => {
              return !baseInfoKeys.includes(item)
            })
            .forEach(key => {
              delete this.form[key]
            })
        },
    
        /**
         * 改变 container
         */
        handleChangeContainer(id, target) {
          const findContainer = this.ContainerOptions.find(v => v.id === id)
          const { id: containerId, name: containerName } = findContainer
          target[0] = { containerId, containerName }
        }
      },
      created() {
        this.frameId === STOCK_FRAME_TYPE.CONTAINER &&
          this.dropdownVisibleChange(true)
      },
      watch: {
        productValues: {
          handler(newProductValues) {
            // console.log(newProductValues);
            // this.tmpContainerId = ''
            this.resetFormInfo()
            this.getFullContainerInfo()
            newProductValues.forEach(element => {
              this.paramTypeObj[element.id] = element.paramType
              this.$set(this.form, element.id, element.paramValues || [])
              // 给预设容器默认值防止v-model取不到值
              if (element.paramType === this.paramTypeColumn.container) {
                if (!this.form[element.id][0]) {
                    this.$set(this.form, element.id, [{
                    containerId: null,
                    containerName: ''
                  }])
                }
              }
              // 控制位置容器数没有值预设容器不必填
              // if (element.fieldName === "位置容器数") {
              //   this.checkContainer = true
              // }
              // 必填项
              if (element.isRequired === 1) {
                const requiredInfo = [
                  { validator: this.validateArrRequired, trigger: 'change' },
                  { required: true, message: '必填', trigger: 'change' }
                ]
                !this.rules[element.id] &&
                  this.$set(this.rules, element.id, requiredInfo)
                if (
                  this.rules[element.id] &&
                  this.rules[element.id].findIndex(item => item.required) < 0
                ) {
                  this.rules[element.id].push(...requiredInfo)
                }
                // this.rules[element.id] = [{ required: true, message: '必填', trigger: 'change' }]
              }
              // 整数
              if (element.paramType === this.paramTypeColumn.integer) {
                !this.rules[element.id] &&
                  this.$set(this.rules, element.id, [
                    { validator: this.validateInteger }
                  ])
                this.rules[element.id] &&
                  this.rules[element.id].push({
                    validator: this.validateInteger
                  })
              }
              // 浮点数
              if (element.paramType === this.paramTypeColumn.float) {
                !this.rules[element.id] &&
                  this.$set(this.rules, element.id, [
                    { validator: this.validateFloat }
                  ])
                this.rules[element.id] &&
                  this.rules[element.id].push({
                    validator: this.validateFloat
                  })
              }
              // 覆盖预设容器的规则
              // if (this.checkContainer && element.paramType === this.paramTypeColumn.container) {
              //   this.rules[element.id] &&
              //     this.$set(this.rules, element.id, [])
              //   // this.rules[element.id] &&
              //   //   this.rules[element.id].push([])
              //   this.checkContainer = false
              // }
            })
          },
          immediate: true
        },
        productSelfInfo: {
          handler(newProductSelfInfo) {
            this.form.name = newProductSelfInfo.name
            this.form.prefix = newProductSelfInfo.prefix
            this.form.icon = newProductSelfInfo.icon
            this.form.unitId = newProductSelfInfo.unitId
            this.form.capacity = newProductSelfInfo.capacity
            this.form.version = newProductSelfInfo.version
          },
          immediate: true,
          deep: true
        },
        frameId: {
          handler(newFramaId) {
            newFramaId === STOCK_FRAME_TYPE.CONTAINER &&
              this.dropdownVisibleChange(true)
          },
          immediate: true
        },
        disabled: {
          handler(newDisabled) {
            this.showForm = this.disabled ? this.form : this.copyForm
            if (newDisabled) {
              this.showForm = this.form
              this.copyForm = _.cloneDeep(this.form)
            } else {
              this.showForm = _.cloneDeep(this.copyForm)
            }
          }
        },
        form: {
          handler() {
            this.copyForm = _.cloneDeep(this.form)
            this.showForm = _.cloneDeep(this.form)
            // Object.keys()
            const targetId = this.productValues.find(item => item.paramName === '位置容器数')?.id
    
            // console.log(targetId, this.form[targetId]?.length > 0 && this.form[targetId][0] !== '')
    
            if (this.showForm[targetId]?.length > 0  && this.showForm[targetId][0] !== '') {
              this.isShowContainerType = true
            } else {
              this.showForm[targetId]?.length > 0 && this.showForm[targetId][0] === '' && this.showForm[targetId].splice(0)
              this.isShowContainerType = false
            }
          },
          deep: true,
          immediate: true
        },
        isShowContainerType: {
          handler() {
            if(!this.isShowContainerType) {
              const containerId = this.productValues.find(item => item.paramName === '预设容器')?.id
              this.showForm[containerId] = []
            }
          }
        }
      }
    }
    </script>
    
    <style lang="scss" scoped>
    .product-base-info-form {
      .link-item-box {
        .link-type {
          margin: 0 2px;
          display: inline-block;
        }
      }
      & > .columns {
        display: flex;
        flex-flow: column;
        section.column-item {
          display: flex;
          flex-flow: row wrap;
          justify-content: space-between;
          align-items: center;
          p.lable {
            flex-grow: 1;
            color: #8c8c8c;
            font-size: 14px;
            user-select: none;
          }
          .right {
            width: 304px;
          }
        }
      }
    }
    .custom-fields,
    .columns {
      margin-right: 25px;
      ::v-deep div.ant-row.ant-form-item {
        display: flex !important;
        flex-flow: row wrap;
        justify-content: space-between;
        align-items: center;
      }
      ::v-deep div.ant-col.ant-col-8.ant-form-item-label.ant-form-item-label-left {
        background-color: red;
        flex-grow: 1;
        color: #8c8c8c;
        font-size: 14px;
        user-select: none;
      }
      ::v-deep .ant-col.ant-col-12.ant-form-item-control-wrapper {
        width: 304px;
        input.ant-input {
          width: 304px;
        }
      }
    }
    </style>
    

    最终版:
    在disable为真或假的时候展示两套状态,用的是showForm展示,在disable为真时,showForm是form,为假时,showForm为深克隆copyForm。

    <template>
      <div class="product-base-info-form">
        <!-- {{ copyForm }} -- {{ form }} -- {{ disabled }} -->
        <!-- {{ showForm }} -->
        <a-form-model
          ref="productBaseInfoRef"
          :model="showForm"
          :rules="rules"
          labelAlign="left"
          :label-col="labelCol"
          :wrapper-col="wrapperCol"
          :colon="false"
        >
          <a-row>
            <a-col>
              <div v-if="frameId === STOCK_FRAME_TYPE.CONTAINER" :gutter="12">
                <div v-if="!disabled">
                  <a-form-model-item
                    prop="icon"
                    :label-col="labelColItem"
                    :wrapper-col="{ span: 4 }"
                  >
                    <a-select v-model="showForm.icon" placeholder="图标">
                      <a-select-option
                        :key="index"
                        :value="item"
                        v-for="(item, index) in productIcons"
                      >
                        <!-- <a-icon :type="item" style="font-size: 16px" /> -->
                        <svg-icon :icon-class="item" :style="{ fontSize: '16px' }" />
                      </a-select-option>
                    </a-select>
                  </a-form-model-item>
    
                  <section class="column-item">
                    <p class="lable">产品名称</p>
                    <a-form-model-item
                      class="right"
                      prop="name"
                      :label-col="labelColItem"
                      :wrapper-col="{ span: 8 }"
                    >
                      <a-input v-model="showForm.name" placeholder="名称"></a-input>
                    </a-form-model-item>
                  </section>
    
                  <section class="column-item">
                    <p class="lable">编码(Prefix)</p>
                    <a-form-model-item
                      class="right"
                      prop="prefix"
                      :label-col="labelColItem"
                      :wrapper-col="{ span: 8 }"
                    >
                      <a-input v-model="showForm.prefix" placeholder="prefix"></a-input>
                    </a-form-model-item>
                  </section>
                </div>
                <a-form-model-item label="容器单位" prop="unitId">
                  <span v-if="disabled">
                    {{ unitOptions.filter(item => item.id == showForm.unitId)[0].unitName }}
                  </span>
                  <a-select
                    v-else
                    @dropdownVisibleChange="dropdownVisibleChange"
                    v-model="showForm.unitId"
                    placeholder="请选择"
                  >
                    <a-select-option
                      :key="item.id"
                      :value="item.id"
                      v-for="item in unitOptions"
                    >
                      {{ item.unitName }}
                    </a-select-option>
                    <template v-slot:notFoundContent v-if="spinning">
                      <a-spin :spinning="spinning"></a-spin>
                    </template>
                  </a-select>
                </a-form-model-item>
                <a-form-model-item label="上限容量" prop="capacity">
                  <span v-if="disabled">{{ showForm.capacity }}</span>
                  <a-input v-else v-model="showForm.capacity"></a-input>
                </a-form-model-item>
              </div>
              <!-- frameId !== STOCK_FRAME_TYPE.CONTAINER -->
              <!-- 可编辑状态 -->
              <div v-else>
                <div v-if="!disabled">
                  <a-form-model-item
                    prop="icon"
                    :label-col="labelColItem"
                    :wrapper-col="{ span: 6 }"
                    label="图标"
                  >
                    <a-select v-model="showForm.icon" placeholder="图标">
                      <a-select-option
                        :key="index"
                        :value="item"
                        v-for="(item, index) in productIcons"
                      >
                        <!-- <a-icon :type="item" style="font-size: 16px" /> -->
                        <svg-icon :icon-class="item" :style="{ fontSize: '16px' }" />
                      </a-select-option>
                    </a-select>
                  </a-form-model-item>
                  <a-form-model-item
                    class="right"
                    prop="name"
                    :label-col="labelColItem"
                    :wrapper-col="{ span: 8 }"
                    label="产品名称"
                  >
                    <a-input v-model="showForm.name" placeholder="名称"></a-input>
                  </a-form-model-item>
                  <a-form-model-item
                    class="right"
                    prop="prefix"
                    :label-col="labelColItem"
                    :wrapper-col="{ span: 8 }"
                    label="编码(Prefix)"
                  >
                    <a-input v-model="showForm.prefix" placeholder="prefix"></a-input>
                  </a-form-model-item>
                </div>
              </div>
            </a-col>
            <a-col
              v-for="item in productValues"
              :key="item.id"
              :label-col="labelColItem"
              :wrapper-col="wrapperColItem">
              <!-- 不是容器的渲染在这里 -->
              <template v-if="item.paramType !== paramTypeColumn.container">
                <a-form-model-item
                :label="item.paramName" :prop="item.id"
                >
                  <div
                    v-if="
                      paramTypeColumn.text === item.paramType ||
                        paramTypeColumn.integer === item.paramType ||
                        paramTypeColumn.float === item.paramType
                    "
                  >
                    <template v-if="disabled">
                      <span v-if="item.isMultipleValue === 2">{{
                        showForm[item.id][0]
                      }}</span>
                      <a-tag v-else :key="index" v-for="(ele, index) in showForm[item.id]">
                        {{ ele }}
                      </a-tag>
                    </template>
                    <template v-else>
                      <a-input
                        v-if="item.isMultipleValue === 2"
                        v-model="showForm[item.id][0]"
                      ></a-input>
                      <a-select
                        v-else
                        v-model="showForm[item.id]"
                        :dropdownStyle="{ display: 'none' }"
                        :dropdownMenuStyle="{ display: 'none' }"
                        mode="tags"
                      ></a-select>
                    </template>
                  </div>
                  <div v-else-if="paramTypeColumn.textArea === item.paramType">
                    <span v-if="disabled">{{ showForm[item.id][0] }}</span>
                    <a-input
                      v-else
                      :auto-size="{ minRows: 3, maxRows: 5 }"
                      v-model="showForm[item.id][0]"
                      type="textarea"
                    ></a-input>
                  </div>
                  <div v-else-if="paramTypeColumn.radioSelect === item.paramType">
                    <span v-if="disabled">{{ showForm[item.id][0] }}</span>
                    <a-select v-else v-model="showForm[item.id][0]">
                      <a-select-option
                        :key="element"
                        v-for="element in item.preDefinedValues"
                      >
                        {{ element }}
                      </a-select-option>
                    </a-select>
                  </div>
                  <div v-else-if="paramTypeColumn.multiSelect === item.paramType">
                    <div v-if="disabled">
                      <a-tag :key="index" v-for="(ele, index) in showForm[item.id]">
                        {{ ele }}
                      </a-tag>
                    </div>
                    <a-select v-else mode="multiple" v-model="showForm[item.id]">
                      <a-select-option
                        :key="element"
                        v-for="element in item.preDefinedValues"
                      >
                        {{ element }}
                      </a-select-option>
                    </a-select>
                  </div>
                  <div v-else-if="paramTypeColumn.time === item.paramType">
                    <span v-if="disabled">{{
                      item.paramValues[0] &&
                        moment(item.paramValues[0]).format('YYYY-MM-DD HH:mm:ss')
                    }}</span>
                    <a-date-picker
                      v-else
                      v-model="item.paramValues[0]"
                      :showTime="true"
                    ></a-date-picker>
                  </div>
                  <div v-else-if="paramTypeColumn.link === item.paramType">
                    <!-- <span>产品链接类型。。。</span> -->
                    <!-- 展示产品链接 -->
                    <div v-if="disabled">
                      <div class="link-item-box">
                        <li
                          class="link-type"
                          :key="ele.referenceId"
                          v-for="ele in item.paramValues"
                          @click="showProductLinkDetail(ele)"
                        >
                          <a-icon type="link" />{{ ele.referenceName }}
                        </li>
                      </div>
                    </div>
                    <div v-else>
                      <a-button @click="selectProduct(item.paramValues)" size="small"
                        ><a-icon type="fullscreen" />选择产品</a-button
                      >
                      <div class="link-item-box">
                        <li
                          class="link-type"
                          :key="ele.referenceId"
                          v-for="ele in item.paramValues"
                          @click="showProductLinkDetail(ele)"
                        >
                          <a-icon type="link" /> {{ ele.referenceName }}
                        </li>
                      </div>
                    </div>
                  </div>
                  <div v-else-if="paramTypeColumn.cycle === item.paramType">
                    <div v-if="disabled">
                      <span
                        v-if="item.paramValues[0].value && item.paramValues[0].cycleType"
                        >{{
                          `${item.paramValues[0].value} ${
                            CycleTypeInfo[item.paramValues[0].cycleType]
                          }`
                        }}</span
                      >
                    </div>
                    <!-- 周期 -->
                    <CycleTypeCom
                      v-else
                      :info="item.paramValues[0]"
                      style="width: 260px"
                    />
                  </div>
                </a-form-model-item>
              </template>
              <template v-if="
                  (item.paramType === paramTypeColumn.container && isShowContainerType) ||
                  (item.paramType === paramTypeColumn.container && frameId === STOCK_FRAME_TYPE.BOX) ||
                  (item.paramType === paramTypeColumn.container && frameId === STOCK_FRAME_TYPE.PLATE)
                ">
                <a-form-model-item
                  :label="item.paramName" :prop="item.id"
                >
    
                  <!-- 选择的关联容器 -->
                  <span v-if="disabled">
                    {{ showForm[item.id][0].containerName }}
                  </span>
                  <a-select v-else :default-value="showForm[item.id][0].containerId" @change="(id) => handleChangeContainer(id, showForm[item.id])" show-search>
                    <!-- 关联容器列表 -->
                    <a-select-option
                      :key="element.id"
                      v-for="element in ContainerOptions"
                      :value="element.id"
                    >
                      {{ element.name }}
                    </a-select-option>
                    <template v-slot:notFoundContent v-if="spinning">
                      <a-spin :spinning="spinning"></a-spin>
                    </template>
                  </a-select>
                </a-form-model-item>
              </template>
            </a-col>
          </a-row>
          <!-- </div> -->
        </a-form-model>
        <product-link-modal ref="productLinkModalRef"></product-link-modal>
        <product-base-info-modal
          ref="productBaseInfoModalRef"
        ></product-base-info-modal>
      </div>
    </template>
    
    <script>
    import moment from 'moment'
    import { queryStockSchemasDetail } from '@/api/material/locationSetting'
    import {
      handleMaterialValidateCodePlus,
      validateInteger,
      validateFloat,
      validateFloatNumber,
      validateArrRequired
    } from '@/common/inspectFunction'
    import {
      paramTypeColumn,
      productIcons,
      STOCK_FRAME_TYPE,
      VOLUME_TYPE_UNIT,
      CycleTypeInfo
    } from '@/common/global'
    
    import { getFullUnitInfo } from '@/api/system/unit'
    
    import ProductBaseInfoModal from './ProductBaseInfoModal'
    import ProductLinkModal from './ProductLinkModal'
    import CycleTypeCom from './fieldRuleSetting/CycleTypeCom'
    
    export default {
      props: {
        productValues: {
          type: Array,
          default() {
            return []
          }
        },
        productSelfInfo: {
          type: Object,
          default() {
            return {}
          }
        },
        icons: {
          type: Array,
          default() {
            return []
          }
        },
        frameId: {
          type: String,
          default() {
            return ''
          }
        }
      },
      components: {
        ProductBaseInfoModal,
        ProductLinkModal,
        CycleTypeCom
      },
      data() {
        return {
          CycleTypeInfo,
          productIcons: this.icons,
          labelCol: { span: 8 },
          wrapperCol: { span: 12 },
          labelColItem: { span: 8 },
          wrapperColItem: { span: 12 },
          paramTypeColumn: Object.freeze(paramTypeColumn),
          baseInfo: {
            prefix: '',
            name: '',
            icon: '',
            unitId: undefined,
            capacity: undefined,
            version: undefined
          },
          form: {
            prefix: '',
            name: '',
            icon: '',
            unitId: undefined,
            capacity: '',
            version: undefined
          },
          showForm: {},
          rules: {
            prefix: [
              { required: true, message: '请填写编号', trigger: 'blur' },
              {
                min: 1,
                max: 32,
                message: '编号长度在1-32个字符之间',
                trigger: 'change'
              },
              {
                validator: this.handleMaterialValidateCodePlus,
                message: '编号格式不正确',
                trigger: 'change'
              }
            ],
            unitId: [{ required: true, message: '请填写单位', trigger: 'blur' }],
            capacity: [
              {
                validator: this.validateFloatNumber,
                message: '容量格式不正确',
                trigger: 'change'
              }
            ],
            name: [
              { required: true, message: '必填', trigger: 'change' },
              {
                min: 1,
                max: 32,
                message: '名称长度在1-32个字符之间',
                trigger: 'change'
              }
            ]
          },
          disabled: true,
          // 后端需要的paramType
          paramTypeObj: {},
          STOCK_FRAME_TYPE: Object.freeze(STOCK_FRAME_TYPE),
          unitOptions: [],
          ContainerOptions: [],
          // tmpContainerId: '',
          spinning: true,
          // checkContainer: false,
          isShowContainerType: false,
        }
      },
      methods: {
        moment,
        dropdownVisibleChange(open) {
          // this.spinning = true
          open && _.isEmpty(this.unitOptions) && this.getFullUnitInfo()
        },
        /**
         * 获取数据库预选单位
         */
        async getFullUnitInfo() {
          this.spinning = true
          const res = await getFullUnitInfo({
            artifacts: [VOLUME_TYPE_UNIT],
            pageSize: -1
          }).finally(() => {
            this.spinning = false
          })
          if (res.code === '200') {
            this.unitOptions = res.data
          }
        },
        /**
         * 获取数据库容器
         */
        async getFullContainerInfo() {
          this.ContainerOptions = []
          this.spinning = true
          const res = await queryStockSchemasDetail({
            stockFrameId: '3',
            pageSize: -1
          }).finally(() => {
            this.spinning = false
          })
          if (res.code === '200') {
            this.ContainerOptions = res.data.result
            // return res.data.result
          }
        },
        /**
         * 自定义编码规则
         */
        handleMaterialValidateCodePlus,
        /**
         * 整数自定义验证
         */
        validateInteger,
        /**
         * 浮点数自定义验证
         */
        validateFloat,
        validateFloatNumber,
    
        validateArrRequired,
    
        /**
         * 验证表单数据规则是否匹配
         */
        validateFormData() {
          let flag = false
          this.$refs.productBaseInfoRef.validate(valid => {
            flag = valid
          })
          return flag
        },
        /**
         * 选择产品
         */
        selectProduct(paramValues) {
          this.$refs.productLinkModalRef.openSelectProductInfoModal(paramValues)
        },
        /**
         * 展示产品详情
         */
        showProductLinkDetail(item) {
          this.$refs.productBaseInfoModalRef.openProductInfoModal({
            id: item.referenceId
          })
        },
        /**
         * 传输产品基本信息和产品种类自定义字段
         */
        async getFullData(callback) {
          if (!this.validateFormData()) {
            return
            // callback(false)
          }
          const target = _.cloneDeep(this.showForm)
          let targetArr = []
          // {...this.baseInfo} = target
          Object.keys(this.baseInfo).forEach(key => {
            this.baseInfo[key] = target[key]
            delete target[key]
          })
          // console.log(target);
          Object.keys(target).forEach(key => {
            targetArr.push({
              id: key,
              paramValues: target[key],
              paramType: this.paramTypeObj[key]
            })
          })
          const _form = { ..._.cloneDeep(this.showForm), version: this.showForm.version + 1 }
          await callback({ ...this.baseInfo, productValues: targetArr })
          this.form = _form
          // this.changeNoShowStatus()
        },
        /**
         * 改变为可以编辑的状态
         */
        changeIsShowStatus() {
          this.disabled = false
        },
        /**
         * 改变为不可编辑的状态
         */
        changeNoShowStatus() {
          this.disabled = true
        },
        /**
         * 清除 form 表单 多余信息
         */
        resetFormInfo() {
          this.$refs.productBaseInfoRef &&
            this.$refs.productBaseInfoRef.resetFields &&
            this.$refs.productBaseInfoRef.resetFields()
          const baseInfoKeys = Object.keys(this.baseInfo)
          Object.keys(this.form)
            .filter(item => {
              return !baseInfoKeys.includes(item)
            })
            .forEach(key => {
              delete this.form[key]
            })
        },
    
        /**
         * 改变 container
         */
        handleChangeContainer(id, target) {
          const findContainer = this.ContainerOptions.find(v => v.id === id)
          const { id: containerId, name: containerName } = findContainer
          target[0] = { containerId, containerName }
        }
      },
      created() {
        this.frameId === STOCK_FRAME_TYPE.CONTAINER &&
          this.dropdownVisibleChange(true)
      },
      watch: {
        productValues: {
          handler(newProductValues) {
            // console.log(newProductValues);
            // this.tmpContainerId = ''
            this.resetFormInfo()
            this.getFullContainerInfo()
            newProductValues.forEach(element => {
              this.paramTypeObj[element.id] = element.paramType
              this.$set(this.form, element.id, element.paramValues || [])
              // 给预设容器默认值防止v-model取不到值
              if (element.paramType === this.paramTypeColumn.container) {
                if (!this.form[element.id][0]) {
                    this.$set(this.form, element.id, [{
                    containerId: null,
                    containerName: ''
                  }])
                }
              }
              // 控制位置容器数没有值预设容器不必填
              // if (element.fieldName === "位置容器数") {
              //   this.checkContainer = true
              // }
              // 必填项
              if (element.isRequired === 1) {
                const requiredInfo = [
                  { validator: this.validateArrRequired, trigger: 'change' },
                  { required: true, message: '必填', trigger: 'change' }
                ]
                !this.rules[element.id] &&
                  this.$set(this.rules, element.id, requiredInfo)
                if (
                  this.rules[element.id] &&
                  this.rules[element.id].findIndex(item => item.required) < 0
                ) {
                  this.rules[element.id].push(...requiredInfo)
                }
                // this.rules[element.id] = [{ required: true, message: '必填', trigger: 'change' }]
              }
              // 整数
              if (element.paramType === this.paramTypeColumn.integer) {
                !this.rules[element.id] &&
                  this.$set(this.rules, element.id, [
                    { validator: this.validateInteger }
                  ])
                this.rules[element.id] &&
                  this.rules[element.id].push({
                    validator: this.validateInteger
                  })
              }
              // 浮点数
              if (element.paramType === this.paramTypeColumn.float) {
                !this.rules[element.id] &&
                  this.$set(this.rules, element.id, [
                    { validator: this.validateFloat }
                  ])
                this.rules[element.id] &&
                  this.rules[element.id].push({
                    validator: this.validateFloat
                  })
              }
              // 覆盖预设容器的规则
              // if (this.checkContainer && element.paramType === this.paramTypeColumn.container) {
              //   this.rules[element.id] &&
              //     this.$set(this.rules, element.id, [])
              //   // this.rules[element.id] &&
              //   //   this.rules[element.id].push([])
              //   this.checkContainer = false
              // }
            })
          },
          immediate: true
        },
        productSelfInfo: {
          handler(newProductSelfInfo) {
            this.form.name = newProductSelfInfo.name
            this.form.prefix = newProductSelfInfo.prefix
            this.form.icon = newProductSelfInfo.icon
            this.form.unitId = newProductSelfInfo.unitId
            this.form.capacity = newProductSelfInfo.capacity
            this.form.version = newProductSelfInfo.version
          },
          immediate: true,
          deep: true
        },
        frameId: {
          handler(newFramaId) {
            newFramaId === STOCK_FRAME_TYPE.CONTAINER &&
              this.dropdownVisibleChange(true)
          },
          immediate: true
        },
        disabled: {
          handler(newDisabled) {
            this.showForm = this.disabled ? this.form : this.copyForm
            if (newDisabled) {
              this.showForm = this.form
              this.copyForm = _.cloneDeep(this.form)
            } else {
              this.showForm = _.cloneDeep(this.copyForm)
            }
          }
        },
        form: {
          handler() {
            this.copyForm = _.cloneDeep(this.form)
            this.showForm = _.cloneDeep(this.form)
          },
          deep: true,
          immediate: true
        },
        showForm: {
          handler() {
            // Object.keys()
            const targetId = this.productValues.find(item => item.paramName === '位置容器数')?.id
            // console.log(targetId, this.form[targetId]?.length > 0 && this.form[targetId][0] !== '')
            if (this.showForm[targetId]?.length > 0  && this.showForm[targetId][0] !== '') {
              console.log('true');
              this.isShowContainerType = true
            } else {
              this.showForm[targetId]?.length > 0 && this.showForm[targetId][0] === '' && this.showForm[targetId].splice(0)
              console.log('false');
              this.isShowContainerType = false
            }
            console.log(1);
          },
          deep: true
        },
        isShowContainerType: {
          handler() {
            if(!this.isShowContainerType) {
              const containerId = this.productValues.find(item => item.paramType === 140)?.id
              console.log(this.showForm);
              this.showForm[containerId].length = 0
            }
          },
          deep: true,
          immediate: true
        }
      }
    }
    </script>
    
    <style lang="scss" scoped>
    .product-base-info-form {
      .link-item-box {
        .link-type {
          margin: 0 2px;
          display: inline-block;
        }
      }
      & > .columns {
        display: flex;
        flex-flow: column;
        section.column-item {
          display: flex;
          flex-flow: row wrap;
          justify-content: space-between;
          align-items: center;
          p.lable {
            flex-grow: 1;
            color: #8c8c8c;
            font-size: 14px;
            user-select: none;
          }
          .right {
            width: 304px;
          }
        }
      }
    }
    .custom-fields,
    .columns {
      margin-right: 25px;
      ::v-deep div.ant-row.ant-form-item {
        display: flex !important;
        flex-flow: row wrap;
        justify-content: space-between;
        align-items: center;
      }
      ::v-deep div.ant-col.ant-col-8.ant-form-item-label.ant-form-item-label-left {
        background-color: red;
        flex-grow: 1;
        color: #8c8c8c;
        font-size: 14px;
        user-select: none;
      }
      ::v-deep .ant-col.ant-col-12.ant-form-item-control-wrapper {
        width: 304px;
        input.ant-input {
          width: 304px;
        }
      }
    }
    </style>
    

    通过改变预设容器在template的位置,用v-if控制它显示还是隐藏,用一个变量控制,这个变量通过监视属性监听,在动态字段的位置容器数有值的情况下才展示。

    <template>
      <a-modal
        v-if="visible"
        :title="title"
        :visible="visible"
        @ok="handleOk"
        @cancel="handleCancel"
        :width="800"
        :height="900"
        :destoryOnClose="true"
        :bodyStyle="{ padding: '0px 10px', minHeight: '500px' }"
      >
        <a-tabs default-active-key="1">
          <a-tab-pane key="1" tab="基本信息" style="padding-left: 10px">
            <a-row>
              <a-form-model
                ref="createBatchInfoRef"
                :model="form"
                :labelCol="{ span: 10 }"
                :wrapperCol="{ span: 14 }"
                :rules="rules"
              >
                <a-row :gutter="16">
                  <a-col :span="12">
                    <a-form-model-item label="种类" prop="frameName">
                      <a-input disabled v-model="form.frameName"></a-input>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="12">
                    <a-form-model-item label="图标" prop="icon">
                      <a-select v-model="form.icon">
                        <a-select-option
                          :value="item"
                          :key="index"
                          v-for="(item, index) in schemaIcons"
                        >
                          <!-- <a-icon :type="item" style="font-size: 16px" /> -->
                          <svg-icon
                            :icon-class="item"
                            :style="{ fontSize: '16px' }"
                          />
                        </a-select-option>
                      </a-select>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="12">
                    <a-form-model-item label="编码" prop="prefix">
                      <a-input v-model="form.prefix"></a-input>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="12">
                    <a-form-model-item label="元件名称" prop="name">
                      <a-input v-model="form.name"></a-input>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="12" v-if="CONTAINER_TYPE === stockFrameInfo.id">
                    <a-form-model-item label="单位" prop="unitId">
                      <a-select
                        @dropdownVisibleChange="dropdownVisibleChange"
                        v-model="form.unitId"
                        placeholder="请选择"
                      >
                        <a-select-option
                          :key="item.id"
                          :value="item.id"
                          v-for="item in unitOptions"
                        >
                          {{ item.unitName }}
                        </a-select-option>
                        <template v-slot:notFoundContent v-if="spinning">
                          <a-spin :spinning="spinning"></a-spin>
                        </template>
                      </a-select>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="12" v-if="CONTAINER_TYPE === stockFrameInfo.id">
                    <a-form-model-item label="容量" prop="capacity">
                      <a-input v-model="form.capacity"></a-input>
                    </a-form-model-item>
                  </a-col>
                  <a-col
                    :key="item.id"
                    :span="12"
                    v-for="item in stockFrameAttribute"
                  >
                    <template v-if="item.paramType !== paramTypeColumn.container">
                      <a-form-model-item :label="item.paramName" :prop="item.id">
                        <template
                          v-if="
                            paramTypeColumn.text === item.paramType ||
                              paramTypeColumn.integer === item.paramType ||
                              paramTypeColumn.float === item.paramType
                          "
                        >
                          <a-input
                            v-if="item.isMultipleValue === 2"
                            v-model="form[item.id][0]"
                          ></a-input>
                          <a-select
                            v-else
                            v-model="form[item.id]"
                            :dropdownStyle="{ display: 'none' }"
                            :dropdownMenuStyle="{ display: 'none' }"
                            mode="tags"
                          ></a-select>
                        </template>
                        <template
                          v-else-if="paramTypeColumn.textArea === item.paramType"
                        >
                          <a-input
                            :auto-size="{ minRows: 3, maxRows: 5 }"
                            class="default-input"
                            v-model="form[item.id][0]"
                            type="textarea"
                          ></a-input>
                        </template>
                        <template
                          v-else-if="paramTypeColumn.radioSelect === item.paramType"
                        >
                          <a-select v-model="form[item.id][0]">
                            <a-select-option
                              :key="element"
                              v-for="element in item.preDefinedValues"
                            >
                              {{ element }}
                            </a-select-option>
                          </a-select>
                        </template>
                        <template
                          v-else-if="paramTypeColumn.multiSelect === item.paramType"
                        >
                          <a-select mode="multiple" v-model="form[item.id]">
                            <a-select-option
                              :key="element"
                              v-for="element in item.preDefinedValues"
                            >
                              {{ element }}
                            </a-select-option>
                          </a-select>
                        </template>
                        <template v-else-if="paramTypeColumn.time === item.paramType">
                          <a-date-picker
                            v-model="item.paramValues[0]"
                            :showTime="true"
                          ></a-date-picker>
                        </template>
                        <template v-else-if="paramTypeColumn.link === item.paramType">
                          <span
                            class="link-type"
                            :key="ele.referenceId"
                            v-for="ele in item.paramValues"
                            @click="showProductLinkDetail(ele)"
                            ><a-icon type="link" /> {{ ele.referenceName }}</span
                          >
                        </template>
                        <!-- <template
                          v-else-if="paramTypeColumn.container === item.paramType && isShowContainerType"
                        >
                          <a-select
                            allowClear
                            @dropdownVisibleChange="dropdownVisibleChange2"
                            @change="
                              id => {
                                handleChangeContainer(id, form[item.id])
                              }
                            "
                          >
                            <a-select-option
                              :key="element.id"
                              v-for="element in ContainerOptions"
                              :value="element.id"
                            >
                              {{ element.name }}
                            </a-select-option>
                            <template v-slot:notFoundContent v-if="spinning">
                              <a-spin :spinning="spinning"></a-spin>
                            </template>
                          </a-select>
                        </template> -->
                      </a-form-model-item>
                    </template>
                    <template v-else-if="
                    (item.paramType === paramTypeColumn.container && isShowContainerType) ||
                    (item.paramType === paramTypeColumn.container && stockFrameInfo.name === '盒') ||
                    (item.paramType === paramTypeColumn.container && stockFrameInfo.name === '板')
                    ">
                      <a-form-model-item :label="item.paramName" :prop="item.id">
                        <a-select
                          show-search
                          @dropdownVisibleChange="dropdownVisibleChange2"
                          @change="
                            id => {
                              handleChangeContainer(id, form[item.id])
                            }
                          "
                        >
                          <a-select-option
                            :key="element.id"
                            v-for="element in ContainerOptions"
                            :value="element.id"
                          >
                            {{ element.name }}
                          </a-select-option>
                          <template v-slot:notFoundContent v-if="spinning">
                            <a-spin :spinning="spinning"></a-spin>
                          </template>
                        </a-select>
                      </a-form-model-item>
                    </template>
                  </a-col>
                </a-row>
              </a-form-model>
            </a-row>
            <span>元件字段:</span>
            <custom-fields
              @getData="getCustomFieldsData"
              ref="customFieldsRef"
            ></custom-fields>
            <span>库位字段:</span>
            <storage-fields
              ref="storageFieldsRef"
              @getData="getStorageLocationFieldsData"
              :showMode="showMode.productKey"
            >
            </storage-fields>
          </a-tab-pane>
          <a-tab-pane
            key="2"
            tab="规则设置"
            style="padding-left: 10px"
          ></a-tab-pane>
        </a-tabs>
      </a-modal>
    </template>
    
    <script>
    import {
      queryStockFrameFields,
      saveStockSchema,
      queryStockSchemasDetail
    } from '@/api/material/locationSetting'
    import { getFullUnitInfo } from '@/api/system/unit'
    import {
      handleValidateCodePlus,
      validateInteger,
      validateFloat,
      validateFloatNumber,
      validateArrRequired
    } from '@/common/inspectFunction'
    import { paramTypeColumn, schemaIcons, VOLUME_TYPE_UNIT } from '@/common/global'
    import CustomFields from '@/views/materialcenter/productManagement/components/ProductCustomFields'
    import { CUSTOM_FIELD_SHOW_MODE } from '@/views/materialcenter/productManagement/components/comm/constValues'
    
    const CONTAINER_TYPE = '3'
    export default {
      components: {
        CustomFields,
        StorageFields: CustomFields
      },
      props: {
        leftSuccess: Function,
        schemaRightSuccess: Function
      },
      data() {
        return {
          schemaIcons: Object.freeze(schemaIcons),
          source: '',
          stockFrameInfo: {},
          visible: false,
          title: '新建元件',
          paramTypeColumn: Object.freeze(paramTypeColumn),
          baseInfo: {
            frameName: '',
            icon: '',
            prefix: '',
            name: '',
            unitId: undefined,
            capacity: undefined
          },
          form: {
            frameName: '',
            icon: '',
            prefix: '',
            name: '',
            unitId: undefined,
            capacity: undefined
          },
          rules: {
            prefix: [
              {
                min: 1,
                max: 64,
                required: true,
                message: '编码的长度在1~64位之间',
                trigger: 'change'
              },
              {
                validator: this.handleValidateCodePlus,
                message: '编号格式不正确',
                trigger: 'change'
              }
            ],
            name: [
              {
                min: 1,
                max: 32,
                required: true,
                message: '元件名称的长度在1~32位之间',
                trigger: 'change'
              }
            ],
            capacity: [
              {
                validator: this.validateFloatNumber
              },
              {
                required: true,
                message: '容量为必填',
                trigger: 'blur'
              }
            ],
            unitId: [
              {
                required: true,
                message: '请填写单位',
                trigger: 'blur'
              }
            ]
          },
          stockFrameAttribute: [],
          // 后端需要的paramType
          paramTypeObj: {},
          showMode: Object.freeze(CUSTOM_FIELD_SHOW_MODE),
          customFieldsData: [],
          storageFieldData: [],
          unitOptions: [], // 单位选项
          CONTAINER_TYPE,
          spinning: true,
          ContainerOptions: [], //容器选项
          tempContainer: '',
          checkContainer: false,
          isShowContainerType: false,
        }
      },
    
      methods: {
        dropdownVisibleChange(open) {
          // this.spinning = true
          open && _.isEmpty(this.unitOptions) && this.getFullUnitInfo()
        },
    
        /**
         * 获取数据库预选单位
         */
        async getFullUnitInfo() {
          this.spinning = true
          const res = await getFullUnitInfo({
            artifacts: [VOLUME_TYPE_UNIT],
            pageSize: -1
          }).finally(() => {
            this.spinning = false
          })
          if (res.code === '200') {
            this.unitOptions = res.data
          }
        },
        dropdownVisibleChange2(open) {
          open && _.isEmpty(this.ContainerOptions) && this.getFullContainerInfo()
        },
        /**
         * 获取数据库容器
         */
        async getFullContainerInfo() {
          this.spinning = true
          const res = await queryStockSchemasDetail({
            stockFrameId: '3',
            pageSize: -1
          }).finally(() => {
            this.spinning = false
          })
          if (res.code === '200') {
            this.ContainerOptions = res.data.result
          }
        },
        /**
         * 自定义编码规则
         */
        handleValidateCodePlus,
        /**
         * 整数自定义验证
         */
        validateInteger,
        /**
         * 浮点数自定义验证
         */
        validateFloat,
        validateFloatNumber,
    
        /**
         * 后端给的值是数组
         * 自定义必填
         */
        validateArrRequired,
        /**
         * 动态表单校验
         */
        dynamicValidate(element) {
          // 必填项
          // console.log(element);
          // 位置容器数没有值预设容器不必填
          // if (element.fieldName === "位置容器数") {
          //   this.checkContainer = true
          // }
          if (element.isRequired === 1) {
            const requiredInfo = [
              { validator: this.validateArrRequired, trigger: 'change' },
              { required: true, message: '必填', trigger: 'change' }
            ]
            !this.rules[element.id] &&
              this.$set(this.rules, element.id, requiredInfo)
            if (
              this.rules[element.id] &&
              this.rules[element.id].findIndex(item => item.required) < 0
            ) {
              this.rules[element.id].push(...requiredInfo)
            }
            // this.rules[element.id] = [{ required: true, message: '必填', trigger: 'change' }]
          }
          // 整数
          if (element.paramType === this.paramTypeColumn.integer) {
            !this.rules[element.id] &&
              this.$set(this.rules, element.id, [
                { validator: this.validateInteger }
              ])
            this.rules[element.id] &&
              this.rules[element.id].push({
                validator: this.validateInteger
              })
          }
          // 浮点数
          if (element.paramType === this.paramTypeColumn.float) {
            !this.rules[element.id] &&
              this.$set(this.rules, element.id, [{ validator: this.validateFloat }])
            this.rules[element.id] &&
              this.rules[element.id].push({
                validator: this.validateFloat
              })
          }
          // if (this.checkContainer && element.paramType === this.paramTypeColumn.container) {
          //   this.rules[element.id] &&
          //     this.$set(this.rules, element.id, [])
          //   // this.rules[element.id] &&
          //   //   this.rules[element.id].push([])
          //   this.checkContainer = false
          // }
        },
        /**
         * 获取自定义字段数据
         */
        getCustomFieldsData(data) {
          this.customFieldsData = data
        },
        /**
         * 获取元件为库位设置的字段信息
         */
        getStorageLocationFieldsData(data) {
          this.storageFieldData = data
        },
        /**
         * 保存库位元件
         */
        async saveStockSchema(data) {
          const res = await saveStockSchema(data)
          if (res.code === '200') {
            this.judgeCallback()
            this.handleCancel()
          }
        },
        /**
         * 判断需要执行的回调
         */
        judgeCallback() {
          switch (this.source) {
            case 'storageComponentLeft':
              this.leftSuccess(this.stockFrameInfo)
              break
            case 'storageSchemaListRight':
              this.schemaRightSuccess()
              break
            default:
              break
          }
        },
    
        /**
         * 获取自定义字段和设置字段的数据
         */
        getCustomFieldsDataAndSettingData() {
          this.$refs.customFieldsRef.getData()
          this.$refs.storageFieldsRef.getData()
        },
    
        /**
         * 获取种类字段数据
         */
        getFrameParams() {
          let targetArr = []
          const target = _.cloneDeep(this.form)
          Object.keys(this.baseInfo).forEach(key => {
            this.baseInfo[key] = target[key]
            delete target[key]
          })
          Object.keys(target).forEach(key => {
            targetArr.push({
              id: key,
              paramValues: target[key],
              paramType: this.paramTypeObj[key]
            })
          })
          // console.log(targetArr);
          return targetArr
        },
    
        /**
         * TODO
         * 模态框确定
         */
        handleOk() {
          this.$refs.createBatchInfoRef.validate(valid => {
            if (valid) {
              this.getCustomFieldsDataAndSettingData()
              const frameParams = this.getFrameParams()
              this.saveStockSchema({
                ...this.baseInfo,
                frameParams: frameParams,
                customParams: {
                  params: this.customFieldsData
                },
                stockParams: {
                  params: this.storageFieldData
                },
                stockFrameId: this.stockFrameInfo.id
              })
            }
          })
        },
        /**
         * 模态框取消
         */
        handleCancel() {
          this.visible = false
          this.$refs.createBatchInfoRef.resetFields()
          this.isShowContainerType = false
          this.form = {
            frameName: '',
            icon: '',
            prefix: '',
            name: '',
            unitId: undefined,
            capacity: undefined
          }
          this.stockFrameAttribute = []
        },
        /**
         * 根据库位种类id获取库位种类属性信息
         */
        async queryStockFrameFields(data) {
          const res = await queryStockFrameFields(data)
          if (res.code === '200') {
            this.stockFrameAttribute = res.data
            this.stockFrameAttribute.forEach(element => {
              this.paramTypeObj[element.id] = element.paramType
              this.$set(this.form, element.id, element.paramValues || [])
              // 校验规则
              this.dynamicValidate(element)
              // console.log(this.form);
            })
          }
        },
        /**
         * 打开模态框
         */
        openCreateStockShemaModal(data, source) {
          this.tempContainer = ''
          this.source = source || ''
          this.visible = true
          this.stockFrameInfo = data
          this.form.frameName = this.stockFrameInfo.name
          this.queryStockFrameFields({ id: this.stockFrameInfo.id })
        },
        /**
         * 改变预选容器
         */
        handleChangeContainer(id, target) {
          if (id) {
            const findContainer = this.ContainerOptions.find(v => v.id === id)
            const { id: containerId, name: containerName } = findContainer
            target[0] = { containerId, containerName }
          }
          // else {
          //   target[0] = {containerId: null, containerName: ""}
          //   // target = []
          // }
        }
      },
      watch: {
        form: {
          handler() {
            // Object.keys()
            const targetId = this.stockFrameAttribute.find(item => item.paramName === '位置容器数')?.id
    
            // console.log(targetId, this.form[targetId]?.length > 0 && this.form[targetId][0] !== '')
    
            if (this.form[targetId]?.length > 0  && this.form[targetId][0] !== '') {
              this.isShowContainerType = true
            } else {
              this.form[targetId]?.length > 0 && this.form[targetId][0] === '' && this.form[targetId].splice(0)
              this.isShowContainerType = false
            }
          },
          deep: true,
        },
        isShowContainerType: {
          handler() {
            if(!this.isShowContainerType) {
              const containerId = this.stockFrameAttribute.find(item => item.paramName === '预设容器')?.id
              this.form[containerId] = []
            }
          }
        }
      },
    }
    </script>
    
    <style lang="scss" scoped></style>