image.png

    1. <template>
    2. <a-modal
    3. v-model="showModal"
    4. :title="titleName"
    5. @ok="handleOk"
    6. okText="确定"
    7. cancelText="取消"
    8. :confirm-loading="submitDisabled"
    9. >
    10. <a-form-model
    11. :model="info"
    12. :rules="rules"
    13. :label-col="labelCol"
    14. :wrapper-col="wrapperCol"
    15. ref="protocolParamsModalRef"
    16. >
    17. <a-form-model-item prop="parameterName" label="参数名称">
    18. <a-input v-model="info.parameterName" placeholder="请输入参数名称" />
    19. </a-form-model-item>
    20. <a-form-model-item prop="parameterType" label="参数类型">
    21. <a-select
    22. v-model="info.parameterType"
    23. placeholder="请选择参数类型"
    24. @change="selectType"
    25. >
    26. <a-select-option
    27. :key="index"
    28. :value="item.value"
    29. v-for="(item, index) in protocolParamsTypeColumn"
    30. ><a-tag :color="item.color">{{ item.label }}</a-tag>
    31. </a-select-option>
    32. <!-- <a-select-option :key="index" v-for="(item, index) in paramsInfo.type"
    33. ><a-tag :color="paramsInfo.color[index]">{{ item }}</a-tag>
    34. </a-select-option> -->
    35. </a-select>
    36. </a-form-model-item>
    37. <div class="params-setting">
    38. <div class="params-setting-select">
    39. <a-select
    40. v-model="info.valueRequired"
    41. style="width: 90px; font-size: 12px"
    42. >
    43. <a-select-option :value="1"> 必填 </a-select-option>
    44. <a-select-option :value="2"> 非必填 </a-select-option>
    45. </a-select>
    46. <a-divider type="vertical" />
    47. </div>
    48. <div class="params-setting-select">
    49. <a-select
    50. style="width: 90px; font-size: 12px"
    51. @change="selectIsMultiple"
    52. :disabled="defaultMultipleOrNoMultiple"
    53. v-model="info.multiValueRequired"
    54. >
    55. <a-select-option :value="1"> 多值 </a-select-option>
    56. <a-select-option :value="2"> 无多值 </a-select-option>
    57. </a-select>
    58. <a-divider type="vertical" />
    59. </div>
    60. <div class="params-setting-select">
    61. <a-select
    62. default-value="noGroup"
    63. style="width: 90px; font-size: 12px"
    64. v-model="info.parameterGroupId"
    65. >
    66. <a-select-option
    67. :key="item.id"
    68. :value="item.id"
    69. v-for="item in protocolParamsGroupList"
    70. >{{ item.groupName }}</a-select-option
    71. >
    72. </a-select>
    73. </div>
    74. </div>
    75. <component
    76. ref="selectParamsInputRef"
    77. @saveParamsValue="saveParamsValue"
    78. :isNew="isNew"
    79. :editProtocolParamsInfo="editProtocolParamsInfo"
    80. :defaultValues.sync="defaultValues"
    81. :defaultInputFence.sync="defaultInputFence"
    82. :triggerSubmit.sync="isSubmit"
    83. :is="componentName"
    84. :isMultiple="info.multiValueRequired"
    85. ></component>
    86. </a-form-model>
    87. </a-modal>
    88. </template>
    89. <script>
    90. import { protocolParamsTypeColumn, paramTypeColumn } from '@/common/global'
    91. import { ProtocolParamsGroupEnum } from '../comm/ProtocolParamsGroupEnum'
    92. import {
    93. saveProtocolParams,
    94. updateProtocolParams,
    95. judgeSaveAS,
    96. saveAsProtocol
    97. } from '@/api/templateManagement'
    98. import ProtocolParamsText from './ProtocolParamsText'
    99. import ProtocolParamsTextArea from './ProtocolParamsTextArea'
    100. import ProtocolParamsSelect from './ProtocolParamsSelect'
    101. import ProtocolParamsMultiSelect from './ProtocolParamsMultiSelect'
    102. import ProtocolParamsInteger from './ProtocolParamsInteger'
    103. import ProtocolParamsFloat from './ProtocolParamsFloat'
    104. import ProtocolParamsTime from './ProtocolParamsTime'
    105. import ProtocolParamsProductLink from './ProtocolParamsProductLink'
    106. import ProtocolParamsEntityLink from './ProtocolParamsEntityLink'
    107. import ProtocolParamsFrame from './ProtocolParamsFrame'
    108. import ProtocolParamsProjectRange from './ProtocolParamsProjectRange'
    109. import ProtocolParamsBatchLink from './ProtocolParamsBatchLink.vue'
    110. export default {
    111. components: {
    112. ProtocolParamsText,
    113. ProtocolParamsTextArea,
    114. ProtocolParamsSelect,
    115. ProtocolParamsMultiSelect,
    116. ProtocolParamsInteger,
    117. ProtocolParamsFloat,
    118. ProtocolParamsTime,
    119. ProtocolParamsProductLink,
    120. ProtocolParamsEntityLink,
    121. ProtocolParamsFrame,
    122. ProtocolParamsProjectRange,
    123. ProtocolParamsBatchLink
    124. },
    125. props: {
    126. isShowModal: {
    127. type: Boolean,
    128. default() {
    129. return false
    130. }
    131. },
    132. protocolId: {
    133. type: String,
    134. required: true
    135. },
    136. // protocol的version
    137. version: Number,
    138. labNoteId: String,
    139. steps: {
    140. type: Array,
    141. required: true
    142. },
    143. editProtocolParamsInfo: {
    144. type: Object,
    145. default() {
    146. return {}
    147. }
    148. },
    149. isNew: {
    150. type: Number, // 1.新建 2.编辑 默认新建
    151. default() {
    152. return 1
    153. }
    154. },
    155. dataSource: {
    156. type: String,
    157. default() {
    158. return 'model'
    159. }
    160. }
    161. },
    162. data() {
    163. return {
    164. // 设置选择的参数类型
    165. protocolParamsTypeColumn,
    166. showModal: this.isShowModal,
    167. labelCol: { span: 5 },
    168. wrapperCol: { span: 17 },
    169. componentNameObj: {
    170. [paramTypeColumn.text]: 'protocolParamsText',
    171. [paramTypeColumn.textArea]: 'protocolParamsTextArea',
    172. [paramTypeColumn.radioSelect]: 'protocolParamsSelect',
    173. [paramTypeColumn.multiSelect]: 'protocolParamsMultiSelect',
    174. [paramTypeColumn.integer]: 'protocolParamsInteger',
    175. [paramTypeColumn.float]: 'protocolParamsFloat',
    176. [paramTypeColumn.time]: 'protocolParamsTime',
    177. [paramTypeColumn.link]: 'protocolParamsProductLink',
    178. [paramTypeColumn.entity]: 'ProtocolParamsEntityLink',
    179. [paramTypeColumn.frame]: 'ProtocolParamsFrame',
    180. [paramTypeColumn.task_note]: 'ProtocolParamsProjectRange',
    181. [paramTypeColumn.batchLink]: 'ProtocolParamsBatchLink',
    182. },
    183. componentName: 'protocolParamsText',
    184. // 1表示多值 2表示无多值
    185. multiValueRequired: 2,
    186. // 1表示必填 2表示非必填
    187. valueRequired: 2,
    188. isSubmit: false,
    189. defaultMultipleOrNoMultiple: false,
    190. info: {
    191. protocolId: this.protocolId,
    192. parameterName: '',
    193. parameterType: paramTypeColumn.text,
    194. valueRequired: 2,
    195. multiValueRequired: 2,
    196. parameterGroupId: ProtocolParamsGroupEnum.NOT_GROUP,
    197. values: [],
    198. // parameter的version
    199. version: this.version
    200. },
    201. rules: {
    202. parameterName: {
    203. min: 1,
    204. max: 128,
    205. required: true,
    206. message: '参数名称长度在1-128个字符之间'
    207. },
    208. parameterType: { required: true, message: '请选择参数类型' }
    209. },
    210. defaultValues: [],
    211. defaultInputFence: [],
    212. titleName: '新建参数',
    213. submitDisabled: false
    214. }
    215. },
    216. computed: {
    217. protocolParamsGroupList() {
    218. return this.$store.state.protocolParamsGroup.protocolParamsGroupList
    219. }
    220. },
    221. watch: {
    222. isShowModal(newVal) {
    223. this.showModal = this.isShowModal
    224. },
    225. showModal(newVal) {
    226. if (newVal === false) {
    227. this.closeModal()
    228. } else {
    229. this.$refs.selectParamsInputRef &&
    230. this.$refs.selectParamsInputRef.resetParamsValues()
    231. }
    232. },
    233. editProtocolParamsInfo: {
    234. handler(newVal) {
    235. if (Object.keys(newVal).length > 0) {
    236. this.selectType(newVal.parameterType)
    237. this.defaultValues = _.cloneDeep(newVal.values)
    238. this.defaultInputFence = _.cloneDeep(newVal.inputFence || [])
    239. this.info = Object.assign(this.info, newVal)
    240. this.selectGroup(newVal.groupId)
    241. }
    242. },
    243. immediate: true
    244. },
    245. isNew: {
    246. handler(newVal) {
    247. if (newVal === 1) {
    248. this.info.parameterName = ''
    249. this.titleName = '新建参数'
    250. } else {
    251. this.titleName = '编辑参数'
    252. }
    253. },
    254. immediate: true
    255. }
    256. },
    257. methods: {
    258. /**
    259. * 模态框确定按钮事件
    260. */
    261. async handleOk() {
    262. // s为 1 来源为模板,s为 2 来源为试验记录
    263. let s = 1
    264. if (this.dataSource === 'labNote') {
    265. s = 2
    266. }
    267. this.submitDisabled = true
    268. // 判断是否需要另存
    269. const resJudgeInfo = await judgeSaveAS({
    270. protocolId: this.protocolId,
    271. s
    272. }).finally(() => {
    273. this.submitDisabled = false
    274. })
    275. if (resJudgeInfo.data.saveAs === 1) {
    276. // 需要另存 如果是实验记录中直接另存 模板中给出提示
    277. if (this.dataSource === 'labNote') {
    278. await this.saveAsProtocol({
    279. referenceId: this.protocolId,
    280. protocolType: resJudgeInfo.data.protocolType,
    281. labNoteId: this.labNoteId
    282. })
    283. this.updateProtocolMade()
    284. } else {
    285. // 在模板中 被实验记录引用 给出提示
    286. let _this = this
    287. this.$confirm({
    288. title: '提示',
    289. content: 'protocol已经在实验中使用,只支持另存',
    290. okText: '确定',
    291. okType: 'warning',
    292. cancelText: '取消',
    293. onOk() {
    294. _this.$parent.visible = true
    295. },
    296. onCancel() {}
    297. })
    298. }
    299. } else if (
    300. resJudgeInfo.data.referenceType === 1 &&
    301. this.dataSource === 'model'
    302. ) {
    303. let _this = this
    304. this.$confirm({
    305. title: '提示',
    306. content: 'protocol已经被模板使用,保存会使相关模板更新',
    307. okText: '确定',
    308. okType: 'warning',
    309. cancelText: '取消',
    310. onOk() {
    311. _this.info.parameterName = _this.info.parameterName.trim()
    312. _this.$refs.protocolParamsModalRef.validate(valid => {
    313. if (valid) {
    314. _this.isSubmit = true
    315. }
    316. })
    317. },
    318. onCancel() {}
    319. })
    320. } else {
    321. this.info.parameterName = this.info.parameterName.trim()
    322. this.$refs.protocolParamsModalRef.validate(valid => {
    323. if (valid) {
    324. this.isSubmit = true
    325. }
    326. })
    327. }
    328. },
    329. /**
    330. * 更新机制 调用方法
    331. */
    332. updateProtocolMade() {
    333. this.info.parameterName = this.info.parameterName.trim()
    334. this.$refs.protocolParamsModalRef.validate(valid => {
    335. if (valid) {
    336. this.isSubmit = true
    337. }
    338. })
    339. },
    340. /**
    341. * 另存protocol
    342. */
    343. async saveAsProtocol(info) {
    344. const res = await saveAsProtocol(info)
    345. if (res.code === '200') {
    346. // this.$emit('update:protocolId', res.data.id)
    347. this.$listeners.updateProtocolId(res.data.id)
    348. this.$store.commit('SET_CURRRENT_PROTOCOL_SAVE_AS_ID', res.data.id)
    349. }
    350. },
    351. closeModal() {
    352. this.$refs.protocolParamsModalRef.clearValidate()
    353. this.$refs.selectParamsInputRef.resetParamsValues()
    354. this.$emit('closeModal')
    355. },
    356. selectType(value) {
    357. // 选择参数类型时 默认值清空
    358. this.defaultValues = []
    359. this.defaultInputFence = []
    360. // 选择渲染的组件
    361. this.componentName = this.componentNameObj[value] || this.componentName
    362. this.defaultMultipleOrNoMultiple = false
    363. if (
    364. value === paramTypeColumn.multiSelect ||
    365. value === paramTypeColumn.link ||
    366. value === paramTypeColumn.entity ||
    367. value === paramTypeColumn.task_note ||
    368. value === paramTypeColumn.batchLink
    369. ) {
    370. // 多值
    371. this.selectIsMultiple(1)
    372. } else {
    373. this.selectIsMultiple(2)
    374. }
    375. if (
    376. value === paramTypeColumn.textArea ||
    377. value === paramTypeColumn.radioSelect ||
    378. value === paramTypeColumn.time ||
    379. value === paramTypeColumn.multiSelect ||
    380. value === paramTypeColumn.link ||
    381. value === paramTypeColumn.entity ||
    382. value === paramTypeColumn.task_note ||
    383. value === paramTypeColumn.batchLink
    384. ) {
    385. this.defaultMultipleOrNoMultiple = true
    386. } else {
    387. this.defaultMultipleOrNoMultiple = false
    388. }
    389. },
    390. /**
    391. * 选择分组
    392. */
    393. selectGroup(parameterGroupId) {
    394. this.info.parameterGroupId =
    395. parameterGroupId || ProtocolParamsGroupEnum.NOT_GROUP
    396. },
    397. selectIsMultiple(value) {
    398. this.info.multiValueRequired = value
    399. },
    400. saveParamsValue(value, options) {
    401. this.isSubmit = false
    402. if (this.info.parameterType === paramTypeColumn.task_note) {
    403. this.info.inputFence = value.map(item => {
    404. return {
    405. referenceType: 40,
    406. referenceId: item
    407. }
    408. })
    409. } else {
    410. if (_.isObject(value) && !_.isArray(value)) {
    411. console.log(value)
    412. this.info.values = _.cloneDeep(value?.values)
    413. this.info.inputFence = _.cloneDeep(value?.inputFence)
    414. } else {
    415. this.info.values = _.cloneDeep(value)
    416. }
    417. }
    418. switch (this.info.parameterType) {
    419. case paramTypeColumn.radioSelect:
    420. case paramTypeColumn.multiSelect:
    421. this.info.options = options
    422. break
    423. case paramTypeColumn.float:
    424. this.info.displayType = options
    425. break
    426. case paramTypeColumn.time:
    427. this.info.timeFormat = options
    428. break
    429. }
    430. this.info.protocolStepId =
    431. this.steps[0].stepId || this.steps[0].protocolStepId
    432. this.info.labNoteId = this.labNoteId
    433. this.info.protocolId = this.protocolId
    434. this.createOrUpdateProtocolParams(this.info)
    435. this.isSubmit = true
    436. this.showModal = false
    437. },
    438. async createOrUpdateProtocolParams(data) {
    439. let res = null,
    440. isEdit = false
    441. if (this.isNew === 1) {
    442. res = await saveProtocolParams(data)
    443. } else {
    444. res = await updateProtocolParams(data)
    445. isEdit = true
    446. }
    447. if (res.code === '200') {
    448. this.info.parameterName = ''
    449. // 更新version
    450. this.info.version = res.data.version
    451. this.$emit('createOrUpdateParams')
    452. isEdit &&
    453. this.$emit('update:isNew', 1) &&
    454. this.$emit('update:editProtocolParamsInfo', {})
    455. }
    456. }
    457. }
    458. }
    459. </script>
    460. <style lang="scss" scoped>
    461. .params-setting {
    462. display: flex;
    463. .params-setting-select {
    464. flex: 1;
    465. }
    466. // ::v-deep .ant-select {
    467. // flex: 1;
    468. // }
    469. ::v-deep .ant-select-selection {
    470. border: none;
    471. box-shadow: none;
    472. }
    473. }
    474. // ::v-deep .ant-modal-content {
    475. // max-height: 800px;
    476. // }
    477. </style>
    1. <template>
    2. <div class="protocol-params-batch-link">
    3. <a-button @click="SelectBatch">
    4. <a-icon type="fullscreen" />选择批次
    5. </a-button>
    6. <div :key="item.referenceId" v-for="item in paramValues">
    7. <span>{{ item.referenceName }}</span>
    8. </div>
    9. <!-- TODO -->
    10. <span v-show="false">
    11. {{paramValues}}
    12. </span>
    13. <LimitFrame v-bind.sync="$attrs" ref="limitFrameRef" />
    14. <batch-link-params-modal ref="batchLinkParamsModalRef" :paramValues.sync="paramValues"></batch-link-params-modal>
    15. </div>
    16. </template>
    17. <script>
    18. import BatchLinkParamsModal from '../comm/BatchLinkParamsModal'
    19. import LimitFrame from './LimitFrame'
    20. export default {
    21. components: {
    22. BatchLinkParamsModal,
    23. LimitFrame
    24. },
    25. props: {
    26. triggerSubmit: {
    27. type: Boolean,
    28. default() {
    29. return false
    30. }
    31. },
    32. defaultValues: {
    33. type: Array,
    34. default() {
    35. return []
    36. }
    37. }
    38. },
    39. data() {
    40. return {
    41. paramValues: []
    42. }
    43. },
    44. methods: {
    45. SelectBatch() {
    46. this.$refs.batchLinkParamsModalRef.openSelectBatchInfoModal()
    47. },
    48. /**
    49. * 重置参数
    50. */
    51. resetParamsValues() {
    52. this.paramValues = []
    53. },
    54. },
    55. watch: {
    56. triggerSubmit: {
    57. handler(newVal) {
    58. if (newVal === true) {
    59. this.$emit('saveParamsValue', { values: this.paramValues, inputFence: this.$refs.limitFrameRef?.getSelectedFrame() })
    60. this.$emit("update:triggerSubmit", false)
    61. }
    62. }
    63. },
    64. defaultValues: {
    65. handler(newVal) {
    66. if (newVal && newVal.length > 0) {
    67. this.paramValues = _.cloneDeep(newVal)
    68. }
    69. },
    70. immediate: true,
    71. deep: true
    72. }
    73. }
    74. }
    75. </script>
    76. <style lang="scss" scoped>
    77. </style>
    1. <template>
    2. <a-modal
    3. title="选择批次"
    4. v-if="visible"
    5. :centered="true"
    6. :visible="visible"
    7. @ok="handleOk"
    8. @cancel="handleCancel"
    9. :width="'80%'"
    10. :destoryOnClose="true"
    11. :bodyStyle="{ padding: '10px 10px', height: '800px', overflowY: 'scroll' }"
    12. >
    13. <bmy-table
    14. ref="bmyTableRef"
    15. :loading="listLoading"
    16. :columns="showColumns"
    17. :row-selection="{
    18. selectedRowKeys: selectedRowKeys,
    19. onChange: onSelectChange,
    20. }"
    21. :searchContentObj="searchContent"
    22. :selectContentObj="selectContent"
    23. :data-source="data"
    24. :pagination="pagination"
    25. rowKey="id"
    26. :isSelectContent="false"
    27. :isSearch="true"
    28. :scroll="{ x: '100%', y: '100%' }"
    29. >
    30. </bmy-table>
    31. </a-modal>
    32. </template>
    33. <script>
    34. import { getFullProductBatchListExt } from '@/api/materialCenter'
    35. const columns = [
    36. {
    37. title: '批次编号',
    38. dataIndex: 'batchName',
    39. searchType: 'string',
    40. width: '200px',
    41. defaultSearch: true,
    42. innerSearch: true
    43. },
    44. {
    45. title: '产品名称',
    46. dataIndex: 'productName',
    47. searchType: 'string'
    48. },
    49. {
    50. title: '框架名称',
    51. dataIndex: 'categoryName'
    52. },
    53. {
    54. title: '创建人',
    55. dataIndex: 'createMan'
    56. },
    57. {
    58. title: '创建时间',
    59. dataIndex: 'createTime'
    60. }
    61. ]
    62. export default {
    63. props: {
    64. paramValues: Array,
    65. filterSearch: {
    66. type: Object,
    67. default: () => {}
    68. },
    69. },
    70. data() {
    71. return {
    72. // BatchName: '',
    73. isSelected: false,
    74. visible: false,
    75. isLoading: false,
    76. BatchLinkValues: [],
    77. selectedArr: [],
    78. data: [],
    79. tmpSelectRecords: [],
    80. showColumns: columns,
    81. listLoading: false,
    82. selectedRowKeys: [], // 选择的条目index
    83. selectedRows: [],
    84. choose: null,
    85. listQuery: Object.assign(
    86. { pageIndex: 1, pageSize: 10 },
    87. this.filterSearch
    88. ),
    89. pagination: {
    90. current: 1,
    91. pageNo: 1,
    92. pageSize: 10, // 默认每页显示数量
    93. showSizeChanger: true, // 显示可改变每页数量
    94. pageSizeOptions: ['10', '20', '50', '100'], // 每页数量选项
    95. showTotal: total => `总共有 ${total} 项`, // 显示总数
    96. onShowSizeChange: (current, pageSize) => {
    97. this.pageSize = pageSize
    98. this.pageNo = 1
    99. this.listQuery = {
    100. pageIndex: 1,
    101. pageSize: pageSize
    102. }
    103. this.current = 1
    104. this.getList()
    105. this.choose = null
    106. }, // 改变每页数量时更新显示
    107. onChange: (page, pageSize) => this.changePage(page, pageSize), //点击页码事件
    108. total: 0 //总条数
    109. },
    110. searchContent: {
    111. searchBody: columns,
    112. handleToolSearch: (value, complexSearch) => {
    113. complexSearch = complexSearch || false
    114. console.log(value)
    115. Object.assign(this.listQuery, value)
    116. let tmp = {
    117. pageIndex: 1,
    118. pageSize: this.listQuery.pageSize
    119. }
    120. Object.assign(tmp, value, { filterSearch: complexSearch })
    121. this.listQuery = tmp
    122. this.getList()
    123. }
    124. },
    125. selectContent: {
    126. selectOutData: columns,
    127. getSelectData: value => {
    128. this.showColumns = value
    129. }
    130. }
    131. }
    132. },
    133. methods: {
    134. /**
    135. * 重置选择框内容
    136. */
    137. resetSelectedContent() {
    138. this.selectedRows = []
    139. this.selectedRowKeys = []
    140. },
    141. /**
    142. * 取消操作
    143. */
    144. handleCancel() {
    145. this.visible = false
    146. },
    147. /**
    148. * 打开模态框
    149. */
    150. openSelectBatchInfoModal() {
    151. this.visible = true
    152. this.$nextTick(() => {
    153. this.getList()
    154. })
    155. // _.isFunction(callback) && (this.successCallback = callback)
    156. },
    157. /**
    158. * 选择表格行数据
    159. */
    160. onSelectChange(selectedRowKeys, selectedRows) {
    161. this.selectedRowKeys = selectedRowKeys
    162. this.selectedRows = selectedRows
    163. },
    164. /**
    165. * 模态框确定
    166. */
    167. handleOk() {
    168. // const paramList = _.cloneDeep(this.selectedRows)
    169. // console.log(paramList);
    170. // const resonseParamList = paramList.map(item => {
    171. const resonseParamList = this.selectedRows.map(item => {
    172. return {
    173. referenceType: item.referenceType,
    174. referenceName: item.batchName,
    175. referenceId: item.id
    176. }
    177. })
    178. this.$emit('update:paramValues', resonseParamList)
    179. console.log(resonseParamList);
    180. // _.isFunction(this.successCallback) && this.successCallback(resonseParamList)
    181. this.handleCancel()
    182. },
    183. /**
    184. * 获取列表信息
    185. */
    186. async getList() {
    187. this.listLoading = true
    188. const res = await getFullProductBatchListExt(Object.assign({parentType:-1},this.listQuery)).finally(() => {
    189. this.listLoading = false
    190. })
    191. if (res.code === '200') {
    192. const cloneResult = _.cloneDeep(res.data)
    193. this.tmpSelectRecords.push(...cloneResult)
    194. this.pagination.current = this.listQuery.pageIndex
    195. this.pagination.pageNo = this.listQuery.pageIndex
    196. this.pagination.pageSize = this.listQuery.pageSize
    197. this.pagination.total = res.totalRecords
    198. this.pagination.current = this.listQuery.pageIndex
    199. this.data = res.data
    200. }
    201. },
    202. /**
    203. * 切换表格页
    204. */
    205. changePage(page, paSize) {
    206. this.pagination.current = page
    207. this.pagination.pageSize = paSize
    208. this.listQuery = {
    209. pageIndex: page,
    210. pageSize: paSize
    211. }
    212. this.choose = null
    213. this.getList()
    214. },
    215. /**
    216. * 选择table行
    217. */
    218. onSelectChange(selectedRowKeys, selectedRows, id) {
    219. this.selectedRowKeys = selectedRowKeys
    220. this.selectedRows = selectedRows
    221. this.tmpSelectRecords.push(...selectedRows)
    222. this.choose = null
    223. },
    224. /**
    225. * 传输选择的记录
    226. */
    227. transferSelectRecords(callback) {
    228. this.tmpSelectRecords = _.uniqBy(this.tmpSelectRecords, 'id')
    229. this.tmpSelectRecords = this.tmpSelectRecords.filter(item => {
    230. return this.selectedRowKeys.includes(item.id)
    231. })
    232. callback(this.tmpSelectRecords)
    233. }
    234. },
    235. watch: {
    236. selectedArr: {
    237. handler(newSelectedArr) {
    238. newSelectedArr.length &&
    239. newSelectedArr.forEach(item => this.selectedRowKeys.push(item))
    240. },
    241. deep: true,
    242. immediate: true
    243. },
    244. filterSearch: {
    245. handler(newVal) {
    246. Object.assign(this.listQuery, newVal)
    247. delete this.listQuery.categoryId
    248. if (newVal.filterSearch === false) {
    249. this.$refs.bmyTableRef &&
    250. this.$refs.bmyTableRef.resetFilterSearchContent &&
    251. this.$refs.bmyTableRef.resetFilterSearchContent()
    252. }
    253. },
    254. deep: true,
    255. // immediate: true
    256. }
    257. }
    258. }
    259. </script>
    260. <style lang="scss" scoped>
    261. ::v-deep .ant-form-item {
    262. margin-bottom: 0px;
    263. }
    264. </style>

    是模仿下面写的。

    1. <template>
    2. <a-modal
    3. title="选择实物"
    4. v-if="visible"
    5. :centered="true"
    6. :visible="visible"
    7. @ok="handleOk"
    8. @cancel="handleCancel"
    9. :width="'80%'"
    10. :destoryOnClose="true"
    11. :bodyStyle="{ padding: '10px 10px', height: '800px', overflowY: 'scroll' }"
    12. >
    13. <product-frame-list ref="productFrameListRef" :currentSelectedKeys="currentSelectedKeys"></product-frame-list>
    14. </a-modal>
    15. </template>
    16. <script>
    17. import ProductFrameList from '@/views/materialcenter/productManagement/components/ProductFrameList'
    18. export default {
    19. props: {
    20. paramValues: Array
    21. },
    22. data() {
    23. return {
    24. visible: false,
    25. }
    26. },
    27. components: {
    28. ProductFrameList
    29. },
    30. computed: {
    31. currentSelectedKeys() {
    32. return this.paramValues.map(item => item.referenceId)
    33. }
    34. },
    35. methods: {
    36. /**
    37. * 模态框确认
    38. */
    39. handleOk() {
    40. if (this.$refs.productFrameListRef.isSelected) {
    41. const targetParams = this.$refs.productFrameListRef.selectedRows.map(item => {
    42. return {
    43. referenceType: item.referenceType,
    44. referenceName: item.name,
    45. referenceId: item.id
    46. }
    47. })
    48. this.$emit('update:paramValues', targetParams)
    49. }
    50. this.handleCancel()
    51. },
    52. /**
    53. * 模态框取消
    54. */
    55. handleCancel() {
    56. this.visible = false
    57. },
    58. /**
    59. * 打开模态框
    60. */
    61. openModalEvent(preThis) {
    62. this.visible = true
    63. this.$nextTick(() => {
    64. this.$refs.productFrameListRef.getList()
    65. })
    66. }
    67. }
    68. }
    69. </script>
    70. <style lang="scss" scoped>
    71. </style>
    1. <template>
    2. <div class="product-frame-list">
    3. <bmy-table
    4. ref="bmyTableRef"
    5. :loading="listLoading"
    6. :row-selection="{
    7. selectedRowKeys: selectedRowKeys,
    8. onChange: onSelectChange
    9. }"
    10. :columns="showColumns"
    11. :data-source="data"
    12. :pagination="pagination"
    13. :searchContentObj="searchContent"
    14. :selectContentObj="selectContent"
    15. :scroll="{ x: '100%', y: '100%' }"
    16. rowKey="id"
    17. :isSearch="true"
    18. :isSelectContent="false"
    19. >
    20. <template v-slot:unitNames="{ text, record }">
    21. <span>{{ showUnitNames(text) }}</span>
    22. </template>
    23. <template v-slot:name="{ record }">
    24. <a class="link-button" @click="handleItemClick(record)">{{
    25. record.name
    26. }}</a>
    27. </template>
    28. <template v-slot:params="{ text, record }">
    29. <a-tooltip placement="bottomLeft">
    30. <template slot="title">
    31. <p v-for="item in text" :key="item.paramName">
    32. {{ item.paramName }}
    33. </p>
    34. </template>
    35. <span>{{ showProductFields(text) }}</span>
    36. </a-tooltip>
    37. </template>
    38. <template v-slot:productBatchFields="{ text, record }">
    39. <a-tooltip placement="bottomLeft">
    40. <template slot="title">
    41. <p v-for="item in text" :key="item.paramName">
    42. {{ item.paramName }}
    43. </p>
    44. </template>
    45. <span>{{ showProductFields(text) }}</span>
    46. </a-tooltip>
    47. </template>
    48. <template v-slot:createInfo="{ record }">
    49. <p>创建人:{{ record.createMan }}</p>
    50. <p>创建时间:{{ record.createTime }}</p>
    51. </template>
    52. <!-- 操作 -->
    53. <div slot="action" slot-scope="{ record }" class="action-container">
    54. <a-space>
    55. <a-tooltip placement="top">
    56. <template slot="title">
    57. <span>编辑产品种类</span>
    58. </template>
    59. <a-icon type="form" @click="handleEditClick(record)" />
    60. </a-tooltip>
    61. <a-popconfirm
    62. title="是否要删除此行?"
    63. @confirm="removeProductFrame(record.id)"
    64. >
    65. <a-tooltip placement="top">
    66. <template slot="title">
    67. <span>删除产品种类</span>
    68. </template>
    69. <a-icon type="delete" />
    70. </a-tooltip>
    71. </a-popconfirm>
    72. </a-space>
    73. </div>
    74. </bmy-table>
    75. <create-product-frame
    76. ref="createProductFrameRef"
    77. :productFrameSuccess="getList"
    78. ></create-product-frame>
    79. </div>
    80. </template>
    81. <script>
    82. import CreateProductFrame from './CreateProductFrame'
    83. import {
    84. getFullProductFrameList,
    85. removeProductFrame,
    86. getFullProductInfoList
    87. } from '@/api/materialCenter'
    88. const columns = [
    89. {
    90. title: 'ID',
    91. dataIndex: 'frameNo',
    92. searchType: 'string'
    93. },
    94. {
    95. title: '种类名称',
    96. dataIndex: 'name',
    97. width: '200px',
    98. defaultSearch: true,
    99. scopedSlots: { customRender: 'name' },
    100. searchType: 'string',
    101. innerSearch: true
    102. },
    103. {
    104. title: '种类编号',
    105. dataIndex: 'prefix',
    106. width: '200px',
    107. // defaultSearch: true,
    108. searchType: 'string',
    109. innerSearch: true
    110. },
    111. {
    112. title: '产品字段',
    113. dataIndex: 'params',
    114. // searchType: 'string',
    115. scopedSlots: { customRender: 'params' },
    116. ellipsis: true
    117. },
    118. {
    119. title: '批次字段',
    120. dataIndex: 'productBatchFields',
    121. scopedSlots: { customRender: 'productBatchFields' },
    122. ellipsis: true
    123. },
    124. {
    125. title: '单位',
    126. dataIndex: 'unitNames',
    127. scopedSlots: { customRender: 'unitNames' }
    128. },
    129. {
    130. title: '创建信息',
    131. scopedSlots: { customRender: 'createInfo' }
    132. },
    133. // {
    134. // title: '创建人',
    135. // dataIndex: 'createMan',
    136. // searchType: 'string'
    137. // },
    138. // {
    139. // title: '创建时间',
    140. // dataIndex: 'createTime',
    141. // searchType: 'time'
    142. // },
    143. {
    144. title: '操作',
    145. dataIndex: 'action',
    146. scopedSlots: { customRender: 'action' },
    147. fixed: 'right',
    148. width: 120
    149. }
    150. ]
    151. export default {
    152. props: {
    153. filterSearch: {
    154. type: Object,
    155. default: () => {}
    156. },
    157. currentSelectedKeys: {
    158. type: Array,
    159. default: () => []
    160. }
    161. },
    162. components: {
    163. CreateProductFrame
    164. },
    165. data() {
    166. return {
    167. /**
    168. * 是否点击了表格的选择
    169. */
    170. isSelected: false,
    171. data: [],
    172. listLoading: false,
    173. showColumns: columns,
    174. choose: null,
    175. listQuery: Object.assign(
    176. { pageIndex: 1, pageSize: 10 },
    177. this.filterSearch
    178. ),
    179. productFrameInfo: {},
    180. selectedRowKeys: this.currentSelectedKeys, // 选择的条目index
    181. selectedRows: [],
    182. pagination: {
    183. current: 1,
    184. pageNo: 1,
    185. pageSize: 10, // 默认每页显示数量
    186. showSizeChanger: true, // 显示可改变每页数量
    187. pageSizeOptions: ['10', '20', '50', '100'], // 每页数量选项
    188. showTotal: total => `总共有 ${total} 项`, // 显示总数
    189. onShowSizeChange: (current, pageSize) => {
    190. this.pageSize = pageSize
    191. this.pageNo = 1
    192. this.listQuery = {
    193. pageIndex: 1,
    194. pageSize: pageSize
    195. }
    196. this.getList()
    197. this.choose = null
    198. }, // 改变每页数量时更新显示
    199. onChange: (page, pageSize) => this.changePage(page, pageSize), //点击页码事件
    200. total: 0 //总条数
    201. },
    202. searchContent: {
    203. searchBody: columns,
    204. handleToolSearch: (value, complexSearch) => {
    205. complexSearch = complexSearch || false
    206. console.log(value)
    207. Object.assign(this.listQuery, value)
    208. let tmp = {
    209. pageIndex: 1,
    210. pageSize: this.listQuery.pageSize
    211. }
    212. Object.assign(tmp, value, { filterSearch: complexSearch })
    213. this.listQuery = tmp
    214. this.getList()
    215. }
    216. },
    217. selectContent: {
    218. selectOutData: columns,
    219. getSelectData: value => {
    220. this.showColumns = value
    221. }
    222. }
    223. }
    224. },
    225. methods: {
    226. /**
    227. * 编辑产品种类
    228. */
    229. handleEditClick(record) {
    230. this.$refs.createProductFrameRef.openCreateProductFrameModal(
    231. 'productFrameList',
    232. record
    233. )
    234. },
    235. /**
    236. * 删除种类
    237. */
    238. async removeProductFrame(id) {
    239. const res = await removeProductFrame({ id })
    240. if (res.code === '200') {
    241. this.getList()
    242. }
    243. },
    244. /**
    245. * 选择table行
    246. */
    247. onSelectChange(selectedRowKeys, selectedRows) {
    248. this.isSelected = true
    249. this.selectedRowKeys = selectedRowKeys
    250. if (selectedRowKeys.length === selectedRows.length) {
    251. this.selectedRows = selectedRows
    252. } else {
    253. this.selectedRows = selectedRowKeys.map(
    254. key =>
    255. this.selectedRows.find(row => row.id === key) ||
    256. selectedRows.find(row => row.id === key)
    257. )
    258. }
    259. },
    260. /**
    261. * 列表点击事件
    262. */
    263. async handleItemClick(record) {
    264. this.listQuery = {
    265. pageIndex: 1,
    266. pageSize: 10,
    267. categoryId: record.id,
    268. name: ''
    269. }
    270. this.listLoading = true
    271. /**
    272. * 请求产品种类/产品基本 list
    273. */
    274. this.productFrameInfo = _.cloneDeep(record)
    275. this.$emit(
    276. 'switchProductClick',
    277. 'product',
    278. this.productFrameInfo,
    279. this.listQuery
    280. )
    281. // this.$emit(
    282. // "changeComponentId",
    283. // "productInfoListRight",
    284. // "productFrameInfoListRight"
    285. // );
    286. this.listLoading = false
    287. },
    288. /**
    289. * 改变页码
    290. */
    291. changePage(page, paSize) {
    292. this.pagination.current = page
    293. this.pagination.pageSize = paSize
    294. this.listQuery = {
    295. pageIndex: page,
    296. pageSize: paSize
    297. }
    298. this.choose = null
    299. this.getList()
    300. },
    301. /**
    302. * 获取框架列表
    303. */
    304. async getList() {
    305. this.listLoading = true
    306. const res = await getFullProductFrameList(this.listQuery).finally(() => {
    307. this.listLoading = false
    308. })
    309. if (res.code === '200') {
    310. this.pagination.current = this.listQuery.pageIndex
    311. this.pagination.pageNo = this.listQuery.pageIndex
    312. this.pagination.pageSize = this.listQuery.pageSize
    313. this.pagination.total = res.totalRecords
    314. this.pagination.current = this.listQuery.pageIndex
    315. this.data = res.data
    316. }
    317. }
    318. },
    319. computed: {
    320. showUnitNames() {
    321. return unitNames => {
    322. return unitNames.join('、')
    323. }
    324. },
    325. showProductFields() {
    326. return productBatchFields => {
    327. return productBatchFields?.map(v => v.paramName).join('、')
    328. }
    329. }
    330. },
    331. watch: {
    332. filterSearch: {
    333. handler(newVal) {
    334. Object.assign(this.listQuery, newVal)
    335. delete this.listQuery.categoryId
    336. if (newVal.filterSearch === false) {
    337. this.$refs.bmyTableRef &&
    338. this.$refs.bmyTableRef.resetFilterSearchContent &&
    339. this.$refs.bmyTableRef.resetFilterSearchContent()
    340. }
    341. },
    342. deep: true,
    343. immediate: true
    344. }
    345. }
    346. }
    347. </script>
    348. <style lang="scss" scoped></style>