<!-- 每日退仓看板 -->
<template>
    <div class="container">
      <div class="tab-nav">
        <div class="date-filter-wrap">
          <span style="font-size: 14px;font-weight: bold;color: black">每日退仓看板</span>
          <RadioGroup v-model="params.status" style="margin-left:20px" @on-change="getList">
              <Radio label="0">
                 
                  <span>未复核</span>
              </Radio>
              <Radio label="1">
                 
                  <span>已复核</span>
              </Radio>
              <Radio label="2">
               
                  <span>待审批</span>
              </Radio>
          </RadioGroup>
          <select-input v-model="params.materialName" @onChange="getList" type="3"></select-input>
          <Select
            v-model="params.userName"
            style="width: 200px"
            @on-change="selectUserName"
            filterable
          >
            <div slot="empty">无匹配数据</div>
            <Option value="">全部</Option>
            <Option
              v-for="i in userList"
              :value="i.label"
              :key="i.id"
              >{{ i.label }}</Option
            >
          </Select>
          
        </div>
        <div class="date-filter-wrap">
          <date-select v-model="params" @change="selectTime"></date-select>
        </div>
      </div>
      <div class="border"></div>
      <div class="tab-nav">
        <Row>
          <i-col span="8" style="display: flex">
            <div style="min-width: 40px; line-height: 32px; text-align: center">直喷:</div>
            <div class="row">
              <Button
                :type="btnIndex === item.userId + '_' + item.technologyType ? 'primary' : 'default'"
                @click="userClick(item)"
                v-for="(item, index) in typeList['A007']"
                :key="index"
              >
                <span>{{ item.realName }}</span>
                
              </Button>
            </div>
          </i-col>
          <i-col span="8" style="display: flex">
            <div style="min-width: 40px; line-height: 32px; text-align: center">打纸:</div>
            <div class="row">
              <Button
                :type="btnIndex === item.userId + '_' + item.technologyType ? 'primary' : 'default'"
                @click="userClick(item)"
                v-for="(item, index) in typeList['A012']"
                :key="index"
              >
                <span>{{ item.realName }}</span>
                
              </Button>
            </div>
          </i-col>
          <i-col span="8" style="display: flex">
            <div style="min-width: 40px; line-height: 32px; text-align: center">热转:</div>
            <div class="row">
              <Button
                :type="btnIndex === item.userId + '_' + item.technologyType ? 'primary' : 'default'"
                @click="userClick(item)"
                v-for="(item, index) in typeList['A008']"
                :key="index"
              >
                <span>{{ item.realName }}</span>
                
              </Button>
            </div>
          </i-col>
        </Row>
      </div>
      <div class="border"></div>
      <div class="table-filter">
        <div class="fabricOne" :style="technologyType == 5 ? 'border:2px solid #0077ff' : ''" style="width: 100%">
          <div class="label" style="border-right: 2px solid #dcdcdc">
            <span>退仓概况</span>
          </div>
          <ul>
            <li>
              金额
              <span>{{ statisticsDetails.price * 1 }}</span>
            </li>
            <li>
              卷数
              <span>{{ statisticsDetails.count }}</span>
            </li>
            <li>
              米数
              <span>{{ statisticsDetails.meters }}</span>
            </li>
            <li>
              面积
              <span>{{ statisticsDetails.area }}</span>
            </li>
          </ul>
        </div>
        
      </div>
      <div class="main">
        <my-table ref="table" :data="data" :columns="columns" :table-page="params" @on-change="changePage"></my-table>
      </div>
      <Modal
        v-model="shenpiModal"
        title="审批"
        class="shenpi"
        width="900"
        >
        <h3>原数据</h3>
        <ul>
          <li>标签值:{{formData.rfid}}</li>
          <li>提交人员:{{formData.realName}}</li>
          <li>退仓时间:{{formData.time}}</li>
          <li>面料名称:{{formData.materialName}}</li>
          <li>退仓米数:{{formData.meters}}</li>
          <li>退仓面积:{{formData.area }}</li>
        </ul>
        <h3>新数据</h3>
        <ul>
          <li>标签值:{{shenpiData.rfid}}</li>
          <li>提交人员:{{formData.realName}}</li>
          <li>退仓时间:{{shenpiData.operationTime || formData.time}}</li>
          <li>面料名称:{{shenpiData.materialName}}</li>
          <li>退仓米数:{{!shenpiData.materialMeters || shenpiData.materialMeters === -1 ?  formData.meters :  shenpiData.materialMeters}}</li>
          <li>退仓面积:{{!shenpiData.materialMeters || shenpiData.materialMeters === -1 ?  formData.area : shenpiData.materialMeters * shenpiData.width / 100 }}</li>
        </ul>
        <div slot="footer">
            <Button type="error" size="large"   @click="handleFlow(0)">拒绝</Button>
            <Button type="primary" size="large"   @click="handleFlow(1)">同意</Button>
        </div>
      </Modal>
      <my-modal-form v-model="show" title="退料修改" :config="formConfig" :rule-validate="ruleValidate" :data="formData" type="edit" @confirm="cfm"></my-modal-form>
    </div>
  </template>
  
  <script>
  import  selectInput  from '@/components/form/select-input'
  import MyTable from '_c/my-table/my-table'
  import axios from 'axios'
  import dateSelect from '@/components/dateSelect/dateSelect'
  import MyModalForm from '_c/my-modal-form/my-modal-form'
  import {dateFormat} from '@/libs/util'
  export default {
    name: 'daily_report',
    components: { MyTable, dateSelect,MyModalForm,selectInput },
    data() {
      return {
        shenpiModal:false,
        formData:{},
        show:false,
        ruleValidate: {
          name: [
            { required: true, message: '仓库名称不能为空', trigger: 'blur' }
          ]
        },
        formConfig: [
        {
            type: 'date',
            label: '退料时间',
            key: 'time',
            placeholder: '请选择退料时间',
            comType:'datetime',
          },
          {
            type: 'input',
            label: '退料人员',
            key: 'realName',
            placeholder: '请选择退料人员',
            disabled:true,
          },
          {
            type: 'materialBtn',
            label: '物料名称',
            key: 'name',
            placeholder: '请输入物料名称',
            multiple: true,
          },
          {
            type: 'input',
            label: '已选物料',
            key: 'name',
            placeholder: '请选择物料',
            disabled:true,
          },
          {
            type: 'input',
            label: '米数',
            key: 'meters',
            placeholder: '请输入米数',
            comType: 'number',
          },
          
          
        ],
        technologyType: '',
        typeList: {},
        data: [],
        columns: [
          {
            title: '序号',
            type: 'index',
            width: 60,
            align: 'center'
          },
          {
            title: '标签值',
            key: 'rfid',
            minWidth: 100,
            align: 'center'
          },
          {
            title: '提交人员',
            key: 'realName',
            minWidth: 100,
            align: 'center'
          },
          {
            title: '退仓时间',
            key: 'time',
            minWidth: 400,
            align: 'center'
          },
          {
            title: '面料名称',
            key: 'materialName',
            minWidth: 100,
            align: 'center'
          },
          {
            title: '退仓米数',
            key: 'meters',
            minWidth: 100,
            align: 'center'
          },
          {
            title: '退仓面积',
            key: 'area',
            minWidth: 100,
            align: 'center'
          },
          {
            title: '操作',
            key: 'action',
            
            align: 'center',
            width: '200px',
            render: (h, params) => {
              return h('div', [
                h(
                  'Icon',
                  {
                    props: {
                      custom: 'iconfont icon-edit',
                      size: '20',
                      color: '#087BE1',
                    },
                    style: {
                      marginRight: '20px',
                      display:(params.row.status === 0 || params.row.flowStatus === 0) ? 'none' : ''
                    },
                    on: {
                      click: () => {
                        this.formDataId = params.row.id
                        params.row.name = params.row.materialName
                        for (const key in params.row) {
                          
                          this.formData[key] = params.row[key]
                        }
                        this.title = '修改'
                        this.formType = 'edit'
                        this.show = true
                      }
                    }
                  },
                  '修改'
                ),
                h(
                  'Icon', 
                  {
                    props: {
                      type: 'ios-paper',
                      size: '20',
                      color: '#087BE1',
                    },
                    style: {
                      marginRight: '20px',
                      display:(params.row.status === 0 || params.row.flowStatus != 0 ) ? 'none' : (this.roleKey != 'supervisor') ? 'none' : ''
                    },
                    on: {
                      click: () => {
                        for (const key in params.row) {
                          
                          this.formData[key] = params.row[key]
                        }
                        axios.post('/cloudApi/stockBack/getFlowData',{id:params.row.id}).then(res => {
                          
                          this.shenpiData = res.data.data
                          this.shenpiModal = true
                          
                        })
                        
                      }
                    }
                  },
                  '审批'
                ),
              ])
            }
          }
        ],
        btnIndex: '',
        shenpiData:{},
        formDataId:null,
        params: {
          pageNum: 1,
          pageSize: 10,
          type: '3',
          beginTime: null,
          endTime: null,
          total: 0,
          technologyType: '',
          jobNo: '',
          userId: '',
          status:1,
        },
        statisticsDetails: {
          scheduleArea: '',
          pickingMoney: '',
          pickingNum: '',
          pickingMeters: '',
          pickingArea: '',
          backMoney: '',
          backNum: '',
          backMeters: '',
          backArea: '',
          useRate: '',
          actualUse: ''
        },
        roleKey:window.localStorage.getItem('roleKey'),
        userList:[],
      }
    },
    mounted() {
      this.getAllList()
      this.getUUserList()
    },
    methods: {
      getUUserList() {
        const v = this
        v.loading = true
        axios
          .post('/cloudApi/uUser/list', {
            deptIdList: ['A012', 'A008', 'A007', 'A017', 'A005'],
          })
          .then((res) => {
            let list = res.data.data.map((item) => {
              return {
                label: item.realname,
                value: item.id,
                name: item.realname,
              }
            })
            this.userList = list
          })
      },
      handleFlow(_type){
        axios.post('/cloudApi/stockBack/handleFlow',{id:this.formData.id,flowResult:_type}).then(res => {
          this.show = false
          this.$Message.info('审核成功')
          this.shenpiModal = false
          this.getList()
        })
      },
      cfm (type, formData) {
        console.log(formData)
        if (type === 'add') {
          
          axios.post('/cloudApi/stockBack/edit',{...formData}).then(res => {
            this.show = false
            this.$Message.info('新增成功')
            this.getList()
          })
        } else if (type === 'edit') {
          
          formData.operationTime = formData.time.length ? formData.time : null
          formData.materialMeters = formData.meters
          formData.materialId = formData.code || formData.materialId
          console.log(formData.operationTime)
          
          axios.post('/cloudApi/stockBack/edit',{...formData,id:this.formDataId}).then(res => {
            this.show = false
            this.$Message.info('编辑成功')
            this.getList()
          }).catch(err=>{
            console.log(err.data)
            this.$Message.info(err.msg)
          })
        }
      },
      selectTime() {
        this.getAllList()
      },
      getAllList() {
        axios
          .post('/cloudApi/stockBack/getBackUser', {
            beginTime: this.params.beginTime,
            endTime: this.params.endTime
          })
          .then(res => {
            this.typeList = res.data.data
            this.getList()
          })
      },
      userClick(item) {
        this.params.userName = ''
        if (this.btnIndex === item.userId + '_' + item.technologyType) {
          this.params.userId = ''
          this.params.jobNo = ''
          this.params.technologyType = ''
          this.btnIndex = item.userId + '_' + ''
        } else {
          this.params.userId = item.userId
          this.params.jobNo = item.jobNo
          this.params.technologyType = item.technologyType
          this.btnIndex = item.userId + '_' + item.technologyType
        }
        this.getList()
      },
      changePage(pageNum) {
        this.params.pageNum = pageNum
        this.getList()
      },
      selectUserName(){
        this.params.userId = ""
        this.getList()
      },
      getList() {
        axios
          .post('/cloudApi/stockBack/getBackStatistics', {
            beginTime: this.params.beginTime,
            endTime: this.params.endTime,
            userId: this.params.userId,
            materialName:this.params.materialName,
            userName:this.params.userName,
          })
          .then(res => {
            this.statisticsDetails = res.data.data
          })
        axios
          .post('/cloudApi/stockBack/getBackPage', {
            pageNum: this.params.pageNum,
            pageSize: this.params.pageSize,
            beginTime: this.params.beginTime,
            endTime: this.params.endTime,
            userId: this.params.userId,
            status:this.params.status,
            materialName:this.params.materialName,
            userName:this.params.userName,
            
          })
          .then(res => {
            this.data = res.data.data.records
            this.params.total = res.data.data.total
          })
      }
    }
  }
  </script>
  
  <style lang="less" scoped>
  .shenpi{
    ul{
      li{
        list-style: none;
        width:48%;
        display: inline-block;
        font-size: 14px;
        line-height: 32px;
      }
    }
  }
  .container {
    height: 100%;
    display: flex;
    flex-direction: column;
    .tab-nav {
      display: flex;
      align-items: center;
      justify-content: space-between;
      .date-filter-wrap {
        display: flex;
        align-items: center;
        .date-filter {
          width: 300px;
          overflow: hidden;
          display: flex;
          justify-content: space-between;
          align-items: center;
          background-color: #ffffff;
          border-radius: 4px;
          &.other {
            width: 100%;
            height: 100%;
            .date-tab {
              display: flex;
              flex-direction: column;
              align-items: center;
              justify-content: center;
              padding: 9px;
              height: 100%;
              white-space: nowrap;
              cursor: auto;
              &.active {
                background-color: #333333;
                font-size: 14px;
                font-weight: bold;
              }
              .num {
                padding-top: 5px;
                font-weight: bold;
                font-size: 14px;
                &.red {
                  color: red;
                  cursor: pointer;
                  text-decoration: underline;
                }
              }
            }
          }
          .date-tab {
            flex: 1;
            padding: 9px 4px;
            line-height: 1;
            text-align: center;
            border: 1px solid #e6e6e6;
            border-radius: 2px;
            border-right: none;
            cursor: pointer;
            font-weight: 500;
            &:first-child {
              border-radius: 4px 0 0 4px;
            }
            &:last-child {
              border-radius: 0 4px 4px 0;
              border-right: 1px solid #e6e6e6;
            }
            &.active {
              background-color: #3f92f9;
              color: #ffffff;
            }
          }
        }
      }
      &.sub-nav {
        .other-tab {
          flex: 1;
          height: 100%;
          display: flex;
          flex-direction: column;
          padding: 5px 10px;
          text-align: center;
          border: 1px solid #e6e6e6;
          border-right: none;
          font-weight: bold;
          cursor: pointer;
          white-space: nowrap;
          &:first-child {
            border-radius: 2px 0 0 2px;
          }
          &:last-child {
            border-radius: 0 2px 2px 0;
            border-right: 1px solid #e6e6e6;
          }
          &.active {
            background-color: #ffffff !important;
            color: blue !important;
            border: 1px solid blue;
          }
        }
      }
      .all {
        margin-right: 20px;
      }
      .row {
        // white-space: nowrap;
        button {
          margin-right: 10px;
          min-width: 120px;
          margin-bottom: 10px;
          &:last-child {
            margin-right: 0;
          }
        }
      }
    }
    .border {
      margin: 10px 0;
      width: 100%;
      height: 1px;
      background-color: #d7d7d7;
    }
    .table-filter {
      display: flex;
      justify-content: space-between;
    }
    .table-filter > div {
      background: #ffffff;
      border: 1px solid #dddcdc;
      font-size: 18px;
      height: 60px;
      line-height: 60px;
      color: #3f3f3f;
      ul {
        display: flex;
        li {
          list-style: none;
          font-size: 12px;
          color: #838383;
          line-height: 24px;
          padding: 6px 0;
          span {
            color: #3f3f3f;
            font-weight: bold;
            font-size: 18px;
            display: block;
          }
        }
      }
    }
    .fabric {
      display: flex;
      .label {
        width: 14%;
        text-align: center;
      }
      ul {
        width: 86%;
        li {
          width: 25%;
          text-align: center;
          line-height: 24px;
          span {
            font-size: 16px !important;
          }
        }
      }
    }
    .fabricOne {
      display: flex;
      .label {
        width: 20%;
        text-align: center;
      }
      .labelOne {
        width: 40%;
        line-height: 30px;
        text-align: center;
      }
      ul {
        width: 60%;
        li {
          width: 100%;
          text-align: center;
          line-height: 24px;
          span {
            font-size: 16px !important;
          }
        }
      }
    }
    .ink {
      display: flex;
      .label {
        width: 25%;
        text-align: center;
      }
      ul {
        width: 75%;
        li {
          width: 50%;
          text-align: center;
        }
      }
    }
    .main {
      flex: 1;
      overflow: hidden;
    }
  }
  ::v-deep {
    .ivu-row {
      width: 100% !important;
    }
    .add-color {
      color: red;
    }
  }
  </style>
  