Lookup类型数据自定义过滤

自定义Lookup查找视图

需要根据实际情况,是onChange触发,还是页面加载form_onLoad的时候就预设

//需求:当要修改旧件名称时(Lookup)只能用新件名称从【替代料】中匹配替代料或被替代料获取目标产品。
function form_onLoad() {
    var new_productnew_id = rtcrm.getLookupId("new_productnew_id");
    if (new_productnew_id == null) {
        return;
    }
    setProductLookUp(new_productnew_id) //页面加载时预设
}

function setProductLookUp(new_productnew_id) {
    //new_srv_partsreplace 替代料
    //product 产品
    var fetchXml = `<fetch  mapping='logical' version='1.0' distinct='true'>
  <entity name='product'>
    <attribute name='name' />
    <attribute name='productid' />
    <link-entity name='new_srv_partsreplace' to='productid' from='new_productid' alias='p1' link-type='outer' />
    <link-entity name='new_srv_partsreplace' to='productid' from='new_product_partsreplaceid' alias='p2' link-type='outer' />
    <filter type='or'>
      <condition attribute='new_productid' entityname='p1' operator='eq' value='${new_productnew_id}' />
      <condition attribute='new_product_partsreplaceid' entityname='p1' operator='eq' value='${new_productnew_id}' />
      <condition attribute='new_productid' entityname='p2' operator='eq' value='${new_productnew_id}' />
      <condition attribute='new_product_partsreplaceid' entityname='p2' operator='eq' value='${new_productnew_id}' />
    </filter>
    <order attribute='productnumber' />
  </entity>
</fetch>`;

    //通用写法
    //【注意】:row标签中的id的值目标实体ID值
    var layoutXml = "<grid name='resultset' object='1' jump='name' select='1' icon='1' preview='1'>" +
        "<row name='result' id='productid'>" +
        "<cell name='name' width='150' />" +
        "</row>" +
        "</grid>";
    try {
        //第一个参数:为目标字段名,第二个参数:检索的目标实体
        rtcrm.customizeLookupView("new_product_id", "product", fetchXml, layoutXml);
    } catch (e) {
        alert(e.message);
    }
}

二、后台接口配合前端Vue过滤lookup数据

后台:

/*
备件订单lookup过滤视图
"page":页数
"count":总数
"orderby":排序
"condition":动态条件
"filterValue":过滤
*/
public LookupViewResult GetProductLookupViewData(string entityName, int page, int count, string select, string orderby, string condition, string filter, string filterValue)
{
    var result = new LookupViewResult();

    var qe = new QueryExpression("new_discount_price");
    qe.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0);
    qe.Criteria.AddCondition("new_approvalstatus", ConditionOperator.Equal, 3);  //已审核
    qe.ColumnSet.AddColumns("new_price", "new_product_id");
    LinkEntity linkEntity = new LinkEntity("new_discount_price", "product", "new_product_id", "productid", JoinOperator.Inner);
    linkEntity.EntityAlias = "p";
    linkEntity.Columns.AddColumns("productnumber", "name");
    linkEntity.LinkCriteria.AddCondition("statecode", ConditionOperator.Equal, 0);
    //筛选明细
    if (!string.IsNullOrWhiteSpace(filterValue))
    {
        var quickFilter = new FilterExpression
        {
            FilterOperator = LogicalOperator.Or,
            Conditions =
            {
                new ConditionExpression("name", ConditionOperator.Like, "%" + filterValue + "%"),
                new ConditionExpression("productnumber", ConditionOperator.Like, "%" + filterValue + "%"),
            }
        };
        linkEntity.LinkCriteria.Filters.Add(quickFilter);
    }
    qe.LinkEntities.Add(linkEntity);
    qe.PageInfo = new PagingInfo
    {
        Count = count,
        PageNumber = page,
        ReturnTotalRecordCount = true
    };

    if (!string.IsNullOrWhiteSpace(condition))
    {
        var cons = condition.Split(',');
        cons.Each(item =>
                  {
                      var con = item.Split(' ');
                      if (con[1].Equals("eq"))
                      {
                          qe.Criteria.AddCondition(con[0], ConditionOperator.Equal, con[2]);
                      }
                  });
    }

    var ec = organizationServiceAdmin.RetrieveMultiple(qe);
    if (ec == null || ec.Entities.Count == 0)
    {
        result.TotalRecordCount = 0;
        return result;
    }

    var listDic = new List<Dictionary<string, string>>();
    foreach (var entity in ec.Entities)
    {
        var dic = new Dictionary<string, string>();
        //产品名称
        if (entity.Contains("p.name"))
        {
            dic.Add("new_product_idname", entity.GetAliasAttributeValue<string>("p.name"));
        }
        dic.Add("productid", entity.GetAttributeValue<EntityReference>("new_product_id").Id.ToString());
        dic.Add("new_price", entity.GetAttributeValue<decimal>("new_price").ToString());
        listDic.Add(dic);
    }
    result.TotalRecordCount = ec.TotalRecordCount;
    result.Data = listDic;
    result.PagingCookie = ec.PagingCookie;
    return result;
}

//接口
[HttpGet, Route("GetProductLookupViewData")]
[Description("折旧物料自定义过滤")]
public LookupViewResult GetProductLookupViewData(string entityName, int page, int count, string select, string orderby, string condition, string filter, string filterValue)
{
    return new SparepartsCommand(this.UserIdentity).GetProductLookupViewData(entityName, page, count, select, orderby, condition, filter, filterValue);
}

//类文件
public class LookupViewResult
{
    public int TotalRecordCount { get; set; }

    public string PagingCookie { get; set; }

    public IList<Dictionary<string, string>> Data { get; set;
    } = new List<Dictionary<string, string>>();
}

返回Json数据:

Data: [{new_product_idname: "九号电动C60-TDT001Z-上海版-罗兰紫黄;九号电自C60-裸车-含电池",}]
0: {new_product_idname: "九号电动C60-TDT001Z-上海版-罗兰紫黄;九号电自C60-裸车-含电池",}
new_price: "3500.0000000000"
new_product_idname: "九号电动C60-TDT001Z-上海版-罗兰紫黄;九号电自C60-裸车-含电池"
productid: "201c3625-5585-eb11-a12b-fa0bf8335e00"
PagingCookie: "<cookie page=\"1\"><new_discount_priceid last=\"{09273524-DE4A-ED11-A139-FA0BF8335E00}\" first=\"{09273524-DE4A-ED11-A139-FA0BF8335E00}\" /></cookie>"
TotalRecordCount: 1

前端vue页面(公司封装protal端):

<rt-header-button-group slot="toolbar">
    <el-button icon="el-icon-tickets" @click="cancelevaluate" type="warning"
               >物料折旧申请</el-button
        >
......
</rt-header-button-group>
methods: {
    //物料折旧申请
    cancelevaluate: function () {
      this.$refs.ApplyDialog.show();
    },
    .......
},

弹框页面:
<template>
  <el-dialog
    width="30%"
    class="rt-dialog"
    title="物料折旧申请"
    :visible.sync="dialogChangeVisible"
    :before-close="clearTheData"
  >
    <el-form
      ref="editForm"
      :rules="rules"
      :model="editForm"
      label-width="120px"
      label-position="left"
      v-loading="loading"
    >
      <div>
        <el-row :gutter="50">
          <el-col :span="24" style="width: 100%">
            <el-form-item
              label="配件名称"
              prop="new_product_id"
              :required="false"
            >
              <rt-lookup
                v-model="editForm.new_product_id"
                entity="product"
                idField="productid"
                :dialogRequestUrl="queryUrl"
                :request-url="queryUrl"
                nameField="new_product_idname"
                dialogFilterFields="new_product_idname"
                dialog-orderby-fields="new_product_idname asc"
                :dialog-display-fields="[
                  { name: 'new_product_idname', label: '产品名称' },
                  { name: 'new_price', label: '折旧价格' },
                ]"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="50">
          <el-col :span="24">
            <el-form-item label="数量" prop="new_qty">
              <rt-input type="number" v-model="editForm.new_qty"></rt-input>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel" :loading="btnLoading">{{
        $t("CANCEL")
      }}</el-button>
      <el-button
        @click="saveChange('editForm')"
        type="primary"
        :loading="btnLoading"
        >{{ $t("BUTTON_DETERMINE") }}</el-button
      >
    </div>
  </el-dialog>
</template>

<script>
export default {
  data: function () {
    return {
      btnLoading: false,
      loading: false,
      dialogChangeVisible: false,
      //过滤Lookup数据接口
      queryUrl: "api/service1portal/Spareparts/GetProductLookupViewData",
      editForm: {
        new_product_id: null,
        new_qty: null,
      },
      rules: {
        new_appealreason: [
          {
            required: true,
            trigger: "change",
          },
        ],
      },
    };
  },
  mounted() {},
  methods: {
    saveChange(editForm) {
      this.$refs[editForm].validate((valid) => {
        if (!this.editForm.new_product_id) {
          rt.showErrorToast("配件名称必填!");
          return;
        }
        if (!this.editForm.new_qty) {
          rt.showErrorToast("数量必填!");
          return;
        }
        if (
          this.editForm.new_qty &&
          this.editForm.new_qty.indexOf(".", 0) != -1
        ) {
          rt.showErrorToast("数量必须为整数!");
          return;
        }
        if (!valid) {
          rt.showErrorToast(this.$t("PleaseInputRequiredFields"));
          return;
        } else {
          this.loading = true;
          var api = "api/service1portal/Spareparts/CreateDepreciation";
          var params = {
            new_product_id: this.editForm.new_product_id.id,
            new_qty: parseInt(this.editForm.new_qty),
          };
          debugger;
          rt.post(api, params)
            .then((res) => {
              this.loading = false;
              rt.showSuccessToast(res);
              this.dialogChangeVisible = false;
              this.$emit("confirm");
              this.editForm.new_product_id = null;
              this.editForm.new_qty = null;
            })
            .catch((err) => {
              this.loading = false;
              this.btnLoading = false;
              rt.showErrorToast(err);
            });
        }
      });
    },
    clearTheData() {
      this.dialogChangeVisible = false;
    },
    cancel() {
      this.dialogChangeVisible = false;
    },
    show(val) {
      this.dialogChangeVisible = true;
    },
  },
};
</script>


   转载规则


《Lookup类型数据自定义过滤》 LoveBin 采用 知识共享署名 4.0 国际许可协议 进行许可。
  目录