<template>
  <div class="management">
    <modify-organ>
      <template v-slot:header>操作员管理</template>
    </modify-organ>
    <list-head :operator="operator" @getuser="getuserfn"></list-head>
    <!-- <list-the-content @PagingOption="PagingOptionNumber" @Pagination="PaginationNumber" :total="total"> -->
    <list-the-content @UpLoat="Load" :ShowHidden="ShowHidden">
      <template #table="{ data }">
        <el-table :row-class-name="tableRowClassName" :header-cell-style="headClass" :data="list" max-height="680">
          <el-table-column type="index" label="序号" :index="indexMethod" width="180"></el-table-column>
          <el-table-column prop="CUST_CODE" label="名称"></el-table-column>
          <!-- <el-table-column prop="ROLE_LIST" label="角色"></el-table-column> -->
          <el-table-column label="角色" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span v-for="(item,index) in scope.row.ROLE_LIST" :key="item.index">
                <span v-if="index !== scope.row.ROLE_LIST.length - 1">
                  {{ item.ROLE_NAME}} /
                </span>
                <span v-else>
                  {{ item.ROLE_NAME}}
                </span>
              </span>
            </template>
          </el-table-column>
          <el-table-column prop="DEPT" label="部门"></el-table-column>
          <!-- <el-table-column prop="CUST_STATUS" label="状态"></el-table-column> -->
          <el-table-column label="状态">
            <template slot-scope="scope">
              <span v-if="scope.row.CUST_STATUS==='0'" style="color:rgba(98, 230, 111, 1)">
                正常
              </span>
              <span v-if="scope.row.CUST_STATUS==='3'" style="color:rgba(255, 41, 41, 1)">
                注销
              </span>
            </template>
          </el-table-column>
          <el-table-column prop="address" label="操作" width="206">
            <template slot-scope="scope">
              <el-button type="text">编辑</el-button><span class="Bar">|</span>
              <el-button type="text" v-if="scope.row.CUST_STATUS==='0'" @click="Reset(scope.row)">密码重置</el-button><span
                class="Bar" v-if="scope.row.CUST_STATUS==='0'">|</span>
              <el-button type="text" v-if="scope.row.CUST_STATUS==='0'" @click="Cancellation(scope.row)">注销</el-button>
              <el-button type="text" v-if="scope.row.CUST_STATUS==='3'" @click="Activation(scope.row)">账户激活</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </list-the-content>
    <!--    弹框   -->
    <template>
      <dialog-box :dialogVisible.sync="Resetfn" @determine="determineReset">
        <template v-slot:show-text>确认重置{{ CUST_CODE }}密码?</template>
      </dialog-box>
      <dialog-box :dialogVisible.sync="Cancellationfn" @determine="determineCancellation">
        <template v-slot:show-text>确认注销{{ CUST_CODE }}?</template>
      </dialog-box>
      <dialog-box :dialogVisible.sync="Activationfn" @determine="determineActivation">
        <template v-slot:show-text>确认激活{{ CUST_CODE }}?</template>
      </dialog-box>
    </template>
  </div>
</template>
<script>
  import ListTheContent from "@/components/ListTheContent/ListTheContent.vue"; // 列表内容
  import ListHead from "@/components/Listhead/ListHead.vue"; // 列表头
  import ModifyOrgan from "@/common/components/ContentHeader.vue"; //公共头部
  import DialogBox from "../common/components/DialogBox.vue"  // 弹框
  export default {
    name: "OperatorList",
    components: {
      ModifyOrgan,
      ListTheContent,
      ListHead,
      DialogBox,
    },
    created() {
      this.AccessToInformation()
    },
    data() {
      return {
        flag: false, // 资金账户 隐藏
        operator: "+ 新增操作员",
        pageNum: "", //序号
        pageSize: "", // 序号
        ROLE_ID: "",  // 角色ID
        input_value_one: "", // 输入框1 客户姓名
        input_value_two: "", // 输入框2
        list: [], // 数据
        Resetfn: false, // 重置密码弹框
        Cancellationfn: false, // 注销弹框
        Activationfn: false, // 激活弹框
        CUST_CODE: "", // 角色名称
        information: "", // row
        more: 1, // 页码
        ShowHidden: 0, // 加载更多 显示隐藏
        reception: [] // 接收新数据
      };
    },
    methods: {
      // 查寻列表 
      AccessToInformation() {
        fql.getUserInfo().then(res => {
          const GetUserInfo = this.$store.state.userInfo  // 操作员
          // console.log(GetUserInfo);
          // aaaa.push(asds)
          // console.log(res);
          let RoleSearch = this.$store.state.roleDict.filter(item => {
            return item.ROLE_NAME === this.input_value_two
          })
          // console.log(RoleSearch);
          if (RoleSearch.length > 0) {
            this.ROLE_ID = RoleSearch[0].ROLE_ID
          } else {
            this.ROLE_ID = this.input_value_two
          }
          let data = {
            ACTION_TYPE: "1", // 操作类型
            OPERATOR: "0922user01", // 操作员
            CUST_NAME: this.input_value_one, // 客户姓名
            ROLE_ID: this.ROLE_ID, // 角色ID
            SYSTEM_ID: "79", // 子系统编号
            PAGE_NO: this.more, //页码
            PAGE_SIZE: 12, // 每页显示条数
            USER_CODE: GetUserInfo.USERCODE,
            INST_USER_CODE: GetUserInfo.USERCODE,
          }
          let that = this
          let folio = this.more
          // let reception = []
          for (let i = 1; i <= this.more; i++) {
            data.PAGE_NO = i
            fql.WFW_USER_MANAGE_SERVICE['查询当前机构下所有操作员'](data).then(function (obj) {
              that.reception.push(...obj.list)
            })
          }
          fql.WFW_USER_MANAGE_SERVICE['查询当前机构下所有操作员'](data).then(function (obj) {
            // console.log(obj)
            // console.log(obj.list);
            let fixaTion = false
            that.list.forEach((item, index) => {
              that.reception.forEach(im => {
                if (item.CUST_CODE === im.CUST_CODE) {
                  fixaTion = true
                }
              })
            })
            if (fixaTion) {
              that.list.forEach((item, index) => {
                that.reception.forEach((im, ix) => {
                  if (item.CUST_CODE === im.CUST_CODE) {
                    item.BIZ_SYS = im.BIZ_SYS
                    item.CUST_CODE = im.CUST_CODE
                    item.CUST_FNAME = im.CUST_FNAME
                    item.CUST_NAME = im.CUST_NAME
                    item.CUST_STATUS = im.CUST_STATUS
                    item.RIGHT_LIST = im.RIGHT_LIST
                    item.ROLE_LIST = im.ROLE_LIST
                    item.USER_CODE = im.USER_CODE
                  }
                })
              })
            } else {
              that.list.push(...obj.list)
            }
            // that.list = that. reception
            that.ShowHidden = obj.RNUM
            if (obj.list.length === 0) {
              that.list = obj.list
            }
          })
        })
      },
      //  加载  更多
      Load: function () {
        this.more++
        fql.getUserInfo().then(res => {
          let RoleSearch = this.$store.state.roleDict.filter(item => {
            return item.ROLE_NAME === this.input_value_two
          })
          // console.log(RoleSearch);
          if (RoleSearch.length > 0) {
            this.ROLE_ID = RoleSearch[0].ROLE_ID
          } else {
            this.ROLE_ID = this.input_value_two
          }
          const GetUserInfo = this.$store.state.userInfo  // 操作员
          let data = {
            ACTION_TYPE: "1", // 操作类型
            OPERATOR: "0922user01", // 操作员
            CUST_NAME: this.input_value_one, // 客户姓名
            ROLE_ID: this.ROLE_ID, // 角色ID
            SYSTEM_ID: "79", // 子系统编号
            PAGE_NO: this.more, //页码
            PAGE_SIZE: 12, // 每页显示条数
            USER_CODE: GetUserInfo.USERCODE,
            INST_USER_CODE: GetUserInfo.USERCODE,
          }
          let that = this
          fql.WFW_USER_MANAGE_SERVICE['查询当前机构下所有操作员'](data).then(function (obj) {
            console.log(obj)
            that.list.push(...obj.list)
            if (obj.list.length === 0) {
              that.$message({
                showClose: true,
                message: '没有更多了',
                type: 'warning'
              });
            }
          })
        })
      },
      // 斑马纹
      headClass() {
        return "background:#375AC7;";
      },
      tableRowClassName({ row, rowIndex }) {
        // console.log(row);
        if ((rowIndex + 1) % 2 === 0) {
          return "warning-row";
        } else {
          return "success-row";
        }
      },
      // 序号
      indexMethod(index) {
        let currentPage = this.pageNum // 当前页码
        let pageSize = this.pageSize // 每页条数
        return index + 1 + (currentPage - 1) * pageSize;  // 返回表格数据
      },
      //  输入框
      getuserfn(data) {
        // this.list=data
        this.input_value_one = data.input_value_one
        this.input_value_two = data.input_value_two
        // 重新渲染
        // this.AccessToInformation()
        fql.getUserInfo().then(res => {
          // aaaa.push(asds)
          // console.log(res);
          let RoleSearch = this.$store.state.roleDict.filter(item => {
            return item.ROLE_NAME === this.input_value_two
          })
          // console.log(RoleSearch);
          if (RoleSearch.length > 0) {
            this.ROLE_ID = RoleSearch[0].ROLE_ID
          } else {
            this.ROLE_ID = this.input_value_two
          }
          const GetUserInfo = this.$store.state.userInfo  // 操作员
          let data = {
            ACTION_TYPE: "1", // 操作类型
            OPERATOR: "0922user01", // 操作员
            CUST_NAME: this.input_value_one, // 客户姓名
            ROLE_ID: this.ROLE_ID, // 角色ID
            SYSTEM_ID: "79", // 子系统编号
            PAGE_NO: this.more, //页码
            PAGE_SIZE: 12, // 每页显示条数
            USER_CODE: GetUserInfo.USERCODE,
            INST_USER_CODE: GetUserInfo.USERCODE,
          }
          let that = this
          fql.WFW_USER_MANAGE_SERVICE['查询当前机构下所有操作员'](data).then(function (obj) {
            that.list = obj.list
            that.ShowHidden = obj.RNUM
          })
        })
      },
      //  密码重置按钮弹框
      Reset(row) {
        // console.log(row);
        this.information = row
        this.Resetfn = true
        this.CUST_CODE = this.information.CUST_CODE
      },
      // 账户激活按钮弹框
      Activation(row) {
        // console.log(row);
        this.information = row
        this.Activationfn = true
        this.CUST_CODE = this.information.CUST_CODE
      },
      // 注销按钮弹框
      Cancellation(row) {
        console.log(row);
        this.information = row
        this.Cancellationfn = true
        this.CUST_CODE = this.information.CUST_CODE
        // this.DEPT = this.information.DEPT
        // console.log(this.CUST_CODE);
      },
      // 密码重置 点击确定
      determineReset() {
        const GetUserInfo = this.$store.state.userInfo  // 操作员
        // console.log(GetUserInfo);
        let data2 = {
          ACCT_CODE: this.information.CUST_CODE, //账号代码
          ACCT_TYPE: "775",   //账号类型
          PWD_TYPE: "5",     //密码类型
          RESET_FLAG: "1",   //是否重置标志
          SYSTEM_ID: "79",   //子系统编号
          ACTION_TYPE: "1",   //操作类型
          OPERATOR: GetUserInfo.USER_CUSTID,   //操作员
          TERMINAL_SOURCE: "85",
          USER_CODE: GetUserInfo.USERCODE,
          INST_USER_CODE: GetUserInfo.USERCODE,
        }
        // let that = this
        fql.WFW_USER_MANAGE_SERVICE['设置操作员初始密码'](data2).then(res1002 => {
          console.log(res1002)
          this.$message({
            type: 'success',
            message: '重置密码成功!'
          });
        }).catch(() => { })
        //  渲染页面
        this.AccessToInformation()
      },
      //  注销弹框 点击确定
      determineCancellation() {
        const ResUserInfo = this.$store.state.userInfo  // 操作员
        let data4 = {
          SYSTEM_ID: "79", // 子系统编号
          CUST_CODE: this.information.CUST_CODE, // 用户登录名
          ACCT_STATUS: "3", // 用户状态
          BUSIN_TYPE: "CWJRY", //业务类型
          ACTION_TYPE: "1", //操作类型
          OPERATOR: ResUserInfo.USER_CUSTID, // 操作员
          USER_CODE: ResUserInfo.USERCODE,
          INST_USER_CODE: ResUserInfo.USERCODE,
        }
        let that = this
        fql.WFW_USER_MANAGE_SERVICE['激活/注销操作员'](data4).then(res1008 => {
          console.log(res1008)
          // console.log(123123);
          if (res1008.RNUM === -1) {
            this.Cancellationfn = false
            this.$message.error('1008' + res1008.msg);
            return
          }
          this.$message({
            type: 'success',
            message: '注销成功!'
          });
          //  渲染页面
          this.AccessToInformation()
        }).catch(() => { })
      },
      // 激活弹框  点击确定
      determineActivation() {
        const ResUserInfo = this.$store.state.userInfo  // 操作员
        let data3 = {
          SYSTEM_ID: "79", // 子系统编号
          CUST_CODE: this.information.CUST_CODE, // 用户登录名
          ACCT_STATUS: "0", // 用户状态 0正常  3注销
          BUSIN_TYPE: "CWJRY", //业务类型
          ACTION_TYPE: "1", //操作类型
          OPERATOR: ResUserInfo.USER_CUSTID, // 操作员
          USER_CODE:ResUserInfo.USERCODE,
          INST_USER_CODE:ResUserInfo.USERCODE,
        }
        let that = this
        fql.WFW_USER_MANAGE_SERVICE['激活/注销操作员'](data3).then(res1008 => {
          console.log(res1008)
          this.$message({
            type: 'success',
            message: '激活成功!'
          });
        }).catch(() => { })
        //  渲染页面
        this.AccessToInformation()
      },
    },
  };
</script>
<style scoped>
  .management {
    background-color: #242b61;
    height: 96%;
    border-radius: 6px;
  }
  .header span {
    float: left;
    color: #ffffff;
    font-size: 14px;
    margin-top: 16px;
  }
</style>