<template>
  <div>
    <el-dialog append-to-body title="客户信息" :visible.sync="showProcess" width="400px">
      <el-table height="580" ref="processTab" :data="processData" border highlight-current-row @selection-change="handleSelect">
        <el-table-column type="selection" width="50" align="center"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" label="客户名称" prop="text" min-width="120"></el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="Cancel">取消</el-button>
        <el-button type="primary" size="small" @click="OK">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  props: ['customer', 'customerCodeList'],
  data () {
    return {
      selection: [],
      showProcess: false,
      processData: []
    }
  },
  methods: {
    handleSelect (selection) {
      this.selection = selection;
    },
    OK () {
      let processCode = [], processDesc = [], code = '', desc = '';
      for (let item of this.selection) {
        processCode.push(item.id);
        processDesc.push(item.text);
      }
      code = processCode.join(',');
      desc = processDesc.join(',');
      this.$emit('getCustomer', code, desc);
      this.showProcess = false;
    },
    Cancel () {
      this.showProcess = false;
    },
    findProcess () {
      let _this = this;
      // 客户信息
      this.axios.post('/PbModelDbService/findSlmCustomerInfoCmdDb').then(function (response) {
        if (response) {
          _this.processData = response.data.data;
          _this.selection = [];
          if (_this.customerCodeList) {
            _this.$nextTick(function () {
              for (let j = 0; j < _this.processData.length; j++) {
                if (_this.customerCodeList.indexOf(_this.processData[j].id) >= 0) {
                  _this.$refs.processTab.toggleRowSelection(_this.processData[j], true);
                }
              }
            });
          }
        }
      });
    }
  },
  watch: {
    customer: function () {
      this.findProcess();
      this.showProcess = true;
    }
  }
}
</script>
<style scoped></style>
