<template>
  <div>
    <div class="d-flex flex-between">
      <div>
        <el-button type="primary" size="medium" @click="addData">
          <span class="d-in-block v-mid el-icon-plus font-size-16"></span>
          <span class="d-in-block v-mid font-size-16">三重一大申报</span>
        </el-button>
        <el-button type="primary" size="medium" @click="exportAll" :disabled="multipleSelection.length == 0">
          <span class="d-in-block v-mid font-size-16">导出</span>
        </el-button>
        <el-button type="danger" size="medium" @click="batchDel" :disabled="multipleSelection.length == 0">
          <span class="d-in-block v-mid font-size-16">删除</span>
        </el-button>
      </div>
      <el-form label-width="100px" :inline="true">
         <el-form-item prop="state_value">
          <el-select class="mr10" v-model="state_value" placeholder="请选择类别">
            <el-option  v-for="item in type_list"  :key="item.value"  :label="item.label"  :value="item.value" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="keyword">
          <el-input placeholder="请输入搜索关键字" v-model="keyword" clearable @clear="getListData">
          </el-input>
        </el-form-item>
        <el-button type="primary" class="ml5" @click="getListData">搜索</el-button>
      </el-form>
    </div>

    <el-tabs v-model="activeName" @tab-click="paneTabSwitch">

      <el-tab-pane label="我申请的" name="first">
        <el-table :data="applyTable" tooltip-effect="dark" v-loading="loading" style="width: 100%" @selection-change="handleSelectionChange">
          <el-table-column type="selection" align="center" width="55"></el-table-column>
          <el-table-column label="序号" align="center" type="index" width="50"></el-table-column>
          <el-table-column label="项目名称" show-overflow-tooltip prop="xm_name" width="auto"></el-table-column>
          <el-table-column label="项目类别"  prop="xm_type" ></el-table-column>
          <el-table-column label="项目理由" show-overflow-tooltip prop="xm_reason"></el-table-column>
          <el-table-column label="申请科室" show-overflow-tooltip prop="department_name"></el-table-column>
          <el-table-column label="项目预算（元）" prop="xm_price"></el-table-column>
          <el-table-column label="申报时间" show-overflow-tooltip prop="xm_sbsj"></el-table-column>
          <el-table-column label="项目方式" show-overflow-tooltip prop="lb_name"></el-table-column>
          <el-table-column label="状态">
            <template slot-scope="scope">
              <div :class="scope.row.xm_status_option_k=='4' ? 'red' : (scope.row.xm_status_option_k=='3' ? 'blue' : ' ') ">
                {{scope.row.xm_status}}
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="150">
            <template slot-scope="scope">
              <el-popover placement="left" width="230" trigger="click" v-if="scope.row.xm_status_option_k=='1'">
                <!--待提交-->
                <el-button type="text" @click="detailShow(scope.row)">详情</el-button>
                <el-button type="text" @click="editShow(scope.row)">编辑</el-button>
                <el-button type="text" @click="applyCheck(scope.row)">提交审核</el-button>
                <el-button type="text" @click="delData(scope.row)">删除</el-button>
                <div slot="reference" class="optionMore" style="padding-left:10%;">
                  <img src="../../../assets/icon/optionIcon.png" style="width:3%;" alt="">
                </div>
              </el-popover>

              <el-popover placement="left" width="230" trigger="click" v-if="scope.row.xm_status_option_k=='2'">

                <el-button type="text" @click="detailShow(scope.row)">详情</el-button>
                <el-button type="text" @click="editShow(scope.row)">编辑</el-button>
                <el-button type="text" @click="applyCheck(scope.row)">重新提交</el-button>
                <el-button type="text" @click="delData(scope.row)">删除</el-button>
                <div slot="reference" class="optionMore" style="padding-left:10%;">
                  <img src="../../../assets/icon/optionIcon.png" style="width:3%;" alt="">
                </div>
              </el-popover>

              <el-popover placement="left" width="185" trigger="click" v-if="scope.row.xm_status_option_k=='3'">
                <el-button type="text" @click="detailShow(scope.row)">详情</el-button>
                <el-button type="text" @click="checkProcess(scope.row)">审核进度</el-button>
                <el-button type="text" @click="delData(scope.row)">删除</el-button>
                <div slot="reference" class="optionMore" style="padding-left:10%;">
                  <img src="../../../assets/icon/optionIcon.png" style="width:3%;" alt="">
                </div>
              </el-popover>

              <el-popover placement="left" width="45" trigger="click" v-if="scope.row.xm_status_option_k=='4'">
                <el-button type="text" @click="detailShow(scope.row)">详情</el-button>
                <div slot="reference" class="optionMore" style="padding-left:10%;">
                  <img src="../../../assets/icon/optionIcon.png" style="width:3%;" alt="">
                </div>
              </el-popover>
              <el-popover placement="left" width="35" trigger="click" v-if="scope.row.xm_status_option_k=='5'">
                <el-button type="text" @click="detailShow(scope.row)">详情</el-button>
                <div slot="reference" class="optionMore" style="padding-left:10%;">
                  <img src="../../../assets/icon/optionIcon.png" style="width:3%;" alt="">
                </div>
              </el-popover>

            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>

      <el-tab-pane label="我审核的" name="second">
        <el-table :data="auditTable" tooltip-effect="dark" style="width: 100%">
          <el-table-column type="selection" align="center" width="55"></el-table-column>
          <el-table-column label="序号" align="center" type="index" width="50"></el-table-column>
          <el-table-column label="项目名称" show-overflow-tooltip prop="xm_name" width="auto"></el-table-column>
          <el-table-column label="项目类别"  prop="xm_type" ></el-table-column>
          <el-table-column label="项目理由" show-overflow-tooltip prop="xm_reason" ></el-table-column>
          <el-table-column label="申请科室" show-overflow-tooltip prop="department_name"></el-table-column>
          <el-table-column label="项目预算（元）" prop="xm_price" ></el-table-column>
          <el-table-column label="申报时间" prop="xm_sbsj" show-overflow-tooltip></el-table-column>
          <el-table-column label="项目方式" prop="lb_name"></el-table-column>
          <el-table-column label="状态">
            <template slot-scope="scope">
              <div :class="scope.row.xm_status_option_k=='4' ? 'red' : (scope.row.xm_status_option_k=='3' ? 'blue' : ' ') ">
                {{scope.row.xm_status}}
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="150">
            <template slot-scope="scope">

              <el-popover placement="left" width="70" trigger="click">
                <el-button type="text" @click="detailShow(scope.row)">详情</el-button>
                <el-button type="text" v-show="scope.row.is_check=='0'"  @click="myCheckSwitch(scope.row)">审核</el-button>
                <div slot="reference" class="optionMore" style="padding-left:10%;">
                  <img src="../../../assets/icon/optionIcon.png" style="width:3%;" alt="">
                </div>
              </el-popover>

            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>

      <el-tab-pane label="审核过的项目" name="third" v-if="isMaster">
        <el-table :data="checkedTable" tooltip-effect="dark" style="width: 100%">
          <el-table-column type="selection" align="center" width="55"></el-table-column>
          <el-table-column label="序号" align="center" type="index" width="50"></el-table-column>
          <el-table-column label="项目名称" show-overflow-tooltip prop="xm_name" width="auto"></el-table-column>
          <el-table-column label="项目类别"  prop="xm_type" ></el-table-column>
          <el-table-column label="项目理由" show-overflow-tooltip prop="xm_reason" ></el-table-column>
          <el-table-column label="申请科室" show-overflow-tooltip prop="department_name" ></el-table-column>
          <el-table-column label="项目预算（元）" prop="xm_price" ></el-table-column>
          <el-table-column label="申报时间" prop="xm_sbsj" show-overflow-tooltip></el-table-column>
          <el-table-column label="项目方式" prop="lb_name"></el-table-column>
          <el-table-column label="状态">
            <template slot-scope="scope">
              <div :class="scope.row.xm_status_option_k=='4' ? 'red' : (scope.row.xm_status_option_k=='3' ? 'blue' : ' ') ">
                {{scope.row.xm_status}}
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="150">
            <template slot-scope="scope">
              <el-popover placement="left" width="230" trigger="click">
                <el-button type="text" @click="detailShow(scope.row)">详情</el-button>
                <el-button type="text" @click="printForm(scope.row)">打印表单</el-button>
                <el-button type="text" @click="getApplyData(scope.row)">获批</el-button>
                <el-button type="text" @click="waitCheck(scope.row)">待审</el-button>
                <div slot="reference" class="optionMore" style="padding-left:10%;">
                  <img src="../../../assets/icon/optionIcon.png" style="width:3%;" alt="">
                </div>
              </el-popover>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>

    </el-tabs>
    <footer class="flex-item-none" style="display: flex; justify-content: flex-end; margin-top: 30px">
      <el-pagination background layout="total,prev, pager, next" :page-size="limit" :total="total"
        :current-page.sync="cur_page" @current-change="handleCurrentChange"></el-pagination>
    </footer>

    <!-- dialog_项目申请新增 -->
    <el-dialog :title="title" :visible.sync="dialogFormVisible" v-if="dialogFormVisible" width="50%;" v-loading.fullscreen="addloading">

      <el-form :model="dialogForm" ref="addForm"  :rules="add_rules" label-width="90px" label-position="left">
        <el-form-item label="项目名称" prop="xmmc">
          <el-input v-model="dialogForm.xmmc" placeholder="请输入项目名称"></el-input>
        </el-form-item>
        <el-form-item label="项目类别" prop="xmlbObj">
          <el-select style="width: 100%" v-model="dialogForm.xmlbObj" placeholder="请选择类型" @change="switchData" filterable >
            <el-option v-for="item in xmlbLIST" :key="item.value+Math.random()" :label="item.label" :value="item">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="项目理由" prop="xmly">
          <el-input v-model="dialogForm.xmly" placeholder="请输入项目理由"></el-input>
        </el-form-item>
        <el-form-item label="申请科室" prop="sqksObj">
          <el-select style="width: 100%" v-model="dialogForm.sqksObj" placeholder="请选择申请科室" filterable  @change="KsLinkLc">
            <el-option v-for="item in orgLIST " :key="item.value+Math.random()" :label="item.label"
              :value="item">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="关联流程" prop="gllcObj">
          <el-select style="width: 100%" v-model="dialogForm.gllcObj" placeholder="请选择关联流程" filterable >
            <el-option v-for="item in lcglLIST " :key="item.value+Math.random()" :label="item.label" :value="item">
            </el-option>
          </el-select>
        </el-form-item>
         <el-form-item label="项目预算" prop="xmys">
          <el-input v-model="dialogForm.xmys" placeholder="请输入项目预算（数字）" oninput="value=value.replace(/^\.+|[^\d.]/g,'')">
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
        <el-form-item label="申报时间" prop="sbsj">
          <el-date-picker v-model="dialogForm.sbsj" type="datetime"  value-format="yyyy-MM-dd HH:mm:ss"  placeholder="选择申报时间" ></el-date-picker>
        </el-form-item>
        <el-form-item label="项目内容" prop="xmnr" >
          <Tinymce  v-model="dialogForm.xmnr" :height="300" placeholder="请输入项目内容" ></Tinymce>
        </el-form-item>
        <el-form-item label="项目方式" prop="xmfs">
          <el-input v-model="dialogForm.xmfs" placeholder="请输入项目方式" ></el-input>
        </el-form-item>
        <el-form-item label="项目附件" >
          <!--  :on-change="handleChange"-->
          <el-upload
            v-model="dialogForm.xmfj"
            class="upload-demo"
            action="#"
            :http-request="appendixHttpRequest"
            :on-remove="handleRemoveAppendix"
            multiple
            :limit="5"
            :file-list="appendixList"
            accept="image/png,image/jpg,image/jpeg,.doc,.docx,.wps,.wpt,.xls,.xlsx,.ppt,.pptx,.pdf,.txt"
            >
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">支持文件类型:.jpg(.jpeg)、.png、.doc(.docx)、.ppt(.pptx)、.xls(.xlsx)、.pps、.wps、.pdf、.txt文件格式，最大支持5个文件</div>
          </el-upload>

        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="addFormSubmit('addForm')">确 定</el-button>
      </div>
    </el-dialog>

    <!-- dialog 审核进度-详情 -->
    <el-dialog title="审核进度" :visible.sync="dialogTableVisible_checkProcess">
      <el-table :data="gridData">
        <el-table-column label="序号" align="center" type="index" width="50"></el-table-column>
        <el-table-column property="sh_dept_name" label="审核部门" show-overflow-tooltip width="150"></el-table-column>
        <el-table-column property="sh_user_name" label="审核人" show-overflow-tooltip width="200"></el-table-column>
        <el-table-column property="modify_dateline" label="审核时间" show-overflow-tooltip></el-table-column>
        <el-table-column  label="操作" show-overflow-tooltip>
          <template  slot-scope="scope">
            <div>
              {{scope.row.sh_status=="2" ? '通过' : '待审核'}}
            </div>
          </template>
        </el-table-column>
        <el-table-column property="sh_reason" label="处理意见"  >
          <template  slot-scope="scope">
            <div>
              {{scope.row.sh_reason!="" ? scope.row.sh_reason : '暂无'}}
            </div>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <!-- dialog 审核 -->
    <el-dialog title="审核" :visible.sync="dialogFormVisible_check" width="600px">
      <el-form :model="dialogForm_check" ref="addForm_check" :rules="rules_check" label-width="90px" label-position="left">
        <el-form-item label="审核结果" prop="shjg">
          <el-radio-group v-model="dialogForm_check.shjg">
            <el-radio :label="2">通过</el-radio>
            <el-radio :label="3">不通过</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="处理意见" prop="clyj">
          <el-input type="textarea" v-model="dialogForm_check.clyj"></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer">
        <el-button @click="dialogFormVisible_check = false">取 消</el-button>
        <el-button type="primary" @click="addFormSubmitCheck('addForm_check')">确 定</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import { xmsq_list, xmsq_add, xmsq_edit, xmsq_del, xmsq_detail,xmlb_list,lcgl_list,xmsh_check,bbys,org_list,org_users } from "./itemApi";
import { useUserStore } from "@/stores/user";
const { real_name, user_id, dept_ids } = useUserStore();
import Tinymce from "@/components/TinymceVue/index.vue";
import FileUpload from "@/components/FileUpload/index.vue";
export default {
  name: "xmsq",
  components: {
    Tinymce,
    FileUpload
  },
  data() {
    return {
      state_value: "",
      keyword: "",
      activeName: "first",
      /**
       * 1:未提交;2:已退回;3:审核中;4:审核通过;
      */
      type_list: [
        {
          label: '全部',
          value:'0'
        },
        {
          label: '待提交',
          value:'1'
        },
        {
          label: '已提交',
          value:'2'
        },
        {
          label: '审核中',
          value:'3'
        },
        {
          label: '不通过',
          value:'4'
        },
        {
          label: '通过',
          value:'5'
        }
      ],
      applyTable: [],
      auditTable: [], //审核列表
      checkedTable: [],
      limit: 10,
      total: 0,
      cur_page: 1,
       extraParameters:{
        api:'json',
        urltype:2,
      },
      updateUrl:window.globalVariables.api+'upload/main/file',
      appendixList: [],
      dialogFormVisible: false,
      xmlbLIST: [],
      orgLIST:[],
      lcglLIST:[],
      dialogForm: {
        xmmc:'',
        xmlbObj:'',
        xmly: '',
        sqksObj:'',
        gllcObj:'',
        xmys: '',
        sbsj: '',
        xmnr: '',
        xmfs: '',
        xmfj: '',
      },
      add_rules: {
        xmmc: [
          { required: true, message: '请输入项目名称', trigger: 'blur'}
        ],
        xmlbObj: [
          { required: true, message: '请选择项目类别', trigger: 'change'}
        ],
        xmly: [
          { required: true, message: '请输入项目理由', trigger: 'blur'}
        ],
        sqksObj: [
          { required: true, message: '请选择申请科室', trigger: 'change'}
        ],
        gllcObj: [
          {required: true, message: '请选择关联流程', trigger: 'change'}
        ],
        xmys: [
          { required: true, message: '请输入项目预算', trigger: 'blur'}
        ],
        sbsj: [
          { required: true, message: '请选择申报时间', trigger: 'change'}
        ],
        xmnr: [
          { required: true, message: '请输入项目内容', trigger: 'blur'}
        ],
        xmfs: [
          { required: true, message: '请输入项目方式', trigger: 'blur'}
        ],
      },
      title: "",
      money: 0,
      totalMoney: 0,
      multipleSelection: [],
      isEdit: false,
      id: "",
      loading: false,
      addloading:false,
      userList: [],
      dialogTableVisible_checkProcess: false,
      gridData: [],
      dialogFormVisible_check: false,
      dialogForm_check: {
        shjg:'',
        clyj: '',
      },
      rules_check: {
        shjg: [
          { required: true, message: '请选择审核结果', trigger: 'change'}
        ],
        clyj: [
          { required: true, message: '请输入处理意见', trigger: 'blur'}
        ]
      },
      xmlbId:'',
      xmID :'',
      timestamp: Date.now(),
      isMaster:false,
    };
  },
  mounted() {
    //初始化进入判断 有些tab项是否要显示
    let local = JSON.parse(window.localStorage.getItem('userInfo'));
    let deptId = local.dept_id;
    let flagBlo = local.dept_master.includes(deptId);
    if(local.dept_master.length>0 || local.user_group_id==100){//是主任 或者 user_group_id=100为项目负责人
      this.isMaster=true;
    }else{
      this.isMaster=false;
    }
    this.getUserList();
    this.getListData();
  },
  methods: {
    //获取用户列表
    getUserList() {
      let data = {
        dept_id: dept_ids[0],
        page: 1,
        limit: 9999
      }
      org_users(data).then(res => {
        if (res.code == 1) {
          this.userList = res.data.page_data;
        }
      })
    },
     //组织机构列表
    orgList() {
      let transObjs = {
        limit:999
      }
      org_list(transObjs)
        .then(res => {
          if (res.code == "1") {
            let singleData = res.data.page_data;
            singleData.forEach(item => {
              this.orgLIST.push({
                label: item.uo_name,
                value: item.uo_id
              })
            })
          }
        })
        .catch(err => { console.log(err) });
    },
    getListData() {
      this.loading = true;
      let transObj = {
        page: this.cur_page,
        limit: this.limit,
        keyword: this.keyword,
        xm_status:this.state_value,
        my_xm:1,//我的申请
      };
      xmsq_list(transObj).then((res) => {
        this.loading = false;
        if (res.code == "1") {
          this.applyTable = res.data.page_data;
          this.cur_page = Number(res.data.page_now);
          this.total = Number(res.data.total_rows);
        }
      });
    },
    //我审核的初始化
    initMyApply() {
      this.loading = true;
        let transObj = {
          page: this.cur_page,
          limit: this.limit,
          keyword: this.keyword,
          xm_status: this.state_value,
          my_check:1,
        };
        xmsq_list(transObj).then((res) => {
          this.loading = false;
          if (res.code == "1") {
            this.auditTable = res.data.page_data;
            this.cur_page = Number(res.data.page_now);
            this.total = Number(res.data.total_rows);
          }
        });
    },
    //审核通过的初始化
    initChecked() {
      this.loading = true;
        let transObj = {
          page: this.cur_page,
          limit: this.limit,
          keyword: this.keyword,
          xm_status: 5,
        };
        xmsq_list(transObj).then((res) => {
          this.loading = false;
          if (res.code == "1") {
            this.checkedTable = res.data.page_data;
            this.cur_page = Number(res.data.page_now);
            this.total = Number(res.data.total_rows);
          }
        });
    },
    //pane 的切换
    paneTabSwitch(tab) {
      if(tab.name=="second"){
        this.initMyApply();
      } else if (tab.name=="third") {
        this.initChecked();
      } else {
        this.getListData();
      }
    },
    //我申请的-详情
    detailShow(item) {
      console.log(item, "00000");
      let chooseID = item.xm_id;
      this.$router.push({ name: "xmlxsb_xmsq_xq", params: { id: chooseID } });
    },
    //多选
    handleSelectionChange(val) {
      this.multipleSelection = [];
      this.multipleSelection = val;
    },
    //导出
    exportAll() {
      let Token = JSON.parse(window.localStorage.getItem('userInfo')).token;
      let expId = [];
       this.multipleSelection.forEach(item => {
        expId.push(item.xm_id);
       })
        let transString = expId.join();
      let link =
        window.globalVariables.api +
        "/jdbg/xmlxsb_xmsq/index?api=xls&page=1&limit=10000&token=" +
        Token+'&ids='+transString;
      window.open(link, "_blank");

    },
    //项目申请-弹出
    addData() {
      this.xmlbList();
      this.orgList();
      this.title = "新建项目申请";
      this.dialogForm = {
        xmmc: '',
        xmlbObj:'',
        xmly: '',
        sqksObj:'',
        gllcObj:'',
        xmys: '',
        sbsj: '',
        xmnr: '',
        xmfs: '',
        xmfj: '',
      };
      this.isEdit = false;
      this.dialogFormVisible = true;
    },
    //我申请的-编辑
    editShow(item) {
      this.xmlbList();
      this.orgList();
      this.title = "编辑三重一大申报";
      this.isEdit = true;
      //请求数据回填
      this.chooseID = item.xm_id;
      let transObj = {
        xm_id:item.xm_id
      }
      xmsq_detail(transObj)
      .then(res=>{
        if(res.code=="1"){
          let singleData = res.data.one_info;
          this.KsLinkLc({ label: singleData.lc_name, value: singleData.lc_id });
          //判断是几个附件
          let ifOneB = res.data.one_info.xm_file.indexOf(",");
          if (ifOneB != '-1') {//能找到，不止一个附件
            let muilArr = res.data.one_info.xm_file.split(',');
            let flileArr=[]
            muilArr.forEach(item => {
              let secSpil = item.split('|');
              flileArr.push({
                url:secSpil[0],
                name: secSpil[1]
              })
            })
            this.appendixList = flileArr;
          } else {
            let singleArr = res.data.one_info.xm_file.split('|');
            this.appendixList = [{
              url:singleArr[0],
              name: singleArr[1]
            }];
          }
          this.dialogForm = {
            xmmc:singleData.xm_name,
            xmlbObj:{label:singleData.lb_name,value:singleData.lb_id},
            xmly: singleData.xm_reason,
            sqksObj:{label:singleData.department_name,value:singleData.department_id},
            gllcObj:{label:singleData.lc_name,value:singleData.lc_id},
            xmys: singleData.xm_price,
            sbsj: singleData.xm_sbsj,
            xmnr: singleData.xm_content,
            xmfs: singleData.xm_type,
            xmfj: singleData.xm_file,
          };

          this.dialogFormVisible = true;

        }
      })
      .catch(err=>{console.log(err)})

    },
    //三重一大申报
    addFormSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.addloading = true;
          //编辑附件格式
          if (this.appendixList.length < 2 && this.appendixList.length>0) {
            let updataString="";
            this.appendixList.forEach(item=>{
              updataString=item.url+'|'+item.name
            })
            this.dialogForm.xmfj = updataString;
          } else {
            let updataString="";
            this.appendixList.forEach(item=>{
              updataString+=item.url+'|'+item.name+','
            })
            //去除最后一个逗号
             let cutLast = updataString.substring(0, updataString.lastIndexOf(','));
            this.dialogForm.xmfj = cutLast;
          }
          let transObj = {
            issubmit:1,
            jdbg_xmlxsb_xmsq: {
              xm_name: this.dialogForm.xmmc,
              lb_name:this.dialogForm.xmlbObj.label,//类别名称
              lb_id:this.dialogForm.xmlbObj.value,//类别id
              xm_reason:this.dialogForm.xmly,//理由
              department_name:this.dialogForm.sqksObj.label,//部门名称
              department_id:this.dialogForm.sqksObj.value,//部门id
              xm_content:this.dialogForm.xmnr,//内容
              xm_file:this.dialogForm.xmfj,// 附件
              xm_type:this.dialogForm.xmfs,//项目方式
              xm_price:this.dialogForm.xmys,//预算
              xm_sbsj: this.dialogForm.sbsj,//申报时间
              lc_id:this.dialogForm.gllcObj.value,//流程ID
            }
          }
          if (!this.isEdit) {
            xmsq_add(transObj).then(res => {
              this.addloading = false;
              if (res.code == 1) {
                this.$message({
                  message: res.msg,
                  type: "success",
                });
                this.dialogFormVisible = false;
                this.getListData();
              } else {
                this.$message({
                  message: res.msg,
                  type: "error",
                });
              }
            })
          } else {//编辑
            transObj.xm_id = this.chooseID;
            xmsq_edit(transObj).then(res => {
              this.addloading = false;
              if (res.code == 1) {
                this.$message({
                  message: res.msg,
                  type: "success",
                });
                this.dialogFormVisible = false;
                this.getListData();
              } else {
                this.$message({
                  message: res.msg,
                  type: "error",
                });
              }
            })
          }

        }
      })
    },
     /**附件上传网络请求*/
     appendixHttpRequest(param){
      const { token } = useUserStore()
      let file=param.file;
      let formData = new FormData();
      formData.append('filedata', file)
      formData.append('api',this.extraParameters.api)
      formData.append('urltype',this.extraParameters.urltype)
      formData.append('token',token);
      //发起axios请求
      let that=this;
      that.$axios({
        method: 'post',
        url: this.updateUrl,
        headers:{'Content-Type': 'multipart/form-data'},
        data: formData
      })
      .then(res=>{
      var response=res.data;
      if(response.code=="1"){//单个上传后台返回的是相对地址
      let tempArr={
        name:response.data.file_name,
        url:response.data.url
      }
      //存入appendixList列表中
        this.appendixList.push(tempArr);
        this.dialogForm.xmfj = this.appendixList;
        this.$message({
        message: response.msg,
        type: 'success'
        })
      }
      })
      .catch(error=>{
      console.log(error)
      })

    },
    /**附件删除*/
    handleRemoveAppendix(file, fileList) {
      var fileName=file.name;
      this.appendixList = this.appendixList.filter(item => item.name !== fileName);

    },
     /**文件上传 暂时未启用*/
    handleChange(file, fileList) {
      //限制文件大小
      if(file.size/1024/1024>5){
      this.$message({
        message: '文件大小不能超过5M',
        type: 'error'
      })
      return false;
      }
      // 开始上传
      const { token } = useUserStore();
      let formData=new FormData();
      formData.append('api','json');
      formData.append('token',token);
      formData.append('filedata',file.raw);

      let that=this;
      that.$axios({
      method: 'post',
      url: this.updateUrl,
      headers:{'Content-Type': 'multipart/form-data'},
      data: formData
      })
      .then(res=>{
      var response=res.data;
      if(response.code=="1"){//单个上传后台返回的是相对地址
      let tempArr={
        name:response.data.file_name,
        url:response.data.url
      }

        //存入appendixList列表中
        this.appendixList.push(tempArr);
        this.$message({
        message: response.msg,
        type: 'success'
        })
      }

      }).catch(error=>{
      console.log(error);
      })
    },

    //我申请的-提交审核
    applyCheck(item) {
      let transObj = {
        issubmit: 1,
        xm_id: item.xm_id,
        jdbg_xmlxsb_xmsq: {
          xm_status:2
        }
      }
      xmsq_edit(transObj)
      .then(res=>{
        if (res.code == "1") {
          this.$message({
            message: res.msg,
            type: "success",
          });
          this.getListData();
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
        }
      })
      .catch(err=>{console.log(err)})
    },
    //审核进度
    checkProcess(item) {
      let transObj = {
        xm_id:item.xm_id
      }
      xmsq_detail(transObj)
      .then(res=>{
        if(res.code=="1"){
          console.log(res,"alvis")
          this.gridData=res.data.one_info.shjl;
        }
      })
      .catch(err=>{console.log(err)})

      this.dialogTableVisible_checkProcess = true;

    },
    //我申请的-删除
    delData(item) {
      let transObj = {
        xm_id: item.xm_id
      };
      this.$confirm("确认删除该申请?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          xmsq_del(transObj).then((res) => {
            if (res.code == 1) {
              this.$message({
                message: "申请删除成功！",
                type: "success",
              });
              this.getListData();
            } else {
              this.$message({
                message: res.msg,
                type: "error",
              });
            }
          });
        })
        .catch(() => { });
    },
    //批量删除
    batchDel() {
      let delId = [];
       this.multipleSelection.forEach(item => {
         delId.push(item.xm_id);
      })
      let transObj = {
        xm_id:delId
      }
      this.$confirm("确认删除选中项目?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          xmsq_del(transObj).then((res) => {
            if (res.code == 1) {
              this.$message({
                message: res.msg,
                type: "success",
              });
              this.getListData();
            } else {
              this.$message({
                message: res.msg,
                type: "error",
              });
            }
          });
        })
        .catch(() => { });
    },
    //打印表单
    printForm(item) {
      let chooseID = item.xm_id;
      this.$router.push({ name: "xmlxsb_xmsq_dybb", params: { id: chooseID } });
    },
    //获批
    getApplyData(item) {
      //编辑接口中的获批阶段
      let transObj = {
        issubmit:1,
        xm_id:item.xm_id,
        jdbg_xmlxsb_xmsq: {
          xm_is_wc:1//是否获批 1是 2否 3待审
        }
      }
      this.$confirm("确认获批该项目?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          xmsq_edit(transObj).then((res) => {
            if (res.code == 1) {
              this.$message({
                message: res.msg,
                type: "success",
              });
              this.initChecked();
            } else {
              this.$message({
                message: res.msg,
                type: "error",
              });
            }
          });
        })
        .catch((err) => {console.log(err)});
    },
    //待审
    waitCheck(item) {
      let transObj = {
        issubmit:1,
        xm_id:item.xm_id,
        jdbg_xmlxsb_xmsq: {
          xm_is_wc:3//待审
        }
      }
      xmsq_edit(transObj).then((res) => {
        if (res.code == 1) {
          this.$message({
            message: res.msg,
            type: "success",
          });
          this.initChecked();
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
        }
      });
    },
    //弹出审核dialog
    myCheckSwitch(item) {
      this.xmID = item.xm_id;
      this.dialogFormVisible_check = true;
    },
    //项目类别
    switchData(val) {
      this.xmlbId = val;
      this.dialogForm.xmlb_id = this.xmlbId;
    },
    //科室选择筛选出流程
    KsLinkLc(val) {
      let transObjs = {
        lc_yydx: val.value,
        lc_status: 1,
        public:1
      }
      lcgl_list(transObjs)
      .then(res=>{
        let singleData = res.data.page_data;
        this.lcglLIST=[];
        singleData.forEach(item => {
          this.lcglLIST.push({
            label: item.lc_name,
            value: item.lc_id
          })
        })
      })
        .catch(err => { console.log(err) })

    },
    //审核提交
    addFormSubmitCheck(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let transObj={
            sh_id:this.xmID,//项目ID
            sh_status: this.dialogForm_check.shjg,
            sh_reason:this.dialogForm_check.clyj,
          }
          xmsh_check(transObj)
          .then(res => {
            if (res.code == "1") {
              this.$message({
                message: res.msg,
                type: 'success'
              });
              this.initMyApply();
              this.dialogFormVisible_check = false;
            } else {
              this.$message({
                message: res.msg,
                type: 'error'
              });
            }
          })
          .catch(err=>{
            console.log(err)
          })
        }
      })
    },

    //翻页
    handleCurrentChange(val) {
      this.cur_page = val;
      this.getListData();
    },
    //项目类别列表数据
    xmlbList() {
      let transObj = {
        lb_status:1
      }
      xmlb_list(transObj)
        .then(res => {
        if(res.code=="1"){
          this.xmlbLIST = [];
          res.data.page_data.forEach(item => {
            this.xmlbLIST.push({
              label: item.lb_name,
              value: item.lb_id,
            })
          })
        }
      })
      .catch(err=>{
        console.log(error)
      })
    },
  },

};
</script>

<style scoped>
.red{
  color:red;
}
.blue{
  color:#4351FF;
}
</style>
