workCard.vue 8.14 KB
<!-- 工牌管理 -->
<template>
  <div>
    <d2-container>
      <div class="header" slot="header" style="padding: 10px 20px">
        <d2-search
          ref="showSearch"
          class="show-search"
          :search-form="searchForm"
          :form-data="showFormData">
        </d2-search>
        <div class="up-btns">
          <el-button @click="handleSearch" size="small" type="primary">
            查询
          </el-button>
          <el-button size="small" @click="handleReset"> 重置 </el-button>
        </div>
      </div>
      <div class="d2-container-content">
        <div class="theader">
          <h2>工牌管理</h2>
          <div>
            <span>最近同步:{{ currentTime }}</span>
            <!-- <el-button @click="handleUpdate" size="small" plain type="primary">
              数据同步
            </el-button> -->
            <auth-button category="Button"
                       :show-btn-ids="['9120301']"/>
          </div>
        </div>
        <d2-table
          ref="cardTable"
          :get-list-api="getListApi"
          :search-form="searchFormSearch"
          :table-params="tableParams"
          :before-search-fn="beforeSearchFn">
          <div slot="store" slot-scope="scope">
            <template
              v-if="scope.scope.storeList && scope.scope.storeList.length > 1">
              <span>{{ scope.scope.storeList.slice(0, 1).join("") }}</span>
              <el-popover placement="top" width="fit-content" trigger="hover">
                <div
                :class="{ scrollHeight: scope.scope.storeList.length >= 10 }"
              >
                <div
                  v-for="(item, index) in scope.scope.storeList"
                  :key="index">
                  {{ item }}
                </div>
                </div>
                <span class="more-info" slot="reference">...({{ scope.scope.storeList.length }})</span>
              </el-popover>
            </template>
            <template v-else>
              <span
                v-if="!scope.scope.storeList || !scope.scope.storeList.length">--</span>
              <span v-else>{{ scope.scope.storeList.join("") }}</span>
            </template>
          </div>
          <div slot="service" slot-scope="scope">
            <template
              v-if="
                scope.scope.serviceList && scope.scope.serviceList.length > 1
              ">
              <span>{{ scope.scope.serviceList.slice(0, 1).join("") }}</span>
              <el-popover placement="top" width="fit-content" trigger="hover">
                <div
                :class="{ scrollHeight: scope.scope.serviceList.length >= 10 }"
              >
                <div
                  v-for="(item, index) in scope.scope.serviceList"
                  :key="index">
                  {{ item }}
                </div>
                </div>
                <span class="more-info" slot="reference">...({{ scope.scope.serviceList.length }})</span>
              </el-popover>
            </template>
            <template v-else>
              <span
                v-if="
                  !scope.scope.serviceList || !scope.scope.serviceList.length
                ">--</span>
              <span v-else>{{ scope.scope.serviceList.join("") }}</span>
            </template>
          </div>
          <auth-button
            slot="auth-button"
            slot-scope="scope"
            :data="scope.scope" />
        </d2-table>
      </div>
    </d2-container>
  </div>
</template>

<script>
import { Util, deepClone } from "@/common/util"
import { employeeBadgelistWithPage, syncBadge } from "@api/resident"
export default {
  name: "WorkCard",
  components: {},
  data() {
    return {
      searchForm: {
        phoneNumber: "",
        employeeName: "",
        badgeManufacturerId: "",
        badgeId: ""
      },
      isQuery: true,
      currentTime: "",
      searchFormSearch: {},
      showFormData: [
        {
          label: "工牌编号",
          name: "badgeId",
          type: "input",
          maxlength: "20",
          isClear: true
        },
        {
          label: "工牌厂商",
          name: "badgeManufacturerId",
          type: "select",
          optionList: [],
          optionId: "confId",
          optionLabel: "confLabel",
          optionsName: "badgeManufacturerList"
        },
        {
          label: "员工姓名",
          name: "employeeName",
          type: "input",
          maxlength: "20",
          isClear: true
        },
        {
          label: "手机号",
          name: "phoneNumber",
          type: "input",
          maxlength: "11",
          isClear: true
        }
      ],
      getListApi: employeeBadgelistWithPage,
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: "list",
        tableOption: false,
        tableColumns: [
          {
            label: "工牌编号",
            prop: "badgeId"
          },
          {
            label: "工牌厂商",
            prop: "badgeManufacturerId",
            formatter: (cellValue) => {
              return this.baseData.badgeManufacturerList.find(item => item.confId == cellValue.badgeManufacturerId).confLabel
            }
          },
          {
            label: "员工",
            prop: "employeeName"
          },
          {
            label: "手机号",
            prop: "phoneNumber"
          },
          {
            label: "归属门店",
            prop: "storeMerchantNo",
            addHtml: "store",
            width: "200px"
          },
          {
            label: "归属服务商",
            addHtml: "service",
            width: "200px",
            prop: "serviceMerchantNo"
          },
          {
            label: "设备绑定时间",
            prop: "bindTime",
            formatter: (cellValue) => {
              return cellValue.bindTime
                ? Util.dateFormate(cellValue.bindTime, "YYYY-MM-DD HH:mm:ss")
                : ""
            }
          }
        ]
      },
      baseData: {
        badgeManufacturerList: [
          {
            confId: "1",
            confLabel: "嘟嘟"
          },
          {
            confId: "2",
            confLabel: "Matepad"
          }
        ]
      }
    }
  },
  mounted() {
    this.currentTime = Util.dateFormate(
      new Date().getTime(),
      "YYYY-MM-DD HH:mm:ss"
    )
    this.getOptionsList()
  },

  methods: {
    beforeSearchFn() {
      return new Promise((resolve) => {
        this.searchFormSearch = deepClone(this.searchForm)
        resolve()
      })
    },
    handleUpdate() {
      if (this.isQuery) {
        this.syncBadge()
        setTimeout(() => {
          this.isQuery = true
        }, 10000)
      }
    },
    syncBadge() {
      syncBadge()
      this.currentTime = Util.dateFormate(
        new Date().getTime(),
        "YYYY-MM-DD HH:mm:ss"
      )
      this.$refs.cardTable.refreshTable(true, true)
      this.isQuery = false
    },
    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]
          )
        }
      })
    },

    handleSearch() {
      this.$refs.cardTable.refreshTable(true, true)
    },
    handleReset() {
      this.searchForm = {
        phoneNumber: "",
        employeeName: "",
        badgeManufacturerId: "",
        badgeId: ""
      }
      this.$refs.cardTable.refreshTable()
    }
  }
}
</script>
  <style scoped lang="scss">
.theader {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  h2 {
    font-weight: 600;
    font-size: 16px;
    color: #333333;
  }
  span {
    font-size: 14px;
    color: #999999;
    margin-right: 10px;
  }
}
</style>