
<template>
  <div class="list-contain">
    <top-nav title="样品列表"
             @query="onSearch"
             :backFunc="returnLast"></top-nav>
    <van-list v-model="loading"
              :finished="finished"
              finished-text="没有更多了"
              @load="onLoad"
              class="data-list">
      <div>
        <van-pull-refresh v-model="loading"
                          @refresh="onRefresh">
          <div v-for="(item, index) in this.tableData"
               :key="index"
               @click="editDetail(item)">
            <div class="data-item">
              <div class="row">
                <div class="left">
                  <span class="fb">{{ item.sampleLineCode }}</span>
                </div>
                <div class="fc8CEE fs28">{{ item.sampleStatusKey }}</div>
              </div>
              <div class="row">
                <div class="left">
                  <span>客户名称：</span>
                  <span class="fc666">{{ item.customer }}</span>
                </div>
                <!-- <div class="right">
                  <span>FW版本：</span>
                  <span class="fc666">{{item.fwVersion}}</span>
                </div> -->
              </div>
              <div class="row">
                <div class="left">
                  <span>代理商：</span>
                  <span class="fc666">{{ item.deptName }}</span>
                </div>
              </div>
              <div class="row">
                <div class="left">
                  <span>FW版本：</span>
                  <span class="fc666">{{item.fwVersion}}</span>
                </div>
              </div>
              <div class="row">
                <div class="left">
                  <span>项目编码：</span>
                  <span class="fc666">{{ item.projectCode }}</span>
                </div>
              </div>
              <div class="row">
                <div class="left">
                  <span>标准PN：</span>
                  <span class="fc666">{{ item.longsysPN}}</span>
                </div>
              </div>
              <div class="row">
                <div class="left">
                  <span>芯片平台：</span>
                  <span class="fc666">{{item.platform}}</span>
                </div>
              </div>
              <div class="row">
                <div class="left">
                  <span>芯片型号：</span>
                  <span class="fc666">{{ item.chipModel}}</span>
                </div>
              </div>
              <div class="row">
                <div class="left">
                  <span>申请数量：</span>
                  <span class="fc666">{{ parseFloat(item.applyQuantity).toLocaleString()}}</span>
                </div>
              </div>
              <div class="row">
                <div class="left">
                  <span>料号：</span>
                  <span class="fc666">{{item.num}}</span>
                </div>
                <div class="right">
                  <img src="@/assets/images/photo.png" />
                  <span class="fc666">{{ item.salesName }}</span>
                </div>
              </div>
            </div>
          </div>
        </van-pull-refresh>
      </div>
    </van-list>
    <search-popup ref="searchRef"
                  @searchClose="searchClose"></search-popup>
  </div>
</template>

<script>
import searchPopup from './search-popup'
import clearkeepAlive from '../../../common/clearkeepAlive'
export default {
  name: 'sample-list',
  components: { searchPopup },
  props: { activeName: String },
  mixins: [clearkeepAlive],
  data () {
    return {
      tableData: [],
      loading: false,
      finished: false,
      form: {},
      // 分页参数
      pager: {
        curPage: 1,
        pageSize: 10,
        total: 0
      }
    }
  },
  methods: {
    onSearch (val) {
      this.$refs.searchRef.showSamplePopup = true
    },
    searchClose (form) {
      this.$refs.searchRef.showSamplePopup = false
      this.reLoad(form)
    },
    editDetail (row) {
      this.$router.push({ name: 'sampleDetail', params: row })
    },
    onRefresh () {
      this.reLoad(this.form)
    },
    reLoad (form) {
      this.pager.curPage = 1
      this.tableData = []
      this.form = form
      this.finished = false
      this.loading = true
      this.onLoad()
    },
    onLoad () {
      let param = {
        currPage: this.pager.curPage,
        pageSize: this.pager.pageSize,
        queryParam: this.form
      }
      this.$axios.post({
        domain: 'crmUrl',
        url: 'sample.listPageSampleByProjectId',
        requestType: 'body',
        data: param,
        success: function (res) {
          if (res.success) {
            let data = res.data.records || []
            this.tableData = [...this.tableData, ...data]
            this.pager.curPage++
            this.loading = false
            if (data.length < this.pager.curPage || data.length === 0) {
              this.finished = true
            }
          } else {
            this.$toast.fail(res.msg)
            this.finished = true
          }
        }.bind(this),
        error: function (res) {
          this.$toast.fail(res.msg)
          this.finished = true
        }.bind(this)
      })
    },
    returnLast () {
      this.clearCache()
      this.$router.back(-1)
    }
  }
}
</script>
