// 汽运卸车反馈
<template>
  <div class="container">
    <el-row>
      <el-col :span="20">
        <h2 class="bg-left title">汽运卸车反馈</h2>
      </el-col>
      <el-col :span="4" class="bg-right">
        <el-button
          class="bg-bottom"
          type="primary"
          size="small"
          @click="revert()"
          ><img
            width="6"
            height="10"
            style="vertical-align: bottom; margin-right: 3px"
            src="../../../public/img/lujing.png"
            alt=""
          />返回</el-button
        >
      </el-col>
    </el-row>
    <div class="center">
    <ws-form ref="deptBudgetList" :model="deptBudgetList" :rules="rules">
      <div class="basicInformation">
        <h2> 任务编号 </h2>
        <ws-info-table>
          <!-- 任务编号 -->
          <ws-form-item label="任务编号" span="1" prop="processNo">
          {{deptBudgetList.processNo}}
        </ws-form-item>
        <!-- 货名 -->
          <ws-form-item label="货名" span="1" prop="goodsName">
            {{deptBudgetList.goodsName}}
        </ws-form-item>
          <!--重量（吨）-->
          <ws-form-item label="重量（吨）" span="1" prop="weight">
          {{deptBudgetList.weight}}
        </ws-form-item>
          <!--发货地址-->
          <ws-form-item label="发货地址" span="1" prop="sendDetailedAddress">
            
            {{deptBudgetList.sendPrivate}}{{deptBudgetList.sendCity}}{{deptBudgetList.sendArea}}
          </ws-form-item>
         <!--发货人-->
          <ws-form-item label="发货人" span="1" prop="sender">
          
          {{deptBudgetList.sender}}
          </ws-form-item>

          <!--发货人电话-->
          <ws-form-item label="发货人电话" span="1" prop="senderPhone">
            
            {{deptBudgetList.senderPhone}}
          </ws-form-item>
          <!--收货地址-->
        <ws-form-item label="收货地址" span="1" prop="receiveDetailedAddress">
            
             {{deptBudgetList.receivePrivate}}{{deptBudgetList.receiveCity}}{{deptBudgetList.receiveArea}}
        </ws-form-item>
         <!--收货人-->
          <ws-form-item label="收货人" span="1" prop="receiver">
            {{deptBudgetList.receiver}}
          </ws-form-item>

          <!--收货人电话-->
          <ws-form-item label="收货人电话" span="1" prop="receiverPhone">
           
             {{deptBudgetList.receiverPhone}}
          </ws-form-item>
          <!--发货日期-->
          <ws-form-item label="发货日期" span="1" prop="deliveryDateStart">
          
          {{deptBudgetList.deliveryDateStart}}
        </ws-form-item>
           <!--最晚发货日期-->
          <ws-form-item label="最晚到货日期" span="1" prop="deliveryDateEnd">
          
          {{deptBudgetList.deliveryDateEnd}}
        </ws-form-item>
          <!--合同编号-->
          <ws-form-item label="合同编号" span="1" prop="contractNo">
            
            {{deptBudgetList.contractNo}}
          </ws-form-item>
          <!-- 运输方式 -->
          <ws-form-item label="运输方式" span="1" prop="tranType">
              {{deptBudgetList.tranType}}
          </ws-form-item>
        </ws-info-table>
      
        <div class="small-title"><h2>卸车详情</h2></div>
        <div class="liaison">
        <div
          style="width: 100%"
          class="flex position"
          v-for="(item, index) in this.freightspace"
          :key="index"
        >
          <ws-info-table>
            <!--司机-->
            <ws-form-item :label="'司机' + (index + 1)" span="1" prop="driver">
               <el-input
                v-show="item.temporaryDriverFlag != 0"
                v-model="item.driver"
                placeholder="请选择司机"
                filterable
                :filter-method="dataFilter"
                @change="selectstaff"
              >
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.staffName"
                  :value="item.staffName"
                />
               </el-input> 
               <span v-show="item.temporaryDriverFlag == 0">{{item.driver}} </span> 
                   
            </ws-form-item>
            <!--电话-->
            <ws-form-item label="司机电话" span="1" prop="driverPhone">
               <ws-input
               v-show="item.temporaryDriverFlag != 0"
                v-model="item.driverPhone"
                placeholder="请输入司机电话"
                maxlength="20"
                size="small"
              /> 
             <span v-show="item.temporaryDriverFlag == 0">{{item.driverPhone}} </span> 
            </ws-form-item>
            <!--车牌号-->
            <ws-form-item label="车牌号" span="1" prop="carNo">
               <ws-input
               v-show="item.temporaryDriverFlag != 0"
                v-model="item.carNo"
                placeholder="请输入车牌号"
                maxlength="20"
                size="small"
              /> 
             <span v-show="item.temporaryDriverFlag == 0">{{item.carNo}} </span> 
            </ws-form-item>
            <!--装车净重-->
            <ws-form-item label="装车(吨)" span="1" prop="loadNetWeight">
              <ws-input
                v-model="item.loadNetWeight"
                placeholder="请输入装车净重"
                maxlength="20"
                size="small"
              />
            </ws-form-item>
            <!--卸车净重(吨)-->
            <ws-form-item label="卸车净重(吨)" span="1" prop="unloadNetWeight">
              <ws-input
                v-model="item.unloadNetWeight"
                placeholder=""
                maxlength="20"
                size="small"
              />
            </ws-form-item>
            <!--磅单-->
            <ws-form-item label="磅单" span="1" prop="loadPoundImg">
              <template slot-scope="scope">
              
                <img
                  width="18"
                  height="20"
                  style="
                    vertical-align: text-top;
                    position: relative;
                    top: -1px;
                  "
                  src="../../../public/img/fujian.png"
                  @click="fujian(scope.row)"
                  alt=""
                />
                <span v-show="item.temporaryDriverFlag == 0" >{{item.signStatus}}</span>
              </template>
            </ws-form-item>
          </ws-info-table>
        </div>
      </div>
      </div>
    </ws-form>
    <div style="text-align: right; padding: 10px">
        <el-button
          class="bg-bottom-up"
          type="primary"
          size="small"
          @click="submit(deptBudgetList)"
          >提交</el-button
        >
      </div>
      <WinseaContentModal
      v-model="accessoryTFs"
      :title="$t('system.noticeCircular.information')"
      @on-cancel="handleClose"
    >
      <p>上传附件</p>
      <ws-upload
        ref="upload"
        table-name="maintain_work_order"
        oss-key="mainPlan"
        :comp-id="compId"
        :file-list="fileList"
        :appendix-ids="appendixIdsAdd"
        :vesselId="deptBudgetList.loadPoundImg"
        :size-limit="size"
        @uploadSuccess="uploadSuccess"
        accept=".jpg, .jpeg, .png, .pdf, .doc, .zip, .rar"
      />
    </WinseaContentModal>
    </div>
  </div>
  
</template>
<script>
import { regionData, CodeToText, TextToCode } from 'element-china-area-data'
import {seeCat, packList, feedback} from '@/model/transport/index'
import{getstaff}from '@/model/warehouse/index'
import Pagination from '@/components/Pagination'
import WsUpload from '@/components/WsUpload'
// import { dayjs, fmoney, EventBus } from 'base-core-lib'
import { dayjs, EventBus } from 'base-core-lib'
export default {
  name: 'viewSpareMoney',
  components: {
    WsUpload,
    Pagination,
  },
  watch: {
    // vesselId(val) {
    //   this.getList()
    // },
    isShow(val) {
      this.showType = val
    },
  },
  data() {
    return {
      //弹出框
      dialogViewSpareMoney: false,
      dialogApproveFormVisible: false,
      // 船舶类型
      monetaryKey: null,
      // 表格显示数据
      tableDate: [],
      // 是否显示
      showType: true,
      // 年
      year: '',
      item:[],
      shipType:[],
      tranType: 3,
      deptBudgetTotal: 0,
      currentPage: 1,
      pageSize: 10,
      searchType: 1,
      searchKeyWord: '',
      contractType: 2,
      startDate: null,
      endDate: null,
      goodnameList: {},
      // 提交类型
      submitType: true,
      storageType: [],
      readonly: true,
      appendixIdsAdd: '',
      uploadSuccess: {},
      onChange: {},
      selectedOptions: [],
        options:[],
      tranCarInfoList: {},
        staffList :[],
      gradeList: [],
      rules: {
        netWeight: [
          {
            required: true,
            type: 'number',
            message: '请输入活动名称',
            trigger: 'blur',
          },
        ],
      },
      fileList:[],
     freightspace: [
        {
          driver: '',
          driverPhone: '',
          carNo: '',
          loadNetWeight: '',
        },
      ],
      size: 10,
      compId: sessionStorage.getItem('ws-pf_compId'),
      deptCircularPage: {},
      packtypeList: {},
      date: {
        year: dayjs().format('YYYY'),
        month: dayjs().format('MM'),
      },
      contractList: [],
      deptBudgetList: {
        warehouseInOutDetail: {},
      },
      historyList: [],

      pickerBeginDateBefore: {
        disabledDate: (time) => {
          return time.getTime() > Date.now()
        },
      },
      accessoryTFs: false,
    }
  },
  mounted() {
    this.deptBudgetList.id = this.$route.query.id
    this.getList()
  },
//  activated(){
//    this.loaddata()
//    this.getList()
//  },
 computed: {
    totalStorage: function () {
      var maxStorage = 0
      for (var i = 0; i < this.freightspace.length; i++) {
        maxStorage += Number(this.freightspace[i].maxStorage)
      }
      return maxStorage
    },
  },
  methods: {
   getList() {
      seeCat({ id: this.deptBudgetList.id })
        .toPromise()
        .then((response) => {
          this.deptBudgetList = response
          //  this.deptBudgetList.tranCarInfoList = response.tranCarInfoList
          this.freightspace = response.tranCarInfoList
          for (var i = 0; i < this.freightspace.length; i++) {
            if (!this.freightspace[i].loadNetWeight) {
              this.freightspace[i].loadNetWeight = 0
            }
          }
        })
    },
    dataFilter(val) {
      this.deptBudgetList.personCharge = val
      if (val) {
        console.log(val)
        this.options = this.staffList.filter((item) => {
          if (
            !!~item.staffName.indexOf(val) ||
            !!~item.staffName.toUpperCase().indexOf(val.toUpperCase())
          ) {
            return true
          }
        })
      } else {
        this.options = this.staffList
      }
    },
    selectstaff(e) {
      for (var i = 0; i < this.staffList.length; i++) {
        if (this.staffList[i].staffName == e) {
          this.deptBudgetList.driverPhone = this.staffList[i].staffMobilePhone
          this.deptBudgetList.personChargeKey = this.staffList[i].staffId
        }
      }
    },
    // loaddata() {
    //   dispatchCat({ id: this.deptBudgetList.id  })
    //     .toPromise()
    //     .then((response) => {
    //       this.deptBudgetList = response
    //         this.freightspace = response.tranCarInfoList
    //         for (var i = 0; i < this.freightspace.length; i++) {
    //         if (!this.freightspace[i].loadNetWeight) {
    //           this.freightspace[i].loadNetWeight = 0
    //         }
    //       }
        //   for(var i = 0; i<this.deptBudgetList.tranCarInfoList.length;i++){
        //    var num  = this.deptBudgetList.tranCarInfoList[i].positionWeight.split("," )  
        //    for(var j = 0;j<num.length;j++){
        //     var num2 = num[j].split("/")
        //      this.freightspace.push({
        //        'impurity': num2[i],
        //        'positionWeight':num2[num2.length-1]
        //      })
        //    }

        //   }
  //   })
  // },
  //上传
    fujian(row) {
      if (
        row.receiveAttachmentPath === null ||
        row.receiveAttachmentPath === ''
      ) {
        EventBus.$emit(
          'warning',
          this.$t('system.noticeCircular.NoInformation')
        )
      } else {
        this.accessoryTFs = true
      }
      this.appendixIdss = row.receiveAttachmentPath
    },
    //返回按钮
    revert() {
      this.freightspace=[]
      this.$router.push({ path: 'tranManagementReceivingFeedback' })
    },
    
    selectdriver() {},
    handleChange(value) {
      this.selectedOptions = value
    },
    returnsales() {
      this.deptBudgetList = {}
      this.freightspace = {}
      this.selectedOptions = ''
      this.$router.push({ path: 'tranManagementReceivingFeedback' })
    },
    //提交按钮
    submit() { 
      this.$confirm(`所有车辆完成卸车任务后，请及时修改任务状态，确定提交卸车信息？`, {
        cancelButtonText: '取消',
        confirmButtonText: '确定',
        type: 'warning',
      })
        .then(() => {
          this.$refs.deptBudgetList.validate((valid) => {
            if (valid) {
              
            //  for(var i = 0; i < this.freightspace.length; i++){
            //    var num  = this.freightspace[i].impurity + "/" + this.freightspace[i].positionWeight
            //    this.arr.push(
            //      num
            //    )  
            //  }
          
            this.tranCarInfoList=this.freightspace
            this.tranCarInfoList.driver = this.deptBudgetList.driver
              this.tranCarInfoList.driverPhone = this.deptBudgetList.driverPhone
              this.tranCarInfoList. carNo = this.deptBudgetList.carNo
              this.tranCarInfoList.loadNetWeight = this.deptBudgetList.loadNetWeigh
              this.tranCarInfoList.unloadNetWeight = this.deptBudgetList.unloadNetWeight
              this.tranCarInfoList.loadPoundImg = this.deptBudgetList.loadPoundImg
              this.tranCarInfoList.tranType = this.deptBudgetList.tranType
            for(var i = 0 ; i<this.tranCarInfoList.length;i++){
                this.tranCarInfoList[i].id = this.freightspace[i].id
                if(this.tranCarInfoList[i].temporaryDriverFlag !=0){
                   this.tranCarInfoList[i].temporaryDriverFlag = 1
                   this.tranCarInfoList[i].tranType = this.tranType
                 }
            }
              var tranProcessInfo = {}
              var tranList = this.tranCarInfoList
              tranProcessInfo.id = this.deptBudgetList.id
              tranProcessInfo.infoId = this.deptBudgetList.infoId
              tranProcessInfo.tranCarInfoList = this.tranCarInfoList
              feedback(tranProcessInfo)
                .toPromise()
                .then((response) => {
                  this.$message.success('添加成功')
                  this.deptBudgetList = {}
                  this.freightspace = {}
                  this.selectedOptions = ''
                  this.$router.push({
                    path: 'tranManagementReceivingFeedback',
                  })
                })
            } else {
              // EventBus.$emit('error', this.$t('showMessage.asteriskRequired'))
              return false
            }
          })
        })
        .catch(() => {
          return false
        })
    },
    resetForm(deptBudgetList) {
      this.$refs[deptBudgetList].resetFields()
    },
    handleClose() {
      this.accessoryTFs = false
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.pageSize = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      console.log(`当前页: ${val}`)
      this.getList()
    },
    selecttaskType(e) {
      for (var i = 0; i < this.taskTypeList.length; i++) {
        if (this.taskTypeList[i].value == e) {
          this.searchType = this.taskTypeList[i].type
        }
      }
    },
    approve() {},
    listQuery() {},
  },
}
</script>
<style lang="scss" scoped>
/deep/.basicInformation {
  .ws-info-table {
    border: none;
  }
  .el-form-item {
    width: 33.3333%;
    border: none;
    .el-form-item__label {
      background: transparent;
      border: none;
    }
    .el-form-item__content {
      border: none;
    }
  }
}
.title {
  position: relative;
  padding-left: 10px;
}
.title::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 30px;
  background: #5473e8;
  position: absolute;
  left: 0;
}
.el-form {
  padding: 0 10%;
}
.el-button--primary {
  background-color: #5878e8;
  border-color: #5878e8;
}
.el-col {
  background: #f6f7fc;
}
.bg-right {
  text-align: right;
  padding: 16px 20px;
}
.center{
  width: 80%;
  margin: 0 auto;
}

//表格文字
/deep/.ws-info-table .el-form-item .el-form-item__label {
  text-align: left;
  font-size: 14px;
  font-weight: 400;
  color: #8890b1;
  line-height: 16px;
}
//蓝标
.small-title {
  position: relative;
  padding: 10px;
  font-weight: 600;
}
.small-title::before {
  position: absolute;
  content: '';
  display: block;
  background: #5473e8;
  width: 4px;
  height: 14px;
  left: 0px;
  top: 13px;
  padding: 4px 2px;
}
.position{
  width: 90%;
}
.position .siji{
  width: 16%;
}
/deep/.position .ws-info-table .el-form-item .el-form-item__label{
  width: 40%;
  text-align: center;
}
.position .zaizhong{
  width: 16%;
}
//减号
.del {
  right: -70px;
}
.bot{
  width: 30%;
}
.position .siji {
  width: 20.5%;
}
/deep/.el-form-item {
  border-right: 0px;
  border-bottom: 0px;
}
/deep/.ws-info-table {
  border-left: 0px;
  border-top: 0px;
}
.ws-info-table .el-form-item .el-form-item__content {
  border-right: 0px;
  border-bottom: 0px;
  border-left: 0px;
  border-top: 0px;
}
/deep/.ws-info-table .el-form-item {
  border-right: 0px;
  border-bottom: 0px;
  border-left: 0px;
  border-top: 0px;
}
/deep/.ws-info-table .el-form-item .el-form-item__content {
  background: #f5f7fa;
  border-radius: 4px;
  border: 1px solid #d8dce6;
  font-family: PingFangSC-Regular, PingFang SC;
  margin-bottom: 5px;
  background-color: #fff;
  font-size: 14px;
  font-weight: 400;
  color: #8890b1;
  line-height: 16px;
}
/deep/.ws-info-table .el-form-item .el-form-item__label {
  background-color: #fff;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #8890b1;
  line-height: 16px;
}
// .flex .position{
//   margin-top: 150px;
//   margin-left: 20px;
// }
.position{
  width: 100%;
}
.position .siji{
  width: 20.6%;
}
</style>
