<template>
    <div>
        <el-form :model="form" ref="dialogForm" label-width="80px" label-position="left">
            <el-divider v-if="contentSetItems && contentSetItems.length > 0 ? true : false">{{$t("reportDesigner.ElementTagSetting")}}</el-divider>
            <el-row :gutter="15" v-for="(data, index) in contentSetItems" :key="index">
                <el-col :span="24" v-if="data.type == 'input' && isShowContent">
                    <el-form-item :label="$t(data.title)" :prop="data.field" :rules="rulesHandle(data)"
                        :label-width="data.labelWidth ? data.labelWidth : '80px'"
                        :style="setFormItemStyle(index, contentSetItems.length)">
                        <el-input v-model="form[data.field]" @change="eventClick(data)" @input="inputClick(data)"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="data.type == 'inputNumber' && isShowContent">
                    <el-form-item :label="$t(data.title)" :prop="data.field" :rules="rulesHandle(data)"
                        :label-width="data.labelWidth ? data.labelWidth : '80px'"
                        :style="setFormItemStyle(index, contentSetItems.length)">
                        <!-- <el-input v-model="form[data.field]" @change="eventClick(data)" @input="inputClick(data)"></el-input> -->
                        <el-input-number v-model="form[data.field]" style="width: 100%" :min="1" :max="10" @change="eventClick" />
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-else-if="data.type == 'featureSelect'">
                    <el-form-item :label="$t(data.title)" :prop="data.field" :rules="rulesHandle(data)"
                        :label-width="data.labelWidth ? data.labelWidth : '80px'"
                        :style="setFormItemStyle(index, contentSetItems.length)">
                        <el-select v-model="form[data.field]" filterable :ref="'select' + data.field + propertyConfig.id" style="width: 100%" @change="eventClick(data)" :multiple="data.multiple">
                            <el-option v-for="item in featureList" :key="item.Key" :label="$t(item.Value)" :value="item.Key"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-else-if="data.type == 'select'">
                    <el-form-item :label="$t(data.title)" :prop="data.field" :rules="rulesHandle(data)"
                        :label-width="data.labelWidth ? data.labelWidth : '80px'"
                        :style="setFormItemStyle(index, contentSetItems.length)">
                        <!-- <sc-select v-model="form[data.field]" :ref="'select' + data.field + propertyConfig.id"
                            :apiObj="data.dataSource" clearable filterable style="width: 100%;"
                            @change="eventClick(data)"></sc-select> -->
                        <el-select v-model="form[data.field]" filterable :ref="'select' + data.field + propertyConfig.id" style="width: 100%" @change="eventClick(data)" :multiple="data.multiple">
                            <el-option v-for="item in selectItems[data.field]" :key="item.Key" :label="$t(item.Value)" :value="item.Key"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-else-if="data.type == 'elSelect' && isShowContent">
                    <el-form-item :label="$t(data.title)" :prop="data.field" :rules="rulesHandle(data)"
                        :label-width="data.labelWidth ? data.labelWidth : '80px'"
                        :style="setFormItemStyle(index, contentSetItems.length)">
                        <el-select v-model="form[data.field]" clearable style="width: 100%" @change="eventClick(data)">
                            <el-option v-for="item in bindContentList" :key="item.Key" :label="item.Value" :value="item.Key"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="data.type == 'switch'">
                    <el-form-item :label="$t(data.title)" :label-width="data.labelWidth ? data.labelWidth : '80px'"
                        :prop="data.field" :rules="rulesHandle(data)">
                        <el-switch v-model="form[data.field]" active-value="1" inactive-value="0"
                            @change="eventClick(data)"></el-switch>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="data.type == 'addButtom'">
                    <el-form-item :label="$t(data.title)" :label-width="data.labelWidth ? data.labelWidth : '80px'"
                        :prop="data.field" :rules="rulesHandle(data)">
                        <el-button type="primary" icon="el-icon-plus" @click="addControl()" :title="data.value"></el-button>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="15" v-if="isShowCommonItem">
                <el-col :span="24">
                    <el-form-item :label="$t('reportDesigner.ScanMode')" :prop="ScanModeId" label-width="80px">
                        <el-select v-model="form['ScanModeId']" clearable style="width: 100%" @change="commonChange(0)">
                            <el-option v-for="item in modeList" :key="item.Id" :label="item.Value" :value="item.Id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="15" v-if="isShowCommonItem">
                <el-col :span="24">
                    <el-form-item :label="$t('reportDesigner.MeasureItem')" :prop="MeasureItemId" label-width="80px">
                        <el-select v-model="form['MeasureItemId']" clearable style="width: 100%" @change="commonChange(1)" :disabled="measureItemList.length<=1?true:false">
                            <el-option v-for="item in measureItemList" :key="item.Id" :label="item.Value" :value="item.Id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="15" v-if="isShowCommonItem">
                <el-col :span="24">
                    <el-form-item :label="$t('reportDesigner.MeasureWay')" :prop="MeasureWayId" label-width="80px">
                        <el-select v-model="form['MeasureWayId']" clearable style="width: 100%" @change="commonChange(2)" :disabled="measureWayList.length<=1?true:false">
                            <el-option v-for="item in measureWayList" :key="item.Id" :label="item.Value" :value="item.Id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="15" v-if="isShowCommonItem">
                <el-col :span="24">
                    <el-form-item :label="$t('reportDesigner.OutputItem')" :prop="OutputItemId" label-width="80px">
                        <el-select v-model="form['OutputItemId']" clearable style="width: 100%" @change="commonChange(3)" :disabled="outputList.length<=1?true:false">
                            <el-option v-for="item in outputList" :key="item.Id" :label="item.Value" :value="item.Id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="15" v-if="isShowCommonItem">
                <el-col :span="24">
                    <el-form-item :label="$t('reportDesigner.UnitType')" :prop="UnitTypeId" label-width="80px">
                        <el-select v-model="form['UnitTypeId']" clearable style="width: 100%" @change="commonChange(4)" :disabled="unitList.length<=1?true:false">
                            <el-option v-for="item in unitList" :key="item.Id" :label="item.Value" :value="item.Id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="15" v-if="isShowCommonItem">
                <el-col :span="24">
                    <el-form-item :label="$t('reportDesigner.UserDefineName')" :prop="UserDefineNameId" label-width="140px" >
                        <el-select v-model="form['UserDefineNameId']" clearable style="width: 100%" @change="commonChange(5)" :disabled="customNameList.length<=1?true:false">
                            <el-option v-for="item in customNameList" :key="item.Id" :label="item.Value" :value="item.Id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>


            <el-row :gutter="15" v-if="isShowOtherItem">
                <el-col :span="24">
                    <el-form-item :label="$t('reportDesigner.ScanMode')" :prop="ScanModeId" label-width="80px">
                        <el-select v-model="form['ScanModeId']" clearable style="width: 100%" @change="otherChange(0)">
                            <el-option v-for="item in modeList" :key="item.Id" :label="item.Value" :value="item.Id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="15" v-if="isShowOtherItem">
                <el-col :span="24">
                    <el-form-item :label="$t('reportDesigner.MeasureCategory')" :prop="MeasureCategoryId" label-width="80px">
                        <el-select v-model="form['MeasureCategoryId']" clearable style="width: 100%" @change="otherChange(1)" :disabled="categoryList.length<=1?true:false">
                            <el-option v-for="item in categoryList" :key="item.Id" :label="item.Value" :value="item.Id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="15" v-if="isShowOtherItem">
                <el-col :span="24">
                    <el-form-item :label="$t('reportDesigner.MeasureItem')" :prop="MeasureItemId" label-width="80px">
                        <el-select v-model="form['MeasureItemId']" clearable style="width: 100%" @change="otherChange(2)" :disabled="measureItemList.length<=1?true:false">
                            <el-option v-for="item in measureItemList" :key="item.Id" :label="item.Value" :value="item.Id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="15" v-if="isShowOtherItem">
                <el-col :span="24">
                    <el-form-item :label="$t('reportDesigner.MeasureWay')" :prop="MeasureWayId" label-width="80px">
                        <el-select v-model="form['MeasureWayId']" clearable style="width: 100%" @change="otherChange(3)" :disabled="measureWayList.length<=1?true:false">
                            <el-option v-for="item in measureWayList" :key="item.Id" :label="item.Value" :value="item.Id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="15" v-if="isShowOtherItem">
                <el-col :span="24">
                    <el-form-item :label="$t('reportDesigner.OutputItem')" :prop="OutputItemId" label-width="80px">
                        <el-select v-model="form['OutputItemId']" clearable style="width: 100%" @change="otherChange(4)" :disabled="outputList.length<=1?true:false">
                            <el-option v-for="item in outputList" :key="item.Id" :label="item.Value" :value="item.Id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="15" v-if="isShowOtherItem">
                <el-col :span="24">
                    <el-form-item :label="$t('reportDesigner.MeasureCalculation')" :prop="MeasureCalculationId" label-width="80px">
                        <el-select v-model="form['MeasureCalculationId']" clearable style="width: 100%" @change="otherChange(5)" :disabled="caculateItemList.length<=1?true:false">
                            <el-option v-for="item in caculateItemList" :key="item.Id" :label="item.Value" :value="item.Id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="15" v-if="isShowOtherItem">
                <el-col :span="24">
                    <el-form-item :label="$t('reportDesigner.UnitType')" :prop="UnitTypeId" label-width="80px">
                        <el-select v-model="form['UnitTypeId']" clearable style="width: 100%" @change="otherChange(6)" :disabled="unitList.length<=1?true:false">
                            <el-option v-for="item in unitList" :key="item.Id" :label="item.Value" :value="item.Id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>


            <el-divider v-if="formatSetItems && formatSetItems.length > 0 ? true : false">{{$t("reportDesigner.FormatSetting")}}</el-divider>
            <el-row :gutter="15" v-for="(data, index) in formatSetItems" :key="index">
                <el-col :span="24" v-if="data.type == 'switch'">
                    <el-form-item :label="$t(data.title)" :label-width="data.labelWidth ? data.labelWidth : '80px'"
                        :prop="data.field" :rules="rulesHandle(data)">
                        <el-switch v-model="form[data.field]" active-value="1" inactive-value="0" @change="eventClick(data)">
                        </el-switch>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="data.type == 'scSwitch'">
                    <el-form-item :label="$t(data.title)" :label-width="data.labelWidth ? data.labelWidth : '80px'"
                        :prop="data.field" :rules="rulesHandle(data)">
                        <el-switch v-model="form[data.field]" active-value="1" inactive-value="0"
                            @change="eventClick(data)"></el-switch>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="data.type=='inputSelect'" >
                    <el-form-item :label="$t(data.title)" :label-width="data.labelWidth ? data.labelWidth : '60px'" :prop="data.field" :rules="rulesHandle(data)">
                        <el-input v-model="form[data.field]" clearable :style="changeInputStyle(data.unit)" @change="eventClick(data)">
                            <template #prepend>
                                <el-select v-model="form[data.defaultOptionType]" style="width: 85px;" @change="eventClick(data)">
                                    <el-option :label="$t(dataOptionItem.label)" :value="dataOptionItem.value" v-for="(dataOptionItem, index) in data.options" :key="index"></el-option>
                                </el-select>
                            </template>
                        </el-input><span>&nbsp;&nbsp;{{data.unit}}</span>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="data.type=='elUpload'" >
                    <el-form-item :label-width="data.labelWidth ? data.labelWidth : '60px'" :prop="data.field" :rules="rulesHandle(data)">
                        <el-upload v-model="form[data.field]" :auto-upload="false" action="" :show-file-list="false"  style="width:100%" class="sc-file-select__upload" :accept="accept" :on-change="uploadChange" :before-upload="uploadBefore" >
                            <el-button type="primary" style="width:100%"  icon="el-icon-upload">{{ $t('reportDesigner.LocalUpload') }}</el-button>
                        </el-upload>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-divider v-if="optionSetItems && optionSetItems.length > 0 ? true : false" style="margin-top: 5px;">{{$t("reportDesigner.SelectorItemsSetting")}}
            </el-divider>
            <el-row :gutter="15" v-for="(data, index) in optionSetItems" :key="index">
                <el-col :span="24" v-if="data.type == 'switch'">
                    <el-form-item :label="$t(data.title)" :label-width="data.labelWidth ? data.labelWidth : '80px'"
                        :prop="data.field" :rules="rulesHandle(data)">
                        <el-switch v-model="form[data.field]" active-value="1" inactive-value="0"
                            @change="changeDataSourceType"></el-switch>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="15" v-for="(data, index) in form.staticDataSourceItems" :key="index">
                <el-col :span="24" v-if="data.type == 'addButtom' && isStaticDataSource">
                    <el-form-item :label="$t(data.title)" :label-width="data.labelWidth ? data.labelWidth : '80px'"
                        :prop="data.field" :rules="rulesHandle(data)">
                        <el-button type="primary" icon="el-icon-plus" circle @click="addModel" :title="data.value">
                        </el-button>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-else-if="data.type == 'inputOption' && isStaticDataSource">
                    <el-form-item :label="(data.title)" :label-width="data.labelWidth ? data.labelWidth : '80px'"
                        :prop="data.field" :rules="rulesHandle(data)">
                        <el-input v-model="form[data.field]" clearable @change="changeModel(0, index, form[data.field],data.field)"
                            style="width:85%;"></el-input>&nbsp;&nbsp;
                        <el-button type="danger" icon="el-icon-delete" circle @click.prevent="removeModel(0, index)"
                            :title="data.tip"></el-button>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="15" v-for="(data, index) in form.dynamicDataSourceItems" :key="index">
                <el-col :span="24" v-if="data.type == 'inputSearch' && !isStaticDataSource">
                    <el-form-item :label="$t(data.title)" :label-width="data.labelWidth ? data.labelWidth : '80px'"
                        :prop="data.field" :rules="rulesHandle(data)">
                        <el-input v-model="form[data.field]" clearable style="width:85%;"></el-input>&nbsp;&nbsp;
                        <el-button type="primary" icon="el-icon-search" circle :title="data.tip"
                            @click="queryOptionData(data.field)"></el-button>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-else-if="data.type == 'inputOption' && !isStaticDataSource">
                    <el-form-item :label="$t(data.title)" :label-width="data.labelWidth ? data.labelWidth : '80px'"
                        :prop="data.field" :rules="rulesHandle(data)">
                        <el-input v-model="form[data.field]" clearable @change="changeModel(1, index, form[data.field],data.field)"
                            style="width:85%;"></el-input>&nbsp;&nbsp;
                        <el-button type="danger" icon="el-icon-delete" circle @click.prevent="removeModel(1, index)"
                            :title="data.tip"></el-button>
                    </el-form-item>
                </el-col>
            </el-row>
        <el-divider v-if="cellSetItems&&cellSetItems.length>0?true:false">{{ $t('reportDesigner.CellSetting') }}</el-divider>
        <div :class="bindActiveStyle(data)" v-for="(data, index) in cellSetItems" :key="index">
            <div @click="cellOperateClick(data)">
                <div class="_fc-l-icon">
                    <i class="fc-icon" :class="data.icon || 'icon-input'"></i>
                </div>
                <span class="_fc-l-name">{{ $t(data.title) }}</span>
            </div>
        </div>
        </el-form>
        <addControl-dialog v-if="dialog.addControl" ref="addControlDialog" @success="handleSaveSuccess">
        </addControl-dialog>
    </div>
</template>

<script>
import common from "@/utils/common"
import tool from '@/utils/tool';
import addControlDialog from './addControl'
import api from "@/api"
export default {
    components: {
        addControlDialog
    },
    props: {
        propertyConfig: { type: Object, default: () => { } },
    },
    data() {
        return {
            dialog: {
                addControl: false
            },
            renderLoading: false,
            form: {
                id: "",
                staticDataSourceItems: [],
                dynamicDataSourceItems: [],

                UnitType: "",
                MeasureCalculation: "",
                OutputItem: "",
                MeasureWay: "",
                MeasureItem: "",
                MeasureCategory: "",
                ScanMode: "",
                UserDefineName: "",
                MeasureItemList: [],
                Formula:"",

                UnitTypeId: 0,
                MeasureCalculationId: 0,
                OutputItemId: 0,
                MeasureWayId: 0,
                MeasureItemId: 0,
                MeasureCategoryId: 0,
                ScanModeId: 0,
                UserDefineNameId: 0,
            },
            contentSetItems: [],
            formatSetItems: [],
            optionSetItems: [],
            cellSetItems: [],
            bindContentList: [],
            selectItems: {},
            addIndex: 0,
            api: null,
			accept: "image/gif, image/jpeg, image/png",
            isStaticDataSource: false,
            maxSize: 10,
            isShowCommonItem: false,
            isShowOtherItem: false,
            isShowContent:true,
            modeList:[],
            categoryList:[],
            measureItemList:[],
            measureWayList:[],
            outputList:[],
            unitList:[],
            customNameList:[],
            caculateItemList:[],
            curOperateField: "",
            customMeasureItemData: {},
            measureDataJson:{},
            featureList: []
        }
    },
    watch: {
        propertyConfig() {
            this.render(this.propertyConfig)
        },
    },
    created() {
        this.initData();
    },
    methods: {
        async initData() {
            this.featureList = await this.$API.template.getFeatureTagAsync.post();
        },
        //其他样式的点击事件
        cellOperateClick(data){
            if (this.propertyConfig.data && this.propertyConfig.data.property && this.propertyConfig.data.property.cellOperate && this.propertyConfig.data.property.cellOperate.length > 0)
            {
                this.propertyConfig.data.property.cellOperate.map(c => {
                    if (c.field === data.field)
                    {
                        this.form[c.field] = !data.value;
                    }
                    else
                    {
                        this.form[c.field] = false;
                    }
                });
            }
            this.eventClick();
        },
        //构建form对象
        bindActiveStyle(data) {
            if (data.value)
            {
                return "_fc-l-item _fc-l-item-G";
            }
            else
            {
                    return "_fc-l-item";
            }
        },
        //修改样式
        changeInputStyle(content) {
            var styleInfo = "";
            if (content === "mm") {
                styleInfo += "width:85%;";
            }
            else {
                styleInfo += "width:100%;";
            }
            return styleInfo;
        },
        //构建form对象
        render(propertyInfo) {
            this.isShowCommonItem = false;
            this.isShowOtherItem = false;
            this.isShowContent = true;
            if (propertyInfo && propertyInfo.data && propertyInfo.data.property) {
                if (propertyInfo.data.property.contentSet && propertyInfo.data.property.contentSet.length > 0) {
                    this.contentSetItems = propertyInfo.data.property.contentSet;
                }
                else {
                    this.contentSetItems = [];
                }
                if (propertyInfo.data.property.formatSet && propertyInfo.data.property.formatSet.length > 0) {
                    this.formatSetItems = propertyInfo.data.property.formatSet;
                }
                else {
                    this.formatSetItems = [];
                }
                if (propertyInfo.data.property.cellOperate && propertyInfo.data.property.cellOperate.length > 0) {
                    this.cellSetItems = propertyInfo.data.property.cellOperate;
                }
                else {
                    this.cellSetItems = [];
                }
                //这里置空
                this.optionSetItems = [];
                this.bindContentList = [];
                this.form.staticDataSourceItems = [];
                this.form.dynamicDataSourceItems = [];
                if (propertyInfo.data.property.dataSourceSet && propertyInfo.data.property.dataSourceSet.length > 0) {
                    this.loadSelectOptionSetting(propertyInfo);
                }
            }
            else {
                //这里置空
                this.cellSetItems = [];
                this.contentSetItems = [];
                this.formatSetItems = [];
                this.optionSetItems = [];
                this.bindContentList = [];
                this.form.staticDataSourceItems = [];
                this.form.dynamicDataSourceItems = [];
            }
            this.bindActiveData(propertyInfo);
            //this.form.id = this.propertyConfig.id
        },
        //加载下拉菜单配置项
        async loadSelectOptionSetting(propertyInfo) {
            if (propertyInfo) {
                var dataSourceSet = propertyInfo.data.property.dataSourceSet[0];
                if (dataSourceSet) {
                    var dataSourceType = {
                        type: dataSourceSet.type, field: dataSourceSet.field, title: dataSourceSet.title, require: dataSourceSet.require,
                        value: dataSourceSet.value, unit: dataSourceSet.unit, rules: dataSourceSet.rules, options: dataSourceSet.options, labelWidth: "270px"
                    };
                    this.optionSetItems.push(dataSourceType);
                }
            }
        },
        //绑定数据源
        async bindDataSource(propertyInfoConfig) {
            if (propertyInfoConfig && propertyInfoConfig.result && propertyInfoConfig.result.property && propertyInfoConfig.result.property.dynamicDataSource && propertyInfoConfig.result.property.staticOptions) {
                var propertyInfo = propertyInfoConfig.result.property;
                this.form[propertyInfo.dataSourceType.field] = propertyInfo.dataSourceType.value;
                this.isStaticDataSource = (propertyInfo.dataSourceType.value === '0' ? true : false);
                //静态；
                var addbuttom = {
                    type: 'addButtom', field: 'addButtom', title: this.$t("reportDesigner.Options"), require: false, value: this.$t("reportDesigner.AddOption"), labelWidth: "270px"
                };
                this.form.staticDataSourceItems.push(addbuttom);
                if (propertyInfo.staticOptions && propertyInfo.staticOptions.length > 0) {
                    propertyInfo.staticOptions.map(c => {
                        var tempOptionItem = {
                            type: 'inputOption', field: common.guid(), title: '', require: true, value: c, labelWidth: "0px",
                            rules: [{ required: true, message: "Please input " + c + " Content", trigger: "blur" }], tip: this.$t("reportDesigner.DeleteOption")
                        };
                        this.form.staticDataSourceItems.push(tempOptionItem);
                    })
                }
                //表示动态数据
                var dynamicApiObj = {
                    type: 'inputSearch', field: 'dynamicApiObj', title: "", require: true, value: propertyInfo.dynamicDataSource.methodString, labelWidth: "0px",
                    rules: [{ required: true, message: "Please input request interface", trigger: "blur" }], tip: this.$t("reportDesigner.LoadingData")
                };
                this.form.dynamicDataSourceItems.push(dynamicApiObj);
                this.form[dynamicApiObj] = dynamicApiObj.value;
                this.api = propertyInfo.dynamicDataSource.api;
                if (propertyInfo.dynamicOptions && propertyInfo.dynamicOptions.length > 0) {
                    propertyInfo.dynamicOptions.map(c => {
                        var tempOptionItem = {
                            type: 'inputOption', field: common.guid(), title: '', require: true, value: c, labelWidth: "0px",
                            rules: [{ required: true, message: "Please input " + c + " Content", trigger: "blur" }], tip: this.$t("reportDesigner.DeleteOption")
                        };
                        this.form.dynamicDataSourceItems.push(tempOptionItem);
                    })
                }
                else {
                    var methodList = propertyInfo.dynamicDataSource.methodString.split('.');
                    var result = await propertyInfo.dynamicDataSource.api[methodList[0]][methodList[1]].post();
                    if (result && result.length > 0) {
                        result.map(c => {
                            var tempOptionItem = {
                                type: 'inputOption', field: common.guid(), title: '', require: true, value: c.Value, labelWidth: "0px",
                                rules: [{ required: true, message: "Please input " + c.Value + " Content", trigger: "blur" }], tip: this.$t("reportDesigner.DeleteOption")
                            };
                            this.form.dynamicDataSourceItems.push(tempOptionItem);
                        })
                    }
                }
            }
        },
        //绑定数据，初始化时或加在Json时需要赋值
        async bindActiveData(propertyInfo) {
            if (propertyInfo && propertyInfo.result && propertyInfo.result.property) {
                var moduleInfo = propertyInfo.result.property;
                //组件切换反绑定
                this.form.bindType = moduleInfo.bindType;
                this.form.bindTypeField = moduleInfo.bindTypeField;
                if (moduleInfo.placeholder && moduleInfo.placeholder.length > 0) {
                    this.form.placeholder = this.$t(moduleInfo.placeholder);
                }
                else {
                    this.form.placeholder = moduleInfo.placeholder;
                }
                this.form.displayFormat = moduleInfo.displayFormat;
                this.form.realTime = moduleInfo.required ? "1" : "0";
                this.form.required = moduleInfo.required ? "1" : "0";
                this.form.editable = moduleInfo.editable ? "1" : "0";
                this.form.multiple = moduleInfo.multiple ? "1" : "0";
                this.form.arrangement = moduleInfo.arrangement ? "1" : "0";
                this.form.imageFile = moduleInfo.imageFile;
                //表格和单元格反绑定
                this.form.cellColumnWidth = moduleInfo.cellColumnWidth;//单位mm
                this.form.cellColumnWidhtType = moduleInfo.cellColumnWidhtType;
                this.form.cellRowHeight = moduleInfo.cellRowHeight;
                this.form.cellRowHeightType = moduleInfo.cellRowHeightType;
                this.form.isHidden = moduleInfo.isHidden ? "1" : "0";

                if (propertyInfo.result.base && propertyInfo.result.base.rowCount && propertyInfo.result.base.rowCount > 0) {
                    this.form.rowCount = propertyInfo.result.base.rowCount;
                    this.form.columnCount = propertyInfo.result.base.columnCount;
                }

                this.form.showImageAndDesc = moduleInfo.showImageAndDesc ? "1" : "0";
                this.form.pageNumberType = moduleInfo.pageNumberType;

                this.form.HospitalIcon = moduleInfo.HospitalIcon ? "1" : "0";
                this.form.HospitalName = moduleInfo.HospitalName ? "1" : "0";
                this.form.ReportTitleName = moduleInfo.ReportTitleName ? "1" : "0";

                this.form.ReportTime = moduleInfo.ReportTime ? "1" : "0";
                this.form.InspectionPhysician = moduleInfo.InspectionPhysician ? "1" : "0";
                this.form.ReportPhysician = moduleInfo.ReportPhysician ? "1" : "0";
                this.form.ImageFile = moduleInfo.ImageFile ? "1" : "0";
				this.form.featureTag = moduleInfo.featureTag;

                //重新处理级联绑定事件
                if (this.form.bindTypeField && this.form.bindTypeField.length > 0) {
                    if (propertyInfo.data.property.contentSet && propertyInfo.data.property.contentSet.length > 0) {
                        var selectList = propertyInfo.data.property.contentSet.filter(c => c.type === "select");
                        if (selectList && selectList.length > 0) {
                            for (var k = 0; k < selectList.length; k++) {
                                var d = selectList[k];
                                if (d.field === 'bindType') {
                                    this.selectItems[d.field] = await api.template.findContentConfigAsync.post();
                                }
                                else if (d.field === 'displayFormat') {
                                    this.selectItems[d.field] = await api.template.getDateModuleOptionsAsync.post();
                                }
                                else if (d.field === 'pageNumberType') {
                                    this.selectItems[d.field] = await api.template.getPageNumberList.post();
                                }
                            }
                        }
                        var dataItem = propertyInfo.data.property.contentSet.filter(item => item.field === this.form.bindTypeField)[0];
                        if (this.form[dataItem.field] && this.form[dataItem.field].length > 0) {
                            if (this.form[dataItem.field] === "CommonMeasure" || this.form[dataItem.field] === "OtherMeasure" ) {
                                //计算项不验证
                                this.initMeasureItem(this.form[dataItem.field], moduleInfo.measureItem);
                            }
                            else {
                                await this.getRemoteData(dataItem.tiedDataSource, { code: this.form[dataItem.field] }, dataItem.tiedBack);
                            }
                        }
                    }
                }
                this.form.bindField = moduleInfo.bindField;
                this.bindDataSource(propertyInfo);
            }
        },
        // //加载数据
        // async initSelectData() {
        //     var result = await api.template.findContentConfigAsync.post();
        //     return result;
        // },
        //查询数据
        async queryOptionData(dynamicField) {
            if (!this.form[dynamicField] || this.form[dynamicField].length <= 0 || this.form[dynamicField].split('.').length <= 1) {
                this.$message.warning(this.$t("reportDesigner.ReadDataFail"));
                return;
            }
            else {
                var methodList = this.form[dynamicField].split('.');
                var result = await this.api[methodList[0]][methodList[1]].post();
                if (result && result.length > 0) {
                    const list = this.form.dynamicDataSourceItems.filter(item => item.type != "inputOption")
                    this.form.dynamicDataSourceItems = list;
                    result.map(c => {
                        var tempOptionItem = {
                            type: 'inputOption', field: common.guid(), title: '', require: true, value: c.Value, labelWidth: "0px",
                            rules: [{ required: true, message: "Please input " + c.Value + " Content", trigger: "blur" }], tip: this.$t("reportDesigner.DeleteOption")
                        };
                        this.form.dynamicDataSourceItems.push(tempOptionItem);
                    })
                }
            }
            this.eventClick();
        },
        //改变数据源类型
        changeDataSourceType(type) {
            this.isStaticDataSource = ((type === 0 || type === "0") ? true : false);
            this.eventClick();
        },
        async getCommonData(jsonData) {
            if (this.measureDataJson) {
                this.modeList = [];
                this.measureItemList = [];
                this.measureWayList = [];
                this.outputList = [];
                this.unitList = [];
                this.customNameList = [];

                if (this.measureDataJson.model)
                {
                    var comModelList = this.measureDataJson.model.filter(c => c.Type === 2);
                    comModelList.forEach((a, index1) => {
                        this.modeList.push({
                            Id: a.Id, Key: a.Key, Value: a.Value
                        });
                        if (index1 === 0) {
                            this.form.ScanModeId = a.Id;
                        }
                        if (jsonData && jsonData.Mode && jsonData.Mode.length > 0) {
                            if (jsonData.Mode === a.Key)
                            {
                                this.form.ScanModeId = a.Id;
                            }
                        }
                    });
                }
                this.bindCommonData(0, jsonData);
            }
        },
        async getOtherData(jsonData) {
            if (this.measureDataJson) {
                this.outputList = [];
                this.modeList = [];
                this.caculateItemList= [];
                this.unitList = [];
                this.categoryList = [];
                this.measureItemList = [];
                this.measureWayList = [];
                if (this.measureDataJson.model)
                {
                    var comModelList = this.measureDataJson.model.filter(c => c.Type === 3);
                    comModelList.forEach((a, index1) => {
                        this.modeList.push({
                            Id: a.Id, Key: a.Key, Value: a.Value
                        });
                        if (index1 === 0) {
                            this.form.ScanModeId = a.Id;
                        }
                        if (jsonData && jsonData.Mode && jsonData.Mode.length > 0) {
                            if (jsonData.Mode === a.Key)
                            {
                                this.form.ScanModeId = a.Id;
                            }
                        }
                    });
                }
                this.bindOtherData(0);
            }
        },
        bindCommonData(type, jsonData) {
            if (type === 0) {
                if (this.measureDataJson.measureItem)
                {
                    this.measureItemList = [];
                    var comMeasureItemList = this.measureDataJson.measureItem.filter(c => c.Type === 2 && c.PId === this.form.ScanModeId);
                    comMeasureItemList.forEach((b, index2) => {
                        this.measureItemList.push({
                            Id: b.Id, Key: b.Key, Value: (b.Value.length > 0 ? b.Value : " ")
                        });
                        if (index2 === 0) {
                            this.form.MeasureItemId = b.Id;
                        }
                        if (jsonData && jsonData.BaseType) {
                            if (jsonData.BaseType === b.Key)
                            {
                                this.form.MeasureItemId = b.Id;
                            }
                        }
                    });
                }
            }
            if (type === 0 || type === 1) {
                if (this.measureDataJson.measureMethod)
                {
                    this.measureWayList = [];
                    var comMeasureMethodList = this.measureDataJson.measureMethod.filter(c => c.Type === 2 && c.PId === this.form.MeasureItemId);
                    comMeasureMethodList.forEach((c, index3) => {
                        this.measureWayList.push({
                            Id: c.Id, Key: c.Key, Value: (c.Value.length > 0 ? c.Value : " ")
                        });
                        //this.measureItemList.push(c.Key);
                        if (index3 === 0) {
                            this.form.MeasureWayId = c.Id;
                        }
                        if (jsonData && jsonData.Method) {
                            if (jsonData.Method === c.Key)
                            {
                                this.form.MeasureWayId = c.Id;
                            }
                        }
                    });
                }
            }
            if (type === 0 || type === 1 || type === 2) {
                if (this.measureDataJson.output)
                {
                    this.outputList = [];
                    var comOutputList = this.measureDataJson.output.filter(c => c.Type === 2 && c.PId === this.form.MeasureWayId);
                    comOutputList.forEach((d, index4) => {
                        this.outputList.push({
                            Id: d.Id, Key: d.Key, Value: (d.Value.length > 0 ? d.Value : " ")
                        });
                        if (index4 === 0) {
                            this.form.OutputItemId = d.Id;
                        }
                        if (jsonData && jsonData.Output) {
                            if (jsonData.Output === d.Key)
                            {
                                this.form.OutputItemId = d.Id;
                            }
                        }
                    });
                }
            }
            if (type === 0 || type === 1 || type === 2 || type === 3) {
                if (this.measureDataJson.unit)
                {
                    this.unitList = [];
                    var comUnitList = this.measureDataJson.unit.filter(c => c.Type === 2 && c.PId === this.form.OutputItemId);
                    comUnitList.forEach((e, index5) => {
                        this.unitList.push({
                            Id: e.Id, Key: e.Key, Value: (e.Value.length > 0 ? e.Value : " ")
                        });
                        if (index5 === 0) {
                            this.form.UnitTypeId = e.Id;
                        }
                        if (jsonData && jsonData.Unit) {
                            if (jsonData.Unit === e.Key)
                            {
                                this.form.UnitTypeId = e.Id;
                            }
                        }
                    });
                }
            }
            if (type === 0 || type === 1 || type === 2 || type === 3 || type === 4) {
                if (this.measureDataJson.type)
                {
                    this.customNameList = [];
                    var comTypeList = this.measureDataJson.type.filter(c => c.Type === 2 && c.PId === this.form.UnitTypeId);
                    comTypeList.forEach((f, index6) => {
                        this.customNameList.push({
                            Id: f.Id, Key: f.Key, Value: (f.Value.length > 0 ? f.Value : " ")
                        });
                        if (index6 === 0) {
                            this.form.UserDefineNameId = f.Id;
                        }
                        if (jsonData && jsonData.UserId) {
                            if (jsonData.UserId.indexOf(f.Key) > 0)
                            {
                                this.form.UserDefineNameId = f.Id;
                            }
                        }
                    });
                }
            }
        },
        commonChange(type) {
            this.bindCommonData(type);
            this.modeList.some(c => {
                if (this.form.ScanModeId === c.Id)
                {
                    this.form.ScanMode = c.Key;
                    if (c.Formula && c.Formula.length > 0) {
                        this.form.ScanMode = "CustomizeCalculation";
                        this.form.Formula = c.Formula;
                    }
                    return true;
                }
            });
            this.measureItemList.some(c => {
                if (this.form.MeasureItemId === c.Id)
                {
                    this.form.MeasureItem = c.Key;
                    if (c.Formula && c.Formula.length > 0) {
                        this.form.MeasureItem = c.Title;
                    }
                    return true;
                }
            });
            this.measureWayList.some(c => {
                if (this.form.MeasureWayId === c.Id)
                {
                    this.form.MeasureWay = c.Key;
                    return true;
                }
            });
            this.outputList.some(c => {
                if (this.form.OutputItemId === c.Id)
                {
                    this.form.OutputItem = c.Key;
                    if (c.Formula && c.Formula.length > 0) {
                        this.form.OutputItem = "ReportTemplate." + c.Title;
                    }
                    return true;
                }
            });
            this.unitList.some(c => {
                if (this.form.UnitTypeId === c.Id)
                {
                    this.form.UnitType = c.Key;
                    return true;
                }
            });
            this.customNameList.some(c => {
                if (this.form.UserDefineNameId === c.Id)
                {
                    this.form.UserDefineName = c.Key;
                    return true;
                }
            });
            this.eventClick();
        },
        bindOtherData(type, jsonData) {
            if (type === 0) {
                if (this.measureDataJson.category)
                {
                    this.categoryList = [];
                    var comCategoryList = this.measureDataJson.category.filter(c => c.Type === 3 && c.PId === this.form.ScanModeId);
                    comCategoryList.forEach((m, index7) => {
                        this.categoryList.push({
                            Id: m.Id, Key: m.Key, Value: (m.Value.length > 0 ? m.Value : " ")
                        });
                        if (index7 === 0) {
                            this.form.MeasureCategoryId = m.Id;
                        }
                    });
                }
            }
            if (type === 0 || type === 1) {
                if (this.measureDataJson.measureItem)
                {
                    this.measureItemList = [];
                    var comMeasureItemList = this.measureDataJson.measureItem.filter(c => c.Type === 3 && c.PId === this.form.MeasureCategoryId);
                    comMeasureItemList.forEach((b, index2) => {
                        this.measureItemList.push({
                            Id: b.Id, Key: b.Key, Value: (b.Value.length > 0 ? b.Value : " ")
                        });
                        if (index2 === 0) {
                            this.form.MeasureItemId = b.Id;
                        }
                        if (jsonData && jsonData.BaseType) {
                            if (jsonData.BaseType === b.Key)
                            {
                                this.form.MeasureItemId = b.Id;
                                this.form.MeasureCategoryId = b.PId;
                            }
                        }
                    });
                }
            }
            if (type === 0 || type === 1 || type === 2) {
                if (this.measureDataJson.measureMethod)
                {
                    this.measureWayList = [];
                    var comMeasureMethodList = this.measureDataJson.measureMethod.filter(c => c.Type === 3 && c.PId === this.form.MeasureItemId);
                    comMeasureMethodList.forEach((c, index3) => {
                        this.measureWayList.push({
                            Id: c.Id, Key: c.Key, Value: (c.Value.length > 0 ? c.Value : " ")
                        });
                        //this.measureItemList.push(c.Key);
                        if (index3 === 0) {
                            this.form.MeasureWayId = c.Id;
                        }
                        if (jsonData && jsonData.Method) {
                            if (jsonData.Method === c.Key)
                            {
                                this.form.MeasureWayId = c.Id;
                            }
                        }
                    });
                }
            }
            if (type === 0 || type === 1 || type === 2 || type === 3) {
                if (this.measureDataJson.output)
                {
                    this.outputList = [];
                    var comOutputList = this.measureDataJson.output.filter(c => c.Type === 3 && c.PId === this.form.MeasureWayId);
                    comOutputList.forEach((d, index4) => {
                        this.outputList.push({
                            Id: d.Id, Key: d.Key, Value: (d.Value.length > 0 ? d.Value : " ")
                        });
                        if (index4 === 0) {
                            this.form.OutputItemId = d.Id;
                        }
                        if (jsonData && jsonData.Output) {
                            if (jsonData.Output === d.Key)
                            {
                                this.form.OutputItemId = d.Id;
                            }
                        }
                    });
                }
            }
            if (type === 0 || type === 1 || type === 2 || type === 3 || type === 4) {
                if (this.measureDataJson.caculateItem)
                {
                    this.caculateItemList = [];
                    var comCaculateItemList = this.measureDataJson.caculateItem.filter(c => c.Type === 3 && c.PId === this.form.OutputItemId);
                    comCaculateItemList.forEach((f, index6) => {
                        this.caculateItemList.push({
                            Id: f.Id, Key: f.Key, Value: (f.Value.length > 0 ? f.Value : " ")
                        });
                        if (index6 === 0) {
                            this.form.MeasureCalculationId = f.Id;
                        }
                        if (jsonData && jsonData.CalculationId) {
                            if (jsonData.CalculationId === f.Key)
                            {
                                this.form.MeasureCalculationId = f.Id;
                            }
                        }
                    });
                }
            }
            if (type === 0 || type === 1 || type === 2 || type === 3 || type === 4 || type === 5) {
                if (this.measureDataJson.unit)
                {
                    this.unitList = [];
                    var comUnitList = this.measureDataJson.unit.filter(c => c.Type === 3 && c.PId === this.form.MeasureCalculationId);
                    comUnitList.forEach((e, index5) => {
                        this.unitList.push({
                            Id: e.Id, Key: e.Key, Value: (e.Value.length > 0 ? e.Value : " ")
                        });
                        if (index5 === 0) {
                            this.form.UnitTypeId = e.Id;
                            if (jsonData && jsonData.Unit) {
                                if (jsonData.Unit === e.Key)
                                {
                                    this.form.UnitTypeId = e.Id;
                                }
                            }
                            //加载type信息用于绑定到json数据中
                            if (this.measureDataJson.type)
                            {
                                var typeTempList = this.measureDataJson.type.filter(c => c.Type === 3 && c.PId === this.form.UnitTypeId);
                                if (typeTempList && typeTempList.length > 0) {
                                    this.form.UserDefineNameId = typeTempList[0].Id;
                                }
                                if (jsonData && jsonData.UserId) {
                                    typeTempList = this.measureDataJson.type.filter(c => c.Type === 3 && c.PId === this.form.UnitTypeId && c.Key === jsonData.UserId);
                                    if (typeTempList && typeTempList.length > 0) {
                                        this.form.UserDefineNameId = typeTempList[0].Id;
                                    }
                                }
                            }
                        }
                    });
                }
            }
        },
        otherChange(type) {
            this.bindOtherData(type);
            this.outputList.some(c => {
                if (this.form.OutputItemId === c.Id)
                {
                    this.form.OutputItem = c.Key;
                    return true;
                }
            });
            this.modeList.some(c => {
                if (this.form.ScanModeId === c.Id)
                {
                    this.form.ScanMode = c.Key;
                    return true;
                }
            });
            this.caculateItemList.some(c => {
                if (this.form.MeasureCalculationId === c.Id)
                {
                    this.form.MeasureCalculation = c.Key;
                    return true;
                }
            });
            this.unitList.some(c => {
                if (this.form.UnitTypeId === c.Id)
                {
                    this.form.UnitType = c.Key;
                    return true;
                }
            });
            this.categoryList.some(c => {
                if (this.form.MeasureCategoryId === c.Id)
                {
                    this.form.MeasureCategory = c.Key;
                    return true;
                }
            });
            this.measureItemList.some(c => {
                if (this.form.MeasureItemId === c.Id)
                {
                    this.form.MeasureItem = c.Key;
                    return true;
                }
            });
            this.measureWayList.some(c => {
                if (this.form.MeasureWayId === c.Id)
                {
                    this.form.MeasureWay = c.Key;
                    return true;
                }
            });
            if (this.measureDataJson.type)
            {
                var typeTempList = this.measureDataJson.type.filter(c => c.Type === 3 && c.PId === this.form.UnitTypeId);
                if (typeTempList && typeTempList.length > 0) {
                    this.form.UserDefineNameId = typeTempList[0].Id;
                    this.form.UserDefineName = typeTempList[0].Key;
                }
            }
            this.eventClick();
        },
        initMeasureItem(dataFieldValue, jsonData) {
            if (dataFieldValue === "CommonMeasure" ) {
                this.isShowCommonItem = true;
                this.isShowOtherItem = false;
                this.isShowContent = false;
                this.addCustomMeasureItemData();
                this.getCommonData(jsonData);
            }
            else {
                this.isShowCommonItem = false;
                this.isShowOtherItem = true;
                this.isShowContent = false;
                this.getOtherData(jsonData);
            }
        },
        //提交
        eventClick(data) {
            if (data && data.changeStatus) {
                if (this.form[data.field] === "CommonMeasure" ) {
                    this.isShowCommonItem = true;
                    this.isShowOtherItem = false;
                    this.isShowContent = false;
                    this.addCustomMeasureItemData();
                    this.getCommonData();
                }
                else if (this.form[data.field] === "OtherMeasure") {
                    this.isShowCommonItem = false;
                    this.isShowOtherItem = true;
                    this.isShowContent = false;
                    this.getOtherData();
                }
                else {
                    this.isShowCommonItem = false;
                    this.isShowOtherItem = false;
                    this.isShowContent = true;
                    this.getRemoteData(data.tiedDataSource, { code: this.form[data.field] }, data.tiedBack);
                }
            }
            if (data && data.field && this.form[data.field]) {
                if((typeof this.form[data.field]=='string')&&this.form[data.field].constructor==String){
                    //this.form[data.field] = this.form[data.field].replace(/^\s*|\s*$/g,"");
                }
                if (this.form[data.field])
                {
                    //有值不处理
                }
                else
                {
                    if (data.value && data.value.length > 0) {
                        this.form[data.field] = this.$t(data.value);
                    }
                    else {
                        this.form[data.field] = data.value;
                    }
                }

                if (data.type === "elSelect") {
                    var curBindItems = this.bindContentList.filter(c => c.Key === this.form[data.field]);
                    if (curBindItems && curBindItems.length > 0) 
                    {
                        var curBindItem = curBindItems[0];
                        if (curBindItem.Id && curBindItem.Id.length > 0)
                        {
                            //Key
                            this.form["isDefault"] = curBindItem.IsDefault;
                        }
                    }
                }
            }
            if (data && !this.form[data.field] && data.require) {
                this.$message.warning(this.$t("reportDesigner.PropertyRequireNotEmpty"));
                return false;
            }
            if (data && (data.field === "rowCount" || data.field === "columnCount")) {
                if (parseInt(this.form[data.field]) <= 0) {
                    this.$message.warning(this.$t("reportDesigner.PropertyValueMustNumber"));
                    return false;
                }
            }
            if (data && this.form[data.field] && data.field === "displayFormat") {
                var selectOptions = this.selectItems[data.field];//this.$refs['select' + data.field + this.propertyConfig.id][0].options;
                var text = selectOptions.filter(c => c.Key === this.form[data.field])[0].Value;
                this.form[data.text] = text;
                if (this.form[data.field] === "yyyy-MM-dd hh:mm" || this.form[data.field] === "yyyy年MM月dd日 hh:mm") {
                    this.form["enable"] = "1";
                    this.form["editable"] = "0";
                    this.form["realTime"] = "1";
                }
                else {
                    this.form["enable"] = "0";
                    this.form["realTime"] = "0";
                }
            }
            if (data && data.field === "realTime") {
                if (this.form[data.field] === "1") {
                    this.form[data.text] = tool.dateFormat(Date.now(), this.form[data.targetField]);
                }
                else {
                    var scOptions = this.$refs['select' + data.targetField + this.propertyConfig.id][0].options;
                    var textContent = scOptions.filter(c => c.value === this.form[data.targetField])[0].label;
                    this.form[data.text] = textContent;
                }
            }
            if (data && this.form[data.field] && data.field === "pageNumberType") {
                if (this.form[data.field] === "Number") {
                    this.form.placeholder = "8";
                }
                else if (this.form[data.field] === "NumberAndTotalNumber") {
                    this.form.placeholder = "88/88";
                }
                else {
                    this.form.placeholder = this.$t("reportDesigner.PageFooterHint");
                }
            }
            if (data && data.field)
            {
                this.form["field"] = data.field;
            }
            // if (data && data.readd) {
            //     this.form["switchReadd"] = data.readd;
            // }
            if (this.propertyConfig.name === "doctorInfo")  {
                if (this.form["ReportTime"] === "0" && this.form["InspectionPhysician"] === "0"
                && this.form["ReportPhysician"] === "0" && this.form["ImageFile"] === "0")
                {
                    this.form[data.field] = "1";
                    this.$message.warning(this.$t("reportDesigner.contentEmptyValidate"));
                    return false;
                }
            }
            if (this.propertyConfig.name === "reportHeader")  {
                if (this.form["HospitalIcon"] === "0" && this.form["HospitalName"] === "0"
                && this.form["ReportTitleName"] === "0")
                {
                    this.form[data.field] = "1";
                    this.$message.warning(this.$t("reportDesigner.contentEmptyValidate"));
                    return false;
                }
            }
            this.$emit("propertyEventClick", this.form);
        },
        //添加控件
        addControl() {
            this.dialog.addControl = true;
            this.$nextTick(() => {
                this.$refs.addControlDialog.open(this.propertyConfig);
            });
        },
        refresh(){
            this.$emit("propertyEventClick", this.form);
        },
        //添加静态项
        addModel() {
            var cString = this.$t('reportDesigner.InsertOption') + this.addIndex;
            var tempOptionItem = {
                type: 'inputOption', field: common.guid(), title: '', require: true, value: cString, labelWidth: "0px",
                rules: [{ required: true, message: "Please input " + cString + " Content", trigger: "blur" }], tip: this.$t('reportDesigner.DeleteOption')
            };
            this.form.staticDataSourceItems.push(tempOptionItem);
            this.addIndex++;
            this.eventClick();
        },
        //删除数据
        removeModel(type, index) {
            if (type === 0) {
                this.form.staticDataSourceItems.splice(index, 1)
            }
            else {
                this.form.dynamicDataSourceItems.splice(index, 1)
            }
            this.eventClick();
        },
        //修改数据
        changeModel(type, index, data, field) {
            if (type === 0) {
                const staticData = this.form.staticDataSourceItems[index];
                if (data && data.replace(/^\s*|\s*$/g,"").length > 0) {
                    staticData.value = data.replace(/^\s*|\s*$/g,"");
                    this.form.staticDataSourceItems.splice(index, 1, staticData);
                }
                else {
                    this.form[field] = this.$t(staticData.value);
                }
            }
            else {
                const dynamicData = this.form.dynamicDataSourceItems[index];
                if (data && data.replace(/^\s*|\s*$/g,"").length > 0) {
                    dynamicData.value = data.replace(/^\s*|\s*$/g,"");
                    this.form.dynamicDataSourceItems.splice(index, 1, dynamicData);
                }
                else {
                    this.form[field] = this.$t(dynamicData.value);
                }
            }
            this.eventClick();
        },
        //获取数据
        async getRemoteData(source, params, tiedBack) {
            var res = []
            try {
                res = await api.template.findContentConfigAsync.post(params);
                if (params && params.code && params.code.length > 0)
                {
                    var tagList = this.$TOOL.data.get("activeTemplateTagList");
                    if (tagList && tagList.length > 0) {
                        var pId = params.code.toString() === "General" ? "0" : "1";
                        tagList.some(c => {
                            if (c.ParentId === pId) 
                            {
                                res.push(c);
                            }
                        })
                    }
                }
            }
            catch (error) {
                return false;
            }
            this.form[tiedBack] = "";
            this.bindContentList = res;
        },
        inputClick(data) {
            var val = this.form[data.field];
            if (!val || val.length <= 0) {
                this.curOperateField = data.field;
            }
            else {
                this.curOperateField = "";
            }
        },
        //处理动态必填
        rulesHandle(data) {
            if (this.curOperateField === data.field) {
                if (data.field === "bindType") {
                    this.form["bindTypeField"] = data.field;
                }
                return data.rules;
            }
            if (data.type === "inputSelect") {
                this.form[data.defaultOptionType] = data.options[0].value;
            }
            if (this.form[data.field])
            {
                //有值不处理
            }
            else
            {
                if (data.value && data.value.length > 0) {
                    this.form[data.field] = this.$t(data.value);
                }
                else {
                    this.form[data.field] = data.value;
                }
            }
            if (data.field === "bindType") {
                this.form["bindTypeField"] = data.field;
            }
            return data.rules;
        },
        //设置样式
        setFormItemStyle(index, length) {
            var styleInfo = "";
            if (index === (length - 1))
            {
                styleInfo += "margin-bottom: 5px;";
            }
            return styleInfo;
        },
        //上传处理
        uploadChange(file){
            var tItem = this;
            this.canvasDataURL(file, function(formData){
                tItem.$emit("propertyEventClick", formData);
            });
        },
        //重绘图片，压缩
        canvasDataURL(file, callback)
        {
            var reader = new FileReader();
            reader.readAsDataURL(file.raw); //调用自带方法进行转换
            var fileSize = parseFloat(parseFloat(parseInt(file["size"]) / 1024 / 1024).toFixed(2));
            var formData = this.form;
            reader.onload = (e) => {
                const image = new Image();
                image.src = e.target.result;
                image.onload = function () { 
                    var that = this;
                    var w = that.width, h = that.height;
                    // 生成canvas
                    var canvas = document.createElement('canvas');
                    var ctx = canvas.getContext('2d');
                    // 创建属性节点
                    var anw = document.createAttribute("width");
                    anw.nodeValue = w;
                    var anh = document.createAttribute("height");
                    anh.nodeValue = h;
                    canvas.setAttributeNode(anw);
                    canvas.setAttributeNode(anh);
                    ctx.drawImage(that, 0, 0, w, h);
                    var quality = 0.8;
                    // 图像质量
                    if (fileSize < 0.8) {
                        //如果图片小于一兆 那么不执行压缩操作
                        quality = 1;
                    }
                    else if (fileSize > 0.8 && fileSize < 1) {
                        //如果图片大于1M并且小于2M 那么压缩0.8
                        quality = 0.8;
                    } else if (fileSize > 1 && fileSize < 2) {
                        //如果图片大于1M并且小于2M 那么压缩0.5
                        quality = 0.5;
                    } else {
                        //如果图片超过2m 那么压缩0.2
                        quality = 0.2;
                    }
                    var base64 = canvas.toDataURL('image/jpeg', quality);
                    formData["imageWidth"] = tool.pxToMM(w);
                    formData["imageHeight"] = tool.pxToMM(h);
                    formData["imageFile"] = base64;
                    callback(formData);
                };
            };
        },
        //上传前处理
        uploadBefore(file){
            const maxSize = file.size / 1024 / 1024 < this.maxSize;
            if (!maxSize) {
                this.$message.warning(this.$t('reportDesigner.MaxUploadFileValue') + ` ${this.maxSize}MB!`);
                return false;
            }
        },
        //重载
        reloadProperty(moduleConfig) {
            this.isShowCommonItem = false;
            this.isShowOtherItem = false;
            this.isShowContent = true;
            this.render(moduleConfig);
        },
        //子页面调用父页面
        handleSaveSuccess(id, selectedItems, cols) {
            this.form["CurrentModuleId"] = id;
            this.form["CurrentModuleSelectedItems"] = selectedItems;
            this.form["CurrentModuleDisplayCols"] = cols;
            this.$emit("propertyEventClick", this.form);
        },
        loadCustomMeasureItemData(data) {
            if (data) {
                this.customMeasureItemData = data;
            }
        },
        loadMeasureDataJson(jsonData) {
            if (jsonData) {
                this.measureDataJson = jsonData;
            }
        },
        addCustomMeasureItemData() {
            if (this.measureDataJson && this.measureDataJson.model && this.measureDataJson.model.length > 0) {
                var tempList = this.measureDataJson.model.filter(c => c.Key === "CustomizeCalculation");
                if (tempList && tempList.length > 0) {
                    var modeIndex = this.measureDataJson.model.indexOf(tempList[0]);
                    this.measureDataJson.model.splice(modeIndex, 1)
                }
                if (this.customMeasureItemData && this.customMeasureItemData.measureItem && this.customMeasureItemData.measureItem.length > 0) {
                    if (this.customMeasureItemData.model && this.customMeasureItemData.model.length > 0) {
                        this.customMeasureItemData.model.some(c => {
                            this.measureDataJson.model.push(c);
                        });
                    }
                    if (this.customMeasureItemData.measureItem && this.customMeasureItemData.measureItem.length > 0) {
                        var tempList1 = this.measureDataJson.measureItem.filter(c => !c.Formula);
                        this.measureDataJson.measureItem = tempList1;

                        this.customMeasureItemData.measureItem.some(c => {
                            this.measureDataJson.measureItem.push(c);
                        })
                    }
                    if (this.customMeasureItemData.measureMethod && this.customMeasureItemData.measureMethod.length > 0) {
                        var tempList2 = this.measureDataJson.measureMethod.filter(c => !c.Formula);
                        this.measureDataJson.measureMethod = tempList2;

                        this.customMeasureItemData.measureMethod.some(c => {
                            this.measureDataJson.measureMethod.push(c);
                        })
                    }
                    if (this.customMeasureItemData.output && this.customMeasureItemData.output.length > 0) {
                        var tempList3 = this.measureDataJson.output.filter(c => !c.Formula);
                        this.measureDataJson.output = tempList3;

                        this.customMeasureItemData.output.some(c => {
                            this.measureDataJson.output.push(c);
                        })
                    }
                    if (this.customMeasureItemData.type && this.customMeasureItemData.type.length > 0) {
                        var tempList4 = this.measureDataJson.type.filter(c => !c.Formula);
                        this.measureDataJson.type = tempList4;

                        this.customMeasureItemData.type.some(c => {
                            this.measureDataJson.type.push(c);
                        })
                    }
                    if (this.customMeasureItemData.unit && this.customMeasureItemData.unit.length > 0) {
                        var tempList5 = this.measureDataJson.unit.filter(c => !c.Formula);
                        this.measureDataJson.unit = tempList5;

                        this.customMeasureItemData.unit.some(c => {
                            this.measureDataJson.unit.push(c);
                        })
                    }
                }
            }
        },
    }
}
</script>

<style>
.el-upload--text {
    width:100%;
}
</style>
