measureConfig.vue 5.86 KB
<template>
  <div>
    <div class="d2-container-content">
      <div class="app-config">
        展业助手收入测算入口配置:
        <el-radio-group v-model="configFlag" @change="radioChange">
          <el-radio :label="0">全员打开</el-radio>
          <el-radio :label="1">全员关闭</el-radio>
          <el-radio :label="2">白名单开启</el-radio>
        </el-radio-group>
      </div>
      <template v-if="configFlag == '2'">
        <div class="theader">
          <h2>白名单管理</h2>
          <div>
            <el-button @click="handleAdd" size="small" type="primary">
              增加
            </el-button>
          </div>
        </div>
        <d2-table ref="measurementConfigTable" :hasNum="false" :get-list-api="getListApi"
          :search-form="searchFormSearch" :table-params="tableParams">
          <template slot="auth-button" slot-scope="scope">
            <el-button type="text" @click="delWhite(scope.scope)">删除</el-button>
          </template>
        </d2-table>
      </template>
    </div>
    <el-dialog class="white-dialog" title="新增白名单" :visible.sync="dialogVisible" width="668px"
      :before-close="handleClose" :close-on-click-modal="false">
      <el-form ref="whiteForm" class="white-form" :model="whiteForm" :rules="rules" label-width="150px">
        <el-form-item label="手机号码:" prop="staffPhone">
          <el-input v-model="whiteForm.staffPhone" maxlength="11" placeholder="请输入手机号码"></el-input>
        </el-form-item>
        <div class="line"></div>
        <el-form-item label="员工姓名:">
          {{ whiteForm.staffName }}
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <template v-if="whiteForm.staffName">
          <el-button type="primary" @click="addWhite">加入白名单</el-button>
        </template>
        <template v-else>
          <el-button type="primary" @click="searchStaff">查询</el-button>
          <el-button @click="dialogVisible = false">取 消</el-button>
        </template>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { Util } from '@/common/util'
import { getWhiteStaff, getSwitchConfig, addSwitchConfig, getStaffInfo, addWhiteStaff, delWhiteStaff } from "@api/resident"
export default {
  name: 'MeasureConfig',
  data() {
    function checkPhone(rule, value, callback) {
      console.log(value);
      if (!Util.checkPhone(value)) {
        callback(new Error('请输入正确的手机号码'))
        return false
      }
      callback()
    }
    return {
      // 收入测算配置
      configFlag: 1,
      getListApi: getWhiteStaff,
      searchFormSearch: {},
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: '员工姓名',
            prop: 'staffName'
          },
          {
            label: '电话号码',
            prop: 'staffPhone'
          },
          {
            label: '适配业务',
            prop: 'staffScenes'
          },
          {
            label: '服务门店',
            prop: 'serviceMerchantName'
          }
        ]
      },
      dialogVisible: false,
      whiteForm: {
        staffName: '',
        staffPhone: ''
      },
      rules: {
        staffPhone: [
          {
          required: true,
          message: '请输入手机号码',
          trigger: 'blur'
        }, {
          validator: checkPhone,
          trigger: 'blur'
        }]
      }
    }
  },
  created() {
    this.getSwitch()
  },
  methods: {
    // 查询测试配置开关
    async getSwitch() {
      const res = await getSwitchConfig()
      if(res) this.configFlag = res.configFlag
    },
    handleAdd() {
      console.log('111');
      this.dialogVisible = true
    },
    handleClose() {
      this.dialogVisible = false
      this.whiteForm = {
        staffName: '',
        staffPhone: ''
      }
    },
    radioChange(e) {
      console.log(e);
      addSwitchConfig({ configFlag: e }).then(res => {
        console.log(res)
        if (res) this.$message.success('修改成功')
      })
    },
    // 查询员工
    searchStaff() {
      this.$refs.whiteForm.validate((valid) => {
        if (valid) {
          const {staffPhone} = this.whiteForm
        // if (!staffPhone) return this.$message.error('请输入手机号码')
        getStaffInfo({staffPhone}).then(res => {
          console.log(res);
          if (res) {
            this.whiteForm.staffName = res.staffName
          } else {
            this.$message.error('不存在该直营驻店人员')
          }        
        })
        }
      })
    },
    // 加入白名单
    addWhite() {
      const {staffPhone, staffName} = this.whiteForm
      addWhiteStaff({staffPhone, staffName}).then(res => {
        console.log(res);
        if (res) {
          this.$message.success('修改成功')
          this.$refs.measurementConfigTable.refreshTable(true, true)
          this.handleClose()
        }
      })
    },
    delWhite(row) {
      console.log(row);
      delWhiteStaff({id: row.id}).then(res => {
        if (res) {
          this.$message.success('删除成功')
          this.$refs.measurementConfigTable.refreshTable(true, true)
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.d2-container-content {
  background-color: #fff;
  margin-top: 0 !important;
  padding: 0 20px 20px !important;
}

.app-config {
  color: #333333;
  font-size: 16px;
  padding: 12.5px 20px;
  background-color: #F8FAFF;
  // margin: 0 20px;
}
.theader {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;

  h2 {
    font-weight: 600;
    font-size: 16px;
    color: #333333;
  }
}

.white-form {
  height: 108px;

  .line {
    width: 100%;
    height: 1px;
    background-color: #E5E5E5;
    margin-bottom: 20px;
  }
}
</style>