<!-- Ames实验（掺入法）平皿培养记录表 -->
<template>
  <div>
    <div class="detail-container">
      <div class="detail-title">
        <img src="@/assets/images/detail-title.png" />{{ formData.bdmc
        }}<img src="@/assets/images/detail-title.png" />
      </div>
      <div class="detail-content">
        <div class="content">
          <BaseInfoFormPackage
            fieldItemLabel="template.common.baseInfo"
            label="template.common.baseInfo"
            :ref="refConf.base"
            :formConfig="baseInfoFormConfig"
            :formData="formData"
          />

          <LineLabel label="template.dl.dl007.yqsyxx" />
          <CustomTable
            :columns="yqsyColumns"
            :ref="refConf.yqsy"
            @onRegentSubmit="(e) => onRegentSubmit(e)"
            :showOperation="fillType === 'actFill'"
            :showAddRow="fillType === 'actFill'"
            :formData="formData"
            :prefixKey="`yqsyTable`"
          >
            <template slot="operation" slot-scope="{ row, rowIndex, columns }">
              <TableOpertaionDelete
                :row="row"
                :rowIndex="rowIndex"
                :columns="columns"
                @deleteRow="() => deleteTableRow(rowIndex, 'yqsyTableRef')"
              ></TableOpertaionDelete>
            </template>
          </CustomTable>

          <BaseInfoFormPackage
            fieldItemLabel="template.dl.dl007.czxx"
            label="template.dl.dl007.czxx"
            :ref="refConf.czInfo"
            :formConfig="czInfoFormConfig"
            :formData="formData"
            @clickButton="handleClickButton"
            @onRegentSubmit="onRegentSubmit"
          />

          <BaseInfoFormPackage
            fieldItemLabel="template.dl.dl007.bz"
            label="template.dl.dl007.bz"
            :ref="refConf.remark"
            :formConfig="remarkConig"
            :formData="formData"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import BaseInfoFormPackage from '@/components/Template/BaseInfoFormPackage'
import TableOpertaionDelete from '@/components/Template/operation/TableOpertaionDelete.vue'
import CustomTable from '@/components/Template/CustomTable.vue'
import LineLabel from '@/components/Template/LineLabel'
import TableList from '@/components/Template/Table'
import Step from '@/components/Template/Step'
import templateMixin from '../../mixins/templateMixin'
import moment from 'moment'

const refConf = {
  base: 'baseInfoRef',
  yqsy: 'yqsyTableRef',
  czInfo: 'czInfoRef',
  remark: 'remarkRef'
}
const refNames = Object.values(refConf)

export default {
  name: 'DL007',
  components: {
    BaseInfoFormPackage,
    LineLabel,
    TableList,
    Step,
    CustomTable,
    TableOpertaionDelete
  },
  mixins: [templateMixin],
  props: {
    fillType: {
      type: String,
      default: 'preFill'
    }
  },
  computed: {
    // 备注表单配置
    remarkConig() {
      return [
        {
          type: 'cellItem',
          config: {
            remark: {
              label: '',
              type: 'textarea',
              fillType: 'actFill',
              span: 1,
              placeholder: 'template.common.remarkPlaceholder',
              maxlength: 1000,
              rows: 5
            }
          }
        }
      ]
    },
    // 试验基本信息表单配置
    baseInfoFormConfig() {
      return [
        {
          type: 'cardItem',
          config: {
            studyMc: {
              label: 'template.common.testName',
              type: 'input',
              disabled: true
            },
            studySn: {
              label: 'template.common.testNumber',
              type: 'input',
              disabled: true
            }
          }
        },
        {
          type: 'conditionItem',
          label: 'template.dl.dl007.sydd',
          config: {
            sydd: {
              span: 1,
              label: 'template.dl.dl007.sydd',
              type: 'select',
              options: this.getDictOptions('business_sydd'),
              fillType: 'actFill',
              otherCode: 'syddOther'
            }
          }
        },
        {
          type: 'cellItem',
          label: 'template.common.configurationTime',
          config: {
            startDate: {
              label: 'template.common.startTime',
              type: 'input',
              disabled: true
            },
            endDate: {
              label: 'template.common.endTime',
              type: 'input',
              disabled: true
            }
          }
        }
      ]
    },
    // 仪器使用信息
    yqsyColumns() {
      return [
        {
          label: 'template.dl.dl007.yqbh',
          prop: 'yqbh',
          bodyType: 'yq',
          bodyFillType: 'actFill'
        },
        {
          label: 'template.dl.dl007.yqmc',
          prop: 'yqmc',
          bodyType: 'input',
          bodyDisabled: true,
          bodyFillType: 'actFill',
          disabled: true
        },
        {
          label: 'template.dl.dl007.yqxh',
          prop: 'yqxh',
          bodyType: 'input',
          bodyDisabled: true,
          bodyFillType: 'actFill',
          disabled: true
        },
        {
          label: 'template.dl.dl007.xccsjzjdrq',
          prop: 'jzrq',
          bodyType: 'input',
          bodyDisabled: true,
          bodyFillType: 'actFill',
          disabled: true
        }
      ]
    },

    // 操作信息表信息
    czInfoFormConfig() {
      return [
        {
          type: 'cellItem',
          config: {
            qxbd: {
              label: 'template.dl.dl007.qxbd',
              type: 'qxbd',
              fillType: 'actFill',
              filledCodes: ['bdmc', 'bdbh']
            },
            pykssj: {
              label: 'template.dl.dl007.pykssj',
              fillType: 'actFill',
              type: 'input',
              disabled: true
            },
            pyjssj: {
              label: 'template.dl.dl007.pyjssj',
              type: 'input',
              fillType: 'actFill',
              maxlength: 200,
              subType: 'button',
              subKey: 'pyjssjButton',
              buttonName: 'template.dl.dl007.jsButton'
            }
          }
        }
      ]
    }
  },
  data() {
    return {
      formData: {},
      refConf
    }
  },
  methods: {
    // 删除表格行
    deleteTableRow(rowIndex, refName) {
      this.$refs[refName].deleteRow(rowIndex)
    },
    // 点击按钮
    handleClickButton(_item, signData) {
      this.$refs.czInfoRef.updateFormData(
        'pyjssj',
        moment().format('YYYY/MM/DD HH:mm'),
        { isUpdateRecord: true, signData }
      )
    },
    // 获取已填写的表单数据
    getFilledFormData() {
      return this.getFilledFormDataByRefs(refNames)
    },
    // 获取填写完成的表单数据
    async getFormData() {
      return await this.validFormFields(refNames)
    },
    // 只做校验
    async validFields() {
      return await this.validFormFields(refNames)
    },
    getResource() {
      const stepResource = this.$refs.yqsyTableRef.getStepResource()
      // 使用的试剂、仪器
      this.resourceTmp = stepResource.sjResource || []
      this.yqResourceTmp = stepResource.yqResource || []
      return this.resourceTmp
    },
    onRegentSubmit(e) {
      const { selectInfo, key, rowIndex } = e
      const { row } = selectInfo

      if (key === 'yqbh') {
        const params = {
          yqmc: row.mc,
          yqxh: row.xh,
          jzrq: row.jzrq
        }
        this.$refs.yqsyTableRef.updateDataSourceByRowIndex(rowIndex, params)
      }
      if (key === 'qxbd') {
        this.$refs.czInfoRef.updateFormData('pykssj', row.startDate)
      }
    },
    // 保存
    async onSave() {
      const formData = this.getStepResource()
      console.log(formData, 'formData')
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss">
.mt-20 {
  margin-top: 20px;
}

.print-btn {
  margin-bottom: 20px;
}
.config-header-end {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-bottom: 15px;
  font-weight: bold;
  font-size: 16px;
  color: #303133;
}
</style>
