outputValue.vue 11.1 KB
<!-- 企微推送产值进度表 -->
<template>
  <d2-container class="outputValue-list">
    <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" :show-btn-ids="['9070301']" />
        </span>
        <auth-button category="Button" :show-btn-ids="['9070303']" />
      </d2-table-header>
      <d2-table ref="outputValueTable" :search-form="tableSearchForm" :table-params="tableParams"
                :get-list-api="getListApi" :before-search-fn="beforeSearchFn">
        <div slot="concatType" slot-scope="scope">
          <p v-if="scope.scope.concatType == 1">督导</p>
          <p v-if="scope.scope.concatType == 2">驻店</p>
        </div>
        <auth-button slot="auth-button" slot-scope="scope" :data="scope.scope" />
      </d2-table>
    </div>
    <d2-file-import-dialog :is-visible="fileVisible"
                           title="上传文件"
                           @closeDialog="handleImport"
                           @confirmDialog="handleConfirmImport"
                           @downloadTemplate="exportTemplate" />
    <d2-dialog :title="chooseType" @closeDialog="handleObject" @confirmDialog="handleConfirmObject"
               :is-visible="pushVisible">
      <slot>
        <el-form :model="pushForm" ref="pushForm" :rules="rules" style="margin-left: 59px;">
          <el-form-item label="类型:" prop="concatType">
            <el-select v-model="pushForm.concatType" clearable style="width: 280px;" placeholder="请选择"
                       @change="changeValue">
              <el-option v-for="item in state" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="商户:" prop="merchantName">
            <el-select v-model="pushForm.merchantName" clearable filterable style="width: 280px;" placeholder="请选择">
              <el-option v-for="item in changeList" :key="item.merchantId" :label="item.merchantName"
                         :value="item.merchantName" />
            </el-select>
          </el-form-item>
          <el-form-item label="姓名:" prop="name">
            <el-input v-model="pushForm.name" style="width: 280px;" placeholder="请输入姓名" clearable />
          </el-form-item>
          <el-form-item label="手机号:" prop="phone" style="margin-left: -15px;">
            <el-input v-model="pushForm.phone" style="width: 280px;" placeholder="请输入手机号" clearable />
          </el-form-item>
        </el-form>
      </slot>
    </d2-dialog>
  </d2-container>
</template>

<script>
import { getMerchantPageSearch } from '../../api/publicAccount'
import { pushObject, addContact, modifyContact, importContact, removeContact } from '../../api/merchant'
import { mapActions, mapState, mapMutations } from 'vuex'
import { deepClone } from '@/common/util'
const state = [
  {
    value: 1,
    label: '督导'
  },
  {
    value: 2,
    label: '驻店'
  }
]
export default {
  name: 'OutputValue',
  data() {
    return {
      state,
      fileVisible: false,
      // 搜索表格数据
      tableSearchForm: {},
      searchForm: {
        name: '',
        phone: '',
        merchantId: ''
      },
      showFormData: [{
        label: '姓名',
        name: 'name',
        type: 'input',
        placeholder: '请输入姓名',
        isClear: true,
        keyFn: this.keyDowmGetList
      }, {
        label: '手机号',
        name: 'phone',
        type: 'input',
        placeholder: '请输入手机号',
        isClear: true,
        keyFn: this.keyDowmGetList
      }, {
        label: '商户号',
        name: 'merchantId',
        type: 'input',
        placeholder: '请输入商户号',
        isClear: true,
        keyFn: this.keyDowmGetList
      }],
      getListApi: pushObject,
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: true,
        tableColumns: [{
          label: '姓名',
          prop: 'name'
        }, {
          label: '手机号',
          prop: 'phone'
        }, {
          label: '类型',
          prop: '',
          addHtml: 'concatType'
        }, {
          label: '商户名称',
          prop: 'merchantName'
        }, {
          label: '商户号',
          prop: 'merchantId'
        }]
      },
      pushForm: {
        concatType: '',
        merchantName: '',
        name: '',
        phone: '',
        merchantId: ''
      },
      chooseId: '',
      pushVisible: false,
      rules: {
        concatType: [{ required: true, message: '请选择类型', trigger: 'change' }],
        merchantName: [{ required: true, message: '请选择商户', trigger: 'change' }],
        name: [{ required: true, message: '请输入姓名', trigger: 'change' }],
        phone: [{ required: true, message: '请输入手机号', trigger: 'change' },
          {
            validator: (rule, value, callback) => {
              const phoneReg = /^(13[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9]|14[0-9])[0-9]{8}$/
              return phoneReg.test(value) ? callback() : callback(new Error('请输入正确的联系号码'))
            },
            trigger: 'change'
          }
        ]
      },
      changeList: [],
      superviseList: [],
      residentialList: [],
      chooseType: ''
    }
  },
  computed: {
    ...mapState({
      updateList: (state) => state.d2admin.user.updateList
    })
  },
  watch: {
    updateRefesh(val) {
      // console.log('val', val)
      if (val == true) {
        this.merchantData()
        this.setUpdateRefesh('false')
      }
    }
  },
  methods: {
    ...mapActions('d2admin/user', ['actionSetDownloadList']),
    ...mapMutations('d2admin/user', ['setUpdateRefesh']),
    beforeSearchFn() {
      return new Promise(resolve => {
        this.tableSearchForm = deepClone(this.searchForm)
        resolve()
      })
    },
    keyDowmGetList() {
      this.$refs.outputValueTable.refreshTable()
    },
    handleConfirmImport({ fileName, fileData }) {
      var params = {
        file: fileData
      }
      importContact(params).then(res => {
        if (res) {
          const list = [...this.updateList, {
            name: fileName,
            ifSuccess: false,
            uuid: res,
            type: 'upload'
          }]

          this.actionSetDownloadList({ list, type: 'updateList' })
          this.notice.okTips('上传成功')
          this.handleImport()
        }
      })
    },
    handleImport() {
      this.fileVisible = !this.fileVisible
    },
    exportTemplate() {
      window.open('http://img01.glsx.com.cn/upload/salesexcel/企微推送对象导入模板.xlsx')
    },
    merchantData(type) {
      const superviseParams = {
        currentPage: 1,
        pageSize: 10000,
        merchantTypeList: [6, 8]
      }
      const residentialParams = {
        currentPage: 1,
        pageSize: 10000,
        merchantTypeList: [2]
      }
      getMerchantPageSearch(superviseParams).then(res => {
        res.list.forEach(e => {
          this.superviseList.push({ merchantId: e.merchantId, merchantName: e.merchantName })
          if (type == 1) {
            this.changeList = this.superviseList
          }
        })
      })
      getMerchantPageSearch(residentialParams).then(res => {
        res.list.forEach(e => {
          this.residentialList.push({ merchantId: e.merchantId, merchantName: e.merchantName })
          if (type == 2) {
            this.changeList = this.residentialList
          }
        })
      })
    },
    // 新增
    handleAdd() {
      this.pushVisible = !this.pushVisible
      this.chooseType = '新增推送对象'
      this.merchantData()
    },
    // 编辑
    handleEdit(row) {
      this.pushVisible = !this.pushVisible
      this.chooseType = '编辑推送对象'
      this.pushForm = {
        concatType: row.concatType,
        merchantName: row.merchantName,
        name: row.name,
        phone: row.phone,
        merchantId: row.merchantId
      }
      this.chooseId = row.id
      this.merchantData(row.concatType)
    },
    // 删除
    handleDelete(row) {
      this.$confirm('数据删除后无法恢复,是否确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        removeContact({ id: row.id }).then(res => {
          this.notice.okTips()
          this.$refs.outputValueTable.refreshTable()
        })
      })
    },
    changeValue(e) {
      this.changeList = []
      this.pushForm.merchantName = ''
      if (e == 1) {
        this.changeList = this.superviseList
      } else if (e == 2) {
        this.changeList = this.residentialList
      }
    },
    // 新增编辑推送对象弹窗
    handleConfirmObject() {
      this.$refs.pushForm.validate(valid => {
        if (valid) {
          if (this.pushForm.concatType == 1) {
            this.superviseList.forEach(e => {
              if (e.merchantName == this.pushForm.merchantName) {
                this.pushForm.merchantId = e.merchantId
              }
            })
          } else if (this.pushForm.concatType == 2) {
            this.residentialList.forEach(e => {
              if (e.merchantName == this.pushForm.merchantName) {
                this.pushForm.merchantId = e.merchantId
              }
            })
          }
          if (this.chooseType == '新增推送对象') {
            addContact({
              merchantId: this.pushForm.merchantId,
              merchantName: this.pushForm.merchantName,
              name: this.pushForm.name,
              phone: this.pushForm.phone,
              concatType: this.pushForm.concatType
            }).then(res => {
              console.log(res)
              this.handleObject()
            })
          }
          if (this.chooseType == '编辑推送对象') {
            modifyContact({
              merchantId: this.pushForm.merchantId,
              merchantName: this.pushForm.merchantName,
              name: this.pushForm.name,
              phone: this.pushForm.phone,
              concatType: this.pushForm.concatType,
              id: this.chooseId
            }).then(res => {
              console.log(res)
              this.handleObject()
            })
          }
        }
      })
    },
    handleObject() {
      this.pushForm = {
        concatType: '',
        merchantName: '',
        name: '',
        phone: '',
        merchantId: ''
      }
      this.chooseType = ''
      this.superviseList = []
      this.residentialList = []
      this.pushVisible = !this.pushVisible
      this.$refs.outputValueTable.refreshTable()
    },
    handleReset() {
      this.searchForm = {
        name: '',
        phone: '',
        merchantId: ''
      }
      this.$refs.outputValueTable.refreshTable()
    }
  }
}
</script>

<style scoped>
.outputValue-list {
  position: relative;
}
</style>