<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="authorityList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="项目岗位" align="center" prop="postName" />
      <el-table-column label="商机-下一步" align="center" prop="boNext">
        <template slot-scope="scope">
          {{scope.row.boNext ? '√' : '×'}}
        </template>
      </el-table-column>
      <el-table-column label="商机-修改" align="center" prop="boEdit">
        <template slot-scope="scope">
          {{scope.row.boEdit ? '√' : '×'}}
        </template>
      </el-table-column>
      <el-table-column label="商机-关闭" align="center" prop="boClose">
        <template slot-scope="scope">
          {{scope.row.boClose ? '√' : '×'}}
        </template>
      </el-table-column>
      <el-table-column label="商机-赢单" align="center" prop="boWin">
        <template slot-scope="scope">
          {{scope.row.boWin ? '√' : '×'}}
        </template>
      </el-table-column>
      <el-table-column label="商机-丢单" align="center" prop="boLose">
        <template slot-scope="scope">
          {{scope.row.boLose ? '√' : '×'}}
        </template>
      </el-table-column>

      <el-table-column label="项目成员-新增" align="center" prop="pojpsnAdd" >
        <template slot-scope="scope">
          {{scope.row.pojpsnAdd ? '√' : '×'}}
        </template>
      </el-table-column>
      <el-table-column label="项目成员-删除" align="center" prop="pojpsnDel">
        <template slot-scope="scope">
          {{scope.row.pojpsnDel ? '√' : '×'}}
        </template>
      </el-table-column>
      <el-table-column label="项目成员-编辑" align="center" prop="pojpsnEdit">
        <template slot-scope="scope">
          {{scope.row.pojpsnEdit ? '√' : '×'}}
        </template>
      </el-table-column>
      <el-table-column label="项目成员-查看" align="center" prop="pojpsnView">
        <template slot-scope="scope">
          {{scope.row.pojpsnView ? '√' : '×'}}
        </template>
      </el-table-column>

      <el-table-column label="任务-新增" align="center" prop="taskAdd" >
        <template slot-scope="scope">
          {{scope.row.taskAdd ? '√' : '×'}}
        </template>
      </el-table-column>
      <el-table-column label="任务-删除" align="center" prop="taskDel">
        <template slot-scope="scope">
          {{scope.row.taskDel ? '√' : '×'}}
        </template>
      </el-table-column>
      <el-table-column label="任务-编辑" align="center" prop="taskEdit">
        <template slot-scope="scope">
          {{scope.row.taskEdit ? '√' : '×'}}
        </template>
      </el-table-column>
      <el-table-column label="任务-查看" align="center" prop="taskView">
        <template slot-scope="scope">
          {{scope.row.taskView ? '√' : '×'}}
        </template>
      </el-table-column>
      <el-table-column label="行动-新增" align="center" prop="behaviorAdd">
        <template slot-scope="scope">
          {{scope.row.behaviorAdd ? '√' : '×'}}
        </template>
      </el-table-column>
      <el-table-column label="行动-删除" align="center" prop="behaviorDel">
        <template slot-scope="scope">
          {{scope.row.behaviorDel ? '√' : '×'}}
        </template>
      </el-table-column>
      <el-table-column label="行动-编辑" align="center" prop="behaviorEdit">
        <template slot-scope="scope">
          {{scope.row.behaviorEdit ? '√' : '×'}}
        </template>
      </el-table-column>
      <el-table-column label="行动-查看" align="center" prop="behaviorView">
        <template slot-scope="scope">
          {{scope.row.behaviorView ? '√' : '×'}}
        </template>
      </el-table-column>
      <el-table-column label="联系人-新增" align="center" prop="contactAdd">
        <template slot-scope="scope">
          {{scope.row.contactAdd ? '√' : '×'}}
        </template>
      </el-table-column>
      <el-table-column label="联系人-删除" align="center" prop="contactDel">
        <template slot-scope="scope">
          {{scope.row.contactDel ? '√' : '×'}}
        </template>
      </el-table-column>
      <el-table-column label="联系人-编辑" align="center" prop="contactEdit">
        <template slot-scope="scope">
          {{scope.row.contactEdit ? '√' : '×'}}
        </template>
      </el-table-column>
      <el-table-column label="联系人-查看" align="center" prop="contactView">
        <template slot-scope="scope">
          {{scope.row.contactView ? '√' : '×'}}
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['material:authority:edit']"
          >修改</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改商机角色权限对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="项目岗位" prop="postName">
          {{form.postName}}
          <!-- <el-input v-model="form.postName"/> -->
        </el-form-item>
        <el-divider content-position="left">
          <dev style="width: 50px; height: 40px; font-size: 18px">商机</dev>
        </el-divider>
        <el-row>
          <el-col :span="8">
            <el-form-item prop="boNext">
              <el-checkbox v-model="form.boNext">下一步</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="boEdit">
              <el-checkbox v-model="form.boEdit">修改</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="boClose">
              <el-checkbox v-model="form.boClose">关闭</el-checkbox>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item prop="boWin">
              <el-checkbox v-model="form.boWin">赢单</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="boLose">
              <el-checkbox v-model="form.boLose">丢单</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="8">
          </el-col>
        </el-row>
        <el-divider content-position="left">
          <dev style="width: 50px; height: 40px; font-size: 18px">项目成员</dev>
        </el-divider>
        <el-row>
          <el-col :span="8">
            <el-form-item prop="taskAdd">
              <el-checkbox v-model="form.pojpsnAdd">新增</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="pojpsnDel">
              <el-checkbox v-model="form.pojpsnDel">删除</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="pojpsnEdit">
              <el-checkbox v-model="form.pojpsnEdit">编辑</el-checkbox>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item prop="pojpsnView">
              <el-checkbox v-model="form.pojpsnView">查看</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="8">
          </el-col>
          <el-col :span="8">
          </el-col>
        </el-row>
        <el-divider content-position="left">
          <dev style="width: 50px; height: 40px; font-size: 18px">任务</dev>
        </el-divider>
        <el-row>
          <el-col :span="8">
            <el-form-item prop="taskAdd">
              <el-checkbox v-model="form.taskAdd">新增</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="taskDel">
              <el-checkbox v-model="form.taskDel">删除</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="taskEdit">
              <el-checkbox v-model="form.taskEdit">编辑</el-checkbox>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item prop="taskView">
              <el-checkbox v-model="form.taskView">查看</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="8">
          </el-col>
          <el-col :span="8">
          </el-col>
        </el-row>
        <el-divider content-position="left">
          <dev style="width: 50px; height: 40px; font-size: 18px">行动</dev>
        </el-divider>
        <el-row>
          <el-col :span="8">
            <el-form-item prop="behaviorAdd">
              <el-checkbox v-model="form.behaviorAdd">新增</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="behaviorDel">
              <el-checkbox v-model="form.behaviorDel">删除</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="behaviorEdit">
              <el-checkbox v-model="form.behaviorEdit">编辑</el-checkbox>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item prop="behaviorView">
              <el-checkbox v-model="form.behaviorView">查看</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="8">
          </el-col>
          <el-col :span="8">
          </el-col>
        </el-row>
        <el-divider content-position="left">
          <dev style="width: 50px; height: 40px; font-size: 18px">联系人</dev>
        </el-divider>
        <el-row>
          <el-col :span="8">
            <el-form-item prop="contactAdd">
              <el-checkbox v-model="form.contactAdd">新增</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="contactDel">
              <el-checkbox v-model="form.contactDel">删除</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="contactEdit">
              <el-checkbox v-model="form.contactEdit">编辑</el-checkbox>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item prop="contactView">
              <el-checkbox v-model="form.contactView">查看</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="8">
          </el-col>
          <el-col :span="8">
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAuthority, getAuthority, delAuthority, addAuthority, updateAuthority } from "@/api/business/spd/bo/authority";
export default {
  name: "Authority",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商机角色权限表格数据
      authorityList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        post: null,
        boNext: null,
        boEdit: null,
        boClose: null,
        boWin: null,
        boLose: null,
        taskAdd: null,
        taskDel: null,
        taskEdit: null,
        taskView: null,
        behaviorAdd: null,
        behaviorDel: null,
        behaviorEdit: null,
        behaviorView: null,
        contactAdd: null,
        contactDel: null,
        contactEdit: null,
        contactView: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询商机角色权限列表 */
    getList() {
      this.loading = true;
      listAuthority(this.queryParams).then(response => {
        this.authorityList = response.rows;
        console.log('this.authorityList',this.authorityList);
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        post: null,
        boNext: null,
        boEdit: null,
        boClose: null,
        boWin: null,
        boLose: null,
        taskAdd: null,
        taskDel: null,
        taskEdit: null,
        taskView: null,
        behaviorAdd: null,
        behaviorDel: null,
        behaviorEdit: null,
        behaviorView: null,
        contactAdd: null,
        contactDel: null,
        contactEdit: null,
        contactView: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商机角色权限";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAuthority(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改商机角色权限";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAuthority(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAuthority(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除商机角色权限编号为"' + ids + '"的数据项？').then(function() {
        return delAuthority(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('material/authority/export', {
        ...this.queryParams
      }, `authority_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
