XhParts.vue 3.87 KB
<!-- *******************  配件选择  *******************  -->
<template>
	<view>
    <view class="list u-flex u-row-between">
			<image class="item-image" :src="mixingImage" v-if="item.required"></image>
			<view class="u-m-r-20">{{item.fieldsTitle}}</view>
			<view class="u-flex-1 add-parts" @click="toParts" v-if="!disabled">
				添加备件<u-icon name="arrow-right" color="#2979ff" size="30"></u-icon>
			</view>
		</view>
    <view class="complete-part">
      <view v-if="lists.length > 0">
        <adjust-parts v-for="(item, index) in lists" :key="index" :info="item" @change="partsChange($event, index)" :disabled="disabled"></adjust-parts>
      </view>
      <view class="u-flex select-part"  v-else>
        <view class="img">
          <image :src="noPartsImage" class="part-icon" />
        </view>
        <view class="u-flex content">
          <text class="title">暂无备件信息</text>
          <text class="desc">可选择备件仓配件</text>
        </view>
        <view class="btn">
          <u-button shape="circle" :custom-style="customStyle" @click="toParts">
            去选择
          </u-button>
        </view>
      </view>
    </view>
	</view>
</template>

<script>
  import adjustParts from "@/components/select-parts/adjust"
	import stringMixin from './stringMixin'
	export default {
		name: 'XhParts',
		components: {
      adjustParts
    },
		mixins: [stringMixin],
		props: {
			orderId: {
				type: String,
				default: ''
			}
		},
		data() {
			return {
        lists: []
			}
		},
    computed: {
      customStyle() {
				return {
					'width': '200rpx',
					'height': '80rpx',
					'color': '#2272FF',
					'font-size': '32rpx',
				}
			},
      mixingImage() {
				return process.uniEnv.qn_base_url + 'mixing.png'
			},
      noPartsImage() {
				return process.uniEnv.qn_base_url + 'no_parts.png'
			},
    },
    mounted() {
      this.getWorkOrderParts()
    },
		methods: {
      getWorkOrderParts() {
        // this.lists = JSON.parse(this.dataValue) || []
		this.lists = this.dataValue ? JSON.parse(this.dataValue) : []
      },
			partsChange(val, index) {
        this.$set(this.lists[index], 'quantity', val)
        this.valueChange(JSON.stringify(this.lists))
      },
      valChange(val) {
        val.forEach(v => {
          const index = this.lists.findIndex(k => k.part_id === v.part_id)
          if (index < 0) {
            this.lists.push(v)
          } else {
            this.$set(this.lists, index, v)
          }
        })
        this.valueChange(JSON.stringify(this.lists))
      },
      toParts() {
        uni.navigateTo({
          url: `/pages/order/parts?workOrderId=${this.orderId}`
        })
      }
		}
	}
</script>

<style lang="scss" scoped>
  .item-image {
    width: 24rpx;
    height: 24rpx;
    margin-right: 10rpx;
  }
  .required {
    padding-right: 10rpx;
    font-size: 28rpx;
    line-height: 40rpx;
    color: #fa3534;
	}
  .add-parts {
    color: #2272FF;
		text-align: right;
  }
	.complete-part {
    .select-part {
      align-items: center;
      height: 240rpx;
      .img {
        display: flex;
        align-items: center;
        margin-right: 30rpx;
        .part-icon {
          width: 110rpx;
          height: 110rpx;
          border-radius: 50%;
        } 
      }
      .content {
        padding-right: 8px;
        flex: 1;
        color: #3b4144;
        flex-direction: column;
        justify-content: space-between;
        overflow: hidden;
        .title {
          text-align: left;
          color: #2272FF;
          font-size: 38rpx;
          font-weight: bold;
          margin-right: auto;
        }
        .desc {
          text-align: left;
          color: #999;
          font-size: 26rpx;
          margin-right: auto;
        }
      }
    }
  }
</style>