<template>
  <div>
    <title-bar title="客户查询" >
      <van-icon slot="left" name="cross" size="24" />
    </title-bar>
    <div class="content">
      <div>
        查企业
        <div>
          <van-search v-model="value" @blur="onClick" placeholder="请输入企业名称或证件" />
        </div>
      </div>
      <div class="result-box">
        <div v-show="flagShow" class="query-history">共有{{mainArray.length}}条搜索结果</div>
        <div v-for="(item,index) in mainArray" :key="index" @click="clickItem(item)" class="query-content">
          <div class="query-content-left">
            <img
              style="width: 4.63%"
              src="@/assets/images/query-history-logo.png"
              alt=""
            />
            <div>{{ item.entName }}</div>
            <div style="margin-left:20px">
              <!-- <span style="color: #999999">统一社会信用代码：</span -->
              >
              <!-- <span style="font-family: 'Arial Normal', 'Arial'"
                >9129181726374820p</span
              > -->
            </div>
          </div>
          <!-- <div class="query-content-right">历史合作企业</div> -->
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import TitleBar from "@/components/general/TitleBar.vue";
import nettyApi from "@/constants/api/ms-netty/netty.api.ts";
import IF from "@/public/factory/InterFaceFactory";
import { NativeUI } from "@/public/ts/NativeUI";
import Public from "@/public/ts/Public";
/**
 * @Description 客户查询
 * @Author JiangTao
 * @Date 2021-11-10 下午 03:30
 */
@Component({
  name: "CustomerInquiry",
  components: { TitleBar },
})
export default class CustomerInquiry extends Vue {
  pageTitle = ""; // 页面标题
  mainArray = []; //公司数组
  value = "";
  flagShow = false; //展示搜索结果
  onClick() {
    // console.log(this.mainArray);
    this.onSearch();
  }
  onSearch() {
    const parm = {
      tc: nettyApi.TRADE_CODE.selectDim,
      ProdId: Public.getProdId(),
      SvrCode: Public.getSvrCode(nettyApi.TRADE_CODE.selectDim),
      ClientNo: "",
      name: this.value,
      orgTypes: "",
    };
    NativeUI.showWaiting("正在查询.....");
    IF.transferDataInter(nettyApi.commonRq, parm).then((res: any) => {
      NativeUI.closeWaiting();
      if (res.rc == "1") {
        this.mainArray = res.dataList;
        this.flagShow = true;
      } else {
        if (res.ret_code != "4999999" && res.ret_code != "000001") {
          NativeUI.toast('暂无公司数据');
          this.mainArray = [];
          this.flagShow = false;
        }
      }
    });
  }
  activated() {
     this.$router.beforeEach((to, from, next) => {
      if (from.path == '/main/workbench') {
        this.value = '';
        this.mainArray = [];
        this.flagShow = false;
      }
      next();
    });
  }
  clickItem(item: any) {
    const parm = {
      tc: nettyApi.TRADE_CODE.selectCus,
      cus_name: item.entName,
    };
    NativeUI.showWaiting("正在查询...");
    IF.transferDataInter(nettyApi.commonRq, parm).then((res: any) => {
      NativeUI.closeWaiting();
      console.log(res);
      if (res.rc == "1") {
        const cusinfo = {
          cus_name: res.cus_name,
          cert_type: res.cert_type,
          cert_code: res.cert_code,
          exist_flag: res.exist_flag,
          cus_id: res.cus_id,
          cus_status: res.cus_status,
        };
        this.$store.commit("setCusInfo", cusinfo);
        this.$router.push({
          path: "/CompanyDetails",
        });
      } else {
        NativeUI.toast(res.msg);
      }
    });
  }
  mounted() {
    this.pageTitle = this.$route.meta?.name;
  }
}
</script>

<style scoped>
.content {
  background-color: #f2f2f2;
}
.content > div:nth-child(1) {
  padding: 2% 8%;
  background-color: white;
  font-size: 143%;
  font-weight: bold;
  margin-bottom: 1%;
}
.content > div:nth-child(2) {
  background-color: white;
  padding: 2% 8%;
}
.result-box{
  margin-bottom: 1.5%;
  overflow-y: auto;
  overflow:scroll;
  height: calc(100vh - 170px);
}
.query-content {
  width: 97%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5%;
  margin-bottom: 1.5%;
  border-bottom: 1px solid #adb5bd;
}
.query-content-left {
  width: 60%;
  display: flex;
  justify-content: flex-start;
  align-items: center;
}
.query-content-left > div:nth-child(2) {
  font-size: 115%;
  font-family: "微软雅黑 Bold", "微软雅黑 Regular", "微软雅黑";
  font-weight: bold;
  margin: 0 2%;
}
.query-content-left > div:nth-child(3) {
  margin-top: 0.2%;
  margin-left: 3%;
}
.query-content-right {
  font-size: 92.9%;
  background-color: #e2eef9;
  padding: 0.3% 0.8%;
  color: #1890ff;
}
.content > div:nth-child(1) {
  display: flex;
  justify-content: space-around;
  align-items: center;
}
.content > div:nth-child(1) div {
  width: 93%;
}

</style>
