<template>
  <div>
    <el-dialog append-to-body title="工序信息" :visible.sync="showProcess" width="600px">
      <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="processCode" min-width="120"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" label="工序描述" prop="processDesc" min-width="120"></el-table-column>
        <el-table-column :show-overflow-tooltip="true" label="备注" prop="memo" 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: ['process', 'codeList'],
  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.processCode);
        processDesc.push(item.processDesc);
      }
      code = processCode.join(',');
      desc = processDesc.join(',');
      this.$emit('getProcess', code, desc);
      this.showProcess = false;
    },
    Cancel () {
      this.showProcess = false;
    },
    findProcess () {
      let _this = this;
      // 一级工序点
      this.axios.post('/ComBaseProcessService/doQueryProcessWeb', [
        {
          object: {processDesc: ''},
          memo1: '0'
        }
      ]).then(function (response) {
        if (response) {
          _this.processData = response.data.data.rows;
          _this.selection = [];
          if (_this.codeList) {
            _this.$nextTick(function () {
              for (let j = 0; j < _this.processData.length; j++) {
                if (_this.codeList.indexOf(_this.processData[j].processCode) >= 0) {
                  _this.$refs.processTab.toggleRowSelection(_this.processData[j], true);
                }
              }
            });
          }
        }
      });
    }
  },
  watch: {
    process: function () {
      this.findProcess();
      this.showProcess = true;
    }
  }
}
</script>
<style scoped></style>
