<style scoped>
  .CLM-Form .el-input__inner {
    background: transparent;
    border: 0;
  }

  .CLM-Form .el-input-group__append {
    background: transparent;
    border: 0;
  }

  .common_Style {
    display: inline-block;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    text-align: center;
    line-height: 30px;
  }

  .classForm_monday {
    background-color: #ced9f8;
    color: #2961FE;
  }

  .classForm_tuesday {
    background-color: #d9f3ff;
    color: #3FC4FF;
  }

  .classForm_wednesday {
    background-color: #f6e2cb;
    color: #F28C1D;
  }

  .classForm_thursday {
    background-color: #ccf3eb;
    color: #02C499;
  }

  .classForm_friday {
    background-color: #f7cfd6;
    color: #F72E52;
  }

  .classForm_saturday {
    background-color: #fff5cc;
    color: #FFCC00;
  }

  .classForm_sunday {
    background-color: #e6e3fe;
    color: #8175FB;
  }

  .planTimeLi2 tbody::before {
    content: '';
    display: table-row;
    height: 20px;
  }

  .customerPhoto {
    width: 55px;
    height: 55px;
  }

  .customerPhoto img {
    width: 100%;
    height: 100%;
  }

  /deep/ .q-field__before,
  /deep/ .q-field__prepend {
    padding-right: 0px !important;
  }
</style>
<template>
  <q-dialog v-model="persistent" content-class="bg-grey-1" persistent transition-show="scale">
    <q-card style="width: 400px;max-width:400px;" class="CLM-Form">
      <q-card-section>
        <div class="text-h6">{{optionTitle}}</div>
      </q-card-section>
      <q-card-section class="q-pt-none scroll" style="max-height: 70vh">
        <div class="row wrap">
          <div class="col-12">
            <q-input filled stack-label maxlength="20" :dense="false" v-model="objOption.CategoryName"
              ref="CategoryName" class="col-12 q-pb-lg" label="名称" :rules="[val => !!val || '请填写客户名称']" />
          </div>
        </div>
        <div class="row wrap">
          <div class="col-12">
            <q-select stack-label color="primary" filled label="类型" option-value="Id" option-label="Name"
              ref="CatetoryType" :options="typeList" class="q-pb-lg" v-model="objOption.CatetoryType"
              :rules="[val => !!val || '请选择类型']" emit-value map-options />
          </div>
        </div>
        <div class="row wrap">
          <div class="col-12">
            <q-field filled label="签约状态" stack-label>
              <template v-slot:control>
                <q-radio dense v-model="objOption.IsContract" :val="0" label="未签约" size="xs" />
                &nbsp;&nbsp;
                <q-radio dense v-model="objOption.IsContract" :val="1" label="已签约" size="xs" />
              </template>
            </q-field>
          </div>
        </div>
        <div class="row wrap" style="margin-top:20px;">
          <div class="col-12">
            <template v-if="objOption.IsContract==1">
              <el-upload class="upload-demo" action="" :show-file-list="false" :http-request="UploadAttachment"
                :multiple="uploadMultple">
                <q-btn color="accent" size="sm" icon="add" label="上传同行合同" />
              </el-upload>
              <a v-if="objOption.ContractUrl" style="margin-left:10px;color:#2961FE;text-decoration:none;"
                :href="objOption.ContractUrl" target="_blank">
                <template v-if="fileObj.FileName&&fileObj.FileName!=''">
                  {{fileObj.FileName}}
                </template>
                查看合同</a>
            </template>
          </div>
        </div>
        <template v-if="isShowTel">
          <div class="row wrap">
            <div class="col-12">
              <q-input filled stack-label maxlength="20" :dense="false" v-model="objOption.linkMan" ref="linkMan"
                class="col-12 q-pb-lg" label="联系人" :rules="[val => !!val || '请填写联系人']" />
            </div>
          </div>
          <div class="row wrap">
            <div class="col-12">
              <q-input filled stack-label maxlength="20" :dense="false" v-model="objOption.linkTel" ref="linkTel"
                class="col-12 q-pb-lg" label="联系电话" />
            </div>
          </div>
        </template>
        <div class="row wrap">
            <div class="col-12">
              <q-input filled stack-label maxlength="20" :dense="false" v-model="objOption.RebateRate" ref="RebateRate"
                class="col-12 q-pb-lg" label="返佣比例%" />
            </div>
          </div>
          <div class="row wrap">
            <div class="col-12">
              <q-input filled stack-label maxlength="20" :dense="false" v-model="objOption.RebateMoney" ref="RebateMoney"
                class="col-12 q-pb-lg" label="返佣固定金额" />
            </div>
          </div>
      </q-card-section>
      <q-separator />
      <q-card-actions align="right" class="bg-white">
        <q-btn label="取消" flat color="grey-10" style="font-weight:400 !important" @click="closeCourseForm" />
        <q-btn label="保存" color="accent q-px-md" style="font-weight:400 !important" :loading="saveCustomLoading"
          @click="saveCourse">
        </q-btn>
      </q-card-actions>
    </q-card>
  </q-dialog>
</template>
<script>
  import {
    UploadSelfFile
  } from '../../api/common/common'
  import {
    saveCustomerCategory,
    queryCustomerCategory,
    GetCatetoryTypeList
  } from "../../api/users/user";
  export default {
    components: {},
    props: {
      customerObj: {
        type: Object,
        default: null
      }
    },
    data() {
      return {
        persistent: true,
        objOption: {
          CategoryName: "",
          CatetoryType: '',
          CategoryId: 0,
          linkMan: "",
          linkTel: "",
          RebateRate : 0,
          RebateMoney : 0,
          IsContract: 0, //是否签约
          ContractUrl: "", //合同信息
        },
        uploadMultple: true,
        typeList: [], //类型
        saveCustomLoading: false,
        optionTitle: '',
        isShowTel: true,
        fileObj: {
          FileName: '',
          FileUrl: ''
        }
      }
    },
    created() {},
    mounted() {
      this.initObj()
      this.getTypeList();
    },
    methods: {
      //初始化表单
      initObj() {
        if (this.customerObj && this.customerObj.CategoryId > 0) {
          this.isShowTel = false;
          let msg = {
            CategoryId: this.customerObj.CategoryId
          }
          queryCustomerCategory(msg).then(res => {
            if (res.Code == 1) {
              let tempData = res.Data;
              this.objOption.CategoryName = tempData.CategoryName;
              this.objOption.CatetoryType = tempData.CatetoryType;
              this.objOption.CategoryId = tempData.CategoryId;
              this.objOption.IsContract = tempData.IsContract;
              this.objOption.ContractUrl = tempData.ContractUrl;
              this.objOption.RebateRate = tempData.RebateRate;
              this.objOption.RebateMoney = tempData.RebateMoney;
            }
          })
          this.optionTitle = "修改客户信息"
        } else {
          this.objOption.CategoryName = '';
          this.objOption.CatetoryType = '';
          this.objOption.CategoryId = 0;
          this.objOption.linkMan = '';
          this.objOption.linkTel = '';
          this.objOption.RebateRate = 0;
          this.objOption.RebateMoney = 0;
          this.objOption.IsContract = 0;
          this.objOption.ContractUrl = '';
          this.optionTitle = "新增客户信息"
          this.isShowTel = true;
        }
      },
      //保存
      saveCourse() {
        this.$refs.CategoryName.validate();
        this.$refs.CatetoryType.validate();
        if (!this.$refs.CategoryName.hasError && !this.$refs.CatetoryType.hasError) {
          saveCustomerCategory(this.objOption).then(res => {
            if (res.Code == 1) {
              this.$q.notify({
                icon: "iconfont icon-chenggong",
                color: "accent",
                timeout: 2000,
                message: "数据保存成功！",
                position: "top",
              });
              this.$emit("success");
              this.closeCourseForm()
            }
          })
        }
      },
      getTypeList() {
        GetCatetoryTypeList({}).then(res => {
          if (res.Code == 1) {
            this.typeList = res.Data;
          }
        })
      },
      //关闭弹窗
      closeCourseForm() {
        this.$emit('close');
        this.persistent = false;
      },
      //上传附件
      UploadAttachment(files) {
        UploadSelfFile('Attachment', files.file, res => {
          if (res.Code == 1) {
            this.fileObj.FileName = res.FileName;
            this.fileObj.FileUrl = res.FileUrl;
            this.objOption.ContractUrl = res.FileUrl;
          }
        })
      },
    },
  }
</script>