<template>
  <div>
    <el-form ref="ruleForm" :model="ruleForm" label-width="80px">
      <el-form-item label="快递" prop="F_Express" >
        <el-select v-model="ruleForm.express" placeholder="请选择快递" class="form_select" clearable>
          <el-option v-for="item in expressList" :key="item.F_Value" :label="item.F_Value" :value="item.F_Value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm()">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { orderListCustomerServiceBulkExpress } from "@/api/customerServiceManagement/orderListCustomerService";
import { getDictionaryValueList } from '@/api/commonAPI'

export default {
  props: {
    rowid: {
      type: Array,
      default: [],
    },
    layerid: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      expressList: [], //快递
      ruleForm: {
        orderids: "", //订单编号
        express: "",
      },
    };
  },
  created() {
    this.getExpress()
    if (this.rowid) {
      this.ruleForm.orderids = this.rowid.join(',').replace(/\s+/g, '')
    }
  },
  methods: {
    submitForm() {
      orderListCustomerServiceBulkExpress(this.ruleForm)
        .then((response) => {
          if (response.state.toLowerCase() === "success") {
            this.$parent.$layer.close(this.layerid);
            this.$parent.getList(); // 重新加载父级数据
            this.$message.success("恭喜你，批量物流成功!");
          }
        })
        .catch(() => {
          this.loading = false;
        });
    },
    // 获取快递
    getExpress() {
      return new Promise(resolve=>{
        const params={
          isleaf:true,
          code:'EXPRESS'
        }
        getDictionaryValueList(params).then(response=>{
          if(response.state.toLowerCase() === 'success'){
            this.expressList = response.data.Rows
          }
        })
      })
    },
  },
};
</script>
<style lang="scss" scoped>
.form_select{
  width: 100%
}
</style>