index.vue 6.36 KB
<template>
  <div class="system-container">

    <div class="container">
      <search-form
        class="searchTop border-shadow"
        :formModel="searchForm"
        :formList="vehicleTypeFormList"
        @input="onInput"
      >
        <span class="inline-b" slot="form-slot">
          <el-button
            type="primary"
            :size="btn_size"
            icon="el-icon-search"
            :id="tableParams.btnId"
            ref="searchButton"
            >搜索</el-button
          >
          <el-button
            type="primary"
            :size="btn_size"
            icon="el-icon-refresh"
            @click="refresh"
            >重置</el-button
          >
        </span>
      </search-form>
      <h3>
        车型管理
        <div class="pull-right">
          <el-button
            type="primary"
            :size="btn_size"
            icon="el-icon-plus"
            @click="btnClick('create')"
            >定制车型库</el-button
          >
        </div>
      </h3>
      <basic-table
        ref="vehicleTypeTable"
        :tableParams="tableParams"
        :getListApi="getListApi"
        :searchForm="searchForm"
        :hasNum="false"
      >
        <span slot="status" slot-scope="scope">
          <span
            class="dot"
            :class="
              scope.scope.enableStatus
                ? USERSTATUS[scope.scope.enableStatus].split(',')[1]
                : ''
            "
          ></span>
          <span class="statusText">{{
            scope.scope.enableStatus
              ? USERSTATUS[scope.scope.enableStatus].split(",")[0]
              : "--"
          }}</span>
        </span>
        <span slot="table-button" slot-scope="scope">
          <el-button
            v-for="(j, idx) in tableParams.tableOption.btnList"
            :key="idx"
            :type="j.type || 'text'"
            :size="btn_size"
            @click="btnClick(j.pType, scope.scope)"
            >{{ j.name }}</el-button
          >
        </span>
      </basic-table>
  
    </div>
  </div>
</template>

<script>
import { getTableList, delelteTableRowData } from "services/vehicletype";
// import {creatIndexDb,addItem,getItem} from '@/utils/indexDb'
export default {
  name: "vehicleTypeManage",
  data() {
    return {
      USERSTATUS: this.$Constants.USER_STATUS,
      searchForm: {},
      vehicleTypeFormList: [
        {
          type: "input",
          inputType: "text",
          prop: "term",
          placeholder: "所属组织|车型库名称",
        },
      ],
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: "list",
        tableColumns: [
          {
            label: "所属组织",
            prop: "tenantName",
          },
          {
            label: "车型库名称",
            prop: "name",
          },
          {
            label: "创建人",
            prop: "creator",
          },
          {
            label: "创建时间",
            prop: "createdDate",
          },
          {
            label: "状态",
            prop: "enableStatus",
            addHtml: "status",
            width: 110,
          },
        ],
        tableOption: {
          width: 170,
          btnList: [
            {
              name: "编辑",
              pType: "edit",
            },
            {
              name: "删除",
              pType: "delete",
            },
            {
              name: "查看",
              pType: "view",
            },
          ],
        },
      },
      getListApi: getTableList,
      vehicleTypeTitle: "add",
      //以下为弹出框表单
      vehicleTypeForm: {
        enableStatus: true,
      },
      vehicleTypeData: [
        { label: "车型库名称:", prop: "name", type: "input", maxlength: 50 },
        //  { label: "组织:", prop: "tenantId", type: "select" },
        { label: "状态:", prop: "enableStatus", type: "switch" },
      ],

      vehicleTypeRules: {
        name: [{ required: true, message: "请输入名称", trigger: "blur" }],
      },
      tenantList: [],
    };
  },
  created(){
  },
  mounted() {
    console.log(this.$store.state)
    localStorage.removeItem('carTree');
    // creatIndexDb();
    // addItem()
  },
  activated() {
    this.$refs.searchButton.$el.click();
  },
  methods: {
    // 重置搜索条件
    refresh() {
      this.searchForm = {};
      this.$refs.vehicleTypeTable.refreshTable();
    },

    //按钮事件
    btnClick(pType, scope) {
      console.log(pType, scope);
      switch (pType) {
        case "create":
          this.vehicleTypeTitle = "add";
          this.vehicleTypeForm = {
            enableStatus: true,
          };

          this.$router.push({ name: "vehicleAddUpadate", query: { title: this.vehicleTypeTitle } });
          //this.handleClose(); //控制弹窗打开
          break;
        case "edit":
          this.vehicleTypeTitle = "edit";
          this.$router.push({
            name: "vehicleAddUpadate",
            query: { title: this.vehicleTypeTitle, id: scope.tenantId },
          });
          break;
        case "view":
          this.vehicleTypeTitle = "view";
          this.$router.push({
            name: "vehicleAddUpadate",
            query: { title: this.vehicleTypeTitle, id: scope.tenantId },
          });
          break;
        case "delete":
          this.delelteTableRowData(scope.tenantId);
          break;
      }
    },
    //编辑触发事件
    editEvent() {
      const that = this;
      this.handleClose();
    },
    // 删除触发事件
    delelteTableRowData(id) {
      const that = this;
      const tipData = {
        that: that,
        tipText: "是否删除当前记录",
        tipTitle: "提示",
        type: "error",
        callBack: () => {
          delelteTableRowData({ tenantId: id }).then((res) => {
            if (res.code == "200") {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.$refs.vehicleTypeTable.refreshTable();
            } else {
              this.$message({
                type: "error",
                message: res.message,
              });
            }
          });
        },
      };
      this.$Common.confirmDialog(tipData);
    },

    //监听回车搜索
    onInput(){
      this.$refs.searchButton.$el.click();
    },
  },
};
</script>

<style lang="scss" scoped>
</style>