const iframe = document.querySelector('iframe#_5bc10dcb-965a-48b2-94a0-9816c4b5f37f');

let udfForm = iframe.contentWindow.getUDFColumnData(this.ui("ID").getVal());

console.log("udfForm", udfForm);

//遍历对象
for (let key in udfForm) {
    this.ui(key).setVal(udfForm[key]);
}

iframe.contentWindow.saveUDF(this.ui("ID").getVal());
;;



const { ref } = DWApi.api.Vue;
const dateValue = ref(new Date());

let rowDatas = this.grid().getCheckedData();
if (rowDatas.length == 0) {
    this.feedback.msg("请选择要提交的数据！", "info");
    return;
}
this.feedback.dialog({
    title: "输入提交日期",
    extendParams: { width: "300px" },
    contextRender: ({ h, resolve }) => {
        return [
            h(resolve("ElDatePicker"), {
                modelValue: dateValue.value,
                'onUpdate:modelValue': value => dateValue.value = value,
                type: "date", // 关键配置：启用日期输入
                format: "YYYY-MM-DD", // 显示格式（可选）
                valueFormat: "YYYY-MM-DD", // 绑定值格式（可选）
            }),
        ]
    },
    buttons: [{
        text: "审批并提交", click: () => {

            DWApi.api.awsuiaxios.post({
                url: "jd",
                data: {
                    cmd: 'com.awspaas.user.apps.donenow_ctt.approve_service',
                    approveDate: dateValue.value,
                    approveIds: rowDatas.map((item) => item.ID).join(',')//逗号分割
                }
            }).then((r) => {
                console.log("获取到的数据：", r)
                this.feedback.msg("提交成功！", "info");

                DWApi.behavior.closeDialog()
            });

        }, type: "primary"
    }]
})


let rowDatas = this.grid().getCheckedData();
if (rowDatas.length != 1) {
    this.feedback.msg("请选择要修改的数据，只允许选择一条！", "info");
    return;
}
let rowData = rowDatas[0];
const { ref } = DWApi.api.Vue;
const nameValue = ref("");
const priceValue = ref("");

nameValue.value = "合同名称：" + rowData.CONTRACT_NAME;
priceValue.value = rowData.DOLLARS;

this.feedback.dialog({
    title: "合同价格调整",
    extendParams: { width: "500px" },
    contextRender: ({ h, resolve }) => {
        return [
            h("span", { innerText: nameValue.value }),
            h("br"),
            h("span", { innerText: "调整后总价：*" }),
            h(resolve("ElInput"), {
                modelValue: priceValue.value,
                'onUpdate:modelValue': (value) => {
                    // 只允许输入数字
                    const validValue = value.replace(/[^0-9.]/g, '');
                    priceValue.value = validValue;
                }
            }),
            h("br")
        ];
    },
    buttons: [
        {
            text: "保存并关闭",
            click: () => {
                DWApi.api.awsuiaxios.post({
                    url: "jd",
                    data: {
                        cmd: 'com.awspaas.user.apps.donenow_ctt.approve_updateExtendedPrice',
                        id: rowData.ID,
                        periodPrice: priceValue.value,//逗号分割
                    }
                }).then((r) => {
                    console.log("获取到的数据：", r)
                    this.feedback.msg("提交成功！", "info");
                    DWApi.behavior.closeDialog()
                });
            },
            type: "primary"
        },
        {
            text: "取消",
            click: () => {
                DWApi.behavior.closeDialog();
            },
            type: "default"
        }
    ]
});















console.log('加载事件', eventContext)
console.log("树形选择", parent.DWApi.searcherCondition.tree.qk);

if (!parent.DWApi.searcherCondition.treeSelectToForm) {
    parent.DWApi.searcherCondition.treeSelectToForm = new Array();
    parent.DWApi.searcherCondition.treeSelectToForm.push(this.ui("CATE_ID"));
}

let treeSelect = parent.DWApi.searcherCondition.tree.qk[0].ConditionValue;
let sql1 = "sqlValue(select NAME from BO_EU_DNIVT_PRODUCT_CATE where NO='" + treeSelect + "')";
sql1 = "@" + sql1;
this.api.executeAtScript(sql1).then(r => {
    console.log(treeSelect, r);
    this.ui("CATE_ID").setVal(treeSelect, r);
});





const { instance, DWApi, data, treeNode, treeConfig } = eventContext;
if (treeNode.level > 2) {
    //子节点无特殊需求可以直接返回
    return true;
}
const array = new Array();//条件组织多个
//默认数据
let field = treeConfig.conditioncolumn;
const Compare = '=', valtype = '文本', value = data.value;
if (treeNode.level == '1') {
    //root节点是组名称一个组可能有多个事件配置多个事件加强以第一个为准
    field = 'NAME';//需要指出新的条件
}
if (treeNode.level == '2') {
    //如果需要查询必须写查询方法，此节点是标题名称
    //此处无特殊需求可以不做处理
}


if (DWApi.searcherCondition.treeSelectToForm) {
    for (let i = 0; i < DWApi.searcherCondition.treeSelectToForm.length; i++) {
        DWApi.searcherCondition.treeSelectToForm[i].setVal(data.value, data.text);
    }
}


array.push({
    'Field': field,
    'Type': valtype,
    'Compare': Compare,
    'ConditionValue': value,
});
this.searcherCondition.tree.qk = array;
this.data.refreshData();
console.log("-----instance-------");
console.log(instance);
console.log("----DWApi--------");
console.log(DWApi);


return false;














const { instance, DWApi, data, treeNode, treeConfig } = eventContext;

console.log("----data--------");
console.log(data);

if (DWApi.searcherCondition.treeSelectToForm) {
    for (let i = 0; i < DWApi.searcherCondition.treeSelectToForm.length; i++) {
        DWApi.searcherCondition.treeSelectToForm[i].setVal(data.value, data.label);
    }
}

const array = new Array();//条件组织多个
//默认数据
let field = treeConfig.conditioncolumn;
const Compare = '=', valtype = '文本', value = data.value;
array.push({
    'Field': field,
    'Type': valtype,
    'Compare': Compare,
    'ConditionValue': value,
});
this.searcherCondition.tree.qk = array;

console.log("----searcherCondition--------");
console.log(array);

this.data.refreshData();
return false;



window.addEventListener("storage", (e) => {
    let nowTime = new Date().getTime();
    if(e.key == "初审机构户籍申请" && nowTime - e.newValue < 2000) {
      delete localStorage['初审机构户籍申请'];
      // setTimeout(() => {
      // 	reloadGridData();
      // },500);
      location.reload();
    }
  })
  
    var ATUI = {
          exceat: function (at, sid) {
              var re = "";
              at = at.replace(/##/g, "@");
              var data = "script=" + encodeURIComponent(at) + ((sid == '' || sid == null || sid == undefined || sid.indexOf("#sid") > 0) ? "" : "&sid=" + sid);
              awsui.ajax.request({
                  type: "POST",
                  url: "../r/jd?cmd=com.awspaas.user.apps.magicportal_expression",
                  data: data,
                  async: false,
                  ok: function (res) {
                      re = res.data.data;
                  }
              });
              return re;
          },
          getUrlParam: function (paraName, url) {
              var arrObj = url.split("?");
              if (arrObj.length > 1) {
                  var arrPara = arrObj[1].split("&");
                  var key;
                  for (var i = 0; i < arrPara.length; i++) {
                      var t = arrPara[i].indexOf("=");
                      if (t > -1) {
                          key = arrPara[i].substring(0, t);
                          if (key == paraName) {
                              return arrPara[i].substring(t + 1);
                          }
                      }
                  }
                  return "";
              } else {
                  return "";
              }
          },
          getCookie: function (name) {
              var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
              if (arr = document.cookie.match(reg)) {
                  return unescape(arr[2]);
              }
              else {
                  return null;
              }
          }
      }
      
      var XXDJ ="";
      var GLDW =""; 
      awsui.ajax.request({
          type: "POST",
          url: "../r/jd?cmd=com.awspaas.user.apps.settle2_sqlvXxdjxx&sid=ck",
        data:{},
          async: false,
          success: function (res) {
             console.log(res)
              XXDJ = res.data.XXDJ2;
              GLDW = res.data.GLDW;
          }
      });

  
  let QYXX = "<br />3、";
      if (XXDJ == "") {
          QYXX = QYXX + "当前政策年没有注册。";
      } else {
          QYXX = QYXX + XXDJ;
          if (GLDW != "")
              QYXX = QYXX + "，" + GLDW;
          QYXX += "。";
      }
  $("#searchertoolbar>.searcherTile").before('<div style="color:red !important;font-weight:bold;padding-left:10px">说明：<br />1、本单位人事管理部门派人事专员携带身份证及单位介绍信来递交相关纸质材料；<br />2、所有填写内容以书面递交材料为准；'+QYXX+'</div>')
  $("#toolDiv").after('<style>#firstmainid{height:calc(100% - 70px)!important;}</style><span style="color:red !important;font-weight:bold;padding-left:10px;line-height:26px;float:left;">若查询最新户籍申请状态，请前往户籍受理查询。</span>')
  resizeDwGrid()