<template>
  <div class="mod-config">
    <el-form label-position="top" style="margin-top: 1px; margin-left: 0px;">
      <el-form-item style="">
        <el-button type="primary" @click="saveData()" v-if="!ifDisableFlag">保存备注</el-button>
      </el-form-item>
      <el-form-item style="height: 500px">
        <el-input
          type="textarea"
          v-model="dataForm.remarkPage "
          :rows="25"
          resize='none'
          maxlength="500"
          :disabled="ifDisableFlag"
          style="height: 500px" >
        </el-input>
      </el-form-item>
    </el-form>

    <Chooselist ref="baseList"  @getBaseData="getBaseData"></Chooselist>
  </div>
</template>

<script>
  import {
    searchBMRemarkPage,
    updateBMRemarkPage,
  } from "@/api/sampleManagement/technicalSpecificationList.js"
  import Chooselist from '@/views/modules/common/Chooselist'
  export default {
    components: {
      Chooselist
    },
    data() {
      return {
        searchData: {
          site: '',
          username: this.$store.state.user.name,
          codeNo: '',
          buNo:'',
        },
        ifDisableFlag:false,
        dataForm:{
          site: '',
          codeNo:'',
          remarkPage:'',
        },
        dataRole: {
          partTypeDesc: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          partName: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
        }
      }
    },
    methods: {
      // 获取基础数据列表S
      getBaseList (val, type) {
        this.tagNo = val
        this.tagNo1 = type
        this.$nextTick(() => {
          let strVal = ''
          if (val === 1013) {
            if(type==1) {
              strVal = this.dataForm.partType
            }
          }
          this.$refs.baseList.init(val, strVal)
        })
      },
      /* 列表方法的回调 */
      getBaseData (val) {
        if (this.tagNo === 1013) {
          if(this.tagNo1==1) {
            this.dataForm.partType = val.Base_id
            this.dataForm.partTypeDesc = val.Base_desc
          }
        }
      },
      //初始化组件的参数
      init(inData) {
        //初始化参数
        this.searchData = JSON.parse(JSON.stringify(inData));
        if(this.searchData.ifDisableFlag){
          this.ifDisableFlag=true
        }
        //刷新表格
        this.searchTable();

      },
      searchTable(){
        searchBMRemarkPage(this.searchData).then(({data}) => {
          if(data.rows.length>0){
            this.dataForm = data.rows[0];
          }else {
            this.dataForm.site=this.searchData.site
            this.dataForm.codeNo=this.searchData.codeNo
          }


        });
      },
      saveData(){
        this.$confirm("是否保存信息？", '保存提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(() => {
          console.log(this.dataForm)
          updateBMRemarkPage(this.dataForm).then(({data}) => {
            if (data && data.code === 0) {
              this.$message.success( '操作成功')
            } else {
              this.$message.error(data.msg)
            }
          })
        }).catch(() => {
          return
        })
      },
    },
  }
</script>

<style scoped>

</style>
