deviceList.vue 5.71 KB
<!-- 设备管理 -->
<template>
  <d2-container class="service-manage">
    <div class="header" slot="header">
      <d2-search
        ref="showSearch"
        class="show-search"
        :search-form="searchForm"
        :form-data="showFormData"
      />
      <div class="up-btns">
        <el-button :id="tableParams.btnId" size="small" type="primary">
          查询
        </el-button>
        <el-button size="small" @click="handleReset"> 重置 </el-button>
      </div>
    </div>
    <div class="d2-container-content">
      <d2-table-header>
        <span slot="left"> <auth-button category="Button" /></span>
      </d2-table-header>
      <d2-table
        ref="deviceTable"
        :search-form="searchForm"
        :table-params="tableParams"
        :get-list-api="getListApi"
        :before-search-fn="beforeSearchFn"
      >
        <auth-button
          slot="auth-button"
          slot-scope="scope"
          :data="scope.scope"
        />
      </d2-table>
    </div>
  </d2-container>
</template>

<script>
import { Util, deepClone } from "@/common/util"
import { trmList, trmDelete } from "@api/deviceManage"
import { mapActions } from "vuex"
import { BaseData } from "@/common/constants.js"
export default {
  name: "DviceList",
  data() {
    return {
      searchForm: {
        posTrmNo: "",
        searchMerchantName: "",
        searchMerchantId: ""
      },
      showFormData: [
        {
          label: "终端编码",
          name: "posTrmNo",
          type: "input",
          placeholder: "请输入POS机的终端编码",
          maxlength: "20",
          isClear: true,
          keyFn: this.keyDowmGetList
        },
        {
          label: "商户名称",
          name: "searchMerchantName",
          type: "input",
          placeholder: "请输入流量方/园区店名称",
          maxlength: "20",
          isClear: true,
          keyFn: this.keyDowmGetList
        },
        {
          label: "商户号",
          name: "searchMerchantId",
          type: "input",
          inputType: "number",
          maxlength: "20",
          placeholder: "请输入流量方/园区店商户号",
          isClear: true,
          keyFn: this.keyDowmGetList
        }
      ],
      maxLength: 10,
      getListApi: trmList,
      // 表格参数
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: "list",
        tableOption: true,
        tableColumns: [
          {
            label: "终端编码",
            prop: "posTrmNo"
          },
          {
            label: "关联园区店",
            prop: "yqMerchantName"
          },
          {
            label: "园区店商户号",
            prop: "yqMerchantId",
            width: "120"
          },
          {
            label: "关联流量方",
            prop: "merchantName"
          },
          {
            label: "流量方商户号",
            prop: "merchantId",
            width: "120"
          },
          {
            label: "最近更新时间",
            prop: "updatedDate",
            width: "160",
            formatter: (cellValue) => {
              return Util.dateFormate(
                cellValue.updatedDate,
                "YYYY-MM-DD HH:mm:ss"
              )
            }
          }
        ]
      },
      baseData: {}
    }
  },

  components: {},

  mounted() {
    this.getBaseData()
    // this.$nextTick(() => {
    //   this.$refs.deviceTable.page.pageSize = 10
    // })
  },

  methods: {
    ...mapActions({ close: "d2admin/page/close" }),
    async getBaseData() {
      this.getOptionsList()
    },

    beforeSearchFn() {
      return new Promise((resolve) => {
        resolve()
      })
    },
    keyDowmGetList() {
      this.$refs.deviceTable.refreshTable()
    },
    handleReset() {
      this.searchForm = {
        posTrmNo: "",
        searchMerchantName: "",
        searchMerchantId: ""
      }
      this.$refs.deviceTable.refreshTable()
    },
    getOptionsList() {
      this.showFormData.forEach((item, index) => {
        if (item.type === "select") {
          if (
            this.baseData[item.optionsName].length &&
            this.baseData[item.optionsName][0][
              this.showFormData[index].optionLabel
            ] !== "全部"
          ) {
            const temp = {}
            temp[this.showFormData[index].optionId] = ""
            temp[this.showFormData[index].optionLabel] = "全部"
            this.baseData[item.optionsName].unshift(temp)
          }
          this.$set(
            this.showFormData[index],
            "optionList",
            this.baseData[item.optionsName]
          )
        }
      })
    },

    handleAdd() {
      this.close({ tagName: "/editDevice" })
      this.$router.push({
        name: "editDevice",
        params: {
          addOrEdit: "add"
        }
      })
    },

    handleEdit(row) {
      this.close({ tagName: "/editDevice" })
      this.$router.push({
        name: "editDevice",
        params: {
          addOrEdit: "edit",
          info: row
        }
      })
    },

    // 删除
    handleDelete(row) {
      this.$confirm("删除后不可恢复,是否确定删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          trmDelete({ id: row.id }).then((res) => {
            this.notice.okTips()
            this.$refs.deviceTable.refreshTable()
          })
        })
        .catch((err) => {
          console.log(err)
        })
    },

    handleHistory(row) {
      this.close({ tagName: "/deviceHistory" })
      this.$router.push({
        name: "deviceHistory",
        query: {
          info: JSON.stringify(row)
        }
      })
    }
  }
}
</script>
<style scoped>
</style>