<template>
  <fullscreen :fullscreen.sync="fullscreen" class="container">
    <div class="container-box">
      <toolList @iconCli="iconCli" :tooltit="tooltit"></toolList>
      <div class="search">
        <el-select v-model="advstatus" @change="advchange">
          <el-option v-for="items in advopt" :key="items.id" :label="items.name" :value="items.id">
          </el-option>
        </el-select>
      </div>
      <div class="tabbox">
        <el-table height="calc(100% - 40px)" class="com-table" ref="multipleTable" :data="tableData"
          tooltip-effect="dark" size="small" border style="width: 100%" v-loading="loading">
          <el-table-column prop="process_id" label="工单编号">
          </el-table-column>
          <el-table-column prop="need_name" label="工单标题"> </el-table-column>
          <el-table-column prop="createId" label="发起人"> </el-table-column>
          <el-table-column prop="proposer" label="发起人姓名">
          </el-table-column>
          <el-table-column prop="proposer_time" label="发起时间">
          </el-table-column>
          <el-table-column prop="taskName" label="状态"> </el-table-column>
          <el-table-column label="操作" width="120px" align="center">
            <template slot-scope="scope">
              <el-button size="mini" type="primary" @click="dialogCheck(scope.row, 1)">查看</el-button>
              <!--<el-button size="mini" type="danger" v-if="scope.row.sts==3"-->
              <el-button size="mini" v-if="scope.row.status === '1'" type="danger" @click="dialogCheck(scope.row, 2)">审核
              </el-button>
              <!-- <el-button
                v-if="
                  userInfo.loginName == scope.row.opName && scope.row.sts == '3'
                "
                size="mini"
                type="primary"
                @click="advSure(scope.row)"
                >归档
              </el-button> -->
            </template>
          </el-table-column>
        </el-table>
        <el-pagination class="pageBox" @current-change="currchange" layout="prev, pager, next" background
          :total="total">
        </el-pagination>
      </div>
      <el-dialog title="广告管理" v-if="dialogStatus" :visible.sync="dialogStatus" width="80%" :destroy-on-close="true"
        :modal-append-to-body="false" :close-on-click-modal="false">
        <div>
          <advert
            v-if="typestatsu === 2"
            @closeEdio="closeEdio"
            :draftStatus="draftStatus"
            :componentInfo="componentInfo"
            :componentStatus="componentStatus"
            :changeinfo="changeinfo"
          ></advert>
        </div>
      </el-dialog>

      <el-dialog title="定稿素材" :visible.sync="dialogStatusc" width="50%" :destroy-on-close="true"
        :modal-append-to-body="false" :close-on-click-modal="false">
        <!-- <el-form>
                    <el-form-item class="info-line online">
                        <span>素材类型</span>
                        <el-select :popper-append-to-body="false" v-model="advtype" placeholder="素材类型">
                            <el-option v-for="item in typeList" :key="item.dataCode" :label="item.dataName"
                                :value="item.dataCode">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-form> -->
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogCli(1)" type="primary">确 定</el-button>
          <el-button @click="dialogCli(2)">取 消</el-button>
        </div>
      </el-dialog>
    </div>
  </fullscreen>
</template>
<script>
import {
  getTodoBase,
  getDoneBase,
  getInitiateBase,
} from "../../../http/api.js";
import mySearch from "../../../components/search.vue";
import toolList from "../../../components/toolList.vue";
import advert from "./components/adverts.vue";

export default {
  components: {
    mySearch,
    toolList,
    advert,
  },
  data() {
    return {
      draftStatus:true,
      clickStatus:"",
      tooltit: "广告管理",
      auditStatus: false,
      fullscreen: false,
      total: 0,
      pageSize: 1,
      tableData: [{}],
      dialogStatus: false,
      disableStatus: false,
      infolist: {},
      userInfo: {},
      params: {},
      typestatsu: 1,
      options: [],
      typeopt: [],
      componentInfo: {},
      componentStatus: false,
      dialogStatusc: false,
      loading: false,
      changeinfo: false,
      saveStatus: false,
      advstatus: "",
      advopt: [
        {
          id: "0",
          name: "待审批",
        },
        {
          id: "1",
          name: "已审批",
        },
        {
          id: "2",
          name: "我发起的",
        },
        {
          id: "3",
          name: "定稿 ",
        },
      ],
      btnctrlStatus: false,
      typeList: [],
      advtype: "",
      dgid: "",
      singleTable: {},
      shParam: {},
      // isBtnShow: false,
      isGDClick: false,
      tableName: "ggsj_process",
    };
  },
  methods: {
    //我的待办
    getQueryList() {
      let list = {
        tableName: this.tableName,
      };
      getTodoBase(this.pageSize, "", list).then((res) => {
        this.tableData = res.data.data;
        this.tableData.map((item) => {
          item.status = "1";
        });
        this.total = res.data.totalRecord;
        this.loading = false;
      });

      // console.log(this.$utilflow);
      // let res = this.$utilflow.getQueryList()
      // console.log(res);
      // this.$http({
      //   url: "/market/waf/queryTodoBase",
      //   method: "post",
      //   headers: {
      //     "Content-Type": "application/json",
      //     page: '{"pageNo":"' + this.pageSize + '","pageSize":"10"}',
      //   },
      //   data: { tableName: this.tableName },
      // }).then((res) => {
      //   // console.log(res);
      //   this.tableData = res.data.data;
      //   // let data = res.data.list;
      //   this.tableData.map((item) => {
      //     // status === 1 需要审核
      //     item.status = "1";
      //   });
      //   console.log(this.tableData);
      //   this.total = res.data.totalRecord;
      //   this.loading = false;
      //   // this.isGDClick = false;
      //   // if(this.advstatus==0){
      //   // 	data.forEach(item => {
      //   //         item.isBtnShow = false;
      //   //         this.getSts(item)
      //   // 	});
      //   // }
      //   // this.tableData = data;
      // });
    },
    //我的已办
    getQueryDone() {
      let list = {
        tableName: this.tableName,
      };
      getDoneBase(this.pageSize, "", list).then((res) => {
        this.tableData = res.data.data;
        this.tableData.map((item) => {
          item.status = "2";
        });
        this.total = res.data.totalRecord;
        this.loading = false;
      });
      // this.$http({
      //   url: "/market/waf/queryDoneBase",
      //   method: "post",
      //   headers: {
      //     "Content-Type": "application/json",
      //     page: '{"pageNo":"' + this.pageSize + '","pageSize":"10"}',
      //   },
      //   data: { tableName: this.tableName },
      // }).then((res) => {
      //   console.log(res);
      //   this.tableData = res.data.data;
      //   // let data = res.data.list;
      //   this.tableData.map((item) => {
      //     // status === 2 不需要审核
      //     item.status = "2";
      //   });
      //   this.total = res.data.totalRecord;
      //   this.loading = false;
      //   // this.isGDClick = false;
      //   // if(this.advstatus==0){
      //   // 	data.forEach(item => {
      //   //         item.isBtnShow = false;
      //   //         this.getSts(item)
      //   // 	});
      //   // }
      //   // this.tableData = data;
      // });
    },
    //我发起的
    getMeLaunch() {
      let list = {
        tableName: this.tableName,
      };
      getInitiateBase(this.pageSize, "", list).then((res) => {
        this.tableData = res.data.data;
        this.tableData.map((item) => {
          if (item.taskName === "起草") {
            item.status = "1";
          } else {
            item.status = "2";
          }
        });
        this.total = res.data.totalRecord;
        this.loading = false;
      });
      // this.$http({
      //   url: "/market/waf/queryInitiateBase",
      //   method: "post",
      //   headers: {
      //     "Content-Type": "application/json",
      //     page: '{"pageNo":"' + this.pageSize + '","pageSize":"10"}',
      //   },
      //   data: { tableName: this.tableName },
      // }).then((res) => {
      //   // let size = this.isNaNStatus(res.data);
      //   this.tableData = res.data.data;
      //   this.tableData.map((item) => {
      //     if (item.taskName === "起草") {
      //       item.status = "1";
      //     } else {
      //       item.status = "2";
      //     }
      //   });
      //   // let data = res.data.list;
      //   this.total = res.data.totalRecord;
      //   this.loading = false;
      // });
    },
    //定稿
    getFinalized() {
      this.$http({
        url: "/market/ggsj/queryDone",
        method: "post",
        headers: {
          "Content-Type": "application/json",
          page: '{"pageNo":"' + this.pageSize + '","pageSize":"10"}',
        },
        data: {},
      }).then((res) => {
        console.log(res);
        // let size = this.isNaNStatus(res.data);
        this.tableData = res.data.data;
        this.tableData.map((item) => {
          item.status = "2";
        });
        // let data = res.data.list;
        this.total = res.data.totalRecord;
        this.loading = false;
      });
    },
    //获取列表
    getList(e) {
      console.log(e);
      switch (e) {
        //我的待办
        case "0":
          this.auditStatus = true;
          this.getQueryList();
          break;
        //我的已办
        case "1":
          this.getQueryDone();
          break;
        //我发起的
        case "2":
          this.getMeLaunch();
          break;
        //定稿
        case "3":
          this.getFinalized();
          break;
      }
      // this.pageSize = n;
      // let _this = this;
      // this.tableData = [];
      // this.loading = true;
      // let param = {
      //   tableName: "ggsj_process",
      // };
      // this.$http({
      //   url: "/market/waf/queryTodoBase",
      //   method: "post",
      //   headers: {
      //     "Content-Type": "application/json",
      //     page: '{"pageNo":"' + n + '","pageSize":"10"}',
      //   },
      //   data: param,
      // }).then((res) => {
      //   console.log(res);
      //   this.tableData = res.data.data;
      //   // let data = res.data.list;
      //   this.total = res.data.totalRecord;
      //   this.loading = false;
      //   // this.isGDClick = false;
      //   // if(this.advstatus==0){
      //   // 	data.forEach(item => {
      //   //         item.isBtnShow = false;
      //   //         this.getSts(item)
      //   // 	});
      //   // }
      //   // this.tableData = data;
      // });
      // this.$http({
      //   url: "/market/waf/queryDoneBase",
      //   method: "post",
      //   headers: {
      //     "Content-Type": "application/json",
      //     page: '{"pageNo":"' + n + '","pageSize":"10"}',
      //   },
      //   data: param,
      // }).then((res) => {
      //   // console.log(res);
      //   // this.tableData = res.data.data;
      //   // // let data = res.data.list;
      //   // this.total = res.data.totalRecord;
      //   // this.loading = false;
      //   // this.isGDClick = false;
      //   // if(this.advstatus==0){
      //   // 	data.forEach(item => {
      //   //         item.isBtnShow = false;
      //   //         this.getSts(item)
      //   // 	});
      //   // }
      //   // this.tableData = data;
      // });
    },
    async getSts(v) {
      await this.$http({
        url: "/bpm/api/taskInit",
        method: "post",
        headers: {
          "Content-Type": "application/json",
        },
        data: {
          taskId: v.taskId,
          woNo: v.id,
        },
      }).then((res) => {
        this.shParam = res.data;
        //  this.dialogCli(1);
        // callback&&callback()
        if (this.isGDClick) {
          this.dialogCli(1);
          return;
        }
        if (res.data.taskName == "需求部门") {
          v.sts = "3";
          return;
        }
        if (res.data.assigneeNo == this.userInfo.loginNo) {
          v.sts = "0";
          v.isBtnShow = true;
          return;
        }
      });
    },
    // 分页
    currchange(v) {
      console.log(123);
      console.log(v);
      this.pageSize = v;
      console.log(this.clickStatus);
      this.getList(this.clickStatus);
    },
    advchange(e) {
      this.total = 0
      this.pageSize = 1
      this.clickStatus = e
      this.getList(this.clickStatus);
    },
    //处理申请
    dialogCheck(n, v) {

      if (v == 1) {
        this.changeinfo = false;
        this.saveStatus = false
      } else {
        if(n.taskName == "科室经理审批"){
          this.draftStatus = false;
        }
        this.changeinfo = true;
      }
      this.typestatsu = 2;
      this.dialogStatus = true;
      let params = {
        woNo: n.id,
        taskId: n.taskId,
      };
      this.componentInfo = n;
      this.componentStatus = true;
    },
    // 归档
    advSure(v) {
      let _this = this;
      // this.dialogStatusc = true;
      this.isGDClick = true;
      this.dgid = v.id;

      this.getSts(v);
    },
    dialogCli(v) {
      let _this = this;

      if (v == 1) {
        // let advTypeName = '';
        // for (let i = 0; i < this.typeList.length; i++) {
        //     if (this.typeList[i].dataCode == this.advtype) {
        //         advTypeName = this.typeList[i].dataName;
        //     }
        // }
        // let param = {
        //     woNo: this.dgid,
        //     advTypeName: advTypeName,
        //     advType: this.advtype
        // }
        let gdParam = {
          woNo: this.dgid,
          // advTypeName: advTypeName,
          // advType: this.advtype
        };

        this.shParam.params.terminalRes = JSON.stringify(
          Object.assign(JSON.parse(this.shParam.params.terminalRes), gdParam)
        );

        let param = this.shParam;
        this.$http({
          // url: "/market/cadv/mkConfirmAdv",
          url: "/bpm/api/submitTask",
          method: "post",
          headers: {
            "Content-Type": "application/json",
          },
          data: param,
        }).then((res) => {
          if (res.data.result === 1) {
            _this.$message({
              message: res.data.desc,
              type: "error",
            });
          } else {
            _this.$message({
              message: "成功",
              type: "success",
            });
            _this.getList(_this.params, _this.pageSize);
          }
        });
      }
      // this.dialogStatusc = false;
      // this.advtype = '';
      return;
    },
    closeEdio() {
      this.getList(this.params, this.pageSize);
      this.typestatsu = 1;
      this.dialogStatus = false;
      this.draftStatus = true;
      this.componentStatus = false;
    },
    gettype() {
      this.$http({
        url: "/sysmgr/cfgDataDicts/queryMap",
        method: "post",
        headers: {
          "Content-Type": "application/json",
        },
        data: {
          dictCodePks: "materType",
        },
      }).then((res) => {
        this.typeList = res.data.body.materType;
      });
    },
    //功能栏
    iconCli(v) {
      if (v === 1) {
        this.getList(this.params, this.pageSize);
      }
      if (v === 2) {
        this.fullscreen = !this.fullscreen;
      }
    },
    ctrlbtn() {
      let v = JSON.parse(window.sessionStorage.childrenMenus);
      for (let i = 0; i < v.length; i++) {
        if (v[i].jspUrl == this.$route.path && v[i].systemflag == "1") {
          this.btnctrlStatus = true;
          return;
        }
      }
    },
  },
  mounted() {
    this.userInfo = JSON.parse(window.sessionStorage.userInfo);
    this.advstatus = String(this.$route.query.type);
    this.clickStatus = this.$route.query.type;
    this.getList(this.advstatus);

    this.ctrlbtn();
    this.gettype();
  },
  created() { },
};
</script>
<style scoped lang="scss">
.approval {
  .roval-box {
    padding: 0 20px;
    margin-top: 20px;
    margin-bottom: 10px;

    .el-input {
      width: calc(100% - 200px);
      display: inline-block;
    }

    span {
      display: inline-block;
      width: 80px;
      font-size: 14px;
      margin-right: 20px;

      .el-input {
        width: 100%;
        display: inline-block;
      }
    }
  }
}

.onetab {
  margin-bottom: 20px;
  padding: 0 20px;
}

.titbox {
  div {
    float: right;

    i {
      font-size: 22px;
      margin-left: 20px;
      cursor: pointer;
    }
  }
}

.tabbox {
  margin-top: 15px;
}

.pageBox {
  text-align: right;
  margin-top: 10px;
}

.info-line {
  width: 100%;
  display: block;
  padding-left: 20px;

  div {
    width: 50%;
    display: inline-block;
  }

  span {
    width: 80px;
    display: inline-block;
    text-align: left;

    i {
      color: red;
      display: inline-block;
      padding-right: 5px;
    }
  }

  .el-select,
  .el-input {
    width: calc(100% - 100px);
  }
}

.online {
  width: 100%;

  .el-select {
    width: calc(100% - 100px);
  }

  span {
    vertical-align: top;
  }

  .el-textarea {
    width: calc(100% - 100px);
  }
}
</style>
