import editView from "@base/views/bd/setting/form_script/edit.vue";
import {selectDialogMixins} from "@base/mixins/selectDialog";
import {getJsxStatus,getJsxBtn} from "@base/views/bd/setting/utils/index";

let modules = {};
modules = {
  name: 'formScriptDialog',
  components: {editView},
  props: ['visiable', 'multi', 'rows', 'param', 'title'],
  mixins: [selectDialogMixins],
  created() {
    this.initSetting();
  },
  mounted() {
    this.initTableM1();
  },
  data() {
    var that = this;
    return {
      showDialog: true,
      falseValue: false,
      selectMulti: true,
      formData: {},
      vxeOption: {},
      activeName: 'second',
      showEdit: false,
      dataId: null,
      showTabs: false
    };
  },
  methods: {
    initTableM1() {
      let that = this;
      let tableOption = {
        vue: this,
        tableRef: 'table-m1',
        tableName: 'user_form_script_dialog-m1',
        path: USER_PREFIX + '/formScript/listPage',
        param: () => {
          return {
            enabled: true,
            scriptType: 0,
            ...this.formData,
            ...this.param
          };
        },
        config: {
          checkboxConfig: {
            checkStrictly: true,
            showHeader: this.selectMulti,
            trigger: 'row'
          }
        },
        columns: [
          {type: 'checkbox', width: 48, resizable: false, fixed: 'left'},
          {
            title: this.$t1('脚本名称'),
            field: 'scriptName',
            width: 180,
            fixed: 'left'
          },
          {
            title: this.$t1('脚本编码'),
            field: 'scriptCode',
            width: 180
          },
          {
            title: this.$t1('脚本说明'),
            field: 'scriptRemark',
            width: 250
          },
          {
            field: 'transactions',
            title: this.$t1('开启事务'),
            width: 150,
            slots: {
              default: ({row}) => {
                if (row.transactions === 1) {
                  return getJsxStatus(null,this.$t1('是'))
                } else {
                  return getJsxStatus('s-3',this.$t1('否'))
                }
              }
            }
          },
          {field: 'serviceName', title: this.$t1('服务名'), width: 150},
          {
            field: 'sid',
            title: this.$t1('唯一标识'),
            width: 250
          },
          {
            field: 'createDate',
            title: this.$t1('创建时间'),
            width: 150
          },
          {
            width: 47,
            fixed: 'right',
            title: '',
            sortable: false,
            slots: {
              default: ({row}) => {
                return getJsxBtn({
                  iconName: "el-icon-edit",
                  content: this.$t1('查看'),
                  onclick: () => {
                    this.openEditDialog(row);
                  }
                });
              }
            }
          }
        ]
      };
      this.$vxeTableUtil.initVxeTable(tableOption).then(opts => {
        this.vxeOption = opts;
      });
    },
    openEditDialog(row) {
      /*this.dataId = !id || typeof id === 'object' ? 0 : id;
      this.activeName = 'first';
      this.$openEditView('showEdit');*/

      let dataId = row?.id || 0;
      if (!dataId) {
        this.dataId = dataId;
        this.activeName = 'first';
        this.$openEditView('showEdit');
      } else {
        this.$refs.xTabs.openEditTab(row);
      }
    },
  }
};
export default modules
