<!-- 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>

          <!-- 成像情况 -->
          <LineLabel label="template.dl.dl008.cxqk" />
          <div class="template-form-item">
          <BaseInfoFormPackage
            :ref="refConf.cxqkqxbb"
            :formConfig="cxqkqxbbInfoFormConfig"
            :formData="formData"
            @clickButton="handleClickButton"
            @onRegentSubmit="onRegentSubmit"
          >
          
          </BaseInfoFormPackage>
          <CustomTable
            :columns="cxqkColumns"
            :ref="refConf.cxqk"
            @onRegentSubmit="(e) => onRegentSubmit(e)"
            :showOperation="false"
            :showAddRow="false"
            :formData="cxqkFormData"
            :prefixKey="`cxqkTable`"
            :isBorder="true"
            :showSort="false"
          >
          </CustomTable>
          <BaseInfoFormPackage
            :ref="refConf.cxqkwrqk"
            :formConfig="cxqkwrqkConfig"
            :formData="formData"
          />
          </div>

          <BaseInfoFormPackage
            fieldItemLabel="template.dl.dl007.bz"
            label="template.dl.dl007.bz"
            :ref="refConf.remark"
            :formConfig="remarkConfig"
            :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',
  cxqkqxbb: 'cxqkqxbbInfoRef',
  cxqk: 'cxqkTableRef',
  cxqkwrqk: 'cxqkwrqkInfoRef',
  remark: 'remarkRef'
}
const refNames = Object.values(refConf)

export default {
  name: 'DL008',
  components: {
    BaseInfoFormPackage,
    LineLabel,
    TableList,
    Step,
    CustomTable,
    TableOpertaionDelete
  },
  mixins: [templateMixin],
  props: {
    fillType: {
      type: String,
      default: 'preFill'
    }
  },
  computed: {
    // 成像情况表格数据
    cxqkFormData() {
      return {
        stepTableFormData: this.formData.stepTableFormData_1 || [],
        headerSelectFields: {}
      }
    },
    // 备注表单配置
    remarkConfig() {
      return [
        {
          type: 'cellItem',
          config: {
            remark: {
              label: '',
              type: 'textarea',
              fillType: 'actFill',
              span: 1,
              placeholder: 'template.common.remarkPlaceholder',
              maxlength: 1000,
              rows: 5
            }
          }
        }
      ]
    },
    // 成像情况-污染情况信息
    cxqkwrqkConfig() {
      return [
        {
          type: 'step',
          config: {
            cxqkwrqk: {
              // 注意：这里选项为污染时需要填写信息，与别的选择中 '其他' 选项不一样
              label: 'template.dl.dl008.wrqk',
              type: 'select',
              span:1,
              options: this.getDictOptions('business_dl_ameswrqk'),
              fillType: 'actFill',
              otherCode: 'cxqkwrqkOther',
              showOtherLabel:false
            }
          }
        }
      ]
    },
    // 试验基本信息表单配置
    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
            }
          }
        }
      ]
    },
    // 成像情况-checkbox网格配置
    cxqkColumns() {
      return [
        {
          label: 'template.dl.dl008.jlzb',
          prop: 'jlzb',
          bodyType: 'input',
          bodyFillType: 'actFill',
          width: 100
        },
        {
          label: 'template.dl.dl008.jzbh1',
          prop: 'jzbh1',
          bodyType: 'checkbox',
          bodyFillType: 'actFill',
          width: 150
        },
        {
          label: 'template.dl.dl008.jzbh2',
          prop: 'jzbh2',
          bodyType: 'checkbox',
          bodyFillType: 'actFill',
          width: 150
        },
        {
          label: 'template.dl.dl008.jzbh3',
          prop: 'jzbh3',
          bodyType: 'checkbox',
          bodyFillType: 'actFill',
          width: 150
        },
        {
          label: 'template.dl.dl008.jzbh4',
          prop: 'jzbh4',
          bodyType: 'checkbox',
          bodyFillType: 'actFill',
          width: 150
        }
      ]
    },
    // 仪器使用信息
    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
        }
      ]
    },

    // 成像情况-前序表单信息
    cxqkqxbbInfoFormConfig() {
      return [
        {
          type: 'step',
          config: {
            cxqkqxbd: {
              label: 'template.dl.dl007.qxbd',
              type: 'qxbd',
              fillType: 'actFill',
              filledCodes: ['bdmc', 'bdbh']
            }
          }
        }
      ]
    }
  },
  data() {
    return {
      formData: {},
      refConf
    }
  },
  mounted() {

  },
  methods: {
    // 删除表格行
    deleteTableRow(rowIndex, refName) {
      this.$refs[refName].deleteRow(rowIndex)
    },
    // 点击按钮
    handleClickButton(_item, signData) {
      this.$refs.cxqkqxbbInfoRef.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 === 'cxqkqxbd') {
        // MOCK:模拟数据回显
        const mockData = [
          {"jlzb":"A","jzbh1":undefined,"jzbh2":undefined,"jzbh3":undefined,"jzbh4":undefined,"jzbh1Label":"001","jzbh2Label":"004","jzbh3Label":"007","jzbh4Label":"010"},
          {"jlzb":"A","jzbh1":undefined,"jzbh2":undefined,"jzbh3":undefined,"jzbh4":undefined,"jzbh1Label":"002","jzbh2Label":"005","jzbh3Label":"008","jzbh4Label":"011"},
          {"jlzb":"A","jzbh1":undefined,"jzbh2":undefined,"jzbh3":undefined,"jzbh4":undefined,"jzbh1Label":"003","jzbh2Label":"006","jzbh3Label":"009","jzbh4Label":"012"}
        ]
        this.$refs[refConf.cxqk].updateDataSource(mockData)
      }
    },
    // 保存
    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>

