

<script>
/* eslint-disable */
// sd-skip-auto-import
import cloneDeep from"lodash.clonedeep";import{Message,Modal}from"ant-design-vue";import sdUserPicker from"@/common/components/sd-user-picker.vue";import sdGroupPicker from"@/common/components/sd-group-picker.vue";import SdConfigProvider from"@/common/components/sd-config-provider.vue";import components from"./_import-components/sd-formula-item-import";var _render=function e(){var a=this,t=a._self._c;return t("span",{class:a.$style.formlua},[!a.paramsOnly?t("span",[a._v(" "+a._s(a.data.label)+" ")]):a._e(),a.data.params?t("span",[!a.paramsOnly?t("span",[a._v("(")]):a._e(),a._l(a.data.params.filter((e=>!a.readonly||e.actual)),(function(e,s){return t("span",{key:s},[s>0?t("span",[a._v(",")]):a._e(),e.selectListItem?t("span",[!a.readonly?t("a-select",{attrs:{"dropdown-match-select-width":false,"label-in-value":"",size:"small",options:e.selectListItem.map((e=>({label:e.label,key:e.data}))),value:{...e.actual,key:e.actual.data}},on:{change:t=>a.$set(e,"actual",{label:t.label,data:t.key})}}):a._e(),a.readonly?t("span",[a._v(a._s(e.actual.label))]):a._e()],1):!e.actual?t("sd-draggable",{class:[(a.data.params.every((e=>!e.actual))||a.data.params.some((e=>!e.actual&&!e.spread)))&&"return"!==a.data.data&&a.check?"required":a.$style.drag,a.$style.dragArea],attrs:{tag:"span",handle:".handle",group:{name:"formula",put:(t,s,l,r)=>a.canPut(e.dataType,l)||!!e.spread&&a.canPut(e.dataType+"[]",l)},list:a.tempList},on:{add:()=>a.added(s)}},[t("span",{attrs:{title:a.constType.includes(e.dataType)?"可点击输入常量":""},on:{click:()=>a.addConstValue(s,e.dataType)}},[a._v(" "+a._s(e.label))])]):t("a-tag",{attrs:{closable:!a.readonly,visible:""},on:{close:function(t){return a.remove(e,s)}}},[t("sd-formula-item",{attrs:{data:e.actual,readonly:a.readonly,check:a.check}})],1)],1)})),!a.paramsOnly?t("span",[a._v(")")]):a._e()],2):a._e()])};var staticRenderFns=[];_render._withStripped=true;export default{name:"SdFormulaItem",components:components,props:{data:{type:Object,required:true},paramsOnly:{type:Boolean,default:false},readonly:{type:Boolean,default:false},check:{type:Boolean,default:false}},data(){return{tempList:[],value:void 0,value2:void 0,constType:["number","string","date","group[]","user[]","string[]","any"]}},inject:["context"],computed:{_constants(){return(this.context.constants||[]).concat(this.context.fields.filter((e=>e.attr?.selectListItem)).map((e=>({caption:e.caption,items:e.attr?.selectListItem}))))}},methods:{added(e){if(this.data.params[e].spread)this.data.params.push(cloneDeep(this.data.params[e]));this.$set(this.data.params[e],"actual",cloneDeep(this.tempList[0]));this.tempList=[]},canPut(e,a){return this.context.canPut(e,a._underlying_vm_.dataType)},addConstValue(e,a){const t=this.$createElement;if(!this.constType.includes(a))return;const s=Modal.confirm({title:"请输入常量",okText:"确认",cancelText:"取消",content:()=>{if("string[]"===a)return t("a-select",{attrs:{mode:"tags"},style:"width: 100%",model:{value:this.value,callback:e=>{this.value=e}}});if("group[]"===a)return t("form",[t(SdConfigProvider,[t(sdGroupPicker,{model:{value:this.value,callback:e=>{this.value=e}}})," "])]);if("user[]"===a)return t("form",[t(SdConfigProvider,[t(sdUserPicker,{model:{value:this.value,callback:e=>{this.value=e}}})])]);if("date"===a)return t(SdConfigProvider,[t("a-date-picker",{model:{value:this.value,callback:e=>{this.value=e}}})]);if("string"===a||"any"===a)return[t("div",[this.value2?void 0:t("a-input",{style:"width: 300px",attrs:{placeholder:"请输入常量"},model:{value:this.value,callback:e=>{this.value=e}}})]),t("div",[this.value||!this._constants.length?void 0:[t("p"),t("a-select",{attrs:{labelInValue:true,"allow-clear":true,placeholder:"请选择常量","show-search":true,"filter-option":this.filterOption},style:"width: 300px",model:{value:this.value2,callback:e=>{this.value2=e}}},[this._constants.map(((e,a)=>t("a-select-opt-group",{attrs:{label:e.caption},key:a},[e.items.map((({value:e,label:a})=>t("a-select-option",{attrs:{value:e+"###"+Math.random()}},[a])))])))])]])];else return t("a-input-number",{model:{value:this.value,callback:e=>{this.value=e}}})},onOk:()=>{if((void 0===this.value||""===this.value)&&!this.value2){Message.warn("请输入常量值");return}if(this.data.params[e].spread)this.data.params.push(cloneDeep(this.data.params[e]));let t=this.value??this.value2.key.split("###")[0];let l=this.value??this.value2.label;if("date"===a){t=this.value.valueOf();l=this.value.format("YYYY-MM-DD")}if("group[]"===a||"user[]"===a){t=JSON.stringify(this.value);l=this.value.map((e=>e.name)).join(",")}if("string[]"===a){t=JSON.stringify(this.value);l=this.value.join(",")}this.$set(this.data.params[e],"actual",{data:t,dataType:a,label:l});this.value2=void 0;this.value=void 0;s.destroy()}})},remove(e,a){if(e.spread){this.data.params.splice(a,1);return}this.$set(e,"actual",void 0)},filterOption(e,a){return a.componentOptions.children[0]?.text?.indexOf(e)>=0||a.componentOptions.propsData?.label?.indexOf(e)>=0}},render:_render,staticRenderFns:staticRenderFns};</script>

<style module lang="scss">
@use '@/common/design' as *;
.formlua {
  span {
    > li {
      display: inline;
    }
    &:global(.ant-tag) {
      padding: 2px 7px;
      margin: 3px;
    }

    font-size: 1em;
  }
  .drag {
    color: $primary-color;
  }
  :global(.required) {
    color: $error-color;
  }
  .drag-area {
    display: inline-block;
    border: 1px dashed #d9d9d9;
  }
  .return {
    width: 100%;
  }
  span.hidden {
    width: 0;
    padding: 2px 0;
    margin: 3px 0;
    visibility: hidden;
  }
}
</style>
