OrderStatusList.vue 3.02 KB
<template>
  <view class="list">
    <view @click="currentId = ''" :class="['item flex', { active: !currentId }]">
      <view class="sprite-icon icon-tag-checked"></view>
      全部
    </view>
    <template v-for="(i, index) in list">
      <view :key="index" @click="currentId = i.id" :class="['item flex', { active: currentId == i.id }]">
        <view class="sprite-icon icon-tag-checked"></view>
        {{ i.name }}
      </view>
    </template>
  </view>
</template>

<script type="text/ecmascript-6">
export default {
  name: 'OrderStatusList',
  inject: ['userInfo'],
  data () {
    return {
          // 订单状态 (0待报价、1待确认、2待支付、3已支付、5已完成、6已退款、9已撤销、11错误订单、-1战败)
      list: Object.freeze([
        {
          name: '待报价',
          value: 0,
          id: 1
        },
        {
          name: '待确认',
          value: 1,
          id: 2
        },
        {
          name: '待支付',
          value: 2,
          id: 3
        },
        {
          name: '已支付',
          value: 3,
          id: 4
        },
        {
          name: '已完成',
          value: 5,
          id: 5
        },
        {
          name: '已退款',
          value: 6,
          id: 6
        },
        {
          name: '已撤销',
          value: 9,
          id: 7
        },
        {
          name: '错误订单',
          value: 11,
          id: 8
        },
        {
          name: '战败',
          value: -1,
          id: 11
        }
      ]),
      currentId: '',
    }
  },
  props: {
    params: Object,
    data: [Array, Object],
  },
  watch: {
    currentId: {
      handler (val) {
        let { params: { idKey } } = this,
          { list } = this,
          item = list.find(item => item.id == val)
        this.$emit('choose', {
          key: idKey,
          value: item ? item.value : null
        })
      },
      deep: true
    }
  },
  mounted () {
    this.initList()
  },
  methods: {
    initList () {
      let { data, params: { idKey }, list } = this
      console.log(data, idKey ,'32938928392')
      if (data[idKey] !== undefined && data[idKey] !== null && data[idKey] !== '') {
        let item = list.find(val => val.value == data[idKey])
        this.currentId = item ? item.id : ''
      }
      this.$emit('onComplete')
    }
  }
}
</script>

<style scoped lang="scss">
.list {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: toRpx(32);
  margin: 0 toRpx(48);
  .item {
    justify-content: center;
    height: toRpx(72);
    border-radius: toRpx(8);
    border: toRpx(2) solid #dce0e6;
    box-sizing: border-box;
    position: relative;
    color: #333333;
    font-size: toRpx(32);
    .sprite-icon {
      display: none;
      position: absolute;
      top: 0;
      right: 0;
    }
  }
  .splice {
    color: #333333;
    font-size: toRpx(32);
    margin: 0 toRpx(8);
  }
  .active {
    border-color: #2c66f7;
    background: #ecf1ff;
    color: #2c66f7;
    .sprite-icon {
      display: block;
    }
  }
}
</style>