<template>
  <view class="z-popup">
    <view class="zhuangtaitubiao" style="justify-content: flex-start !important">
      <view class="title">接收确认</view>
      <view class="row">
        <view class="label">客户名称：</view>
        <view class="value">{{ detail.userName }}</view>
      </view>
      <view class="row">
        <view class="label">客户电话：</view>
        <view class="value">{{ detail.userMobile }}</view>
      </view>
      <view class="row">
        <view class="label">客户地址：</view>
        <view class="value">{{ detail.address }}</view>
      </view>
      <view class="row">
        <view class="label">选择小工：</view>
        <view class="value price">
          <checkbox-group @change="changeXz" style="width: 100%">
            <label
              v-for="(item, index) in workerList"
              :key="index"
              style="width: 50%; display: inline-block; margin-bottom: 20rpx"
            >
              <checkbox :value="item.workerId" :checked="item.isSelect" />{{ item.workerName }}
            </label>
          </checkbox-group>
        </view>
      </view>
      <view class="kakakakak">
        <u-button text="取消"></u-button>
        <view style="min-width: 30rpx" @click="quxiao"></view>
        <u-button type="primary" text="确认接收" @click="querenss"></u-button>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    detail: {
      type: Object,
      default: () => ({})
    },
    type: {
      type: [String, Number],
      default: 0
    },
    callback: {
      type: Function,
      default: () => {}
    }
  },
  data() {
    return {
      workerList: [],
      checkboxValues: []
    }
  },
  mounted() {
    this.getBrandList()
  },
  methods: {
    getBrandList() {
      if (this?.detail?.id) {
        this.$api
          .post('/pg/order/base/slave/worker/team', {
            orderBaseId: this?.detail?.id
          })
          .then(res => {
            this.workerList = res.data
          })
      }
    },
    changeXz(v) {
      this.checkboxValues = v.target.value
    },
    querenss() {
      if (this.type == 1) {
        // 接单
        this.$modal({
          title: '接单确认',
          content: '确认接单？'
        })
          .then(() => {
            this.$api
              .post('/pg/order/base/rece', {
                orderBaseId: this.detail.id,
                workerList: this.checkboxValues.join(',')
              })
              .then(res => {
                this.callback?.()
              })
          })
          .catch(() => {})
      } else if (this.type == 2) {
        // 抢单
        this.$modal({
          title: '抢单确认',
          content: '确认抢单？'
        })
          .then(() => {
            this.$api
              .post('/pg/order/base/qd', {
                orderBaseId: this.detail.id,
                workerList: this.checkboxValues.join(',')
              })
              .then(res => {
                this.callback?.()
              })
          })
          .catch(() => {})
      } else if (this.type == 3) {
        // 更换
        this.$modal({
          title: '更换小工确认',
          content: '确认更换？'
        })
          .then(() => {
            this.$api
              .post('/pg/order/base/change/slave/worker/team', {
                orderBaseId: this.detail.id,
                workerList: this.checkboxValues.join(',')
              })
              .then(res => {
                this.callback?.()
              })
          })
          .catch(() => {})
      }
    },
    quxiao() {
      this.$emit('close')
    }
  }
}
</script>

<style scoped lang="scss">
.z-popup {
  position: fixed;
  background: rgba(0, 0, 0, 0.2);
  width: 100%;
  height: 100vh;
  z-index: 1000000000;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  transition: top 0.5s;
  box-sizing: border-box;
  padding: 60rpx;
  display: flex;
  justify-content: center;
  align-items: center;
  .zhuangtaitubiao {
    width: 100%;
    height: auto;
    box-sizing: border-box;
    padding: 30rpx;
    background: #fff;
    border-radius: 20rpx;
    margin-bottom: 50rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
  }
  .title {
    font-size: 28rpx;
    font-weight: bold;
    align-items: left;
  }
  .row {
    display: flex;
    align-items: left;
    margin-top: 30rpx;
    width: 100%;
    .label {
      color: $sec-font;
      min-width: 160rpx;
    }
    .price {
      width: 100%;
    }
  }
  .kakakakak {
    width: 100%;
    height: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 40rpx;
  }
}
</style>
