<template>
  <div id="containt">
    <el-tabs v-model="activeName" class="tab-box">
      <el-tab-pane :label="$t1('常规')" name="first">
        <editView v-if="showEdit" visible-key="showEdit" :_dataId.sync="dataId" :parent-target="_self"
                  @reload="$reloadHandle" :formTemplate="formTemplate"></editView>
      </el-tab-pane>
      <el-tab-pane :label="$t1('列表')" name="second">
        <div class="grid-height">
          <vxe-grid ref="table-m1" v-bind="vxeOption" @resizable-change="$vxeTableUtil.onColumnWitchChange"
                    @custom="$vxeTableUtil.customHandle">
            <template #form>
              <div class="clearfix screen-btns">
                <div class="fl">
                  <vxe-button status="primary" class="button-sty" icon="el-icon-plus" @click="openEditDialog">{{ $t1('新增') }}
                  </vxe-button>
                  <div class="txt-name el-icon-house">
                    表单模板名称：
                    <span>{{ formTemplate.formName }}</span>
                  </div>
                </div>
                <div class="fr">
                  <vxe-button icon="el-icon-brush" class="button-sty" @click="resetEvent" type="text" status="primary"
                              plain>{{$t1('重置')}}
                  </vxe-button>
                  <vxe-button status="warning" icon="el-icon-search" class="button-sty" @click="searchEvent">{{ $t1('搜索') }}
                  </vxe-button>
                </div>
              </div>
            </template>
            <template #row_edit>
              <a href="#" class="a-link"><i class="el-icon-edit"/></a>
            </template>
          </vxe-grid>
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import editView from './itemEdit.vue';

export default {
  name: 'itemList',
  components: {editView},
  props: ['formTemplate'],
  data() {
    return {
      activeName: 'second',
      dataId: 0,
      showEdit: false,
      vxeOption: {},
      formData: {}
    };
  },
  mounted() {
    this.initTableList();
  },
  methods: {
    searchEvent() {
      this.$refs['table-m1'].commitProxy('reload');
    },
    resetEvent() {
      this.formData = {};
      this.$refs['table-m1'].commitProxy('reload');
    },
    openEditDialog(id) {
      this.dataId = !id || typeof id == 'object' ? 0 : id;
      this.activeName = 'first';
      this.$openEditView('showEdit');
    },
    initTableList() {
      let that = this;
      let tableOption1 = {
        vue: that,
        tableRef: 'table-m1',
        tableName: 'user_wf_obj_config_item_list-m1',
        path: USER_PREFIX + '/wf_obj_config_item/list',
        param: () => {
          return {
            objTypeCode: this.formTemplate.formCode
          }
        },
        config: {
          maxHeight: '',
          proxyConfig: {
            props: {
              result: "objx",
              total: "objx.length",
            }
          }
        },
        columns: [
          {type: 'checkbox', width: 48, resizable: false, fixed: 'left'},
          {
            title: '流程模版名称',
            field: 'modelName',
            width: 150,
            fixed: 'left'
          },
          {
            title: '流程模版KEY',
            field: 'modelKey',
            width: 150
          },
          {
            title: '单据类型编码',
            field: 'objTypeCode',
            width: 150
          },
          {
            title: '跳过相邻任务',
            field: 'skipAdjacentTask',
            width: 150,
            slots: {
              default: ({row}) => {
                if (row.skipAdjacentTask) {
                  return [<div class="txt-status">是</div>];
                } else {
                  return [<div class="txt-status s-3">否</div>];
                }
              }
            }
          },
          {
            title: '允许提交到驳回节点',
            field: 'toRejectNode',
            width: 180,
            slots: {
              default: ({row}) => {
                if (row.toRejectNode) {
                  return [<div class="txt-status">是</div>];
                } else {
                  return [<div class="txt-status s-3">否</div>];
                }
              }
            }
          },
          {
            field: 'createDate',
            title: this.$t1('创建时间'),
            width: 200
          },
          {
            width: 150,
            fixed: 'right',
            sortable: false,
            title: '',
            slots: {
              default: ({row}) => {
                return [
                  <a
                    href="javascript:void(0);"
                    class="a-link"
                    onclick={() => {
                      this.openEditDialog(row.id);
                    }}
                  >
                    <el-tooltip enterable={false} effect="dark" content={ this.$t1('查看') } placement="top"
                                popper-class="tooltip-skin">
                      <i class="el-icon-edit"/>
                    </el-tooltip>
                  </a>,
                  <a
                    href="javascript:void(0);"
                    onClick={() => {
                      this.wfEdit(row.modelId);
                    }}
                    class="a-link"
                  >
                    <el-tooltip enterable={false} effect="dark" content="流程设计" placement="top"
                                popper-class="tooltip-skin">
                      <i class="iconfont icon-liuchengguanli-shejiqi_liucheng"/>
                    </el-tooltip>
                  </a>,
                  <a
                    href="javascript:void(0);"
                    class="a-link"
                    onClick={() => {
                      this.deleteItem(row);
                    }}
                  >
                    <el-tooltip enterable={false} effect="dark" content="删除" placement="top"
                                popper-class="tooltip-skin">
                      <i class="el-icon-delete"/>
                    </el-tooltip>
                  </a>
                ];
              }
            }
          }
        ]
      };
      this.$vxeTableUtil.initVxeTable(tableOption1).then(opts => {
        that.vxeOption = opts;
      });
    },
    deleteItem(row) {
      this.$baseConfirm('您确定要删除吗？').then(() => {
        this.$http({
          method: 'post',
          url: USER_PREFIX + '/wf_obj_config_item/delete',
          data: {id: row.id},
          success: res => {
            this.$message({
              message: res.content,
              type: 'success',
              duration: 500,
            });
            this.searchEvent()
          }
        });
      });
    },
    wfEdit(modelId) {
      this.$emit('openWfDesignDialog', modelId);
    }
  }
};
</script>
