<template>
  <div class="app-container">
    <sticky style="margin-bottom: 10px;">
      <btn ref="btn" />
    </sticky>
    <el-form ref="ysjl" :model="ysjl" class="el-form" label-position="right" label-width="130px">
      <fieldset>
        <legend>基本信息</legend>
        <el-row :gutter="20">
          <el-col :span="9">
            <el-form-item label="记录编号" prop="jilubianhao">
              <el-input v-model="ysjl.jilubianhao" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="9">
            <el-form-item label="设计压力" prop="shejiyali">
              <el-input v-model="param.shejiyali" :disabled="edit">
                <template slot="append">
                  MPa
                </template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item label="允许/监控使用压力" label-width="150px" prop="shiyongyali">
              <el-input v-model="param.shiyongyali" :disabled="edit">
                <template slot="append">
                  MPa
                </template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="9">
            <el-form-item label="试验压力" prop="shiyanyali">
              <el-input v-model="param.shiyanyali" :disabled="edit">
                <template slot="append">
                  MPa
                </template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item label="主体材质" prop="zhuticaizhi">
              <el-input v-model="param.zhuticaizhi" :disabled="edit" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="9">
            <el-form-item label="试验介质" prop="shiyanjiezhi">
              <el-input v-model="param.shiyanjiezhi" :disabled="edit" />
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item label="介质温度" prop="jiezhiwendu">
              <el-input v-model="param.jiezhiwendu" :disabled="edit">
                <template slot="append">
                  ℃
                </template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="9">
            <el-form-item label="试压部位" prop="shiyabuwei">
              <el-input v-model="param.shiyabuwei" :disabled="edit" />
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item label="环境温度" prop="huanjingwendu">
              <el-input v-model="param.huanjingwendu" :disabled="edit">
                <template slot="append">
                  ℃
                </template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="9">
            <el-form-item label="压力表量程" prop="yalibiaoliangcheng">
              <el-input v-model="param.yalibiaoliangcheng" :disabled="edit">
                <template slot="append">
                  MPa
                </template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item label="精度" prop="yalibiaojingdu">
              <el-input v-model="param.yalibiaojingdu" :disabled="edit">
                <template slot="append">
                  级
                </template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="9">
            <el-form-item label="机泵型号" prop="jibengxinghao">
              <el-input v-model="param.jibengxinghao" :disabled="edit" />
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item label="耐压种类" prop="naiyazhonglei">
              <el-select v-model="param.naiyazhonglei" style="width: 100%;" :disabled="edit" @change="changeNyzl">
                <el-option v-for="item in nyzl" :key="item.value" :label="item.value" :value="item.value" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </fieldset>
      <fieldset>
        <legend>试验程序记录</legend>
        <el-row v-if="yeya" id="sss" :gutter="2" style="font-size: 18px;font-weight: bolder;padding-left: 25px;">
          缓慢升压至允许/监控使用压力 <el-input v-model="param.huanshengyali" :disabled="edit" class="underlines" /> MPa, 升压时间<el-input v-model="param.hmsy1sj" :disabled="edit" class="underlines" /> min, 保压 <el-input v-model="param.huanshengbaoyashijian" :disabled="edit" class="underlines" /> min,确认无泄漏;<br>
          缓慢升压至试验压力<el-input v-model="param.syhuanshengyali" :disabled="edit" class="underlines" />MPa, 升压时间<el-input v-model="param.hmsy2sj" :disabled="edit" class="underlines" /> min, 保压<el-input v-model="param.syhuanshengbaoyashijian" :disabled="edit" class="underlines" /> min;<br>
          缓慢降压至允许/监控使用压力<el-input v-model="param.huanjiangyali" :disabled="edit" class="underlines" />MPa, 降压时间<el-input v-model="param.hmjy1sj" :disabled="edit" class="underlines" /> min, 保压<el-input v-model="param.huanjiangbaoyashijian" :disabled="edit" class="underlines" />min;<br>
          检验容器<el-input v-model="param.jyrqxielou" :disabled="edit" class="underlines" /> 渗漏，
          <el-input v-model="param.jyrqbianxing" :disabled="edit" class="underlines" />可见的变形，
          <el-input v-model="param.jyrqyixiang" :disabled="edit" class="underlines" /> 异常的响声。
        </el-row>
        <el-row v-else :gutter="2" style="font-size: 18px;font-weight: bolder;padding-left: 25px;">
          1. 缓慢升压至试验压力的10%：<el-input v-model="param.hmsy1" :disabled="edit" class="underlines" />MPa, 升压时间<el-input v-model="param.hmsy1sj" :disabled="edit" class="underlines" /> min, 保压<el-input v-model="param.hmsy1by" :disabled="edit" class="underlines" /> min;<br>
          2. 缓慢升压至试验压力的50%：<el-input v-model="param.hmsy2" :disabled="edit" class="underlines" />MPa, 升压时间<el-input v-model="param.hmsy2sj" :disabled="edit" class="underlines" /> min, 保压<el-input v-model="param.hmsy2by" :disabled="edit" class="underlines" /> min;<br>
          3. 缓慢升压至试验压力的60%：<el-input v-model="param.hmsy3" :disabled="edit" class="underlines" />MPa, 升压时间<el-input v-model="param.hmsy3sj" :disabled="edit" class="underlines" /> min, 保压<el-input v-model="param.hmsy3by" :disabled="edit" class="underlines" /> min;<br>
          4. 缓慢升压至试验压力的70%：<el-input v-model="param.hmsy4" :disabled="edit" class="underlines" />MPa, 升压时间<el-input v-model="param.hmsy4sj" :disabled="edit" class="underlines" /> min, 保压<el-input v-model="param.hmsy4by" :disabled="edit" class="underlines" /> min;<br>
          5. 缓慢升压至试验压力的80%：<el-input v-model="param.hmsy5" :disabled="edit" class="underlines" />MPa, 升压时间<el-input v-model="param.hmsy5sj" :disabled="edit" class="underlines" /> min, 保压<el-input v-model="param.hmsy5by" :disabled="edit" class="underlines" /> min;<br>
          6. 缓慢升压至试验压力的90%：<el-input v-model="param.hmsy6" :disabled="edit" class="underlines" />MPa, 升压时间<el-input v-model="param.hmsy6sj" :disabled="edit" class="underlines" /> min, 保压<el-input v-model="param.hmsy6by" :disabled="edit" class="underlines" /> min;<br>
          7. 缓慢升压至试验压力<el-input v-model="param.hmsy7" :disabled="edit" class="underlines" />MPa, 升压时间<el-input v-model="param.hmsy7sj" :disabled="edit" class="underlines" /> min, 保压<el-input v-model="param.hmsy7by" :disabled="edit" class="underlines" /> min;<br>
          8. 缓慢降压至允许/监控使用压力<el-input v-model="param.huanjiangyali" :disabled="edit" class="underlines" />MPa, 降压时间<el-input v-model="param.hmjy1sj" :disabled="edit" class="underlines" /> min, 保压<el-input v-model="param.huanjiangbaoyashijian" :disabled="edit" class="underlines" />min, 降压至0MPa时间<el-input v-model="param.hmjy2sj" :disabled="edit" class="underlines" /> min;<br>
          容器 <el-input v-model="param.jyrqxielou" :disabled="edit" class="underlines" /> 渗漏, <el-input v-model="param.jyrqbianxing" :disabled="edit" class="underlines" /> 可见的变形, <el-input v-model="param.jyrqyixiang" :disabled="edit" class="underlines" /> 异常的响声。<br>
        </el-row>
      </fieldset>
      <fieldset>
        <legend>检验信息</legend>
        <el-row :gutter="20">
          <el-col :span="9">
            <el-form-item label="试验人员" prop="shiyanyuan">
              <el-select v-model="param.shiyanyuan" :disabled="edit" placeholder="请选择人员" style="width: 232px;">
                <el-option v-for="user in users" :key="user.id" :label="user.nickname" :value="user.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item label="试验日期" label-width="135px" prop="shiyanriqi">
              <el-date-picker v-model="param.shiyanriqi" :disabled="edit" type="date" value-format="yyyy-MM-dd" placeholder="选择日期" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="9">
            <el-form-item label="检验日期" label-width="135px" prop="jianyanjieshuriqi">
              <el-date-picker v-model="ysjl.jianyanjieshuriqi" :disabled="edit" type="date" value-format="yyyy-MM-dd" placeholder="选择日期" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="试验结果" prop="shiyanjielun">
          <el-input v-model="param.shiyanjielun" :disabled="edit" type="textarea" rows="4" style="width: 800px;" />
        </el-form-item>
        <el-form-item label="" prop="jianyanrenyuan" style="display: none;">
          <el-input v-model="ysjl.jianyanrenyuan" type="text" />
        </el-form-item>
      </fieldset>
    </el-form>
  </div>
</template>
<script>
import Sticky from '@/components/Sticky'
import btn from '@/views/common/FxButton'
export default {
  name: 'RqZbgNysy2100',
  components: { Sticky, btn },
  data() {
    return {
      ysjl: {},
      param: {},
      dialogVisible: false,
      edit: false,
      state: '',
      info: {
        ysjlId: this.$route.query.id,
        jyxm: this.$route.query.jyxm
      },
      users: [],
      fileList: [],
      nyzl: [{ value: '液压' }, { value: '气压' }, { value: '气液组合' }],
      yeya: true
    }
  },
  watch: {
    state: function(val) {
      this.$refs.picture.stateChange(val)
    }
  },
  created() {
    this.getInfo()
    this.getUserList(this.$route.query.departmentId)
  },
  methods: {
    getInfo() {
      this.api({
        url: '/fx/getFxByYsjlId',
        method: 'get',
        params: {
          ysjlId: this.$route.query.id,
          jyxm: this.$route.query.jyxm
        }
      }).then(data => {
        this.ysjl = data.ysjl
        this.state = 'create'
        if (data.param !== null && data.param !== undefined) {
          // 有无损原始记录参数
          this.state = 'update'
          this.param = data.param
          if (this.param.shiyanyuan !== null && this.param.shiyanyuan.length > 0) {
            this.param.shiyanyuan = Number(this.param.shiyanyuan)
          }
          this.fileList = JSON.parse(data.param.imagePath) === null ? JSON.parse('[]') : JSON.parse(data.param.imagePath)
          if (this.fileList.length > 0) {
            for (let i = 0; i < this.fileList.length; i++) {
              this.fileList[i].url = process.env.VUE_APP_IMG_URL + '2000/nysy/' + this.fileList[i].name
            }
          }
        } else {
          this.yeya = true
          this.param = {
            naiyazhonglei: '液压',
            jyrqxielou: '无',
            jyrqbianxing: '无',
            jyrqyixiang: '无',
            shiyanjielun: '合格'
          }
        }
        this.changeNyzl(this.param.naiyazhonglei)
        if (this.ysjl.flowstatus === 4) {
          this.state = 'finish'
          this.edit = true
        }
        this.$refs.btn.getParentInfo(this.ysjl, this.param, null, null, this.state, this.$route.query.jyxm, true, false)
        this.$refs.picture.getChange(this.ysjl.shebeizhongleidaima, this.state, this.fileList, 1)
      })
    },
    getUserList(val) {
      this.api({
        url: '/user/getUserListByDepartmentId',
        method: 'get',
        params: {
          departmentId: val
        }
      }).then(data => {
        this.users = data
      })
    },
    changed(item) {
      this.param.buzhijiantu = item
    },
    changeNyzl(item) {
      if (item === '液压') {
        this.yeya = true
      } else {
        this.yeya = false
      }
      this.buildSyNycx()
    },
    /**
     * 构建试验耐压程序记录数据
     */
    buildSyNycx() {
      let sychengxujilu
      if (this.yeya) {
        sychengxujilu = '缓慢升压至允许/监控使用压力' + (this.param.huanshengyali ? this.param.huanshengyali : ' ') + 'MPa,保压' + (this.param.huanshengbaoyashijian ? this.param.huanshengbaoyashijian : ' ') + 'min,确认无泄漏;\n\r' +
          '缓慢升压至试验压力' + (this.param.syhuanshengyali ? this.param.syhuanshengyali : ' ') + 'MPa,保压' + (this.param.syhuanshengbaoyashijian ? this.param.syhuanshengbaoyashijian : ' ') + 'min;\n\r' +
          '缓慢降压至允许/监控使用压力' + (this.param.huanjiangyali ? this.param.huanjiangyali : ' ') + 'MPa，保压' + (this.param.huanjiangbaoyashijian ? this.param.huanjiangbaoyashijian : ' ') + 'min;\n\r' +
          '检验容器' + (this.param.jyrqxielou ? this.param.jyrqxielou : ' ') + '渗漏，' + (this.param.jyrqbianxing ? this.param.jyrqbianxing : ' ') + '可见的变形，' + (this.param.jyrqyixiang ? this.param.jyrqyixiang : ' ') + '异常的响声。'
      } else {
        sychengxujilu = '1. 缓慢升压至试验压力的10%：' + (this.param.hmsy1 ? this.param.hmsy1 : ' ') + 'MPa,保压' + (this.param.hmsy1by ? this.param.hmsy1by : ' ') + 'min;\n\r' +
          '2. 缓慢升压至试验压力的50%：' + (this.param.hmsy2 ? this.param.hmsy2 : ' ') + 'MPa,保压' + (this.param.hmsy2by ? this.param.hmsy2by : ' ') + 'min;\n\r' +
          '3. 缓慢升压至试验压力的60%：' + (this.param.hmsy3 ? this.param.hmsy3 : ' ') + 'MPa,保压' + (this.param.hmsy3by ? this.param.hmsy3by : ' ') + 'min;\n\r' +
          '4. 缓慢升压至试验压力的70%：' + (this.param.hmsy4 ? this.param.hmsy4 : ' ') + 'MPa,保压' + (this.param.hmsy4by ? this.param.hmsy4by : ' ') + 'min;\n\r' +
          '5. 缓慢升压至试验压力的80%：' + (this.param.hmsy5 ? this.param.hmsy5 : ' ') + 'MPa,保压' + (this.param.hmsy5by ? this.param.hmsy5by : ' ') + 'min;\n\r' +
          '6. 缓慢升压至试验压力的90%：' + (this.param.hmsy6 ? this.param.hmsy6 : ' ') + 'MPa,保压' + (this.param.hmsy6by ? this.param.hmsy6by : ' ') + 'min;\n\r' +
          '7. 缓慢升压至试验压力' + (this.param.hmsy7 ? this.param.hmsy7 : ' ') + 'MPa,保压' + (this.param.hmsy7by ? this.param.hmsy7by : ' ') + 'min;\n\r' +
          '8. 缓慢降压至允许/监控使用压力' + (this.param.huanjiangyali ? this.param.huanjiangyali : ' ') + 'MPa，保压' + (this.param.huanjiangbaoyashijian ? this.param.huanjiangbaoyashijian : ' ') + 'min;\n\r' +
          '容器' + (this.param.jyrqxielou ? this.param.jyrqxielou : ' ') + '渗漏，' + (this.param.jyrqbianxing ? this.param.jyrqbianxing : ' ') + '可见的变形，' + (this.param.jyrqyixiang ? this.param.jyrqyixiang : ' ') + '异常的响声。'
      }
      this.param.sychengxujilu = sychengxujilu
    },
    beforeSaveBuildData() {
      this.buildSyNycx()
    }
  }
}
</script>
<style>
  .underlines{
    width:100px;
    height: 40px;
  }
  .underlines .el-input__inner{
    border-top-style: none;
    border-left-style: none;
    border-right-style: none;
    border-radius: 0px;
    text-align: center;
  }
</style>
