<template>
  <div class="editAudit" ref="editAudit"></div>
  <a-modal
    class="editAudit_modal generalModel"
    v-model:visible="operationsModal"
    :footer="null"
    :get-container="() => $refs.editAudit"
    width="50%"
    height="55rem"
    :maskClosable="false"
    :centered="true"
    :closable="false"
    :mask="true"
    wrapClassName="#app"
    :keyboard="false"
  >
    <div class="generalModel_btn">
      <div class="generalModel_closeIcon" @click.stop="cancelDsign">
        <svg
          width="100%" height="100%"
          viewBox="0 0 46 46"
          fill="none"
          xmlns="http://www.w3.org/2000/svg"
        >
          <circle cx="23" cy="23" r="23" fill="black" fill-opacity="0.3" />
          <rect
            x="32.5063"
            y="12"
            width="3"
            height="29"
            rx="1.5"
            transform="rotate(45 32.5063 12)"
            fill="white"
          />
          <rect
            x="34.6274"
            y="32.5059"
            width="3"
            height="29"
            rx="1.5"
            transform="rotate(135 34.6274 32.5059)"
            fill="white"
          />
        </svg>
      </div>
    </div>
    <div class="modal_title_text">
      <div>{{ title }} </div>
    </div>
    <div class="allUserPoeration_center admin_page">
      <div class="admin_state_item">
        <span>Commission: <span>*</span></span>
        <input
          v-model="commission"
          placeholder="Please enter Commission"
          type="text"
          style="width: 250px"
        />
      </div>
	  <!-- {{ currentState }} -->
	  <div class="admin_state_item">
		<span>State:</span>
		<a-select v-model:value="currentState" style="width:250px" optionFilterProp="label" :options="state" placeholder="Please select" allowClear show-search></a-select>
	</div>
    </div>
    <div class="allUserPoeration_btn admin_page">
      <div class="admin_search_item" @click="cancelDsign">Close</div>
      <div class="admin_search_item" @click="setOk">OK</div>
    </div>
  </a-modal>
  <div class="mark_loading" v-show="loadingShow">
    <a-spin size="large" />
  </div>
</template>
<script>
import {
  defineComponent,
  ref,
  reactive,
  watch,
  onMounted,
  nextTick,
  toRefs,
} from "vue";
import { Https } from "@/tool/https";
import { Modal, message } from "ant-design-vue";
import { ExclamationCircleOutlined } from "@ant-design/icons-vue";
import md5 from "md5";
export default defineComponent({
  components: {},
  emits: ["searchHistoryList"],
  props:{
  },
  setup(props, { emit }) {
    let operations = reactive({
      operationsModal: false,
      loadingShow: false,
      title: "",
    });
    let operationsData = reactive({
      id: "",
      commission: "",
    });
	let currentState = ref('')
	let state = ref([
		{
			label:'Active',
			value:'Active',
		},
		{
			label:'Delete',
			value:'Delete',
		},
		{
			label:'Inactive',
			value:'Inactive',
		},
	])
    let init = (data) => {
		let funStr = 'Edit'
      operations.operationsModal = true;
      operations.title = funStr;
      if (funStr == "Edit") {
        operationsData.id = data.id;
        operationsData.commission = data.commissionPercent;
        currentState.value = data.status;
      }
    };
    
    let setEditData = () => {
      return {
        id: operationsData.id,
        commission: operationsData.commission,
        operationType: currentState.value,
      };
    };
    let cancelDsign = () => {
      operationsData.id = "";
      operationsData.commission = "";
      currentState.value = "";
      operations.operationsModal = false;
    };
    let setOk = () => {
      let data;
	  data = setEditData();
	   if (
          !data.commission
        )
          return message.warning("Please check the input box marked with *");
        Https.axiosGet(Https.httpUrls.editAffiliate, {params:data}).then(
          (rv) => {
            if (rv) {
              cancelDsign();
              emit("searchHistoryList");
            }
          }
        );
    };
    return {
      ...toRefs(operations),
      ...toRefs(operationsData),
      cancelDsign,
      init,
	  state,
	  currentState,
      setOk,
    };
  },
  data() {
    return {};
  },
  mounted() {},
  methods: {},
});
</script>
<style lang="less" scoped>
:deep(.editAudit_modal) {
  .ant-modal-body {
    display: flex;
    flex-direction: column;
  }
}
</style>
<style lang="less" scoped>
.editAudit_modal {
  .closeIcon {
    z-index: 2;
  }
  .allUserPoeration_btn {
    display: flex;
    flex-direction: row;
    height: auto;
    justify-content: flex-end;
    padding: 1rem 0;
    .admin_search_item {
      margin-bottom: 0;
    }
  }
  .allUserPoeration_center {
    flex: 1;
    overflow-y: auto;
    flex-direction: row;
    flex-wrap: wrap;
  }
}
</style>
