<template>
  <tui-input disabled
             :required="required"
             :label="label"
             textRight
             :value="value"
             @click="!disabled && suppliers()"
             :placeholder="disabled ? '' : '请选择'">
    <template v-if="!disabled"
              #right>
      <tui-icon name="arrowright"
                :size="24"></tui-icon>
    </template>
  </tui-input>
</template>
<script>
export default {
  props: ["value", "required", "label", "disabled"],
  methods: {
    suppliers() {
      let fetchUrl = null;
      let navigationBarTitleText = null;
      let supplier_org_code = null;
      if (this.label.indexOf("调入") > -1) {
        fetchUrl = "materialDispatcher/DispatchMaterial/callin_suppliers";
        supplier_org_code = "选择调用单位";
        navigationBarTitleText = "项目编码:";
      } else if (this.label.indexOf("用料") > -1) {
        fetchUrl = "materialDispatcher/DispatchMaterial/use_suppliers";
        supplier_org_code = "选择用料单位";
        navigationBarTitleText = "统一社会信用代码:";
      } else {
        fetchUrl = "materialDispatcher/DispatchMaterial/suppliers";
        supplier_org_code = "选择供应商";
        navigationBarTitleText = "统一社会信用代码: ";
      }
      // 跳转页面
      uni.navigateTo({
        url: "/pages/common/selectBlank/selectBlank",
        events: {
          rowClick: (row) => {
            this.$emit("input", row);
          },
        },
        success: (res) => {
          // 通过eventChannel向被打开页面传送数据
          res.eventChannel.emit("acceptDataFromOpenerPage", {
            navigationBarTitleText: supplier_org_code,
            cardProps: {
              renderText: {
                title: (row) => row.supplier_name,
                footer: (row) => navigationBarTitleText + row.supplier_org_code,
              },
            },
            inputProps: {
              placeholder: "请输入供应商名称检索",
            },
            fetchUrl: fetchUrl,
          });
        },
      });
    },
  },
};
</script>
