<!-- 质检详情 -->
<template>
  <div class="container">
    <div class="tab-nav">
      <div class="date-filter-wrap" style="width: 100%;justify-content: space-between">
        <span style="font-size: 14px;font-weight: bold;color: black">质检详情</span>
        <span style="cursor: pointer" @click="back">&lt;&lt;返回</span>
      </div>
    </div>
    <div class="border"></div>
    <div>
      <div class="row">
        <div class="col">
          <div class="label">合同编码：</div>
          <div class="value">{{ infoData.purchaseBillNo }}</div>
        </div>
        <div class="col">
          <div class="label">批次号：</div>
          <div class="value">{{ infoData.batchNo }}</div>
        </div>
        <div class="col">
          <div class="label">物料编码：</div>
          <div class="value">{{ infoData.materialCode }}</div>
        </div>
        <div class="col">
          <div class="label">物料名称：</div>
          <div class="value">{{ infoData.materialName }}</div>
        </div>
        <div class="col">
          <div class="label">到货时间：</div>
          <div class="value">{{ infoData.arrivalDate }}</div>
        </div>
        <div class="col">
          <div class="label">到货数量：</div>
          <div class="value">{{ infoData.quantity }}</div>
        </div>
      </div>
      <div class="row">
        <div class="col">
          <div class="label">质检人员：</div>
          <div class="value">{{ infoData.checkUserName }}</div>
        </div>
        <div class="col">
          <div class="label">质检时间：</div>
          <div class="value">{{ infoData.checkDate }}</div>
        </div>
        <div class="col">
          <div class="label">质检面积：</div>
          <div class="value">{{ infoData.checkSquare }}</div>
        </div>
        <div class="col">
          <div class="label">质检结论：</div>
          <div class="value">{{ infoData.result }}</div>
        </div>
        <div class="col"></div>
        <div class="col"></div>
      </div>
    </div>
    <div class="border"></div>
    <div class="table-filter" style="height: auto">
      <div class="filter-item" style="margin-right: 0">
        <RadioGroup @on-change="stateChange">
          <Radio :label="''">
            全部
            <span style="color: #f11111">（{{ data.length }}）</span>
          </Radio>
          <Radio :label="1">
            合格
            <span style="color: #f11111">（{{ data.filter(item => item.checkJudgmentStr === '合格').length }}）</span>
          </Radio>
          <Radio :label="2">
            不合格
            <span style="color: #f11111">（{{ data.filter(item => item.checkJudgmentStr !== '合格').length }}）</span>
          </Radio>
        </RadioGroup>
      </div>
    </div>
    <div class="main">
      <my-table :data="filterData" :columns="columns" :is-show-filter="false" :is-show-page="false" :table-page="params"></my-table>
    </div>
  </div>
</template>

<script>
import MyTable from '_c/my-table/my-table'
import { GetContractQtyCheckBill } from '@/api/applyPurchase'
import { openPic } from '@/libs/util'
export default {
  name: 'quality_record_detail',
  components: {
    MyTable
  },
  data () {
    return {
      infoData: {},
      data: [],
      filterData: [],
      columns: [
        {
          title: '序号',
          type: 'index',
          width: 60,
          align: 'center'
        },
        {
          title: '物料标签值',
          key: 'rfidCode',
          minWidth: 200
        },
        {
          title: '抽检米数',
          key: 'checkQty',
          minWidth: 150
        },
        {
          title: '短少',
          key: 'lakeNum',
          minWidth: 150
        },
        {
          title: '抽纱',
          key: 'drawnworkNum',
          minWidth: 150
        },
        {
          title: '褶皱',
          key: 'foldNum',
          minWidth: 150
        },
        {
          title: '脏污',
          key: 'dirtNum',
          minWidth: 150
        },
        {
          title: '破洞',
          key: 'potholeNum',
          minWidth: 150
        },
        {
          title: '缩水',
          key: 'shrinkPercent',
          minWidth: 150
        },
        {
          title: '质检结论',
          key: 'checkJudgmentStr',
          minWidth: 150
        },
        {
          title: '图片',
          key: 'imageUrl',
          minWidth: 200,
          render: (h, params) => {
            let arr = params.row.imageUrl.split(',')
            let els = []
            arr.forEach(item => {
              els.push(
                h('p', {
                  style: {
                    cursor: 'pointer',
                    color: 'blue',
                    padding: '3px 0',
                    textDecoration: 'underline'
                  },
                  on: {
                    click () {
                      openPic(item)
                    }
                  }
                }, item.split('/')[item.split('/').length - 1])
              )
            })
            return h('div',
              els
            )
          }
        }
      ],
      params: {
        pageIndex: 1,
        pageSize: 20,
        total: 0
      }
    }
  },
  watch: {
    /* 相同详情页面 数据刷新问题 */
    $route (to, from) {
      this.infoData = JSON.parse(this.$route.query.data)
      this.getList()
    }
  },
  methods: {
    back () {
      this.$store.commit('closeTag', this.$route)
      setTimeout(() => {
        this.$router.push('quality_record')
      }, 500)
    },
    stateChange (val) {
      if (val === 1) {
        this.filterData = this.data.filter(item => item.checkJudgmentStr === '合格')
      } else if (val === 2) {
        this.filterData = this.data.filter(item => item.checkJudgmentStr !== '合格')
      } else {
        this.filterData = [ ...this.data ]
      }
    },
    getList () {
      GetContractQtyCheckBill({
        purchaseBillNo: this.infoData.purchaseBillNo,
        qtyCheckNo: this.infoData.qtyCheckNo
      }).then(res => {
        if (res.code === 0) {
          this.data = res.result[0] && res.result[0].checkDetails
          this.filterData = [ ...this.data ]
        }
      })
    }
  },
  mounted () {
    this.infoData = JSON.parse(this.$route.query.data)
    this.getList()
  }
}
</script>

<style lang="less" scoped>
.container {
  height: 100%;
  display: flex;
  flex-direction: column;
  .tab-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    .date-filter-wrap {
      display: flex;
      align-items: center;
    }
  }
  .row {
    margin-bottom: 5px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    width: 100%;
    &:last-child {
      margin-bottom: 0;
    }
    .col {
      padding: 0 5px;
      flex: 1;
      overflow: hidden;
      display: flex;
      align-items: flex-start;
      .label {
        font-weight: bold;
        white-space: nowrap;
      }
    }
  }
  .main {
    flex: 1;
    overflow: hidden;
  }
  .border {
    margin: 10px 0;
    width: 100%;
    height: 1px;
    background-color: #d7d7d7;
  }
}
.table-filter {
  padding-bottom: 10px;
  height: 42px;
  line-height: 32px;
  overflow: hidden;
  .filter-item {
    margin-right: 10px;
    float: left;
  }
}
</style>
