<template>
  <div class="container">
    <div style="padding: 0px 20px">
      <div ref="lxHeader">
        <LxHeader icon="md-apps" text="转办记录" style="margin-bottom: 10px; border: 0px; margin-top: 15px">
          <div slot="content"></div>
          <slot>
            <div>
              <Input class="vm10" style="width: 200px; margin-right: 10px" v-model="searchFields.keyword" placeholder="关键字搜索" />
              <el-select class="vm10" filterable v-model="searchFields.area_id" placeholder="请选择所属片区">
                <el-option v-for="item in selects.areaList" :key="item.id" :label="item.name" :value="item.id">
                </el-option>
              </el-select>
              <el-select class="vm10" filterable v-model="searchFields.name" placeholder="请选择转办来源">
                <el-option v-for="item in selects.nameList" :key="item.id" :label="item.value" :value="item.value">
                </el-option>
              </el-select>
              <el-select class="vm10" filterable v-model="searchFields.has_user_id" placeholder="请选择派单状态">
                <el-option v-for="item in selects.sendList" :key="item.id" :label="item.value" :value="item.id">
                </el-option>
              </el-select>
              <el-date-picker class="vm10" v-model="acceptTime" type="daterange" range-separator="至"
                start-placeholder="开始创建日期" end-placeholder="结束创建日期" value-format="yyyy-MM-dd">
              </el-date-picker>
              <el-date-picker class="vm10" v-model="endTime" type="daterange" range-separator="至"
                start-placeholder="开始完成日期" end-placeholder="结束完成日期" value-format="yyyy-MM-dd">
              </el-date-picker>
              <Button type="primary" @click="load" style="margin-left: 10px">查询</Button>
              <!-- <Button type="primary" @click="edit()" style="margin-left: 10px">新增</Button> -->
            </div>
          </slot>
        </LxHeader>
      </div>
      <div ref="lxTable">
        <el-table :data="tableData" class="v-table" :height="tableHeight" style="width: 100%">
          <el-table-column type="index" width="50" label="序号" fixed="left" align="center"> </el-table-column>
          <el-table-column :prop="column.field" :align="column.align" v-for="(column,index) in columns"
            :label="column.title" :width="column.width" :fixed="column.fixed">
              <template slot-scope="scope">
                <div v-if="column.type=='opt'">
                  <Button v-if="scope.row['accept_status']==4" ghost size="small" @click="edit(scope.row,'pd')" type="primary"
                    style="margin-left: 10px;">审核</Button>
                   <!-- <Button v-if="scope.row['accept_status']==0&&scope.row['user_id']!=0" ghost size="small" @click="edit(scope.row,'pd')" type="primary"
                      style="margin-left: 10px;">改派单</Button> -->
                  <Button ghost size="small" @click="info(scope.row,'ck')" type="primary"
                    style="margin-left: 10px;">查看</Button>
                  <!-- <Button ghost size="small" @click="del(scope.row)" type="error" style="margin-left: 10px;">删除</Button> -->
                </div>
                <div v-else-if="column.type=='accept_status'">
                  <el-tag v-if="scope.row['accept_status']==0&&scope.row['user_id']==0||scope.row['user_id']==null" type="info">待派单</el-tag>
                  <el-tag v-if="scope.row['accept_status']==0&&scope.row['user_id']>0">已派单</el-tag>
                  <el-tag v-if="scope.row['accept_status']==1" type="warning">已签收</el-tag>
                  <el-tag v-if="scope.row['accept_status']==2" type="success">已完成</el-tag>
                   <el-tag v-if="scope.row['accept_status']==4" type="info">待审核</el-tag>
                    <el-tag v-if="scope.row['accept_status']==5" type="warning">审核不通过</el-tag>
                </div>
                <div v-else>{{scope.row[column.field]}}</div>
              </template>
          </el-table-column>
        </el-table>
        <div class="pagination">
          <el-pagination @current-change="handleCurrentChange" :current-page="paginations.page"
            :page-size="paginations.page_size" background layout="prev, pager, next" :total="paginations.total">
          </el-pagination>
        </div>
      </div>

      <el-dialog class="common-dialog" title="转办记录" :visible.sync="dialogFormVisible" width="40%">
        <div class="dialogConcent">
          <el-scrollbar style="flex: 1">
            <el-form :model="form" :rules="rules" ref="form" label-position="right" :label-width="formLabelWidth">
              <el-row>
                <el-col :span="24">
                  <el-form-item label="处理人" prop="user_id">
                    <el-select filterable style="width:100%" v-model="form.user_id" placeholder="请选择或输入查找处理人">
                        <el-option
                          v-for="item in personList"
                          :key="item.id"
                          :label="item.name"
                          :value="item.id">
                        </el-option>
                      </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="转办类型" prop="type">
                    <el-radio-group v-model="form.type">
                      <el-radio :label="1">转巡查</el-radio>
                      <el-radio :label="2">转养护</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
                </el-row>
            </el-form>
          </el-scrollbar>
        </div>

        <div slot="footer" class="dialog-footer">
          <el-button @click="resetForm('form')">取 消</el-button>
          <el-button type="primary" v-preventReClick @click="submitForm('form')">确认</el-button>
        </div>
      </el-dialog>



      <!-- 工单详情 -->


      <el-dialog class="common-dialog" :visible.sync="dialogVisible">
        <img width="100%" :src="dialogImageUrl" alt="">
      </el-dialog>

      <maintainInfo @update="updeatshow" ref="maintain" :dialogFormDetailVisible='showinfo'></maintainInfo>







    </div>
  </div>
</template>

<script>

  import {
    listsend,
    getsend,
    storesend,
    savesend,
    delsend
  } from '../../../api/rain/order.js'
  import {
    listarea
  } from '../../../api/basic/area.js'
  import {listCommonuser} from"../../../api/common.js"
  import {listaccount} from "../../../api/basic/account.js"
  import LxHeader from "@/components/LxHeader/index.vue";
  import maintainInfo from '@/views/rain/order/components/maintainInfo'
  export default {
    components: {
      LxHeader,
      maintainInfo
    },
    data() {
      return {
        showinfo:false,
        maintainid:0,
        tableHeight: 0,
        dialogOrderFormVisible:false,
        dialogxcFormDetailVisible:false,
        dialogFormVisible: false,
        formLabelWidth: "120px",
        dialogImageUrl: "",
        dialogVisible: false,
        tableData: [],
        personList:[],
        rainEquipmentEndFiles:[],
        rainEquipmentFiles:[],
        worksheetFiles:[],
        tableHeight: 0,
        searchFields: {
          has_user_id:4
        },
        paginations: {
          page: 1,
          page_size: 15,
          total: 0
        },
        form: {
          user_id:"",
          type:"1"
        },

        rules: {

        },
        tableList:{
          rain_inspection_info:{},
          worksheet_info:{}
        },
        rainEquipmentInfo:{},
        acceptTime:"",
        endTime:"",
        selects:{
          nameList:[{
            id:"",
            value:"所有"
          },{
            id:1,
            value:"工单派单"
          },{
            id:2,
            value:"巡查派单"
          },{
            id:3,
            value:"养护派单"
          }],
          areaList:[{
            id:"",
            name:"所有"
          }],
          sendList:[{
            id:"",
            value:"所有"
          },{
            id:0,
            value:"待派单"
          },{
            id:1,
            value:"已派单"
          },{
            id:2,
            value:"已签收"
          },{
            id:3,
            value:"已完成"
          },{
            id:4,
            value:"待审核"
          },{
            id:5,
            value:"审核不通过"
          }]
        },
        columns: [
          {
            field: "name",
            title: "转办来源",
            type: "string",
            align: "left",
            width:180
          },
          // {
          //   field: "fromName",
          //   title: "来源",
          //   type: "string",
          //   align: "left",
          //   width:180
          // },
          // {
          //   field: "accept_date",
          //   title: "接收时间",
          //   type: "string",
          //   align: "center",
          //   width:180
          // },
          {
            field: "areaName",
            title: "所属片区",
            type: "string",
            align: "center",
            width:180
          },
          {
            field: "content",
            title: "工作内容",
            type: "string",
            align: "left",
            width:240
          },
          {
            field: "address",
            title: "位置地址",
            type: "string",
            align: "left",
            width:240
          },
          // {
          //   field: "dealName",
          //   title: "处理时限",
          //   type: "string",
          //   align: "center",
          //   width:180
          // },
          {
            field: "end_time",
            title: "要求完成时间",
            type: "string",
            align: "center",
            width:180
          },
          {
            field: "accept_status",
            title: "状态",
            type: "accept_status",
            align: "center",
            width:180
          },
          {
            field: "adminName",
            title: "提交人",
            type: "string",
            align: "center",
            width:180
          },
          {
            field: "created_at",
            title: "提交日期",
            type: "string",
            align: "center",
            width:180
          },
          {
            field: "操作",
            title: "操作",
            width: 220,
            type: "opt",
            fixed:"right"
          }
        ],
      }
    },
    created() {
      this.initLoad();
      this.load();

    },
    watch:{
      acceptTime(newVal, oldVal) {
        if (newVal) {
          this.searchFields.start_accept_date = newVal[0]
          this.searchFields.end_accept_date = newVal[1]
        } else {
          this.searchFields.start_accept_date = ""
          this.searchFields.end_accept_date = ""
        }

      },
      endTime(newVal, oldVal) {
        if (newVal) {
          this.searchFields.start_end_time = newVal[0]
          this.searchFields.end_end_time = newVal[1]
        } else {
          this.searchFields.start_end_time = ""
          this.searchFields.end_end_time = ""
        }

      },
    },
    methods: {
      handlePictureCardPreview(file) {
        this.dialogImageUrl = file.url;
        this.dialogVisible = true;
      },
updeatshow(e){
  this.showinfo = e
},
      initLoad() {
        var that = this;
        var clientHeight = document.documentElement.clientHeight
        var lxHeader_height = 96.5; //查询 头部
        var paginationHeight = 37; //分页的高度
        var topHeight = 50; //页面 头部
        let tableHeight = clientHeight - lxHeader_height - topHeight - paginationHeight - 20;
        that.tableHeight = tableHeight;
        listaccount({
          page: 1,
          page_size: 999
        }).then(response => {
          var that = this
          that.personList = response.data
        }).catch(error => {
          console.log(error)
          reject(error)
        });

        listarea({
          page: 1,
          page_size: 999,
        }).then(response => {
          for(var m of response.data){
            that.selects.areaList.push({
              id:m.id,
              name:m.name
            })
          }
        }).catch(error => {
          console.log(error)
          reject(error)
        });
      },
      handleCurrentChange(page) {
        this.paginations.page = page;
        this.load();
      },
      load() {
        listsend({
          page: this.paginations.page,
          page_size: this.paginations.page_size,
          ...this.searchFields
        }).then(response => {
          var that = this
          for(var m of response.data){
            for(var k in that.tableList){
              if(m[k]){
                 m.areaName = m[k].area ? m[k].area.name : (m[k].area_info?m[k].area_info.name:"")
                 m.adminName = m.admin?m.admin.name:""
                m.address = m[k].address
                m.end_time =m[k].end_time
                m.content = m[k].content
              }
            }
          }
          this.tableData = response.data;
          this.paginations.total = response.total;
        }).catch(error => {
          console.log(error)
          reject(error)
        });
      },
      showsfalse(val){
        console.log(val)
        this.showinfo = false
      },
      info(obj,what) {
        var that = this;
        this.showinfo = true
        this.$refs.maintain.info(obj.rain_maintain_id)
      },
     edit(obj) {
       this.form = this.$options.data().form
       var that = this;
       getsend(obj.id).then(res => {
         let result = Object.assign(that.form, res);
         // this.$set(that.form,res);
         that.form = result;
         // that.dialogFormVisible = true
         that.form.user_id = result.user_id==0 ? "":result.user_id
         that.form.type = result.type==0 ? 1:result.type
         that.form.accept_status = 0
         this.$Modal.confirm({
           title: '确认审核该条数据？',
           onOk: () => {
             savesend(that.form).then(response => {
               this.$Message.success('操作成功');
               that.load();
               that.dialogFormVisible = false;
             }).catch(error => {
               //reject(error)
             })
           },
           onCancel: () => {
             //this.$Message.info('Clicked cancel');
           }
         });

       }).catch(error => {
         //reject(error)
       })
       // this.dialogFormVisible = true;
     }

    }
  }
</script>

<style>
  .dialogConcent {
    overflow-y: auto;
  }
  .width100{
    width:100%;
  }
  .files_check .el-upload.el-upload--picture-card {
    display: none;
  }
  .vm10{
    margin-right:10px;
    margin-bottom:10px;
    height: 32px;
    vertical-align: bottom;
  }
  .vm10 input {
    height: 32px;
    vertical-align: middle;
  }

  .vm10 .el-select__caret.el-input__icon.el-icon-arrow-up {
    line-height: 30px;
  }
  .vm10 .el-input__icon.el-range__icon.el-icon-date,.vm10 .el-range-separator{
    line-height: 25px;
  }
  .selerchcontent button{
    vertical-align: top;
  }
</style>
