<template>
  <div>
    <div class="tab-header webtop">
      <!-- 标题 -->
      <div>旧件处理申请</div>
      <!-- start 添加修改按钮 -->
      <div>
        <el-button type="info" size="small" @click="handleReturn()">关闭</el-button>
      </div>
      <!-- end 添加修改按钮 -->
      <!-- end 详情按钮 -->
    </div>
    <div class="listconadd">
      <el-form ref="form_obj" :model="formobj" class="formaddcopy02">
        <div class="title">
          <div>基础信息</div>
        </div>
        <el-row class="first_row">

          <el-col :span="8">
            <div class="span-sty">申请人</div>
            <el-form-item><span class="addinputInfo">{{ formobj.createByName }}</span></el-form-item>
          </el-col>
          <el-col :span="8">
            <div class="span-sty">申请部门</div>
            <el-form-item><span class="addinputInfo">{{ formobj.deptName }}</span></el-form-item>
          </el-col>


          <!--     <el-col :span="12">
            <div class="span-sty">单据编号</div>
            <el-form-item><span class="addinputInfo">{{ formobj.billNo }}</span></el-form-item>
          </el-col> -->
          <el-col :span="8">
            <div class="span-sty">申请日期</div>
            <el-form-item><span class="addinputInfo">{{ formobj.createTime }}</span></el-form-item>
          </el-col>

        </el-row>

        <el-row>

          <el-col :span="8">
            <div class="span-sty">处理原因</div>
            <el-form-item><span class="addinputInfo">{{ formobj.handleReasonValue }}</span></el-form-item>
          </el-col>
          <el-col :span="8">
            <div class="span-sty">处理方式</div>
            <el-form-item><span class="addinputInfo">{{ formobj.handleModeValue }}</span></el-form-item>
          </el-col>
          <el-col :span="8">
            <div class="span-sty">收益总额</div>
            <el-form-item><span class="addinputInfo">{{ totalQuantity }}</span></el-form-item>
          </el-col>

        </el-row>

        <el-row>

          <el-col :span="24">
            <div class="span-sty">备注</div>
            <el-form-item><span class="addinputInfo">{{ formobj.remarks }}</span></el-form-item>
          </el-col>

        </el-row>

        <el-row>

          <el-col :span="24">
            <div class="span-sty">附件</div>
            <el-form-item class="trightb_item">
              <el-image style="width: 120px;height: 120px; margin: 10px;" class="addinputInfo"
                v-for="(item,index) in formobj.filePaths" :src="item" :preview-src-list="[item]">
              </el-image>
            </el-form-item>
          </el-col>

        </el-row>

        <div class="title">
          <div>待处理旧件列表</div>
        </div>
        <el-table v-loading="listLoading" :data="formobj.asOldparthandleList" border>
          <el-table-column fixed width="60" label="序号" type="index" :index="indexMethod" align="center" />
          <!-- <el-table-column prop="vinNo" label="车架号" align="center" /> -->
          <el-table-column prop="goodsID" label="商品ID" align="center" />
          <el-table-column prop="goodsSpuName" label="商品名称" align="center" />
          <el-table-column prop="goodsSkuCode" label="商品编码" align="center" />
          <!-- <el-table-column prop="supplierName" label="供应商" align="center" /> -->
          <el-table-column prop="goodsSkuOwnSpec" label="规格" align="center" />
          <el-table-column prop="unit" label="单位" align="center" />
          <el-table-column prop="manufacturerName" label="厂家" align="center" />
          <!-- <el-table-column prop="vinNo" label="车架号" align="center" /> -->
          <!-- <el-table-column prop="sourceBillNo" label="维修单号" align="center" /> -->
          <!-- <el-table-column prop="warehouseName" label="仓库" align="center" />
        <el-table-column prop="warehouseRackCode" label="库位" align="center" />
        <el-table-column prop="supplierName" label="供应商" align="center" /> -->
          <!-- <el-table-column prop="price" label="单价" align="center" /> -->
          <el-table-column prop="count" label="库存数量" align="center" />
          <el-table-column prop="profit" label="收益金额" align="center" />
        </el-table>

      </el-form>

    </div>


  </div>
</template>

<script>
  import req from '@/api/storage/oldPartsCope.js'
  export default {
    data() {
      return {
        listLoading: false,
        submitdisabled: false,
        formobj: {
          "sid": "",
          "remarks": "",
          "createBySid": "",
          "createByName": "",
          "createDeptSid": "",
          "createDeptName": "",
          "createTime": "",
          "billNo": "",
          "filePaths": [],
          "useOrgSid": "",
          "useOrgName": "",
          "orgSidPath": "",
          "procDefId": "",
          "nodeId": "",
          "procInstId": "",
          "nodeState": "",
          "taskId": "",
          "finishTime": "",
          "totalProfit": "",
          "asOldparthandleList": [

          ]
        },
        hideUploadBtn: false,

        // commodity商品
        commodityKey: 1,
        commodityLoading: false,
        commodityQuery: {
          current: 1,
          size: 2,
          total: 0,
          params: {
            name: '',
            inOrg: "",
            outOrg: ""
          }
        },
        commodityData: [],
        imgList: [],
      }
    },
    created() {},
    computed: {
      // 收益总额
      totalQuantity() {
        let quantity = 0
        if (this.formobj.asOldparthandleList.length > 0) {
          this.formobj.asOldparthandleList.forEach((e) => {
            quantity += Number(e.profit)
          })
        }

        this.formobj.totalProfit = quantity

        return quantity
      },
    },
    methods: {

      indexMethod(index) {
        return Number(index) + 1
      },

      handleReturn(isreload) {
        if (isreload === 'true') this.$emit('reloadlist')
        this.imgList = []
        this.formobj = {
          "sid": "",
          "remarks": "",
          "createBySid": "",
          "createByName": "",
          "createDeptSid": "",
          "createDeptName": "",
          "createTime": "",
          "billNo": "",
          "filePaths": [],
          "useOrgSid": "",
          "useOrgName": "",
          "orgSidPath": "",
          "procDefId": "",
          "nodeId": "",
          "procInstId": "",
          "nodeState": "",
          "taskId": "",
          "finishTime": "",
          "totalProfit": "",
          "asOldparthandleList": []
        }
        this.$emit('doback')
      },

      showAdd() {},
      showEdit(row) {
        var params = {
          sid: row.sid
        }

        req.init(row.sid)
          .then(resp => {
            if (resp.success) {
              this.formobj = resp.data

              for (var i = 0; i < resp.data.filePaths.length; i++) {
                this.imgList.push({
                  url: resp.data.filePaths[i].url
                })
              }

            }
          })
          .catch(e => {
            this.formobj = {}
          })
      },

    }
  }
</script>
<style scoped>
  .span-sty {
    width: 130px !important;
  }

  .addinputInfo {
    margin-left: 120px !important;
  }

  .formaddcopy02 .el-row .el-col /deep/ .el-form-item .addinputw {
    margin-left: 120px !important;
    width: calc(100% - 115px);
  }

  .first_row {
    border-top: 1px solid #E0E3EB;
  }

  .titleOne {
    padding: 7px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
</style>
