<style>
.customerDialogBox.add-box .add-tit {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 20px;
}
.customerDialogBox.add-box .add-tit p {
  display: flex;
  align-items: center;
  font-weight: bold;
  color: rgba(17, 17, 17, 1);
  font-size: 14px;
}
.customerDialogBox.add-box .add-tit p span {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: #409efe;
  border-radius: 50%;
  margin-right: 10px;
}
.customerDialogBox.add-box .el-dialog__header {
  padding: 15px 20px;
  background: rgba(255, 255, 255, 1);
}
.customerDialogBox.add-box .dialog-footer {
  text-align: center;
  background-color: rgba(248, 250, 251, 1);
  padding-bottom: 20px;
}
.customerDialogBox.add-box .el-dialog__footer {
  padding: 0;
}
.customerDialogBox.add-box .el-dialog__body {
  background-color: rgba(248, 250, 251, 1);
  padding-top: 20px;
  max-height: 500px;
  overflow: auto;
}
.customerDialogBox .add-box-btn.el-button {
  border-radius: 0;
  background-color: #409efecc;
  border-color: #409efecc;
  color: white;
  padding: 12px 43px;
}
.customerDialogBox .add-box-btn.el-button:hover {
  background-color: #409efe;
  border-color: #409efe;
  color: white;
}
.customerDialogBox .add-box-btn.el-button.add-box-cancel {
  color: #409efecc;
  background-color: white;
}
.customerDialogBox .add-box-btn.el-button.add-box-cancel:hover {
  color: #409efe;
  background-color: white;
}
.customerDialogBox .el-input .el-input-group__append {
  background-color: #409efe;
  border-color: #409efe;
  color: #fff;
}
.customerDialogBox .form-box .form-box-tit {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}
.customerDialogBox .form-box .radius {
  display: flex;
  width: 4px;
  height: 4px;
  background: rgba(255, 164, 117, 1);
  border-radius: 50%;
  margin-right: 10px;
}
.customerDialogBox .up-img-box .uib-item {
  margin-right: 30px;
  width: 120px;
  height: 120px;
  background-color: white;
  position: relative;
  margin-bottom: 30px;
}
.customerDialogBox .up-img-box .uib-item p {
  position: absolute;
  bottom: -30px;
  font-size: 12px;
  text-align: center;
  width: 100%;
}
.customerDialogBox .up-img-box .uib-item:hover .imgzhe-btn {
  opacity: 1;
}
.customerDialogBox .imgzhe {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
}
.customerDialogBox .imgzhe .imgzhe-btn {
  background: rgba(0, 0, 0, 0.6);
  width: 100%;
  height: 100%;
  text-align: center;
  line-height: 120px;
  position: absolute;
  top: 0;
  opacity: 1;
  transition: all linear 0.5s;
}
.customerDialogBox .imgzhe .imgzhe-btn i {
  font-size: 22px;
  margin-right: 5px;
  color: white;
  cursor: pointer;
}
.customerDialogBox .up-ctrl {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
}
.customerDialogBox .up-ctrl > div {
  width: 100%;
  height: 100%;
  text-align: center;
  line-height: 140px;
}
</style>
<template>
    <el-dialog :visible.sync="dialogTableVisible" @closed="closedDialog" :close-on-click-modal="false" class="add-box add-box1 customerDialogBox">
        <div class="add-tit" slot="title">
            <p><span></span>{{name}}</p>
            <span icon="el-icon-close"></span>
        </div>
        <div class="form-box" v-if="show">
            <el-form :model="form" ref="form" class="MyEditForm" :rules="rules">
                <p class="form-box-tit"><span class="radius"></span> 基本信息</p>
                <el-row :gutter="30">
                  <el-col :span="8">
                        <div class="MyEditForm-item">
                            <el-form-item label="预计人数" prop="GuestCount">
                                <el-input placeholder="请输入预计人数" onkeyup="this.value=this.value.replace(/[^\d.]/g,'');" v-model="form.GuestCount"></el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                    <el-col :span="8">
                        <div class="MyEditForm-item">
                            <el-form-item label="出发城市" prop="StartCityName">
                                <el-input placeholder="请输入出发城市" v-model="form.StartCityName"></el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                    <el-col :span="8">
                        <div class="MyEditForm-item">
                            <el-form-item label="到达城市" prop="EndCityName">
                                <el-input placeholder="请输入到达城市" v-model="form.EndCityName"></el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                    <!-- <el-col :span="8">
                        <div class="MyEditForm-item">
                            <el-form-item label="商机名称" prop="BusinessName">
                                <el-input placeholder="请输入商机名称" v-model="form.BusinessName"></el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                    <el-col :span="8">
                        <div class="MyEditForm-item">
                            <el-form-item label="客户名称" prop="CustomerId">
                                <el-select v-model="form.CustomerId" :disabled="type==='1' ? true : false" placeholder="请选择客户" v-if="!isGuest">
                                    <el-option 
                                        v-for="item in CustomerList"
                                        :key="item.CustomerId"
                                        :label="item.CustomerName"
                                        :value="item.CustomerId">
                                    </el-option>
                                </el-select>
                                <el-select v-model="form.CustomerId" :disabled="type==='1' ? true : false" placeholder="请选择客户" v-else>
                                    <el-option 
                                        v-for="item in CustomerList"
                                        :key="item.Id"
                                        :label="item.GuestName"
                                        :value="item.Id">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </div>
                    </el-col> -->
                    
                </el-row>
                 <el-row :gutter="30">
                     <el-col :span="8">
                        <div class="MyEditForm-item">
                            <el-form-item label="报价金额" prop="Money">
                                <el-input placeholder="请输入报价金额" onkeyup="this.value=this.value.replace(/[^\d.]/g,'');" v-model="form.Money"></el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <div class="MyEditForm-item label-pad-left">
                            <el-form-item label="备注">
                                <el-input type="textarea" placeholder="订单备注" v-model="form.Remark"></el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                </el-row>
            </el-form>
        </div>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" class="add-box-btn" @click="submitForm('form')">确 定</el-button>
            <el-button class="add-box-btn add-box-cancel" @click="dialogTableVisible = false, resetForm('form')">取 消</el-button>
        </div>
    </el-dialog>
</template>
<script>
export default {
  props: [
    "ID",
    "name",
    "CustomerId",
    "ContactId",
    "type",
    "isGuest",
    "TicketOrderId",
    "GuestId",
  ],
  data() {
    return {
      CustomerList: [],
      LineList: [],
      LineTeamList: [],
      dialogTableVisible: false,
      form: {
        OrderId: 0,
        GuestId: null,
        GuestCount: 1,
        StartCityName: "",
        EndCityName: "",
        Money: null,
        Remark: "",
      },
      BusinessStatusEnum: [],
      rules: {
        GuestCount: [
          { required: true, message: "请选择客户", trigger: "change" },
        ],
        StartCityName: [
          { required: true, message: "请输入出发城市", trigger: "blur" },
        ],
        EndCityName: [
          { required: true, message: "请输入到达城市", trigger: "blur" },
        ],
        Money: [
          { required: true, message: "请输入报价金额", trigger: "change" },
        ],
        Remark: [{ required: true, message: "请输入备注", trigger: "blur" }],
      },
      show: true,
    };
  },
  watch: {
    ID: {
      handler(val, oldVal) {
        console.log(val,'-1-11-');
        this.form.GuestId = val
      },
      deep: true,
    },
    CustomerId: {
      handler(val, oldVal) {
        console.log(val);
      },
      deep: true,
    },
    isGuest: {
      handler(val, oldVal) {
        if (val) {
          this.form.CustomerType = 1;
          this.getGuestList();
        } else {
          this.getCustomerList();
        }
      },
      deep: true,
    },
  },
  mounted() {
    // console.log(this.isGuest);
    if (this.isGuest) {
      this.form.CustomerType = 1;
      this.getGuestList();
    } else {
      this.getCustomerList();
    }
    this.getLineList();
    this.GetBusinessStatusEnum();
    let $this = this;
    if (this.CustomerId !== 0) {
      this.form.CustomerId = this.CustomerId;
    }
    setTimeout(() => {
      $this.dialogTableVisible = true;
    }, 50);
    if (this.ID !== 0) {
      let msg = {
        BusinessId: this.ID,
      };
      if (this.isGuest) {
        msg.CustomerType = 1;
      }
      this.apipost("/api/Customer/GetAllBusinessModel", msg, (res) => {
        if (res.data.resultCode == 1) {
          let data = res.data.data;
          if (data.LineId) {
            this.getLineTeamList(data.LineId, 1);
          }
          this.form = data;
        }
      });
    }
  },
  methods: {
    //获取系列列表
    getLineTeamList(lineId, type) {
      if (!type) {
        this.form.LineteamId = "";
      }
      this.apipost2(
        "b2b_get_GetLineTeam",
        {
          lineId: lineId,
        },
        (res) => {
          if (res.data.resultCode == 1) {
            this.LineTeamList = res.data.data;
          }
        }
      );
    },
    getLineList() {
      this.apipost2("line_post_GetAllList", {}, (res) => {
        if (res.data.resultCode == 1) {
          this.LineList = res.data.data;
        }
      });
    },
    GetBusinessStatusEnum() {
      this.apipost("/api/Customer/GetBusinessStatusEnum", {}, (res) => {
        if (res.data.resultCode == 1) {
          this.BusinessStatusEnum = res.data.data;
        }
      });
    },
    getGuestList() {
      this.apipost("/api/Customer/GetGuesstCustomerByCreateList", {}, (res) => {
        if (res.data.resultCode == 1) {
          this.CustomerList = res.data.data;
        }
      });
    },
    getCustomerList() {
      this.apipost("/api/Customer/GetCustomerListByCreateInfo", {}, (res) => {
        if (res.data.resultCode == 1) {
          this.CustomerList = res.data.data;
        }
      });
    },
    closedDialog() {
      this.MsgBus.$emit("closeTicketOrderDialogBox");
    },
    addData() {
      this.apipost("/api/Order/SetGuestOrderInfo", this.form, (res) => {
        if (res.data.resultCode == 1) {
          this.dialogTableVisible = false;
          // 有id 发送更新抽屉消息
          if (this.CustomerId !== 0) {
            this.$message.success("操作成功");
            this.MsgBus.$emit("RefreshInfoBox");
          } else {
            this.$message.success("操作成功");
          }
          this.$emit("getList");
          this.MsgBus.$emit("RefreshbusSelect");
          this.resetForm("form");
        } else {
          this.$message.error(res.data.message);
        }
      });
    },
    submitForm(addMsg) {
      console.log(this.form, '-----')
      return
      //提交创建、修改表单
      this.$refs[addMsg].validate((valid) => {
        if (valid) {
          this.addData();
        } else {
          return false;
        }
      });
    },
    resetForm(formName) {
      this.MsgBus.$emit("closeTicketOrderDialogBox");
      // 重置表单
      this.form = {
        ID: 0,
        CustomerId: 0,
        BudgetPrice: "",
        LineId: "",
        BusinessName: "",
        BusinessStatus: "",
        LineteamId: "",
        DepartTime: "",
        GuestCount: 0,
        Remark: "",
      };
      this.$refs[formName].resetFields();
    },
  },
};
</script>
