<template>
  <div class="">
    <el-card>
      <el-row style="margin-bottom: 10px;">
          <span style=";font-size: 20px;">兑换详情</span>
      </el-row>
      <el-row :gutter="24">
        <el-col :span="7">
          <el-image 
            style="width: 100px; height: 100px"
            :src="imagePath+dataForm.coverImage"
            fit="cover"></el-image>
        </el-col>
        <el-col :span="15">
          <el-descriptions title="" :colon=false :column="1">
              <el-descriptions-item label="礼品名称:">{{ dataForm.giftName }}</el-descriptions-item>
              <el-descriptions-item label="兑换数量:">{{dataForm.exchangeQuantity}}</el-descriptions-item>
              <el-descriptions-item ></el-descriptions-item>
              <el-descriptions-item label="用户手机号:">
                <el-tag size="small">{{ dataForm.mobile }}</el-tag>
                </el-descriptions-item>
          </el-descriptions>
        </el-col>
      </el-row>
    </el-card>
    <el-card style="margin-top: 20px;">
      <el-form :model="editForm" ref="form" :rules="rules" size="small" :inline="true" label-width="100px">
      <el-row v-if="flag">
        <el-form-item  label="处理结果" prop="processingResult" >
          <el-radio-group :disabled="!flagOrderStart" v-model="editForm.processingResult">
            <el-radio label='0'>快递发货</el-radio>
            <el-radio label='1'>拒绝</el-radio>
          </el-radio-group>

          <span style="display: block; width: 400px; color: red;font-size: 10px;">用户的收货地址请在订单详情中查看
如当前实物礼品关联商品信息,将会在发货完成后直接更新对应的商品库存</span>

        </el-form-item>
      </el-row>
      <el-row v-if="!flag">
        <el-form-item   label="处理结果2" prop="processingResult" >
          <el-radio-group :disabled="!flagOrderStart" v-model="editForm.processingResult">
            <el-radio label='0'>快递发货</el-radio>
            <el-radio label='1'>拒绝</el-radio>
          </el-radio-group>

          <span style="display: block; width: 400px; color: red;font-size: 10px;">用户的收货地址请在订单详情中查看
如当前实物礼品关联商品信息,将会在发货完成后直接更新对应的商品库存</span>

        </el-form-item>
      </el-row>
      <template v-if="editForm.processingResult == 0 " && flag>
        <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item label="快递公司" prop="courierCompanies">
            <el-select v-model="editForm.courierCompanies" style="width: 150px" placeholder="全部">
              <el-option
              v-for="dict in dict.type.courier_companies"
                  :key="dict.label"
                  :label="dict.label"
                  :value="dict.label"
              />
              <el-option value="0" label="其他快递"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col v-if="editForm.courierCompanies == '0'" :span="12">
          <el-form-item label="快递名称" label-width="80px" prop="name">
          <el-input v-model="editForm.name" style="width: 150px"></el-input>
        </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-form-item label="快递单号" prop="theTrackingNumber">
          <el-input v-model="editForm.theTrackingNumber" style="width: 250px"></el-input>
        </el-form-item>
      </el-row>
      </template>
      <el-row>
        <el-form-item label="处理备注">
          <el-input type="textarea" v-model="editForm.notes" style="width: 250px"></el-input>
          </el-form-item>
      </el-row>
    </el-form>
    <div style="float: right; margin-bottom: 20px;">
        <el-button type="primary" @click="submit">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-card>
  </div>
</template>

<script>
import {updateOrderApi} from "@/api/integral/order";

export default {

  name: "outcome",
  dicts: ['zhzt','lplx','courier_companies',],

  props: {
    dataForm:{},
    flagOrderStart:false,
  },
  data() {
    return {
      editForm:{
        processingResult:'0', //处理结果
        courierCompanies:'', //
        name:'', //
        theTrackingNumber:'', //单号
        notes:'', //溃堤单号
      },
      flag:true,
      stateFlag: true,
      // 图片根目录
      imagePath: process.env.VUE_APP_SERVER_URL,

      rules:{
        processingResult: [
          { required: true, message: "请选择处理结果", trigger: "change" },
        ],
        courierCompanies: [
          { required: true, message: "请选择快递公司", trigger: "blur" },
        ],
        name: [
          { required: true, message: "快递名称不能为空", trigger: "blur" },
        ],
        noites: [
          { required: true, message: "快递单号不能为空", trigger: "blur" },
        ],
      }
    }
  },

  created(){
    console.log("dataForm",this.dataForm)
    console.log("flagOrderStart",this.flagOrderStart)
    if (this.dataForm.shippingType=="物流配送") {
      this.flag == true
    }else {
      this.flag == false
    }
    

    // 回显
    if (!this.flagOrderStart) {
      this.editForm.courierCompanies = this.dataForm.courierCompanies
      this.editForm.theTrackingNumber = this.dataForm.theTrackingNumber
      this.editForm.notes =  this.dataForm.notes
    }
		if (this.dataForm.orderStatus == '已拒绝') {
			this.editForm.processingResult='1' //处理结果
		}
   
  },
  methods: {

  submit: function() {
    let this_ = this

    this_.$refs["form"].validate(valid => {
        if (valid) {
          let file = {
            id : this_.dataForm.id,
            orderStatus: '',
            courierCompanies:this_.editForm.courierCompanies,
            theTrackingNumber:this_.editForm.theTrackingNumber, //单号
            notes:this_.editForm.notes, //溃堤单号
          }

          if (this.editForm.processingResult == '1') {
            file.orderStatus='已拒绝'
          }else if (this.flag) {
            file.orderStatus='已发货'
          } else {
            file.orderStatus='已完成'
          }
          if (this_.editForm.courierCompanies == 0) {
            file.courierCompanies = file.name
          }
          updateOrderApi(file).then(res=>{
            this.$modal.msgSuccess("处理成功");

          })
        }
      })
    this.$emit('send-data', 'Data from child');
  },
  cancel() {
    this.$emit('send-data', 'Data from child');
  }
  

  }
}
</script>

<style scoped>

</style>
