index.vue 10.3 KB
<template>
  <d2-container class="customer-tags">
    <div class="header" slot="header">
      <d2-search
        ref="showSearch"
        class="show-search"
        :search-form="searchForm"
        :label-width="'100px'"
        :form-data="showFormData"
      >
      </d2-search>
      <div class="up-btns">
        <el-button size="small" type="primary" @click="handleSearch">
          查询
        </el-button>
        <el-button size="small" @click="handleReset"> 重置 </el-button>
      </div>
    </div>
    <div class="d2-container-content">
      <d2-table-header title="账号列表">
        <el-button
          size="small"
          icon="el-icon-plus"
          type="primary"
          @click="handleAdd"
        >
          新建总部账号
        </el-button>
      </d2-table-header>

      <d2-table
        ref="table"
        :get-list-api="getListApi"
        :search-form="searchFormSearch"
        :table-params="tableParams"
        :before-search-fn="beforeSearchFn"
      >
        <div slot="auth-button" slot-scope="scope">
          <span style="margin-right: 10px">
            <template v-if="scope.scope.ownerShipType == 0">
              <auth-button
                :data="scope.scope"
                :show-btn-ids="['9160102', '9160104']"
              />
            </template>

            <el-button
              size="small"
              type="text"
              @click="handleDisabled(scope.scope)"
              style="margin-left: 10px"
            >
              {{ scope.scope.useStatus == 0 ? "启用" : "禁用" }}
            </el-button>
          </span>
        </div>
      </d2-table>
    </div>
    <add-account-dialog
      :visible.sync="addVisible"
      @dialogClose="dialogClose"
      :detailInfo="detailInfo"
    ></add-account-dialog>
  </d2-container>
</template>

<script>
import { getAccountList, switchAccount, deleteAccount } from "@/api/large.js"
import { businessSceneOpt } from "@/common/constants"
import { Util, deepClone } from "@/common/util"
import addAccountDialog from "./components/addAccountDialog.vue"
export default {
  components: {
    addAccountDialog
  },
  data() {
    return {
      addVisible: false,
      getListApi: getAccountList,
      tableData: [{}],
      tableParams: {
        listName: "list",
        tableOption: {
          width: "100"
        },
        tableColumns: [
          {
            label: "姓名",
            prop: "accountName"
          },
          {
            label: "手机号",
            prop: "accountPhone"
          },
          {
            label: "架构",
            prop: "ownerShipType",
            formatter: (cellValue) => {
              return {
                1: "驻店",
                0: "总部"
              }[cellValue.ownerShipType]
            }
          },
          {
            label: "岗位",
            prop: "ownerPost"
          },
          {
            label: "中心",
            prop: "ownerCenter"
          },
          {
            label: "部门",
            prop: "ownerDept"
          },
          {
            label: "创建人",
            prop: "createdBy"
          },
          {
            label: "创建时间",
            formatter: (cellValue) => {
              return cellValue.createdDate
                ? Util.dateFormate(cellValue.createdDate, "YYYY-MM-DD HH:mm:ss")
                : "-"
            }
          },
          {
            label: "更新人",
            prop: "updatedBy"
          },
          {
            label: "更新时间",
            formatter: (cellValue) => {
              return cellValue.updatedDate
                ? Util.dateFormate(cellValue.updatedDate, "YYYY-MM-DD HH:mm:ss")
                : "-"
            }
          },
          {
            label: "状态",
            formatter: (cellValue) => {
              return {
                1: "启用",
                0: "禁用"
              }[cellValue.useStatus]
            },
            className: (cellValue) => {
              return {
                1: "greenSpot",
                0: "ashSpot"
              }[cellValue.useStatus]
            }
          }
        ]
      },
      searchFormSearch: {},
      searchForm: {
        accountName: "",
        accountPhone: "",
        ownerShipType: "",
        ownerPost: "",
        useStatus: ""
      },
      showFormData: [
        {
          label: "员工姓名",
          name: "accountName",
          type: "input",
          isClear: true
        },
        {
          label: "手机号码",
          name: "accountPhone",
          type: "input",
          isClear: true
        },
        {
          label: "岗位",
          name: "ownerPost",
          type: "input",
          isClear: true
        },
        {
          label: "归属架构",
          name: "ownerShipType",
          type: "select",
          //   multiple: true,
          isClear: true,
          optionList: [
            {
              confValue: "全部",
              confId: ""
            },
            {
              confValue: "总部",
              confId: "0"
            },
            {
              confValue: "驻店",
              confId: "1"
            }
          ],
          optionId: "confId",
          optionLabel: "confValue"
        },
        {
          label: "状态",
          name: "useStatus",
          type: "select",
          isClear: true,
          optionList: [
            {
              confValue: "全部",
              confId: ""
            },
            {
              confValue: "启用",
              confId: "1"
            },
            {
              confValue: "禁用",
              confId: "0"
            }
          ],
          optionId: "confId",
          optionLabel: "confValue"
        }
      ],
      baseData: {}
    }
  },
  mounted() {
    // this.getOptionsList()
    // this.initSelect()
  },
  methods: {
    // 启用/禁用
    handleDisabled(row) {
      console.log(row)
      let text = row.useStatus == "1" ? "禁用" : "启用"
      this.$confirm(`是否确认${text}?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          switchAccount({
            id: row.id,
            useStatus: row.useStatus == "1" ? "0" : "1"
          }).then((res) => {
            this.$message.success(`${text}成功`)
            this.$refs.table.refreshTable(true, true)
          })
        })
        .catch((err) => {
          console.log(err)
        })
    },
    // 删除方案
    handleDelete(row) {
      this.$confirm("是否确认删除该员工", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          deleteAccount({ id: row.id }).then((res) => {
            this.$message.success("删除成功")
            this.$refs.table.refreshTable(true, true)
          })
        })
        .catch((err) => {
          console.log(err)
        })
    },
    dialogClose() {
      this.addVisible = false
      this.$refs.table.refreshTable(true, true)
    },
    handleAdd() {
      this.detailInfo = {}
      this.addVisible = true
    },
    handleEdit(data) {
      this.detailInfo = data
      this.addVisible = true
    },
    handleDetail(data) {
      console.log("row", data)
      let businessTypeName =
        data.businessType === 0 || data.businessType
          ? businessSceneOpt.find((item) => item.confId === data.businessType)
              .confValue
          : "-"
      this.$router.push({
        path: "/inVerbalConfigView",
        query: {
          ...data,
          businessTypeName: businessTypeName
        }
      })
    },
    beforeSearchFn(type = 1) {
      return new Promise((resolve, reject) => {
        this.searchFormSearch = deepClone(this.searchForm)
        resolve()
      })
    },
    handleSearch() {
      this.page = this.$options.data.call(this).page
      this.$refs.table.refreshTable(true, true)
    },
    handleReset() {
      this.searchForm = this.$options.data.call(this).searchForm
      console.log("this.searchForm", this.searchForm)
      this.handleSearch()
    },
    async exportTable() {
      try {
        await this.beforeSearchFn()
        const res = await recordExport({
          ...this.searchFormSearch
        })
        if (res) window.open(res)
      } catch (error) {
        if (error) this.$message.error(error)
      }
    },
    // initSelect() {
    //   // 使用 Promise.all 处理多个异步任务,并捕获所有可能的错误
    //   Promise.allSettled([this.getClassLabelList()])
    //     .then((results) => {
    //       // 检查每个任务的结果
    //       results.forEach((result, index) => {
    //         if (result.status === "rejected") {
    //           console.error(`Task ${index} failed:`, result.reason)
    //         }
    //       })
    //       // 统一调用 getOptionsList
    //       this.getOptionsList()
    //     })
    //     .catch((err) => {
    //       console.error("Unexpected error in initSelect:", err)
    //       this.getOptionsList() // 确保即使有意外错误也调用 getOptionsList
    //     })
    // },

    // getClassLabelList() {
    //   return new Promise((resolve, reject) => {
    //     getClassLabelList({})
    //       .then((res) => {
    //         this.baseData.classLabelList = res
    //         resolve(res) // 返回结果以便主流程感知
    //       })
    //       .catch((err) => {
    //         console.error("Error in getClassLabelList:", err)
    //         reject(err) // 捕获并传递错误
    //       })
    //   })
    // },
    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
            ] !== "全部"
          ) {
            // if (item.optionsName != "brandList") {
            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]
          )
        }
      })
    }
  }
}
</script>

<style></style>