<template>
  <view class="page">
    <view class="search-container">
      <view class="input-con">
        <view class="input">
          <image src="/static/image/search.png" mode=""></image>
          <input
            v-model="keyword"
            @confirm="searchList"
            confirm-type="search"
            class="f28_302"
            type="text"
            placeholder="输入工单编号或者用户名称进行搜索"
          />
        </view>
      </view>
    </view>

    <view class="list-container">
      <view class="item" v-for="(item, index) in dataList" :key="index" @tap.stop="toDetail(item.id)">
        <view class="main">
          <view class="row">
            <text class="label number">工单单号</text>
            <text class="value number">{{ item.dispatchOrderNo }}</text>
          </view>
          <view class="row">
            <text class="label">预约时间</text>
            <text class="value">{{ item.reportDate }}</text>
          </view>
          <view class="row">
            <text class="label">完工时间</text>
            <text class="value">{{ item.repairDate }}</text>
          </view>
          <view class="row">
            <text class="label">用户姓名</text>
            <text class="value">{{ item.userName }}</text>
          </view>
          <view class="row">
            <text class="label">总费用</text>
            <text class="value">{{ item.totalFee }}</text>
          </view>
        </view>
      </view>
    </view>

    <view v-if="dataList.length <= 0" class="no-text">
      <image src="/static/image/no-data.png"></image>
      <view class="texts">暂无数据</view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      salaryNo: null,
      summaryBatchNo: null,
      type: null,
      keyword: '',
      dataList: []
    }
  },

  // 下拉刷新
  onPullDownRefresh() {
    this.getList()
  },

  onLoad({ salaryNo, summaryBatchNo, type }) {
    this.salaryNo = salaryNo
    this.summaryBatchNo = summaryBatchNo
    this.type = type

    const { websit_number, number } = this.$store.state.userInfo.websit_worker
    this.websitNumber = websit_number
    this.workerNumber = number

    this.getList()
  },

  methods: {
    // 获取列表
    getList() {
      let url = ''
      let params = {}
      if (this.type == 1) {
        url = '/daily/mywallet/repair/detail'
        params = {
          workerNumber: this.workerNumber,
          salaryNo: this.salaryNo || '',
          summaryBatchNo: this.summaryBatchNo || '',
          q: this.keyword
        }
      } else if (this.type == 2) {
        url = '/daily/mywallet/repair/month/detail'
        params = {
          workerNumber: this.workerNumber,
          salaryNo: this.salaryNo || '',
          summaryBatchNo: this.summaryBatchNo || '',
          q: this.keyword
        }
      } else {
        url = '/daily/mywallet/not/issue/list'
        params = {
          workerNumber: this.workerNumber,
          salaryNo: this.salaryNo || '',
          summaryBatchNo: this.summaryBatchNo || '',
          q: this.keyword,
          install: false
        }
      }

      this.$axios({
        url,
        method: 'get',
        params,
        isLoading: 1
      })
        .then(res => {
          this.dataList = res.data
        })
        .finally(() => {
          uni.stopPullDownRefresh()
        })
    },

    searchList() {
      this.getList()
    },

    toDetail(id) {
      uni.navigateTo({
        url:
          '/packageMine/pages/repairSettle/detail?salaryNo=' +
          (this.salaryNo || '') +
          '&summaryBatchNo=' +
          (this.summaryBatchNo || '') +
          '&id=' +
          id +
          '&type=' +
          this.type
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.page {
}

.search-container {
  background-color: #ffffff;
  width: 100%;
  border-bottom: 2rpx solid #e5e5e5;
  padding: 0 30rpx;

  .input-con {
    @include flex_ac;
    height: 88rpx;
    width: 100%;

    .input {
      @include flex_ac;
      flex: 1;
      padding: 0 24rpx;
      height: 64rpx;
      background: #f7f7f7;
      border-radius: 32rpx;

      input {
        flex: 1;
      }

      image {
        width: 28rpx;
        height: 28rpx;
        margin-right: 16rpx;
      }
    }
  }
}

.list-container {
  padding: 30rpx 30rpx 0;

  .item {
    margin-bottom: 20rpx;

    &:last-child {
      margin-bottom: 0;
    }

    .date {
      font-size: 30rpx;
      color: #666666;
      margin-bottom: 10rpx;
    }

    .main {
      color: #666666;
      background: #ffffff;
      padding: 15rpx 30rpx;
      border-radius: 20rpx;

      .row {
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 60rpx;

        .label {
          font-size: 28rpx;
          color: #666666;
        }

        .value {
          font-size: 28rpx;
          color: #333333;

          &.orange {
            color: #e95505;
          }
        }

        .number {
          color: #333333;
        }
      }
    }
  }
}

.no-text {
  height: 100%;
  width: 100%;
  margin-top: 50rpx;
  text-align: center;

  image {
    width: 450rpx;
    height: 250rpx;
    margin-bottom: 40rpx;
  }

  .texts {
    color: #cccccc;
    font-size: 28rpx;
  }
}
</style>
