‘<!--
  @description:订单列表-查看功能/编辑作废
  @author: 苏志刚/wxy
  @routerPath:/procurement/procurementOrderNotarize
  @date： 2020-07-08 10:41:12
-->
<template>
  <div v-loading="loading" class="p0-16">
    <section class="title title_border">
      <i class="iconfont icon-fanhui pointer" @click="back()" />
      查看订单
    </section>
    <el-form ref="ruleForm" :model="formData" :rules="rules">
      <!-- 订单基本信息  isEdit 00 可编辑-->
      <procurementOrderBase
        v-if="orderInfo.tenderId"
        :order-project-click="orderProjectClick"
        :order-supplier-click="orderSupplierClick"
        :order-info-base="orderInfo"
        :is-edit="'00'"
      />
      <!-- 行项目列表 -->
      <procurementOrderLineItemComp
        ref="procurementOrderLineItemComp"
        :line-item-info-list="tenderMaterielInfoList"
        :line-item-other="lineItemOther"
      />
      <p v-if="this.$route.params.status === '01' || this.$route.params.status === '00'" class="page-title">
        6.审核消息
      </p>
      <section v-if="this.$route.params.status === '01' || this.$route.params.status === '00'" class="mb16">
        <!-- 审核信息组件 -->
        <procurementAuditList :audit-list="procurementSignUpAuditList" />
      </section>
      <!-- 操作状态作废 00 -->
      <p v-if="this.$route.params.linkStatus === '00'" class="page-title">
        7.作废
      </p>
      <div v-if="this.$route.params.linkStatus === '00'" class="mb16">
        <table class="from_table">
          <tr class="singleRow">
            <td>
              <el-form-item label="作废原因" prop="abolishReason" />
            </td>
            <td colspan="3">
              <el-input
                v-model="formData.abolishReason"
                :autosize="{ minRows: 3, maxRows: 3 }"
                type="textarea"
                maxlength="1000"
                show-word-limit
                style="width: 96%"
                placeholder="允许输入1000个汉字"
              />
            </td>
          </tr>
          <tr class="singleRow">
            <td>附件说明</td>
            <td colspan="3">
              <upload
                ref="upload"
                :data="abolishData"
                :auto-delete="true"
                :auto-upload="true"
                tip-text="上传附件格式（*.doc;*.docx;*.pdf;*.png;*.jpg;*.zip;*.jpeg;*.txt;*.xlsx;*.xls;*.ppt;*.pptx;*.rar）"
                accept=".doc,.docx,.pdf,.png,.jpg,.zip,.jpeg,.txt,.xlsx,.xls,.ppt,.pptx,.rar"
                title=""
                file-ref="fileRef"
              />
            </td>
          </tr>
        </table>
      </div>
      <!-- 订单状态  08 -->
      <p v-if="this.$route.params.orderStatus === '08'" class="page-title">
        7.作废
      </p>
      <div v-if="this.$route.params.orderStatus === '08'" class="mb16">
        <table class="from_table">
          <tr class="singleRow">
            <td>
              作废原因
            </td>
            <td colspan="3">
              {{ orderInfo.abolishReason }}
            </td>
          </tr>
          <tr class="singleRow">
            <td>附件说明</td>
            <td colspan="3">
              <downloadFile :data="abolishData" />
            </td>
          </tr>
        </table>
      </div>
    </el-form>
    <!--确认订单操作按钮-->
    <!-- status 03 供应商桌面 orderStatus 订单状态  04 未审核/未接单 -->
    <div v-if="this.$route.params.status === '03' && orderInfo.orderStatus === '04'" class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <el-button type="primary" :loading="confirmLoading" @click="confirmOrder">
            确认接单
          </el-button>
        </div>
      </div>
    </div>
    <!-- status 02 供应商 orderStatus 订单状态  04 未审核/未接单 -->
    <div v-if="this.$route.params.status === '02' && orderInfo.orderStatus === '04'" class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <el-button type="primary" :loading="confirmLoading" @click="confirmOrder">
            确认接单
          </el-button>
        </div>
      </div>
    </div>
    <!--作废操作按钮-->
    <div v-if="this.$route.params.linkStatus === '00'" class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <el-button type="primary" :loading="confirmLoading" @click="cancellationSubmit('ruleForm')">
            提交
          </el-button>
          <el-button @click="back()">
            返回
          </el-button>
        </div>
      </div>
    </div>
    <!-- 查看采购单弹框 -->
    <orderProjectBase :dialog-data="orderProjectDialog" />
    <!-- 查看供应商报价弹框 -->
    <procurementSuplierOffer :dialog-data="orderSupplierDialog" />
  </div>
</template>

<script>
/* api接口*/
import {
  queryProcurementOrderInfo,
  listProcurementOrderProductPages,
  supplierReceivingOrders,
  abolishOrders,
  queryProcurementOrderAudit
} from '@/api/procurement/procurementContract'
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'
import { commonMxin } from '@/mixins/commonMxin'
import { orderManagementGroupMixin } from '../mixins/orderManagementGroupMixins'
import { orderManagementMixins } from '../mixins/orderManagementMixins'
import { filterObj, filterDictText } from '@/assets/js/utils' // 深拷贝
/* 组件*/
import upload from '@comp/common/updownload/upload' // 文件上传组件
import downloadFile from '@comp/common/updownload/downloadFile'
import procurementOrderBase from './procurementOrderBaseComp' // 订单的基本信息
import procurementOrderLineItemComp from './procurementOrderLineItemTableComp' // 订单行项目列表组件
import procurementAuditList from '@/views/procurement/components/procurementAuditComp/procurementAuditComp-detail' // 审核信息公共组件
import orderProjectBase from './procurementOrderProjectBase-dialog' // 采购单查看弹框
import procurementSuplierOffer from '@/views/procurement/components/procurementLookSupplierOffer-dialog' // 查看供应商报价弹框

/* 公用方法*/
import { characters1_auto } from '@/assets/js/validate'// 校验输入内容
import { moneyFormat } from '@assets/js/utils'// 常用方法
export default {
  name: 'OrderManagementDetail',
  components: {
    downloadFile,
    upload,
    procurementOrderBase,
    procurementOrderLineItemComp, // 订单行项目列表组件
    procurementAuditList, // 订单审核组件
    orderProjectBase, // 订单-查看采购单弹框
    procurementSuplierOffer // 订单-查看供应商报价弹框
  },
  mixins: [
    ListMixin,
    commonMxin,
    orderManagementGroupMixin,
    orderManagementMixins
  ],
  data() {
    return {
      loading: true, // loading加载效果
      confirmLoading: false,
      moneyFormat: moneyFormat, // 金额添加千分位
      tenderMaterielInfoList: [], //
      // 行项目的其他数据
      lineItemOther: {
        currency: '', // 币种
        isEdit: '00' // 是否可编辑 00 是 其他否
      },
      searchForm: {
        isOperation: '', // 业务操作
        orderBy: 0, // 排序
        orderId: this.$route.params.orderId // 订单id
      },
      formData: {
        orderId: this.$route.params.orderId, // 订单id
        abolishReason: '' // 作废原因
      },
      // 采购单查看弹框
      orderProjectDialog: {
        dialog: false,
        tenderId: '' // 项目id
      },
      // 供应商报价单查看弹框
      orderSupplierDialog: {
        dialog: false,
        stageId: '', // 轮次id
        packId: '', // 标段id
        supplierId: '' // 供应商id
      },
      procurementSignUpAuditList: [], // 审核消息列表
      rules: {
        abolishReason: [{ required: true, validator: characters1_auto, trigger: 'blur' }] // 作废原因
      }
    }
  },
  created() {
    this.orderTerms.bizId = this.$route.params.orderId // 订单条款附件id
    this.orderApproval.bizId = this.$route.params.orderId // 订单内部审核附件id
    this.abolishData.bizId = this.$route.params.orderId // 作废附件id
  },
  mounted() {
    // 获取计量单位
    this.initUnit()
    // 查询数据字典
    this.getProcurementOderInfo()
    // 查询字典信息
    this.initWebTypeGroup()
    // 获取订单详情信息
    this.getOrderInfo()
    // 获取审核信息
    this.initAuditList()
  },
  methods: {
    filterDictText, // 引入字典值替换文本通用方法
    // 订单查看采购单事件
    orderProjectClick(tenderId) {
      // 获取项目id
      this.orderProjectDialog.tenderId = tenderId
      // 打开采购单查看弹框
      this.orderProjectDialog.dialog = true
    },
    // 订单查看报价信息事件
    orderSupplierClick(supplierClickType) {
      // 点击查看报价单返回true
      if (supplierClickType) {
        // 获取轮次id
        this.orderSupplierDialog.stageId = this.orderInfo.stageId
        // 获取标段id
        this.orderSupplierDialog.packId = this.orderInfo.packId
        // 获取供应商id
        this.orderSupplierDialog.supplierId = this.orderInfo.winningDepartId
        // 开启弹框
        this.orderSupplierDialog.dialog = true
      }
    },
    // 获取订单详情信息
    getOrderInfo() {
      queryProcurementOrderInfo(this.$route.params.orderId)
        .then(res => {
          this.orderInfo = {
            ...res.data,
            // 订单条款有值复制 无知追加默认
            orderTerms: res.data.orderTerms ? res.data.orderTerms : this.orderClauseContent
          }
          this.orderInfo.orderStatus = this.$route.params.orderStatus
          // 币种
          this.lineItemOther.currency = this.orderInfo.currency
          // 行项目信息
          this.getMaterialInfo()
        })
        .catch(() => {})
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 获取行项目信息
    getMaterialInfo() {
      // 查询条件
      const params = this.getQueryParams()
      listProcurementOrderProductPages(params)
        .then(res => {
          this.tenderMaterielInfoList = res.data.records
          this.loading = false
        })
        .catch(() => {})
    },
    // 获取审核意见列表
    initAuditList() {
      queryProcurementOrderAudit(this.$route.params.orderId).then(res => {
        this.procurementSignUpAuditList = res.data
      })
    },
    // 确认订单
    confirmOrder(row) {
      this.$confirm('确认接受订单吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn'
      }).then(() => {
        this.confirmLoading = true
        supplierReceivingOrders(this.$route.params.orderId).then(res => {
          this.$message({
            type: 'success',
            message: '操作成功',
            onClose: () => {
              this.confirmLoading = false
              // 采购员
              // if (this.$route.params.status === '01') {
              this.$router.push({
                path: '/procurement/procurementOrderList'
              })
              return
            } })
        }).catch(() => {
          this.confirmLoading = false
        })
      }).catch(() => {})
    },
    // 返回按钮
    back() {
      // 供应商桌面
      if (this.$route.params.status === '03') {
        this.$router.push({
          path: '/procurement/procurementDesktopSupplier'
        })
        return
      }
      this.$router.push({
        path: '/procurement/procurementOrderList'
      })
    },
    // 附件上传
    principalFile(file, fileList) {
      this.principalList = fileList
    },
    // 作废订单
    cancellationSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$confirm('确认作废该订单吗？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            confirmButtonClass: 'confirmBtn',
            cancelButtonClass: 'cancelBtn'
          }).then(() => {
            this.confirmLoading = true
            // 调用订单作废请求
            this.orderCancellation(this.formData)
          }).catch(() => {})
        } else {
          this.$message({ type: 'warning', message: '作废原因不能为空' })
          return false
        }
      })
    },
    // 订单作废请求
    orderCancellation(data) {
      abolishOrders(data).then(res => {
        this.confirmLoading = false
        this.$message.success({ message: '操作成功' })
        // 采购员
        this.$router.push({
          path: '/procurement/procurementOrderList'
        })
      }).catch(() => {
        this.confirmLoading = false
      })
    }
  }
}
</script>

<style lang="less" scoped>
</style>
