<template>
  <div class="detail-container">
    <el-page-header content="审批" @back="goBack" />

    <div class="main-title">
      <div class="title">工程订单 <span style="margin-left: 20px">经销商名称：{{detailData.customerName}}</span></div>
    </div>

    <div class="diy-table-1">
      <el-row>
        <el-col :span="8" class="item">
          <div class="label">工程订单号</div>
          <div class="value">{{ detailData.enginOrderNo }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">订单日期</div>
          <div class="value">{{ detailData.orderDate }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">单据状态</div>
          <div class="value">{{ detailData.examineStatus | statusFilter }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">经销商编码</div>
          <div class="value">{{ detailData.customerNumber }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">经销商名称</div>
          <div class="value">{{ detailData.customerName }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">机型类别</div>
          <div class="value">{{ detailData.refMachineType }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">工程登录编号</div>
          <div class="value">{{ detailData.refEnginRecordNo }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">项目名称</div>
          <div class="value">{{ detailData.refProjectName }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">行业类别</div>
          <div class="value">{{ detailData.refTradeCategory }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">跨区厂编号</div>
          <div class="value">{{ detailData.refFactoryNo }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">使用单位</div>
          <div class="value">{{ detailData.refUseUnit }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">工程登录类型</div>
          <div class="value">{{ detailData.refPromiseStatus }}</div>
        </el-col>
        <!--        <el-col :span="8" class="item">-->
        <!--          <div class="label">销售类型</div>-->
        <!--          <div class="value">{{detailData.saleTypeName}}</div>-->
        <!--        </el-col>-->
        <el-col :span="8" class="item">
          <div class="label">联系人</div>
          <div class="value">{{ detailData.refLinkman }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">固定电话</div>
          <div class="value">{{ detailData.refTel }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">移动电话</div>
          <div class="value">{{ detailData.refPhone }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">权限分类</div>
          <div class="value">{{ detailData.refPowerCategory }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">工程登录类型</div>
          <div class="value">{{ detailData.refPromiseStatus }}</div>
        </el-col>
        <el-col :span="24" class="item">
          <div class="label">安装地址</div>
          <div class="value">{{ detailData.refInstallAddress }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">不扣押金</div>
          <div class="value">
            {{ detailData.takeDeposit ? '是' : '否' }}
            <!-- <el-checkbox v-model="detailData.takeDeposit">{{detailData.takeDeposit ? '是':'否'}}</el-checkbox> -->
          </div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">文件编号</div>
          <div class="value">{{ detailData.fileNo }}</div>
        </el-col>
        <el-col :span="8" class="item">
          <div class="label">业务员</div>
          <div class="value">{{ detailData.serviceName }}</div>
        </el-col>
        <el-col :span="24" class="item">
          <div class="label">格力回复</div>
          <div class="value">
            <el-input v-model="detailData.geLiNote" placeholder="请输入格力回复" />
          </div>
        </el-col>
        <el-col :span="24" class="item">
          <div class="label">格力内部备注</div>
          <div class="value">
            <el-input v-model="detailData.geLiInerNote" placeholder="请输入格力内部备注" />
          </div>
        </el-col>
        <el-col :span="24" class="item">
          <div class="label">备注</div>
          <div class="value">
            <el-input v-model="detailData.remark" placeholder="请输入备注" />
          </div>
        </el-col>
        <el-col :span="6" class="item">
          <div class="label">制单人</div>
          <div class="value">{{ detailData.createName }}</div>
        </el-col>
        <el-col :span="6" class="item">
          <div class="label">制单日期</div>
          <div class="value">{{ detailData.createTime }}</div>
        </el-col>
        <el-col :span="6" class="item">
          <div class="label">关闭人</div>
          <div class="value">{{ detailData.closeName }}</div>
        </el-col>
        <el-col :span="6" class="item">
          <div class="label">关闭日期</div>
          <div class="value">{{ detailData.closeTime }}</div>
        </el-col>
        <el-col :span="24" class="item">
          <div class="label">计划单</div>
          <div class="value">
            <el-radio-group v-model="detailData.isPlanOrder" disabled>
              <el-radio label="true">计划单</el-radio>
              <el-radio label="false">非计划单</el-radio>
            </el-radio-group>
          </div>
        </el-col>
      </el-row>
    </div>

    <div class="main-title">
      <div class="title">货品信息</div>
    </div>

    <div class="table" style="margin-top: 20px">
      <el-table
        :data="detailData.items"
        element-loading-text="Loading"
        border
        fit
        highlight-current-row
        stripe
        max-height="400"
        show-summary
        :summary-method="$getSummaries"
      >
        <el-table-column align="center" label="序号" type="index" width="50" />
        <el-table-column align="left" label="引用记录" prop="useRefCount" min-width="100" show-overflow-tooltip />
        <el-table-column align="left" label="销售类型" prop="saleTypeName" min-width="100" show-overflow-tooltip />
        <el-table-column align="left" label="物料编码" prop="materialNumber" min-width="120" show-overflow-tooltip />
        <el-table-column align="left" label="产品编码" prop="materialOldNumber" min-width="120" show-overflow-tooltip />
        <el-table-column align="left" label="产品名称" prop="materialName" min-width="160" show-overflow-tooltip />
        <el-table-column align="left" label="规格型号" prop="specification" min-width="350" show-overflow-tooltip />
        <el-table-column align="left" label="单位" prop="unit" min-width="100" show-overflow-tooltip />
        <el-table-column align="right" label="单价" prop="price" min-width="100" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.price | numToFixed }}
            <!-- <el-input v-model="scope.row.price" size="small" type="number" @mousewheel.native.prevent></el-input> -->
          </template>
        </el-table-column>
        <el-table-column align="right" label="工程登录数量" prop="enginNum" min-width="100" show-overflow-tooltip />
        <el-table-column align="right" label="数量" prop="number" min-width="100" show-overflow-tooltip />
        <el-table-column align="right" label="订单金额" prop="totalAmount" min-width="100" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.totalAmount | numToFixed }}
          </template>
        </el-table-column>
        <el-table-column
          align="left"
          label="返利类型"
          prop="customerWalletName2"
          min-width="100"
          show-overflow-tooltip
        />
        <el-table-column
          align="right"
          label="使用返利金额"
          prop="payRebateAmount"
          min-width="100"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            {{ scope.row.payRebateAmount | numToFixed }}
          </template>
        </el-table-column>
        <el-table-column align="right" label="返利比例" min-width="100" prop="rebateRate" show-overflow-tooltip />

        <el-table-column align="right" label="格力折扣" prop="discAmount" min-width="100" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.discAmount | numToFixed }}
          </template>
        </el-table-column>
        <el-table-column
          align="left"
          label="现金钱包"
          prop="customerWalletName"
          min-width="100"
          show-overflow-tooltip
        />
        <el-table-column align="right" label="实付金额" prop="payAmount" min-width="100" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.payAmount | numToFixed }}
          </template>
        </el-table-column>
        <el-table-column align="left" label="是否直调" prop="isDirectTransfer" min-width="100" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.isDirectTransfer ? '是' : '否' }}
          </template>
        </el-table-column>
        <el-table-column
          align="right"
          label="直调数量"
          prop="directTransferQty"
          min-width="100"
          show-overflow-tooltip
        />
        <el-table-column align="right" label="已发货数量" prop="hasSendQty" min-width="100" show-overflow-tooltip />
        <el-table-column align="left" label="备注" prop="remark" min-width="160" show-overflow-tooltip />
        <el-table-column align="left" label="税率" prop="tax" min-width="100" show-overflow-tooltip />
        <el-table-column align="left" label="仓库" prop="correspondName" min-width="100" show-overflow-tooltip />
      </el-table>
    </div>

    <div class="main-title">
      <div class="title">审批信息</div>
    </div>
    <div class="diy-table-1">
      <el-row :gutter="0">
        <el-col :span="12" class="item">
          <div class="label">审批人</div>
          <div class="value">{{ userName }}</div>
        </el-col>
        <el-col :span="12" class="item">
          <div class="label">审批日期</div>
          <div class="value">{{ getDate() }}</div>
        </el-col>
        <el-col :span="24" class="item">
          <div class="label">审批说明</div>
          <div class="value">
            <el-input v-model="examineForm.remark" placeholder="请输入审批说明" />
          </div>
        </el-col>
      </el-row>
    </div>

    <div class="page-footer">
      <div class="footer">
        <el-button type="primary" @click="clickSubmitForm(1)">审批通过</el-button>
        <el-button type="warning" @click="clickSubmitForm(0)">审批驳回</el-button>
        <el-popconfirm title="确定关闭吗？" style="margin-left: 10px" @onConfirm="goBack">
          <el-button slot="reference">返回列表</el-button>
        </el-popconfirm>
      </div>
    </div>
  </div>
</template>

<script>
import { getOrderDetail, examineCom } from '@/api/supply/engin'

export default {
  name: 'CommerceExamine',
  componentName: 'CommerceExamine',
  filters: {
    statusFilter(val) {
      const statusList = [
        { label: '已保存', value: 'SAVE' },
        { label: '待审核', value: 'WAIT' },
        { label: '审核通过', value: 'OK' },
        // { label: '审核驳回', value: 'FAIL' },,
        { label: '已关闭', value: 'CLOSE' }
      ]
      const obj = statusList.find(o => o.value == val)
      return obj ? obj.label : ''
    }
  },
  props: ['listItem'],
  data() {
    return {
      userName: JSON.parse(localStorage.getItem('supply_user')).nickName,
      detailData: {},

      formLoading: false,
      examineForm: {
        remark: ''
      }
    }
  },

  created() {
    this.getDetail()
  },

  methods: {
    getDate() {
      var date = new Date()
      var seperator1 = '-'
      var year = date.getFullYear()
      var month = date.getMonth() + 1
      var strDate = date.getDate()
      if (month >= 1 && month <= 9) {
        month = '0' + month
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = '0' + strDate
      }
      var currentdate = year + seperator1 + month + seperator1 + strDate
      return currentdate
    },

    // 返回列表
    goBack() {
      this.$emit('backListFormDetail')
    },

    // 获取详情
    getDetail() {
      getOrderDetail({ id: this.listItem.parentId }).then(res => {
        if (res.data.items) {
          res.data.items.forEach(item => {
            item.number = (item.qty * 100 - item.retiredQty * 100) / 100
            item.sums1 = ['number', 'directTransferQty', 'qty', 'enginNum', 'refundableQty', 'tdQty']
            item.sums2 = ['totalAmount', 'payAmount', 'price', 'payRebateAmount', 'discAmount']
            item.correspondName = res.data.correspondName
          })
        }
        res.data.isPlanOrder = String(res.data.isPlanOrder)

        this.detailData = res.data

        this.examineForm.remark = res.data.examineNote
      })
    },

    // 审批
    clickSubmitForm(val) {
      this.$confirm('此操作将审批订单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          const params = this.detailData
          params.examineNote = this.examineForm.remark
          params.examineResult = val
          examineCom(params).then(res => {
            this.$successMsg()
            this.goBack()

          })
        })
        .catch(() => {})
    }
  }
}
</script>

<style scoped lang="scss">
.detail-container {
  width: 100%;
  height: 100%;
}
.main-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  height: 60px;
  border-bottom: 1px solid #dcdfe6;
  margin-bottom: 20px;
  .title {
    font-size: 16px;
    font-weight: 600;
    padding-left: 10px;
  }
}
</style>
