// 创建运输任务
<template>
  <div class="container">
    <el-row>
      <el-col :span="12">
        <h2 class="bg-left title">创建运输任务</h2>
      </el-col>
      <el-col :span="12" class="bg-right">
        <el-button
          class="bg-bottom"
          type="primary"
          size="small"
          @click="returnsales()"
          ><img
            width="6"
            height="10"
            style="vertical-align: bottom; margin-right: 3px"
            src="../../../public/img/lujing.png"
            alt=""
          />返回</el-button
        >
      </el-col>
    </el-row>
    <ws-form
      ref="deptBudgetList"
      :rules="mainReportAdd"
      :model="deptBudgetList"
    >
      <div
        style="width: 100%"
        class="flex position"
        v-for="(item, index) in freightspace"
      >
        <div class="flex">
          <!-- <div class="driver">货车信息-{{ index + 1 }}</div> -->
          <ws-info-table class="el-table">
            <!--任务编号-->
            <ws-form-item
              label="任务编号"
              span="1"
              prop="taskNo"
              class="forlist"
              width="400px"
            >
              <ws-input
                v-model="item.taskNo"
                placeholder="请输入任务编号"
                maxlength="20"
                size="small"
              />
            </ws-form-item>
            <!-- 任务类型 -->
          <ws-form-item prop="taskType" label="任务类型" span="1">
            <ws-select
              v-model="taskType"
              placeholder=""
              class="typeselect"
              @change="selectstorageType"
            >
              <ws-option
                v-for="item in storageType"
                :key="item.constKey"
                :label="item.constValue"
                :value="item.constValue"
              />
            </ws-select>
          </ws-form-item>
          <!-- 合同编号 -->
          <ws-form-item prop="contractNo" label="合同编号" span="1">
            <ws-select
              v-model="contractNo"
              placeholder="请输入合同编号"
              class="typeselect"
              @change="selectstorageType"
            >
              <ws-option
                v-for="item in storageType"
                :key="item.constKey"
                :label="item.constValue"
                :value="item.constValue"
              />
            </ws-select>
          </ws-form-item>
          <!-- 货名 -->
          <ws-form-item prop="goodsName" label="货名" span="1">
            <ws-select
              v-model="deptBudgetList.goodsName"
              placeholder=""
              class="typeselect"
              @change="selectgoodsName"
            >
              <ws-option
                v-for="item in goodnameList"
                :key="item.constKey"
                :label="item.constValue"
                :value="item.constValue"
              />
            </ws-select>
            </ws-form-item>
            <!--重量（吨）-->
          <ws-form-item label="重量（吨）" span="1" prop="weight">
            <ws-input
              @input="grossWeightchange"
              v-model="deptBudgetList.weight"
              placeholder="请输入重量"
              maxlength="20"
              size="small"
            />
          </ws-form-item>
          </ws-info-table>
        </div>
      </div>
    </ws-form>
    <ws-form
      ref="deptBudgetList"
      :rules="mainReportAdd"
      :model="deptBudgetList"
    >
      <div
        style="width: 100%"
        class="flex position"
        v-for="(item, index) in freightspace1"
      >
        <div class="flex">
          <ws-info-table class="el-table">
            <el-radio v-model="item.radio" label="1">只有库发货</el-radio>
              <el-radio v-model="item.radio" label="2">临时库发货</el-radio>
            <!-- <ws-form-item label="" span="1"> -->
            <ws-select
              v-model="deptBudgetList.inOutType"
              placeholder=""
              class="typeselect"
              @change="selectstorageType"
            >
              <ws-option
                v-for="item in storageType"
                :key="item.constKey"
                :label="item.constValue"
                :value="item.constValue"
              />
            </ws-select>
            
          <!-- </ws-form-item> -->
            <!--始发地-->
            <ws-form-item label="始发地" span="1">
            <ws-select
              v-model="deptBudgetList.inOutType"
              placeholder=""
              class="typeselect"
              @change="selectstorageType"
            >
              <ws-option
                v-for="item in storageType"
                :key="item.constKey"
                :label="item.constValue"
                :value="item.constValue"
              />
            </ws-select>
          </ws-form-item>
            <!--始发地详细地址-->
            <ws-form-item
            label="始发地详细地址"
            span="1"
            prop="startDetailedAddress"
            class="readonly bg-right"
          >
            <ws-input
              v-model="deptBudgetList.driverName"
              placeholder="请输入始发地详细地址"
              maxlength="20"
              size="small"
            />
          </ws-form-item>
        
          <ws-form-item prop="receiveWarehouse" label="" span="10"></ws-form-item>
          <!-- 收获库点 -->
            <ws-form-item
            label="收获库点"
            span="1"
            prop="contractNo"
            class="readonly bg-right"
          >
           <ws-select
              v-model="deptBudgetList.inOutType"
              placeholder=""
              class="typeselect"
              @change="selectstorageType"
            >
              <ws-option
                v-for="item in storageType"
                :key="item.constKey"
                :label="item.constValue"
                :value="item.constValue"
              />
            </ws-select>
          </ws-form-item>
          
          <!-- 终到地 -->
           <ws-form-item
            label="终到地"
            span="1"
            prop="contractNo"
            class="readonly bg-right"
          >
            <ws-select
              v-model="deptBudgetList.inOutType"
              placeholder=""
              class="typeselect"
              @change="selectstorageType"
            >
              <ws-option
                v-for="item in storageType"
                :key="item.constKey"
                :label="item.constValue"
                :value="item.constValue"
              />
            </ws-select>
          </ws-form-item>
          <!-- 终到地详细地址 -->
              <ws-form-item
            label="终到地详细地址"
            span="1"
            prop="endDetailedAddress"
            class="readonly bg-right"
          >
            <ws-input
              v-model="deptBudgetList.endDetailedAddress"
              placeholder="请输入始发地详细地址"
              maxlength="20"
              size="small"
            />
          </ws-form-item>
          </ws-info-table>
        </div>
         
      </div>
    </ws-form>
    <span class="zi">运输方式</span>
  <el-checkbox-group v-model="checkList" prop="tranType">
    <el-checkbox label="汽运" prop="1"></el-checkbox>
    <el-checkbox label="火运" prop="2"></el-checkbox>
    <el-checkbox label="船运" prop="3"></el-checkbox>
  </el-checkbox-group>
  
    <ws-form
      ref="deptBudgetList"
      :rules="mainReportAdd"
      :model="deptBudgetList"
    >
    <div class="small-title">运输阶段1（123456789）</div>
    <!--运输方式-->
    <div class="neifor">
        <ws-info-table>
          <!--运输方式-->
          <ws-form-item label="运输方式" span="1" prop="waterContent">
            <ws-input
              v-model="deptBudgetList.waterContent"
              placeholder="请输入运输方式"
              maxlength="120"
              size="small"
            />
          </ws-form-item>
          <!--发货日期-->
          <ws-form-item label="发货日期" span="1" prop="impurity">
            <ws-input
              v-model="deptBudgetList.impurity"
              placeholder="请输入发货日期"
              maxlength="120"
              size="small"
            />
          </ws-form-item>
          <!--最晚到货日期-->
          <ws-form-item label="最晚到货日期" span="1" prop="bulkDensity">
            <ws-input
              v-model="deptBudgetList.bulkDensity"
              placeholder="请输入最晚到货日期"
              maxlength="120"
              size="small"
            />
          </ws-form-item>
        </ws-info-table>
      </div>
       <div class="nei">
         <ws-info-table>
          <!--发货地区-->
          <ws-form-item label="发货地区" span="1" prop="waterContent">
            <ws-select
              v-model="deptBudgetList.inOutType"
              placeholder="请输入发货地区"
              class="typeselect"
              @change="selectstorageType"
            >
              <ws-option
                v-for="item in storageType"
                :key="item.constKey"
                :label="item.constValue"
                :value="item.constValue"
              />
            </ws-select>
          </ws-form-item>
          <!--发货地详细地址-->
          <ws-form-item label="发货地详细地址" span="1" prop="impurity">
            <ws-input
              v-model="deptBudgetList.impurity"
              placeholder="请输入发货地详细地址"
              maxlength="120"
              size="small"
            />
          </ws-form-item>
          <!--发货人-->
          <ws-form-item label="发货人" span="1" prop="bulkDensity">
            <ws-input
              v-model="deptBudgetList.bulkDensity"
              placeholder="请输入发货人"
              maxlength="120"
              size="small"
            />
          </ws-form-item>
          <!--发货人电话-->
          <ws-form-item label="发货人电话" span="1" prop="bulkDensity">
            <ws-input
              v-model="deptBudgetList.bulkDensity"
              placeholder="请输入发货人电话"
              maxlength="120"
              size="small"
            />
          </ws-form-item>
        </ws-info-table>
      </div>
      <div class="nei">
         <ws-info-table>
          <!--收货日期-->
          <ws-form-item label="收货地区" span="1" prop="waterContent">
             <ws-select
              v-model="deptBudgetList.inOutType"
              placeholder="请输入收货地区"
              class="typeselect"
              @change="selectstorageType"
            >
              <ws-option
                v-for="item in storageType"
                :key="item.constKey"
                :label="item.constValue"
                :value="item.constValue"
              />
            </ws-select>
          </ws-form-item>
          <!--收货地详细地址-->
          <ws-form-item label="收货地详细地址" span="1" prop="impurity">
            <ws-input
              v-model="deptBudgetList.impurity"
              placeholder="请输入收货地详细地址"
              maxlength="120"
              size="small"
            />
          </ws-form-item>
          <!--发货人-->
          <ws-form-item label="收货人" span="1" prop="bulkDensity">
            <ws-input
              v-model="deptBudgetList.bulkDensity"
              placeholder="请输入收货人"
              maxlength="120"
              size="small"
            />
          </ws-form-item>
          <!--发货人电话-->
          <ws-form-item label="收货人电话" span="1" prop="bulkDensity">
            <ws-input
              v-model="deptBudgetList.bulkDensity"
              placeholder="请输入收货人电话"
              maxlength="120"
              size="small"
            />
          </ws-form-item>
        </ws-info-table>
      </div>
    </ws-form>
    <!-- 提交 -->
    <div style="text-align: right; padding: 10px" class="center">
      <el-button
        class="bg-bottom"
        type="primary"
        size="small"
        @click="submit(deptBudgetList)"
        >提交</el-button
      >
    </div>
  </div>
</template>
<script>
import { provinceAndCityData, CodeToText } from 'element-china-area-data'

import {addtrantask} from '@/model/transport/index'
import WsUpload from '@/components/WsUpload'
import mapDrag from '@/components/mapdrag/mapdrag'
export default {
  name: 'viewSpareMoney',
  components: {
    WsUpload,
    mapDrag,
  },
  watch: {
    vesselId(val) {
      this.getVesselData()
    },
    isShow(val) {
      this.showType = val
    },
  },
  data() {
    let self = this
    return {
       checkList: [],
      deptBudgetList: {
        totalStorage: 0,
        drivercarInfo: {
          goodsName: '',
        },
        driverPayeeInfo: {},
      },
      radio: '1',
      carModelList: [],
      carLengthList: [],
      options_: provinceAndCityData,
      heightData: '600px',
      zoom: 7,
      selectedOptions: [],
      center: [116.244694, 39.517344],
      window: '',
      district: null,
      listDate: { country: '中国', level: 'country', city: '' },
      citylist: [],
      compId: sessionStorage.getItem('ws-pf_compId'),
      mainReportAdd: {},
      appendixIdsAdd: '',
      size: 10,
      value1: '',
      unitList: [],
      freightspace: [
        {
          carNumber: '',
          carModel: '高栏',
          carModelKey: '1',
          carLength: '13',
          carLengthKey: '1',
          carLoad: '',
          yearManufacture: '',
        },
      ],
      freightspace1: [
        {
          account_type: '',
          radio: '1',
          payeeName: '',
          payeeNumberCard: '',
          compName: '',
          bankDeposit: '',
          bankCard: '',
        },
      ],
      name: '',
      age: '',
    }
  },
  activated() {
    this.loaddata()
    this.showType = this.isShow
  },
  computed: {},
  methods: {
    addtrantask(){

    },
    IdCard(UUserCard) {
      //获取年龄
      var myDate = new Date()
      var month = myDate.getMonth() + 1
      var day = myDate.getDate()
      var age = myDate.getFullYear() - UUserCard.substring(6, 10) - 1
      if (
        UUserCard.substring(10, 12) < month ||
        (UUserCard.substring(10, 12) == month &&
          UUserCard.substring(12, 14) <= day)
      ) {
        age++
      }
      this.age = age
    },
    loaddata() {
      // 车型
      packList({ constId: 'TRAN1' })
        .toPromise()
        .then((response) => {
          this.carModelList = response
        })
      // 车长
      packList({ constId: 'TRAN2' })
        .toPromise()
        .then((response) => {
          this.carLengthList = response
        })
    },
    confirmPositioncity() {
      this.listDate.level = 'city'
      this.listDate.country = this.name
    },
    // 关闭 dialog时 处理文件url 初始化upload组件
    handleClose() {
      this.dialogViewSpareMoney = false
    },
    add() {
      this.freightspace.push({
        carNumber: '',
        carModel: '高栏',
        carModelKey: '1',
        carLength: '13',
        carLengthKey: '1',
        carLoad: '',
        yearManufacture: '',
      })
    },
    del(index) {
      if (this.freightspace.length > 1) {
        this.freightspace.splice(index, 1)
      }
    },
    add1() {
      this.freightspace1.push({
        account_type: '',
        radio: '1',
        payeeName: '',
        payeeNumberCard: '',
        compName: '',
        bankDeposit: '',
        bankCard: '',
      })
    },
    del1(index) {
      if (this.freightspace1.length > 1) {
        this.freightspace1.splice(index, 1)
      }
    },
    handleChange(value) {
      this.selectedOptions = value
    },
    returnsales() {
      this.$router.push({ path: 'tranManagementTransport' })
    },
    },
    selectcarModel(e) {
      for (var i = 0; i < this.carModelList.length; i++) {
        if (this.carModelList[i].constValue == e) {
          this.deptBudgetList.carModelKey = this.carModelList[i].constKey
        }
      }
    },
    selectcarLength(e) {
      for (var i = 0; i < this.carLengthList.length; i++) {
        if (this.carLengthList[i].constValue == e) {
          this.deptBudgetList.carLengthKey = this.carLengthList[i].constKey
        }
      }
    },
    onChange(files) {
      this.fileNum = files
      this.$refs.upload.handleSaveBill().then((res) => {
        console.log(files)
      })
    },

    submit() {
      console.log(this.freightspace)

      this.$refs.deptBudgetList.validate((valid) => {
        if (valid) {
          this.deptBudgetList.compId = sessionStorage.getItem('ws-pf_compId')
          this.deptBudgetList.residentCityProvincial =
            CodeToText[this.selectedOptions[0]]
          this.deptBudgetList.residentCityMunicipal =
            CodeToText[this.selectedOptions[1]]
          this.deptBudgetList.driverCarInfoList = this.freightspace
          this.deptBudgetList.driverPayeeInfoList = this.freightspace1
          addDriver(this.deptBudgetList)
            .toPromise()
            .then((response) => {
              this.$message.success('添加成功')
              this.$router.push({ path: 'tranManagementDriver' })
            })
        } else {
          EventBus.$emit('error', this.$t('showMessage.asteriskRequired'))
          return false
        }
      })
    },
    resetForm(deptBudgetList) {
      this.$refs[deptBudgetList].resetFields()
    },
}
</script>

<style lang="scss" scoped>
.position {
  position: relative;
}
.add,
.del {
  position: absolute;
  right: -38px;
  top: 9px;
  cursor: pointer;
}
.del {
  right: -70px;
}
.amap-page-container {
  width: 300px;
  height: 300px;
}
.el-form {
  padding: 0 10%;
}
/deep/.ws-info-table .el-form-item {
  border-right: 1px solid #cdd2dc;
  border-bottom: 1px solid #cdd2dc;
}
.readonly {
  position: relative;
}
.title {
  position: relative;
}
.el-car {
  width: 413px;
}
.title::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 30px;
  background: #5473e8;
  position: absolute;
  left: 0;
}
.el-col {
  background: #f6f7fc;
}
/deep/.ws-info-table .el-form-item .el-form-item__content {
  padding: 0 25px;
  border-left: 1px solid #cdd2dc;
  background: #fafbfc;
}
/deep/.ws-info-table .el-form-item .el-form-item__label {
  width: 140px;
  text-align: center;
  background: #f0f2f6;
  // border: 1px solid #cdd2dc;
}
.button-container {
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: center;
  background-color: #fff;
  width: 100%;
  height: 50px;
  padding: 0 10px;
  & > div {
    margin-left: 10px;
    display: flex;
    flex-wrap: nowrap;
    flex-direction: row;
    & > span {
      line-height: 50px;
    }
  }

  /deep/.auditFlow-box {
    position: unset;
    margin-left: 10px;
    &/deep/.auditFlow-icon {
      width: auto;
      padding-right: 30px;
    }
    &/deep/.auditFlow-main {
      position: absolute;
    }
  }
}
.box-app {
  display: inline-block;
  float: left;
  margin-left: 30px;
  line-height: 50px;
}
/deep/.el-dialog {
  .el-form-item {
    margin-bottom: 0 !important;
    .el-input--medium {
      textarea {
        min-height: 100px !important;
      }
    }
  }
}
.collapse-bottom {
  margin-bottom: 20px;
}
.input-main .textarea .el-textarea__inner {
  width: 100%;
  z-index: 1;
}
.bg-left {
  padding-left: 30px;
}
.bg-right {
  padding-right: 10px;
  text-align: right;
}
.bg-bottom {
  margin: 15px 0px;
}
.wenzi {
  width: 900px;
  margin: 0 auto;
}
.wenzi h3 {
  display: inline-block;
  left: 10px;
}
.wenzi p {
  display: inline-block;
}
.center {
  width: 900px;
  margin: 0 auto;
}
.el-form-item__label {
  text-align: center;
}
.el-table {
  width: 1240px;
}
.ce {
  width: 900px;
  margin: 0 auto;
}
.driver {
  width: 120px;
  margin-top: 10px;
  font-weight: bold;
}

// 控制select为只读的时候显示样式
/deep/.ws-class-table-col {
  height: auto;
  padding: 0px 2px;
  /deep/.el-input__inner {
    padding: 0px 2px;
  }
}
.winseaview-view {
  padding: 0 0 20px;
}
.container {
  overflow: scroll;
  height: 93vh;
}
/deep/.ws-info-table .el-form-item .el-form-item__label {
  width: 80px;
}
/deep/.ws-info-table .el-form-item {
  width: 25%;
}
.el-textarea__inner {
  display: none;
}
.el-form {
  margin-top: 50px;
}
.readonly {
  width: 16%;
}
.el-cascader {
  width: 145px;
}
.forlist {
  width: 20%;
}
.el-form-item.forlist.is-success.el-form-item--small {
  width: 20%;
}
.el-form-item.forlist.el-form-item--small {
  width: 20%;
}
.el-form-item.readonly.is-success.el-form-item--small.showLableToopTip {
  width: 20%;
}
.el-form-item.el-car.el-form-item--small {
  width: 33.3%;
}
.zi{
   margin-left: 170px;
}
.el-checkbox-group{
  margin-left: 240px;
    margin-top: -17px;
}
/deep/.neifor {
  .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;
    }
  }
}
/deep/.nei {
  .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;
    }
  }
}
.ws-info-table .el-form-item .el-form-item__label {
    width: min-content;
}
.el-select>.el-input {
    display: block;
    width: 190px;
}
.ws-info-table .el-form-item {
    width: 20%;
    border: none;
    background: transparent;
}

</style>