<template>
  <div class="app-container">
    <el-form :model="form" :rules="rules" ref="form" label-width="100px" label-position="right" size="mini">
      <div class="filter-container clearfix">
        <template v-if="orderCategory == 1">
          <el-button type="primary" size="small" @click="save(1)" :disabled="clickLoading">保存</el-button>
          <el-button type="green" size="small" @click="save(2)" :disabled="clickLoading">保存并提交</el-button>
        </template>
        <template v-else>
          <el-button type="primary" size="small" @click="editOrder(1)" :disabled="clickLoading">修改保存</el-button>
          <el-button type="green" size="small" @click="editOrder(2)" :disabled="clickLoading">修改并提交</el-button>
        </template>
        <el-tag v-if="idOrder" type="success">{{ form.stateMemo }}</el-tag>
        <span v-if="idOrder">
          ({{ orderCode }})<span v-if="form.businessKind==3"
                                 style="display: inline-block;color: red">(补{{ form.rePrintIndex }})</span>
        </span>
        <template v-if="orderCategory != 1">
            <span v-if="form.originFileLink"><el-link
              :href="form.originFileLink"
              target="_blank">{{ form.fileDescription }}</el-link></span>
          <span v-else style="color: red;font-weight: 700">订单未上传原图文件</span>
        </template>
        <el-button type="primary" size="mini" @click="calculatePrice(1)">计算价格</el-button>
      </div>
      <el-row :gutter="20">
        <el-col :span="5">
          <el-form-item label="产品类型">
            <el-input v-model="form.productName" disabled></el-input><!--新建时下拉选择，其他时候不能编辑-->
          </el-form-item>
          <el-form-item label="客户名称">
            <el-input v-show="$route.query.editType!=2" v-model="form.clientName" disabled class="input-with-select">
            </el-input>
            <el-input
              v-show="$route.query.editType==2"
              style="width: 263px"
              v-model="form.clientName"
              disabled
              class="input-with-select"
              @click.native="createInnerVisible = true;innerType = 2;innerTitle ='选择客户'"
            >
              <el-button
                slot="append"
                @click="createInnerVisible = true;innerType = 2;innerTitle ='选择客户'">选择
              </el-button>
            </el-input>
          </el-form-item>
          <el-form-item label="使用预存">
            <el-checkbox :true-label='1' :false-label="0" v-model="form.usePreStore"></el-checkbox>
            <el-tag @click="getBalanceMoney" style="cursor: pointer" size="mini">查看余额</el-tag>
            <span v-show="balanceSpan" style="color: #e4493c">{{balanceMoney}}&nbsp;元</span>
          </el-form-item>
          <el-form-item label="印品名称" prop="orderName">
            <el-input v-model="form.orderName"></el-input>
          </el-form-item>
          <el-form-item label="款数">
            <el-input type="number" @keyup.native="proving($event)" v-model="form.kindCount"></el-input>
          </el-form-item>
          <el-form-item label="需要拍照">
            <el-checkbox :true-label='1' :false-label="0" v-model="form.traceFlag"></el-checkbox>
          </el-form-item>
          <el-form-item label="印刷要求">
            <el-select
              multiple
              style="width: 100%"
              v-model="printRequireOption">
              <el-option
                v-for="item in printRequireOptions"
                :key="item.id"
                :label="item.dictLabel"
                :value="item.dictValue">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="成品裁切" prop="cutKind">
            <el-select
              style="width: 100%;"
              collapse-tags
              v-model="form.cutKind">
              <el-option
                v-for="item in orderPrintOptions"
                :key="item.id"
                :label="item.dictLabel"
                :value="item.dictValue">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="生产备注">
            <el-input type="textarea" :rows='6' v-model="form.orderMemo"></el-input>
          </el-form-item>
          <el-form-item label="用纸要求">
            <el-checkbox :true-label='1' :false-label="0" v-model="form.paperRequireFlag"></el-checkbox>
          </el-form-item>
          <el-form-item label="包装要求" prop="boxRequire">
            <el-select
              style="width: 100%;"
              collapse-tags
              v-model="form.boxRequire">
              <el-option
                v-for="item in packingMethodOptions"
                :key="item.id"
                :label="item.dictLabel"
                :value="item.dictValue">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="打包方式">
            <el-select
              style="width: 100%;"
              collapse-tags
              v-model="form.packKind">
              <el-option
                label="均匀打包"
                :value="0">
              </el-option>
              <el-option
                label="按要求打包"
                :value="1">
              </el-option>
            </el-select>
          </el-form-item>
          <template v-if="form.packKind == 1">
            <el-form-item label="打包要求">
              <el-button size="mini" type="green" @click="addPackRequire">增加</el-button>
              <el-table border :data="packrequireList" size="mini">
                <el-table-column label="包数" prop="packNum">
                  <template slot-scope="{row}">
                    <el-input
                      type="number"
                      @keyup.native="proving($event)"
                      v-model="row.packNum"
                      size="mini"></el-input>
                  </template>
                </el-table-column>
                <el-table-column label="每包数量" prop="countNum">
                  <template slot-scope="{row}">
                    <el-input
                      @keyup.native="proving($event)"
                      type="number"
                      v-model="row.countNum"
                      size="mini"></el-input>
                  </template>
                </el-table-column>
                <el-table-column label="总数">
                  <template slot-scope="{row}">
                    <span>{{ parseInt(row.packNum) * parseInt(row.countNum) }}</span>
                  </template>
                </el-table-column>
              </el-table>
            </el-form-item>
          </template>
        </el-col>
        <el-col :span="19">

          <el-tabs type="border-card">
            <el-tab-pane label="部件信息">
              <div>
                <span>共计<span>{{ partListNew.length }}</span>个部件</span>
                <el-button v-if="productInfo.length == 1" type="primary" size="small" @click="addPartBtn(0)">增加部件
                </el-button>
                <el-dropdown v-else @command="addPartBtn">
                  <el-button size="mini" type="primary">
                    增加部件<i class="el-icon-arrow-down el-icon--right"></i>
                  </el-button>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item v-for="(info,infoIndex) in productInfo" :key="infoIndex" :command="infoIndex">
                      {{ info.partName }}
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
                <span class="box-header-right" @click="closeAll">全部折叠</span><span class="box-header-right"
                                                                                  @click="openAll">全部展开</span>
              </div>
              <div style="clear: both"></div>
              <div class="partInfoList" style="max-height: 690px;overflow: scroll">
                <el-card class="box-card" v-for="(item,index1) in partListNew">
                  <div slot="header" class="clearfix">
                    <span class="box-header-title">{{ form.productName }} - {{ item.partName }}</span>
                    <i class="box-header-icon el-icon-caret-top" @click="unfold($event,index1,2)"></i>
                    <span class="box-header-right" @click="removePartInfo(index1)">删除</span>
                    <span class="box-header-right" @click="copyPartInfo(index1)">复制</span>
                  </div>
                  <div class="box-content" :id="index1">
                    <el-form :inline="true" size="mini">
                      <el-form-item label="部件名称">
                        <el-input v-model="item.partName"></el-input>
                      </el-form-item>
                      <el-form-item label="出血">
                        <el-input oninput="if(!/^[0-9]+$/.test(value)) value=value.replace(/\D/g,'');if(value>9)value=9;if(value<=0)value=''" v-model="item.bloodValue" type="number" style="width: 80%"></el-input>
                        (mm)
                      </el-form-item>
                    </el-form>
                    <el-card class="box-card">
                      <div slot="header" class="clearfix">
                        <span>部件参数</span>
                      </div>
                      <el-table
                        :header-cell-style="{background:'#eef1f6',color:'#606266'}"
                        :data="[1]"
                        size="small"
                        style="width: 100%"
                        border
                        @row-click="handleCurrentChange">
                        <template v-for="(parameter,index2) in item.paramValueList">
                          <template>
                            <el-table-column
                              :key="index2"
                              :label="parameter.parameterName">
                              <template scope="scope">
                                <template v-if="parameter.selectKind == 0">
                                  <template v-if="parameter.productParameter.fieldType == 2">
                                    <el-input size="small" type="number" v-model="parameter.paramValue"></el-input>
                                  </template>
                                  <template v-else-if="parameter.productParameter.fieldType == 3">
                                    <el-input size="small" type="number" v-model="parameter.paramValue"></el-input>
                                  </template>
                                  <template v-else-if="parameter.productParameter.fieldType == 1">
                                    <el-input size="small" maxlength="20" type="text" v-model="parameter.paramValue"></el-input>
                                  </template>
                                  <template v-else-if="parameter.productParameter.fieldType == 6">
                                    <el-input size="small" v-model="parameter.paramValue"
                                              @blur="verifies1(parameter.paramValue,parameter.parameterName)"></el-input>
                                  </template>
                                  <template v-else-if="parameter.productParameter.fieldType == 7">
                                    <el-input size="small" v-model="parameter.paramValue"
                                              @blur="verifies2(parameter.paramValue,parameter.parameterName)"></el-input>
                                  </template>
                                  <template v-else>
                                    <el-input  size="small" type="number" v-model="parameter.paramValue"></el-input>
                                  </template>
                                </template>
                                <template v-if="parameter.selectKind == 2">
                                  <el-select
                                    v-model="parameter.paramValue"
                                    filterable
                                    :placeholder="parameter.placeHolder"
                                    @input.native="selectBlur1($event,index1,index2)">
                                    <el-option
                                      v-for="item in parameter.itemList"
                                      :key="item.id"
                                      :label="item.itemName"
                                      :value="item.itemValue"></el-option>
                                  </el-select>
                                </template>
                                <template v-if="parameter.selectKind == 3">
                                  <el-select v-model="parameter.paramValue" placeholder="请选择"
                                             @change="parameterSelect($event,index1,index2)">
                                    <el-option
                                      v-for="item in parameter.itemList"
                                      :key="item.id"
                                      :label="item.itemName"
                                      :value="item.itemValue"></el-option>
                                  </el-select>
                                </template>
                                <template v-if="parameter.selectKind == 4">
                                  <template v-if="parameter.productParameter.fieldType == 4">
                                    <!--弹窗选择纸张档案-->
                                    <el-button @click="parameterChoose(index1,index2,1,'选择纸张档案')">
                                      {{ parameter.paramDisplay ? parameter.paramDisplay : '选择纸张档案' }}
                                    </el-button>
                                  </template>
                                  <template v-else-if="parameter.productParameter.fieldType == 5">
                                    <!--弹窗选择辅料档案-->
                                    <el-button @click="parameterChoose(index1,index2,2,'选择辅料档案')">
                                      {{ parameter.paramDisplay ? parameter.paramDisplay : '选择辅料档案' }}
                                    </el-button>
                                  </template>
                                </template>
                              </template>
                            </el-table-column>
                          </template>
                        </template>
                      </el-table>
                    </el-card>
                    <el-card class="box-card">
                      <div slot="header" class="clearfix">
                        <span>部件工序</span>
                      </div>
                      <el-button type="green" size="small" @click="addProcess(index1)">增加工序</el-button>
                      <el-table
                        :header-cell-style="{background:'#eef1f6',color:'#606266'}"
                        :data="partProcessList[index1]"
                        class="tb-edit"
                        style="width: 100%;margin-top: 10px"
                        border
                        :ref="'partProcess'+index1"
                        highlight-current-row
                        @selection-change="!bInRemoving && handleSelectionChange($event,index1)"
                        @row-click="handleCurrentChange">
                        <el-table-column
                          type="selection"
                          :selectable="checkSelectable"
                          width="55">
                        </el-table-column>
                        <el-table-column
                          label="工序"
                          width="120"
                          prop="processName">
                          <template scope="scope">
                            <span>{{ scope.row.processName }}</span>
                          </template>
                        </el-table-column>
                        <el-table-column
                          prop="idMaterial"
                          label="工序物料"
                          width="450"
                          show-overflow-tooltip>
                          <template scope="scope">
                            <el-button @click="processChoose(index1,scope.$index,scope.row)">
                              {{ scope.row.materialName ? scope.row.materialName : '请选择辅料' }}
                            </el-button>
                            <el-button size="mini" v-if="scope.row.idMaterial" type="danger"
                                       @click="scope.row.materialName='';scope.row.idMaterial=0">取消选择
                            </el-button>
                          </template>
                        </el-table-column>
                        <el-table-column
                          prop="processMemo"
                          label="工序说明"
                          show-overflow-tooltip>
                          <template scope="scope">
                            <el-input
                              size="small"
                              v-model="scope.row.processMemo"
                              @change="handleEdit(scope.$index, scope.row)"></el-input>
                            <span>{{ scope.row.processMemo }}</span>
                          </template>
                        </el-table-column>
                        <el-table-column
                          prop="obvRevId"
                          width="180"
                          label="工序位置"
                          show-overflow-tooltip>
                          <template scope="scope">
                            <el-select v-model="scope.row.obvRevId" placeholder="请选择">
                              <el-option
                                v-for="item in obvRevIdOptions"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                              </el-option>
                            </el-select>

                            <template v-if="scope.row.obvRevId == 1">
                              <span>正面</span>
                            </template>
                            <template v-else-if="scope.row.obvRevId == 2">
                              <span>反面</span>
                            </template>
                          </template>
                        </el-table-column>
                        <el-table-column
                          prop="processQty"
                          label="工序数量"
                          show-overflow-tooltip>
                          <template scope="scope">
                            <el-input
                              size="small"
                              type="number"
                              v-model="scope.row.processQty"></el-input>
                            <span>{{ scope.row.processQty }}</span>
                          </template>
                        </el-table-column>
                        <!--                  <el-table-column-->
                        <!--                    prop="processMoney"-->
                        <!--                    label="工序价格"-->
                        <!--                    show-overflow-tooltip>-->
                        <!--                    <template scope="scope">-->
                        <!--                      <el-input-->
                        <!--                        size="small"-->
                        <!--                        v-model="scope.row.processMoney"-->
                        <!--                        @change="handleEdit(scope.$index, scope.row)"></el-input>-->
                        <!--                      <span>{{ scope.row.processMoney }}</span>-->
                        <!--                    </template>-->
                        <!--                  </el-table-column>-->
                        <!--                  <el-table-column-->
                        <!--                    prop="processPrice"-->
                        <!--                    label="工序单价"-->
                        <!--                    show-overflow-tooltip>-->
                        <!--                    <template scope="scope">-->
                        <!--                      <el-input-->
                        <!--                        size="small"-->
                        <!--                        v-model="scope.row.processPrice"-->
                        <!--                        @change="handleEdit(scope.$index, scope.row)"></el-input>-->
                        <!--                      <span>{{ scope.row.processPrice }}</span>-->
                        <!--                    </template>-->
                        <!--                  </el-table-column>-->
                        <!--                  <el-table-column-->
                        <!--                    prop="processRule"-->
                        <!--                    label="工序规格"-->
                        <!--                    show-overflow-tooltip>-->
                        <!--                    <template scope="scope">-->
                        <!--                      <el-input-->
                        <!--                        size="small"-->
                        <!--                        v-model="scope.row.processRule"-->
                        <!--                        @change="handleEdit(scope.$index, scope.row)"></el-input>-->
                        <!--                      <span>{{ scope.row.processRule }}</span>-->
                        <!--                    </template>-->
                        <!--                  </el-table-column>-->
                        <!--                  <el-table-column-->
                        <!--                    prop="materialQty"-->
                        <!--                    label="物料数量"-->
                        <!--                    show-overflow-tooltip>-->
                        <!--                    <template scope="scope">-->
                        <!--                      <el-input-->
                        <!--                        size="small"-->
                        <!--                        v-model="scope.row.materialQty"-->
                        <!--                        @change="handleEdit(scope.$index, scope.row)"></el-input>-->
                        <!--                      <span>{{ scope.row.materialQty }}</span>-->
                        <!--                    </template>-->
                        <!--                  </el-table-column>-->
                      </el-table>
                    </el-card>
                  </div>
                </el-card>
              </div>
            </el-tab-pane>
            <el-tab-pane label="发货/付款信息">

              <el-card class="box-card">
                <div slot="header" class="clearfix">
                  <span class="box-header-title">发货信息</span> &nbsp;&nbsp;
                  <!--            <el-radio-group fill="#E6A23C" v-model="addressType" size="mini">-->
                  <!--              <el-radio-button :label="0">单地址</el-radio-button>-->
                  <!--              <el-radio-button :label="1">多地址</el-radio-button>-->
                  <!--            </el-radio-group>&nbsp;&nbsp;-->
                  <template v-if="orderCategory == 1">
                    <el-button
                      size="mini"
                      type="primary"
                      @click="addressDialog">选择收货地址
                    </el-button>&nbsp;&nbsp;
                    <el-button size="mini" v-if="addressType == 1" @click="addAddressItem">增加地址</el-button>
                  </template>
                  <el-form
                    :model="form"
                    :rules="rules"
                    :inline="true"
                    label-width="100px"
                    label-position="right"
                    size="mini"
                    style="display: initial">
                    <el-form-item label="交货时间" class="itemlabel" prop="deliverDate">
                      <el-date-picker
                        v-model.trim="form.deliverDate"
                        type="date"
                        :editable="false"
                        value-format='yyyy-MM-dd'
                        placeholder="选择日期"
                        align="right"
                        @change="mentChange"
                        :picker-options="pickerOptions"
                        style="margin-top: 5px;width: 140px">
                      </el-date-picker>
                    </el-form-item>
                    <el-form-item label="" class="itemlabel">
                      <el-input disabled style="margin-top: 5px" v-model.trim="form.deliverTime" placeholder="时间"></el-input>
                    </el-form-item>
                    <el-form-item>
                      <el-button
                        style="margin-top: 5px"
                        @click="calcSendDate">计算时间
                      </el-button>
                    </el-form-item>
                  </el-form>
                  <template v-if="orderCategory == 1">
                    <el-input type="textarea" size="mini" style="width: 50%" placeholder="粘贴地址" v-model="parseAddress"
                              clearable></el-input>
                    <el-button size="mini" type="green" @click="parseAddressBtn">识别</el-button>
                  </template>
                  <i class="box-header-icon el-icon-caret-top" @click="unfold($event,'shippingInfo',2)"></i>
                </div>
                <div class="box-content" id="shippingInfo">

                  <el-row :gutter="20" v-if="orderCategory == 1">
                    <template v-if="addressType == 0">
                      <el-form
                        :model="sendAddressList[0]"
                        :rules="rules"
                        label-width="100px"
                        label-position="right"
                        size="mini">
                        <el-row>
                          <el-col :span="6">
                            <el-form-item label="联系人">
                              <el-input v-model="sendAddressList[0].linkMan" placeholder="请输入联系人"></el-input>
                            </el-form-item>
                          </el-col>
                          <el-col :span="6">
                            <el-form-item label="联系电话">
                              <el-input v-model="sendAddressList[0].linkPhone" placeholder="请输入联系电话"></el-input>
                            </el-form-item>
                          </el-col>
                          <el-col :span="6">
                            <el-form-item label="发货方式">
                              <el-select
                                v-model="sendAddressList[0].sendKind"
                                filterable
                                placeholder="请选择"
                                style="width: 100%">
                                <el-option
                                  v-for="item in sendKinds"
                                  :key="item.id"
                                  :label="item.modeName"
                                  :value="item.modeName">
                                </el-option>
                              </el-select>
                            </el-form-item>
                          </el-col>
                          <!--                      <el-col :span="6">-->
                          <!--                        <el-form-item label="发货区域">-->
                          <!--                          <el-select v-model="sendAddressList[0].sendRegion" placeholder="请选择" style="width: 100%">-->
                          <!--                            <el-option-->
                          <!--                              v-for="item in shipAreaList"-->
                          <!--                              :key="item.id"-->
                          <!--                              :label="item.areaName"-->
                          <!--                              :value="item.areaName">-->
                          <!--                            </el-option>-->
                          <!--                          </el-select>-->
                          <!--                        </el-form-item>-->
                          <!--                      </el-col>-->

                        </el-row>
                        <el-row>
                          <!--                      <el-col :span="12">-->
                          <!--                        <el-form-item label="二次交货时间">-->
                          <!--                          <el-date-picker-->
                          <!--                            v-model="form.reSecondaryDate"-->
                          <!--                            type="datetime"-->
                          <!--                            placeholder="选择日期时间"-->
                          <!--                            align="right"-->
                          <!--                            :picker-options="pickerOptions"-->
                          <!--                            style="width: 100%">-->
                          <!--                          </el-date-picker>-->
                          <!--                        </el-form-item>-->
                          <!--                      </el-col>-->
                          <el-col :span="10">
                            <el-form-item label="省市区">
                              <el-cascader
                                style="width: 90%"
                                size="mini"
                                filterable
                                :options="option"
                                v-model="addressOption[0]"
                                @change="changeAddress($event,0)"
                              >
                              </el-cascader>
                            </el-form-item>
                          </el-col>
                          <el-col :span="12">
                            <el-form-item label="详细地址">
                              <el-input v-model="sendAddressList[0].sendAddress"></el-input>
                            </el-form-item>
                          </el-col>
                        </el-row>
                      </el-form>
                    </template>
                    <template v-else>
                      <!--                  <el-form v-for="(sendAddressInfo) in sendAddressList" :model="sendAddressInfo" :rules="rules" label-width="100px" label-position="right" size="mini">-->
                      <el-table
                        v-if="orderCategory == 1"
                        :header-cell-style="{background:'#eef1f6',color:'#606266'}"
                        class="tb-edit"
                        :data="sendAddressList"
                        style="width: 100%"
                        border
                        highlight-current-row
                        @row-click="currentAddress">
                        <el-table-column
                          prop="linkMan"
                          label="联系人"
                          width="100px"
                          show-overflow-tooltip>
                          <template scope="scope">
                            <el-input
                              size="small"
                              v-model="scope.row.linkMan"
                              @change="handleEdit(scope.$index, scope.row)"></el-input>
                            <span>{{ scope.row.linkMan }}</span>
                          </template>
                        </el-table-column>
                        <el-table-column
                          prop="linkPhone"
                          label="联系电话"
                          width="150px"
                          show-overflow-tooltip>
                          <template scope="scope">
                            <el-input
                              size="small"
                              v-model="scope.row.linkPhone"
                              @change="handleEdit(scope.$index, scope.row)"></el-input>
                            <span>{{ scope.row.linkPhone }}</span>
                          </template>
                        </el-table-column>
                        <el-table-column
                          label="发货方式"
                          width="230px"
                          show-overflow-tooltip>
                          <template scope="scope">
                            <el-select
                              size="small"
                              v-model="scope.row.sendKind"
                              filterable
                              @change="sendKindChange(scope.row.sendKind)"
                              placeholder="请选择"
                              style="width: 120px;display: inline-block">
                              <template v-if="!scope.row.sendType">
                                <el-option
                                  v-for="item in sendKinds"
                                  :key="item.id"
                                  :label="item.modeName"
                                  :value="item.modeName">
                                </el-option>
                              </template>
                              <template v-else>
                                <el-option
                                  v-for="item in sendKinds"
                                  :key="item.id"
                                  :label="item.logisticName"
                                  :value="item.logisticName">
                                </el-option>
                              </template>
                            </el-select>
                            <el-checkbox
                              style="width: 60px;display: inline-block"
                              v-model="scope.row.sendType"
                              @change="chooseLogistics(scope.row)">物流
                            </el-checkbox>
                            <span>{{ scope.row.sendKind }}</span>
                          </template>
                        </el-table-column>
                        <!--                      <el-table-column-->
                        <!--                        prop="addressQty"-->
                        <!--                        label="发货数量"-->
                        <!--                        show-overflow-tooltip>-->
                        <!--                        <template scope="scope">-->
                        <!--                          <el-input-->
                        <!--                            size="small"-->
                        <!--                            v-model="scope.row.addressQty"-->
                        <!--                            @change="handleEdit(scope.$index, scope.row)"></el-input>-->
                        <!--                          <span>{{ scope.row.addressQty }}</span>-->
                        <!--                        </template>-->
                        <!--                      </el-table-column>-->
                        <!--                        <el-table-column-->
                        <!--                          label="发货区域"-->
                        <!--                          width="150px"-->
                        <!--                          show-overflow-tooltip>-->
                        <!--                          <template scope="scope">-->
                        <!--                            <el-select v-model="scope.row.sendRegion" placeholder="请选择" style="width: 100%">-->
                        <!--                              <el-option-->
                        <!--                                v-for="item in shipAreaList"-->
                        <!--                                :key="item.id"-->
                        <!--                                :label="item.areaName"-->
                        <!--                                :value="item.areaName">-->
                        <!--                              </el-option>-->
                        <!--                            </el-select>-->
                        <!--                            <span>{{ scope.row.sendRegion }}</span>-->
                        <!--                          </template>-->
                        <!--                        </el-table-column>-->
                        <el-table-column
                          label="省市区"
                          width="200px"
                          show-overflow-tooltip>
                          <template scope="scope">
                            <el-cascader
                              style="width: 90%"
                              size="mini"
                              filterable
                              :options="option"
                              v-model="addressOption[scope.$index]"
                              @change="changeAddress($event,scope.$index)"
                            >
                            </el-cascader>
                            <span>{{ scope.row.sendProvince }}-{{ scope.row.sendCity }}-{{
                                scope.row.sendDistrict
                              }}</span>
                          </template>
                        </el-table-column>
                        <el-table-column
                          prop="sendAddress"
                          label="详细地址"
                          show-overflow-tooltip>
                          <template scope="scope">
                            <el-input
                              size="small"
                              v-model="scope.row.sendAddress"
                              @change="handleEdit(scope.$index, scope.row)"></el-input>
                            <span>{{ scope.row.sendAddress }}</span>
                          </template>
                        </el-table-column>
                        <el-table-column width="80px" label="操作">
                          <template slot-scope="scope">
                            <el-button
                              size="mini"
                              type="danger"
                              @click="deleteAddressItem(scope.$index)">
                              删除
                            </el-button>
                          </template>
                        </el-table-column>
                      </el-table>
                      <el-table
                        v-if="orderCategory != 1"
                        :header-cell-style="{background:'#eef1f6',color:'#606266'}"
                        :data="form.deliverInformList"
                        style="width: 100%">
                        <el-table-column
                          prop="linkMan"
                          label="收货人"
                          width="100px"
                          show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column
                          prop="linkPhone"
                          label="联系电话"
                          width="150px"
                          show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column
                          label="发货方式"
                          prop="sendKind"
                          width="150px"
                          show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column
                          label="省市区"
                          width="200px"
                          show-overflow-tooltip>
                          <template scope="scope">
                            <span>{{ scope.row.sendProvince }}-{{ scope.row.sendCity }}-{{
                                scope.row.sendDistrict
                              }}</span>
                          </template>
                        </el-table-column>
                        <el-table-column
                          prop="sendAddress"
                          label="详细地址"
                          show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column
                          prop="needDeliverQty"
                          label="发货数量"
                          show-overflow-tooltip>
                        </el-table-column>
                      </el-table>
                      <!--                  </el-form>-->
                    </template>
                    <!--                  <el-col :span="9">-->
                    <!--                    <el-table size="mini" border>-->
                    <!--                      <el-table-column label="每箱数量"></el-table-column>-->
                    <!--                      <el-table-column label="箱数"></el-table-column>-->
                    <!--                    </el-table>-->
                    <!--                  </el-col>-->
                  </el-row>
                  <template v-else>
                    <delivery-notice :deliverDate="form.deliverDate" @handleGet="handleGet" :deliverTime="form.deliverTime" ref="deliveryNotice" :type="1"></delivery-notice>
                  </template>
                </div>
              </el-card>
              <el-form :model="form" :rules="rules" label-width="100px" label-position="right" size="mini">
                <el-card class="box-card">
                  <div slot="header" class="clearfix">
                        <span class="box-header-title">价格信息</span>
                    <el-button type="primary" size="mini" @click="calculatePrice(1)">计算价格</el-button>
                    <i class="box-header-icon el-icon-caret-top" @click="unfold($event,'priceInfo',2)"></i>
                  </div>
                  <div class="box-content" id="priceInfo">
                    <el-row :gutter="20">
                      <el-col :span="12">

                        <el-row>
                          <!--                <el-col :span="4">-->
                          <!--                  <el-form-item label="单价" prop="orderPrice">-->
                          <!--                    <el-input-->
                          <!--                      v-model="form.orderPrice"-->
                          <!--                      placeholder="请输入单价"></el-input>-->
                          <!--                  </el-form-item>-->
                          <!--                </el-col>-->
                          <el-col :span="8">
                            <el-form-item
                              label="总金额"
                              prop="orderMoneyTotal">
                              <el-input
                                v-model="form.orderMoneyTotal"
                                auto-complete="off"
                                type="number"
                                placeholder="请输入总金额"></el-input>
                            </el-form-item>
                            <!--                  <el-form-item-->
                            <!--                    label="总金额"-->
                            <!--                    prop="orderMoneyTotal">-->
                            <!--                    <el-input-->
                            <!--                      v-model="form.orderMoneyTotal"-->
                            <!--                      auto-complete="off"-->
                            <!--                      oninput="value=value.replace(/[^0-9.]/g,'')"-->
                            <!--                      placeholder="请输入总金额"></el-input>-->
                            <!--                  </el-form-item>-->
                          </el-col>
                          <!--                <el-col :span="4">-->
                          <!--                  <el-form-item label="预收款" prop="orderMoneyPre">-->
                          <!--                    <el-input-->
                          <!--                      type="number"-->
                          <!--                      v-model="form.orderMoneyPre"-->
                          <!--                      auto-complete="off"-->
                          <!--                      placeholder="请输入预收款"></el-input>-->
                          <!--                  </el-form-item>-->
                          <!--                </el-col>-->
                          <el-col :span="8">
                            <el-form-item label="印工金额">
                              <el-input
                                v-model="form.orderMoneyPrint"
                                type="number"
                                ></el-input>
                            </el-form-item>
                          </el-col>
                          <el-col :span="8">
                            <el-form-item label="后工金额">
                              <el-input
                                v-model="form.orderMoneyProcess"
                                type="number"
                                ></el-input>
                            </el-form-item>
                          </el-col>
                          <!--                  <el-col :span="4">-->
                          <!--                    <el-form-item label="订单运费" prop="orderMoneySend">-->
                          <!--                      <el-input-->
                          <!--                        v-model="form.orderMoneySend"-->
                          <!--                        oninput="value=value.replace(/[^0-9.]/g,'')"-->
                          <!--                        placeholder="请输入订单运费"></el-input>-->
                          <!--                    </el-form-item>-->
                          <!--                  </el-col>-->
                          <el-col :span="24">
                            <el-form-item label="付款方式">
                              <el-table
                                :data="payType"
                                ref="payTypeTable"
                                class="tb-edit"
                                style="width: 450px;margin-top: 5px"
                                :show-summary="true"
                                :summary-method="getSummaries"
                                border
                                highlight-current-row
                                @row-click="handleCurrentChange">
                                <el-table-column
                                  label="付款方式"
                                  width="120"
                                  prop="name">
                                </el-table-column>
                                <el-table-column
                                  prop="value"
                                  label="金额"
                                  width="120">
                                  <template scope="scope">
                                    <el-input
                                      size="small"
                                      type="number"
                                      v-model="scope.row.value"
                                      @change="handleEdit(scope.$index, scope.row)"></el-input>
                                    <span>{{ scope.row.value }}</span>
                                  </template>
                                </el-table-column>
                                <el-table-column
                                  prop="guarantee"
                                  label="担保人">
                                  <template scope="scope">
                                    <el-input
                                      size="small"
                                      v-model="scope.row.guarantee"
                                      @change="handleEdit(scope.$index, scope.row)"></el-input>
                                    <span>{{ scope.row.guarantee }}</span>
                                  </template>
                                </el-table-column>
                              </el-table>
                            </el-form-item>
                          </el-col>
                        </el-row>
                      </el-col>
                      <el-col :span="12">
                        <el-card v-if="partListNew.length>0">
                          <p v-for=" (part,index) in partListNew" :key="index">
                            [{{ part.partName }}]
                            <template v-for="parameter in part.paramValueList">
                              <label style="color: #20a0ff">{{ parameter.parameterName }}:</label>
                              <span v-if="parameter.fieldType == 6 || parameter.fieldType == 7">{{
                                  parameter.paramValue
                                }}</span>
                              <span v-else-if="parameter.selectKind == 2">{{ parameter.paramValue }}</span>
                              <span v-else>{{ parameter.paramDisplay }}</span>&nbsp;
                            </template>
                            <br>
                            <label style="color: #20a0ff">工艺:</label>
                            <template v-if="part.processList.length>0" v-for="process in part.processList">
                              <span>{{ process.processName }}</span><span
                              v-if="process.materialName">({{ process.materialName }},)</span><span
                              v-if="process.processMemo">({{ process.processMemo }})</span><br>
                            </template>
                          </p>
                        </el-card>
                        <el-card style="margin-top: 10px" v-if="PriceInfo">
                          <p>{{PriceInfo}}</p>
                        </el-card>
                      </el-col>
                    </el-row>
                  </div>
                </el-card>

              </el-form>
            </el-tab-pane>
            <!--      <el-tab-pane label="发货通知信息" v-if="orderCategory != 1">-->
            <!--        <el-table-->
            <!--          :header-cell-style="{background:'#eef1f6',color:'#606266'}"-->
            <!--          :data="form.deliverInformList"-->
            <!--          style="width: 100%">-->
            <!--          <el-table-column-->
            <!--            prop="linkMan"-->
            <!--            label="收货人"-->
            <!--            width="100px"-->
            <!--            show-overflow-tooltip>-->
            <!--          </el-table-column>-->
            <!--          <el-table-column-->
            <!--            prop="linkPhone"-->
            <!--            label="联系电话"-->
            <!--            width="150px"-->
            <!--            show-overflow-tooltip>-->
            <!--          </el-table-column>-->
            <!--          <el-table-column-->
            <!--            label="发货方式"-->
            <!--            prop="sendKind"-->
            <!--            width="150px"-->
            <!--            show-overflow-tooltip>-->
            <!--          </el-table-column>-->
            <!--          <el-table-column-->
            <!--            label="省市区"-->
            <!--            width="200px"-->
            <!--            show-overflow-tooltip>-->
            <!--            <template scope="scope">-->
            <!--              <span>{{scope.row.sendProvince}}-{{scope.row.sendCity}}-{{scope.row.sendDistrict}}</span>-->
            <!--            </template>-->
            <!--          </el-table-column>-->
            <!--          <el-table-column-->
            <!--            prop="sendAddress"-->
            <!--            label="详细地址"-->
            <!--            show-overflow-tooltip>-->
            <!--          </el-table-column>-->
            <!--          <el-table-column-->
            <!--            prop="needDeliverQty"-->
            <!--            label="发货数量"-->
            <!--            show-overflow-tooltip>-->
            <!--          </el-table-column>-->
            <!--        </el-table>-->
            <!--      </el-tab-pane>-->
          </el-tabs>
        </el-col>
      </el-row>

    </el-form>

    <!--复制数量弹窗开始-->
    <el-dialog title="复制部件数量" :close-on-click-modal="false" :visible.sync="copeNumVisible">
      <el-form size="mini">
        <el-form-item label="复制数量">
          <el-input v-model="copeNum" type="number"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="copeNumVisible = false">取 消</el-button>
        <el-button type="primary" @click="copeFun">确 定</el-button>
      </span>
    </el-dialog>
    <!--复制数量弹窗结束-->

    <!--部件参数选择弹窗开始-->
    <el-dialog width="850px" top="20px" :close-on-click-modal="false" :title="dialogTitle" :visible.sync="parameterChooseVisible">
      <!--      <basePaperInfo-->
      <!--        v-if="parameterChooseType == 1"-->
      <!--        :is-choose="true"-->
      <!--        @choosePaper='choosePaper'-->
      <!--        :partId="partId"-->
      <!--        :productId="form.idProduct"-->
      <!--        :key="timer"></basePaperInfo>-->

      <paper-quote
        v-if="parameterChooseType == 1"
        :is-choose="true"
        @choosePaper='choosePaper'
        :partId="partId"
        :productId="form.idProduct"
        :parameterId='parameterId'
        :key="timer"></paper-quote>
      <accessoriesInfo
        v-if="parameterChooseType == 2"
        :is-choose="true"
        @chooseAccessories='chooseAccessoriesByParameter'></accessoriesInfo>
    </el-dialog>
    <!--部件参数选择弹窗结束-->

    <!--增加工序弹窗开始-->
    <el-dialog title="增加工序" width="750px" :visible.sync="processVisible">
      <div style="margin-bottom: 10px">
        <el-input
          @input="processSearchData"
          v-model="processSearch.keyWord"
          placeholder="关键字"
          style="width: 200px;"
          @keyup.enter.native="processSearchData"/>

        <el-button class="filter-item" type="primary" icon="el-icon-search" @click="processSearchData">
          搜索
        </el-button>
      </div>
      <el-table
        :data="processList"
        v-loading="listLoading"
        max-height="600px"
        row-key="id"
        border
        default-expand-all>
        <el-table-column label="操作" align="center" width="80" class-name="small-padding fixed-width">
          <template slot-scope="{row}">
            <el-button @click="addThis(row)" type="primary" size="mini">
              选择
            </el-button>
          </template>
        </el-table-column>
        <el-table-column
          prop="processName"
          label="工序名称">
        </el-table-column>
      </el-table>
      <pagination
        v-show="processListData.total>0"
        :total="processListData.total"
        :page.sync="processListData.page"
        :limit.sync="processListData.pageSize"
        style="margin-top: 10px"
        @pagination="getProcessList"/>
    </el-dialog>
    <!--增加工艺弹窗结束-->

    <el-dialog class="processDialog" width="850px" :close-on-click-modal="false" title="选择工艺"
               :visible.sync="processChooseVisible">
      <select-accessories
        :key="timer" :is-choose="true" @chooseAccessories='chooseAccessories'
        :materialTypeIds='materialTypeIds'></select-accessories>
      <!--      <accessoriesInfo :is-choose="true" @chooseAccessories='chooseAccessories'></accessoriesInfo>-->
    </el-dialog>
    <!--    增加地址-->
    <Addressdny ref="address" :is-choose="true" @chooseAddress='chooseAddress'></Addressdny>

    <el-dialog title="提示" :visible.sync="commitVisible" width="500px">
      <el-form>
        <span>订单文件已处理，请选择文件操作</span>
        <el-form-item>
          <el-radio-group v-model="commitInfo.needImageProcess">
            <el-radio :label="1">文件需要重新处理</el-radio>
            <el-radio :label="2">无需处理文件</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item>
          <el-table size="mini" :data="commitInfo.infoList" border>
            <el-table-column label="处理人" prop="userName"></el-table-column>
            <el-table-column label="处理时间" prop="dispatchTime">
              <template slot-scope="{row}">
                <span v-if="row.dispatchTime">{{ row.dispatchTime |getTime }}</span>
              </template>
            </el-table-column>
            <el-table-column label="订单类型" prop="originFlag">
              <template slot-scope="{row}">
                <span v-if="row.originFlag == 0">本单</span>
                <span v-else>原单</span>
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="commitVisible = false">取 消</el-button>
        <el-button type="primary" @click="commitBtn">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="innerTitle" :append-to-body="true" :visible.sync="createInnerVisible">
      <clientInfo v-if="innerType == 2" :is-choose="true" @chooseClient='chooseClientByPay'></clientInfo>
    </el-dialog>
  </div>
</template>

<script>
import {
  getDetailPrintOrder, getWorkProcessList,
  getProductDetailInfo, getAddressInfo, getshipAreaListInfo, getshipModeListInfo,
  getLogisticsInfoList,
  addPrintOrder, addAndCommitPrintOrder, updatePrintOrder, editAndCommitPrintOrder,
  calcOrderSendDate,
  quotePrintOrder,
  orderFormToken, parseAddress,
  reprintCommitOrder,reprintOrder,getClientBalanceMoneyWeb
} from '@/api/order/orderDetail.js'
import basePaperInfo from '@/views/baseInfo/paper/basePaperInfo'
import accessoriesInfo from '@/views/baseInfo/accessories/accessoriesInfo'
import Pagination from '@/components/Pagination'
import {regionData, CodeToText, TextToCode} from 'element-china-area-data'
import {getDictTypeInfo} from '@/api/productFile/partWorkProcessInfo'
import Addressdny from '@/components/Dialog/Addressdny'
import PaperQuote from '@/views/baseInfo/paperQuote/paperQuote'
import {checkCompleteDispatchOrder} from '@/api/order/tobeReviewed'
import SelectAccessories from "@/views/select/accessoriesInfo";
import {getWorkProcess} from "@/api/productFile/workProcessInfo";
import DeliveryNotice from "@/components/deliveryNotice/deliveryNotice";
import clientInfo from '@/views/doc/client/clientList'

const form = {
  /* 订单信息*/
  businessKind:'',
  fileDescription: '',
  originFileLink: '',
  orderStatePrePay: '',
  voidFlag: '',
  orderState: '', // 订单状态
  orderName: '', // 订单名称
  idProduct: '', // 产品ID
  idClient: '', // 客户id
  clientName: '', // 客户名称
  productName: '', // 产品类型
  productSize: '', // 产品规格
  orderQty: '', // 订单印量
  kindCount: '', // 款数
  printRequire: '', // 印刷要求
  cutKind: '', // 成品裁切
  packRequire: '', // 打包要求
  boxRequire: '', // 包装要求
  packKind: 0, // 打包方式 0均匀打包、1按要求打包
  orderMemo: '', // 订单备注
  orderType: '', // 订单类型
  sendMemo: '', // 发货备注
  deliverDate: '', // 交货日期
  deliverTime:'',//交货时间
  paperRequireFlag: 0,
  traceFlag: 0,
  usePreStore: 0,
  /* 发货信息*/
  sendAddressList: [],

  needImageProcess: 0,
  rePrintNeedImageProcess: 0,

  /* 价格信息*/
  orderMoneyTotal: 0, // 总金额
  orderPrice: 0, // 订单价格
  orderMoneyPre: 0, // 订单定金
  orderMoneyPrint: 0, // 印工金额
  orderMoneyProcess: 0, // 后工金额
  orderMoneySend: '', // 订单运费
  payKind: '', // 付款方式

  // 部件信息
  partList: [],
  versionCode:'',
}

const sendAddressInfo = {
  linkMan: '', // 联系人
  linkPhone: '', // 联系电话
  sendProvince: '', // 发货地址省
  sendCity: '', // 发货地址市
  sendDistrict: '', // 发货地址区
  sendAddress: '', // 详细地址
  sendKind: '', // 发货方式
  sendRegion: '', // 发货区域
  addressQty: '', // 发货数量
  sendType: false
}

const packrequire = {
  packNum: 0,
  countNum: 0
}

export default {
  components: {
    DeliveryNotice,
    SelectAccessories,
    PaperQuote,
    Addressdny,
    Pagination, basePaperInfo, accessoriesInfo,clientInfo
  },
  props: {
    isEdit: {
      type: Boolean,
      default: false
    }
  },
  data() {
    // 验证金额
    const validateMoney = (rule, value, callback) => {
      // console.log(rule)
      // console.log(value)
      if (value == null) {
        callback(new Error('金额不能为空'))
      } else if ((value + '').indexOf('.') == -1) {
        if (typeof value === 'string') {
          value = Number(value)
        }
        value = (value).toFixed(2) // 不足补位
        var name = rule.fullField
        this.form[name] = value
        callback()
      } else if (value.split('.').length > 2) {
        callback(new Error('输入正确格式的金额')) // 防止输入多个小数点
      } else {
        value = Math.round(value * Math.pow(10, 2)) / Math.pow(10, 2) // 四舍五入
        value = Number(value).toFixed(2) // 不足补位
        var name = rule.fullField
        this.form[name] = value
        callback()
      }
    }
    return {
      balanceSpan:false,
      balanceMoney:'',
      innerTitle: '',
      innerType: 2,
      createInnerVisible:false,
      PriceInfo:"",
      valueTime:"",
      formToken: '',
      orderCategory: 1, // 1.新建，2.修改
      editType: 1, //1 正常，2补印
      versionCode:'',
      pageFrom: 0, //0普通 1待编辑页面 2待审核页面
      baseInfo: {},
      idOrder: '',
      dialogStatus: 1, // 1增加，2修改
      dialogTitle: '',
      listLoading: false,
      packrequireList: [], // 打包要求列表
      // 基本信息
      form: Object.assign({}, form),
      // printRequireGroup: [],
      printRequireOptions: [],
      printRequireOption: [],
      orderPrintOptions: [],
      packingMethodOptions: [],
      parameterChooseVisible: false, // 参数选择弹窗
      parameterChooseType: 1,
      parameterList: [],
      parametersearch: {
        keyWord: ''
      },

      processChooseVisible: false, // 工序辅料选择弹窗
      materialTypeIds: '',
      processVisible: false, // 增加工序弹窗
      processList: [],
      processSearch: {
        keyWord: '',
        specialFlag: 1,
        voidFlag: 0
      },

      copeNumVisible: false, // 复制部件数量弹窗
      copeNum: '',
      copeIndex: '', // 复制部件的index值

      // 部件角标
      parameterIndex1: 0,
      parameterIndex2: 0,
      partId: '',
      parameterId: '',
      // 工序
      processIndex: 0,

      name: '',
      // activeNames: ['0_1', '0_2'],

      // 部件
      partList: [],

      // 付款方式
      payType: [
        {
          id: 0,
          name: '现金收款',
          value: '0',
          guarantee: ''
        },
        {
          id: 1,
          name: '物流代收',
          value: '0',
          guarantee: ''
        },
        {
          id: 2,
          name: '担保人',
          value: '0',
          guarantee: ''
        },
        {
          id: 3,
          name: '预存',
          value: '0',
          guarantee: ''
        },
        {
          id: 4,
          name: '预收款',
          value: '0',
          guarantee: ''
        }
      ],
      sums: '',

      // 时间选项快捷方式
      pickerOptions: {
        shortcuts: [{
          text: '今天',
          onClick(picker) {
            picker.$emit('pick', new Date())
          }
        }, {
          text: '明天',
          onClick(picker) {
            const date = new Date()
            date.setTime(date.getTime() + 3600 * 1000 * 24)
            picker.$emit('pick', date)
          }
        }],
        disabledDate(time) {
          // 如果没有后面的-8.64e7就是不可以选择今天的
          return time.getTime() < Date.now() - 8.64e7
        }
      },

      //解析地址
      parseAddress: '',

      // 表格页码
      listData: {
        total: 0,
        page: 1,
        pageSize: 10
      },
      processListData: {
        total: 0,
        page: 1,
        pageSize: 10
      },

      addressType: 1,
      // 发货信息
      sendAddressList: [
        Object.assign({}, sendAddressInfo)
      ],
      // 省市区选项
      addressOption: [],
      // 发货方式
      sendKinds: [],
      // 发货区域
      shipAreaList: [],
      option: regionData,
      selectedOptions: '',
      addressVisible: false,

      // 面数选项
      obvRevIdOptions: [{
        value: 1,
        label: '正面'
      }, {
        value: 2,
        label: '反面'
      }],

      /* 新建订单*/
      // 部件信息
      productInfo: [], // 产品信息
      partListNew: [],
      partProcessList: [], // 部件参数列表
      selectedProcessList: [], // 选中部件参数列表
      bInRemoving: false, // 是否在删除部件事件中

      // 文件上传
      files: [],
      fileList: [],
      fileKind: 0,
      fileDescription: '',
      showUpload: true,

      // 点击等待
      clickLoading: false,

      timer: '',

      commitVisible: false,
      commitInfo: {
        needImageProcess: 1,
        infoList: []
      },
      hasFile: false,
      jsTotalMoney: 0,

      // 验证规则
      rules: {
        orderName: [{required: true, trigger: 'blur', message: '请填写订单名称'}],
        cutKind: [{required: true, trigger: 'blur', message: '请选择'}],
        boxRequire: [{required: true, trigger: 'blur', message: '请选择'}],
        orderMoneyTotal: [{required: true, trigger: 'blur', validator: validateMoney}],
        orderMoneyPre: [{trigger: 'blur', validator: validateMoney}],
        orderMoneyPrint: [{trigger: 'blur', validator: validateMoney}],
        orderMoneyProcess: [{trigger: 'blur', validator: validateMoney}],
        deliverDate: [{required: true, trigger: 'blur', message: '请选择交货时间'}]
      }
    }
  },
  created() {
    this.idOrder = this.$route.query.id
    this.orderCode = this.$route.query.orderCode
    this.editType = this.$route.query.editType
    this.versionCode = this.$route.query.versionCode
    this.pageFrom = this.$route.query.pageFrom
  },
  mounted() {
    this.baseInfo = this.$route.params.info
    // console.log(this.$route.params.info);
    this.orderCategory = this.$route.params.orderCategory
    this.tempRoute = Object.assign({}, this.$route)
    this.init()
    if (this.orderCategory != 1) {
      this.setTagsViewTitle()
    }
    this.getToken()
  },
  watch: {
    // 印刷要求
    printRequireOption(value) {
      this.form.printRequire = value.join(',')
    }
  },
  methods: {
    loadNumber: function (event) {
      var el = event.currentTarget;
      var elValue = el.value;
      var reg = /^((?!0)\d{1,2}|100)$/;
      if (!elValue.match(reg)) {
        elValue = "";
        console.log("b")
        return false;
      } else {
        return true;
      }

    },
    getBalanceMoney(){
      var _that = this;
      _that.balanceSpan = true;
      var data = {
        'idClient': _that.form.idClient
      }
      getClientBalanceMoneyWeb(data).then(response => {
        console.log('getProductInfo', response.data);
        _that.balanceMoney = response.data;
      }).catch(err => {
        // console.log(err);
        _that.$message.error(err)
      })
    },
    chooseClientByPay(data) {
      this.createInnerVisible = false
      // console.log(data);
      this.form.clientName = data.clientName;
      this.form.idClient = data.id;
    },
    handleGet(data){
      var _that = this
      _that.form.deliverDate = data.slice(0,10);
      _that.form.deliverTime = data.slice(11,19);
    },
    mentChange(){
      var _that = this
      _that.$nextTick(function() {
        // console.log(_that.getNewDate());
        _that.form.deliverTime = _that.getNewDate();
      })
    },
    getNewDate(){
      //获取当前时间
      var _this = this;
      let yy = new Date().getFullYear();
      let mm = new Date().getMonth()+1;
      let dd = new Date().getDate();
      let hh = new Date().getHours();
      let mf = new Date().getMinutes()<10 ? '0'+new Date().getMinutes() : new Date().getMinutes();
      let ss = new Date().getSeconds()<10 ? '0'+new Date().getSeconds() : new Date().getSeconds();
      if(hh<10){
        return '0'+hh+':'+mf+':'+'00';
      }else {
        return hh+':'+mf+':'+'00';
      }

    },
    // 设置标签名称
    setTagsViewTitle() {
      const title = this.tempRoute.meta.title
      // console.log("tempRoute2",this.tempRoute);
      const route = Object.assign({}, this.tempRoute, {title: `${title}-${this.orderCode}`})
      // console.log("route",route)
      this.$store.dispatch('tagsView/updateVisitedView', route)
    },
    getToken() {
      orderFormToken().then(res => {
        // console.log(res);
        this.formToken = res.data
      })
    },

    // 初始化页面
    init() {
      var _that = this

      if (_that.orderCategory == 1) {
        _that.form.clientName = _that.baseInfo.clientName
        _that.form.idClient = _that.baseInfo.idClient
        _that.form.orderName = _that.baseInfo.orderName
        _that.form.idProduct = _that.baseInfo.idProduct
        _that.form.productName = _that.baseInfo.productName
        _that.form.orderType = _that.baseInfo.orderType
        _that.form.businessKind = _that.baseInfo.businessKind

        _that.getDefaultAddress()
        _that.getProductInfo()
      } else {
        _that.getInfo()
      }
      _that.balanceMoney=0;
      _that.balanceSpan = false;
      _that.getDictInfo('PrintRequire')
      _that.getDictInfo('OrderPrintDesc')
      _that.getDictInfo('PackingMethod')
      _that.getAreaList()
      _that.getSendKind()
    },

    // 获取订单详情
    getInfo() {
      const _that = this
      if (!_that.idOrder) {
        return
      }
      if (_that.idOrder == undefined) {
        return
      }
      if (_that.idOrder <= 0) {
        return
      }
      var dataParms = {
        'idOrder': _that.idOrder
      }
      getDetailPrintOrder(dataParms).then(response => {
        // console.log('order', response)
        var data = response.data
        if (data.originFileLink) {
          _that.hasFile = true
        } else {
          _that.hasFile = false
        }
        _that.form = {
          /* 订单信息*/
          businessKind: data.businessKind,
          fileDescription: data.fileDescription,
          originFileLink: data.originFileLink,
          orderState: data.orderState,
          versionCode: _that.versionCode,
          stateMemo: data.stateMemo,
          orderStatePrePay: data.orderStatePrePay,
          voidFlag: data.voidFlag,
          orderName: data.orderName, // 订单名称
          orderCode: data.orderCode,
          idProduct: data.idProduct, // 产品ID
          idClient: data.idClient, // 客户id
          clientName: data.clientName, // 客户名称
          productName: data.productName, // 产品类型
          productSize: data.productSize, // 产品规格
          orderQty: data.orderQty, // 订单印量
          kindCount: data.kindCount, // 款数
          printRequire: data.printRequire, // 印刷要求
          cutKind: (data.cutKind).toString(), // 成品裁切
          packKind: data.packKind,
          boxRequire: data.boxRequire,
          orderMemo: data.orderMemo, // 订单备注
          orderType: data.orderType, // 订单类型
          sendMemo: data.sendMemo, // 发货备注
          deliverDate: "", // 交货日期
          deliverTime: "", // 交货时间
          /* 发货信息*/
          sendAddressList: data.sendAddressList,
          /* 价格信息*/
          orderMoneyTotal: data.orderMoneyTotal, // 总金额
          orderPrice: data.orderPrice, // 订单价格
          orderMoneyPre: data.orderMoneyPre, // 订单定金
          orderMoneyPrint: data.orderMoneyPrint, // 印工金额
          orderMoneyProcess: data.orderMoneyProcess, // 后工金额
          orderMoneySend: data.orderMoneySend, // 订单运费
          payKind: data.payKind, // 付款方式
          paperRequireFlag: data.paperRequireFlag,
          traceFlag: data.traceFlag,
          usePreStore: data.usePreStore,

          //补印信息
          needImageProcess: data.needImageProcess,
          rePrintIndex: data.rePrintIndex,

          // 部件信息
          partList: [],
          deliverInformList: data.deliverInformList
        }
        if(data.deliverDate){
          _that.form.deliverDate = data.deliverDate.slice(0,10); // 交货日期
          _that.form.deliverTime = data.deliverDate.slice(11,19); // 交货日期
        }
        if(_that.editType==2){
          _that.form.usePreStore = 0
        }
        if (data.packRequire) {
          var packrequire = data.packRequire.split('+')
          // console.log(packrequire);
          var packrequireList = []
          packrequire.forEach(item => {
            var packrequireItem = {
              packNum: item.split('*')[0],
              countNum: item.split('*')[1]
            }
            packrequireList.push(packrequireItem)
          })
          _that.packrequireList = packrequireList
        }
        _that.partListNew = data.partList
        _that.sendAddressList = data.sendAddressList;
        (data.sendAddressList).forEach(address => {
          var addressOption = []
          // if (address.sendProvince) {
          //   addressOption.push(TextToCode[address.sendProvince].code)
          // }
          // if (address.sendCity) {
          //   addressOption.push(TextToCode[address.sendProvince][address.sendCity].code)
          // }
          // if (address.sendDistrict) {
          //   addressOption.push(TextToCode[address.sendProvince][address.sendCity][address.sendDistrict].code)
          // }
          _that.addressOption.push(addressOption)
        })
        data.partList.forEach(item => {
          _that.partProcessList.push(item.processList)
        })
        if (data.printRequire != '' && data.printRequire != null) {
          _that.printRequireOption = data.printRequire.split(',')
        }
        _that.getProductInfobyEdit()
        // 付款方式
        if (data.payKind) {
          var paykindString = data.payKind
          var paykindList = paykindString.split('+');
          paykindList.forEach(item => {
            var itemList = item.split(':')
            _that.payType[itemList[0]].value = itemList[2]
            // if (itemList[0] == 2) {//by夏玉
            //   _that.payType[itemList[0]].guarantee = itemList[3]
            // }
            _that.payType[itemList[0]].guarantee = itemList[3]
          })
        }

        _that.$nextTick(() => {
          _that.partProcessList.forEach((processList, index) => {
            processList.forEach(process => {
              var name = 'partProcess' + index
              _that.$refs[name][0].toggleRowSelection(process, true)
            })
          })

          _that.$refs.deliveryNotice.currentIdClient = data.idClient
          _that.$refs.deliveryNotice.currentIdOrder = data.id
          _that.$refs.deliveryNotice.openNotices()

        })

      }).catch(err => {
        // console.log(err)

        _that.$message.error(err)
      })
    },

    // 获取产品详细信息
    getProductInfo() {
      const _that = this
      var data = {
        'idProduct': _that.baseInfo.idProduct
      }
      getProductDetailInfo(data).then(response => {
        // console.log('getProductInfo', response)
        var res = response.data
        _that.productInfo = res.partInfoList
        var partList = _that.createPartArr()
        _that.partListNew = partList
        // console.log(_that.partListNew)
        _that.$nextTick(() => {
          _that.partProcessList.forEach((processList, index) => {
            // console.log(processList);
            processList.forEach(process => {
              if (process.isRequired == 0) {
                var name = 'partProcess' + index
                _that.$refs[name][0].toggleRowSelection(process, true)
              }
            })
          })
        })
      }).catch(err => {
        // console.log(err);
        _that.$message.error(err)
      })
    },
    getProductInfobyEdit() {
      const _that = this
      var data = {
        'idProduct': _that.form.idProduct
      }
      getProductDetailInfo(data).then(response => {
        // console.log('productInfo', response)
        var res = response.data
        _that.productInfo = res.partInfoList
      }).catch(err => {
        _that.$message.error(err)
      })
    },
    // 勾选置灰
    checkSelectable(row) {
      // console.log(row);
      if (row.isRequired == 0) {
        return false
      } else {
        return true
      }
    },
    // 重组部件数组
    createPartArr() {
      const _that = this
      var partInfoList = _that.productInfo
      var partList = []

      for (let i = 0; i < partInfoList.length; i++) {
        var partItem = {
          'idPart': partInfoList[i].id,
          'partName': partInfoList[i].partName,
          'bloodValue': partInfoList[i].partBlood,
          'originFile': '',
          'paramValueList': [],
          'processList': []
        }

        // 工序
        var workProcessList = partInfoList[i].workProcessList
        var processList = []
        var selectedList = []
        // console.log('workProcessList', workProcessList)
        workProcessList.forEach(item => {
          // console.log(item);
          if (item.workProcess.specialFlag == 1) {
            var processItem = {
              'isRequired': item.isRequired,
              'idProcess': item.idWorkProcess,
              'processName': item.workProcess.processName,
              'materialTypeIds': item.workProcess.materialTypeIds,
              'processMemo': '',
              'obvRevId': 1,
              'processPrice': '', // 工序单价、
              'processQty': '',
              'processMoney': '',
              'processRule': '',
              'idMaterial': '',
              'materialName': ''
            }
            processList.push(processItem)
            if (item.isRequired == 0) {
              var selectedItem = processItem
              selectedList.push(selectedItem)
            }
          }
        })
        _that.selectedProcessList.push(selectedList)
        _that.partProcessList.push(processList)
        // console.log('partProcessList', _that.partProcessList)
        // 部件参数
        var parameterInfo = partInfoList[i].parameterList
        parameterInfo.forEach(item => {
          item.paramDisplay = item.defaultValue
          item.paramValue = item.defaultValue
        })
        partItem.paramValueList = JSON.parse(JSON.stringify(parameterInfo))
        // parameterInfo.forEach(item => {
        //   // console.log(item);
        //   if (item.parentId == 0) {
        //     var paramValueItem = {
        //       'idParamter': item.idParameter,
        //       'paramValue': item.defaultValue,
        //       'paramDisplay': '',
        //       'productParameter': item,
        //       'paramterList': item.children,
        //       'selectKind': item.selectKind
        //     }
        //     partItem.paramValueList.push(paramValueItem)
        //   }
        // })
        partList.push(partItem)
        // partList.push(parameterInfo)
        // console.log(partItem);
        // _that.partListNew = partList
      }
      // console.log(partList)
      return partList
    },
    createPartArrByAdd(index) {
      const _that = this
      var partInfoList = _that.productInfo
      var partList = []
      var selectedList = []

      for (let i = 0; i < partInfoList.length; i++) {
        var partItem = {
          'idPart': partInfoList[i].id,
          'partName': partInfoList[i].partName,
          'bloodValue': partInfoList[i].partBlood,
          'originFile': '',
          'paramValueList': [],
          'processList': []
        }
        if (i == index) {
          // 工序
          var workProcessList = partInfoList[i].workProcessList
          var processList = []

          // console.log('workProcessList', workProcessList)
          workProcessList.forEach((item, processIndex) => {
            if (item.workProcess.specialFlag == 1) {
              var processItem = {
                'isRequired': item.isRequired,
                'idProcess': item.idWorkProcess,
                'processName': item.workProcess.processName,
                'materialTypeIds': item.workProcess.materialTypeIds,
                'processMemo': '',
                'obvRevId': 1,
                'processPrice': '', // 工序单价、
                'processQty': '',
                'processMoney': '',
                'processRule': '',
                'idMaterial': '',
                'materialName': ''
              }
              processList.push(processItem)
              if (item.isRequired == 0) {
                var selectedItem = processItem
                selectedList.push(selectedItem)
              }
            }
          })
          // console.log('processList',processList)
          _that.selectedProcessList.push(selectedList)
          _that.partProcessList.push(processList)
          // console.log('partProcessList', _that.partProcessList)
        }
        // 部件参数
        var parameterInfo = partInfoList[i].parameterList
        // console.log('parameterInfo',parameterInfo);
        parameterInfo.forEach(item => {
          item.id = 0
          item.paramDisplay = item.defaultValue
          item.paramValue = item.defaultValue
        })
        partItem.paramValueList = JSON.parse(JSON.stringify(parameterInfo))
        // parameterInfo.forEach(item => {
        //   // console.log(item);
        //   if (item.parentId == 0) {
        //     var paramValueItem = {
        //       'idParamter': item.idParameter,
        //       'paramValue': item.defaultValue,
        //       'paramDisplay': '',
        //       'productParameter': item,
        //       'paramterList': item.children,
        //       'selectKind': item.selectKind
        //     }
        //     // var partParameterItemList = []
        //     // parameterInfo.forEach(childItem => {
        //     //   if (childItem.parentId == item.id) {
        //     //     partParameterItemList.push(childItem)
        //     //   }
        //     // })
        //     // paramValueItem.productParameter['partParameterItemList'] = partParameterItemList
        //     partItem.paramValueList.push(paramValueItem)
        //   }
        // })
        // console.log('partItem',partItem);
        partList.push(partItem)
        // console.log(partItem);
        // _that.partListNew = partList
      }
      return partList
    },

    // 默认发货地址
    getDefaultAddress() {
      // console.log('默认发货地址', this.form)
      var _that = this
      var data = {
        idClient: _that.form.idClient
      }
      getAddressInfo(data).then(response => {
        // console.log('AddressInfo', response)
        const data = response.data
        // //  组合表单数据
        _that.sendAddressList[0].sendKind = data.shipModeName
        _that.sendAddressList[0].sendRegion = data.shipArea
        _that.sendAddressList[0].linkMan = data.receiveMan
        _that.sendAddressList[0].linkPhone = data.receivePhone
        _that.sendAddressList[0].sendAddress = data.address
        _that.sendAddressList[0].sendProvince = data.province
        _that.sendAddressList[0].sendCity = data.city
        _that.sendAddressList[0].sendDistrict = data.area
        var addressOption = []

        if (data.province) {
          addressOption.push(TextToCode[data.province].code)
          addressOption.push(TextToCode[data.province][data.city].code)
          addressOption.push(TextToCode[data.province][data.city][data.area].code)
        }
        _that.addressOption.push(addressOption)
        // console.log(addressOption)
      }).catch(err => {
        // console.log(err)
        _that.$message.error(err)
        _that.sendAddressList = []
      })
    },
    // 获取发货方式
    getSendKind() {
      var _that = this
      getshipModeListInfo().then(response => {
        // console.log('getSendKind', response)
        _that.sendKinds = response.data
      }).catch(err => {
        // console.log(err)
      })
    },
    // 获取物流档案
    getLogisticsInfo() {
      var _that = this
      var data = {
        params: {
          enable: 1
        }
      }
      getLogisticsInfoList(data).then(response => {
        // console.log('getSendKind', response)
        _that.sendKinds = response.data
      }).catch(err => {
        // console.log(err)
      })
    },
    // 获取发货区域
    getAreaList() {
      var _that = this
      getshipAreaListInfo().then(response => {
        // console.log('shipArea', response)
        const data = response.data
        // //  组合表单数据
        _that.shipAreaList = response.data
        // console.log(_that.shipAreaList);
      }).catch(err => {
        // console.log(err)
      })
    },
    // 修改省市区
    changeAddress(value, index) {
      var _that = this
      _that.sendAddressList[index].sendProvince = CodeToText[value[0]]
      _that.sendAddressList[index].sendCity = CodeToText[value[1]]
      _that.sendAddressList[index].sendDistrict = CodeToText[value[2]]
    },

    // 获取字典
    getDictInfo(typeText) {
      const _that = this
      var data = {
        'dictTypeText': typeText
      }

      // console.log(data)
      getDictTypeInfo(data).then(response => {
        // console.log(response)
        const data = response.data
        if (typeText == 'PrintRequire') {
          _that.printRequireOptions = data
        } else if (typeText == 'OrderPrintDesc') {
          _that.orderPrintOptions = data
        } else if (typeText == 'PackingMethod') {
          _that.packingMethodOptions = data
        }
      }).catch(err => {
        _that.$message.error(err)
      })
    },

    // 添加打包要求
    addPackRequire() {
      const _that = this
      var packrequireItem = Object.assign({}, packrequire)
      _that.packrequireList.push(packrequireItem)
    },
    // 禁止输入小数，负数
    proving(e) {
      var keynum = window.event ? e.keyCode : e.which // 获取键盘码
      if (keynum == 189 || keynum == 109) { // 禁止输入负数
        this.$message.warning('禁止输入负数')
        e.target.value = 0
      }
      if (keynum == 110 || keynum == 190) { // 禁止输入负数
        this.$message.warning('禁止输入小数')
        e.target.value = ''
      }
    },

    addressDialog() {
      const _that = this;
      // _that.addressVisible = true
      // _that.$nextTick(function() {
      this.$refs.address.outerVisible = true
      _that.$refs.address.idClient = _that.form.idClient
      // this.$refs.address.clientName = name
      var pageNum = 1
      _that.$refs.address.getInfo(pageNum, '')
      _that.$refs.address.searchVal = ''
      // })
    },
    // 选择地址
    chooseAddress(row) {
      var sendAddressItem = Object.assign({}, sendAddressInfo)
      sendAddressItem.sendKind = row.shipModeName
      sendAddressItem.sendRegion = row.shipArea
      sendAddressItem.linkMan = row.receiveMan
      sendAddressItem.linkPhone = row.receivePhone
      sendAddressItem.sendAddress = row.address
      sendAddressItem.sendProvince = row.province
      sendAddressItem.sendCity = row.city
      sendAddressItem.sendDistrict = row.area

      var addressOption = []
      if (row.province) {
        addressOption.push(TextToCode[row.province].code)
        addressOption.push(TextToCode[row.province][row.city].code)
        addressOption.push(TextToCode[row.province][row.city][row.area].code)
      }
      if(row.shipModeName){
        this.sendKindChange(row.shipModeName)
      };

      if (this.addressType == 0) {
        this.sendAddressList.splice(0, 1, sendAddressItem)

        this.addressOption.splice(0, 1, addressOption)
        // this.sendAddressList[0] = sendAddressItem
        // console.log(this.sendAddressList)
      } else {
        this.sendAddressList.push(sendAddressItem)

        this.addressOption.push(addressOption)
      }
      this.$refs.address.outerVisible = false
    },
    // 增加收货地址
    addAddressItem() {
      var sendAddressItem = Object.assign({}, sendAddressInfo)
      this.sendAddressList.push(sendAddressItem)
      this.addressOption.push([])
      this.getSendKind()
    },
    // 选择物流档案
    chooseLogistics(row) {
      const _that = this
      // console.log(row)
      if (row.sendType) {
        _that.getLogisticsInfo()
      } else {
        _that.getSendKind()
      }
    },
    currentAddress(row, event, column) {
      const _that = this
      if (row.sendType) {
        _that.getLogisticsInfo()
      } else {
        _that.getSendKind()
      }
    },
    // 删除收货地址
    deleteAddressItem(index) {
      this.sendAddressList.splice(index, 1)
      this.addressOption.splice(index, 1)
    },
    // 验证尺寸
    verifies1(value,parameterName) {
      var reg = /^(\d+([.]\d+)?)\*(\d+([.]\d+)?)$/;
      if(!reg.test(value)){
        this.$message.error('请输入正确的'+parameterName)
        return
      }
    },
    // 验证尺寸
    verifies2(value,parameterName) {
      var reg = /^(\d+([.]\d+)?)\*(\d+([.]\d+)?)\*(\d+([.]\d+)?)$/;
      if(!reg.test(value)){
        this.$message.error('请输入正确的'+parameterName)
        return
      }
    },
    // 增加部件
    addPartBtn(command) {
      var _that = this
      var partInfo = _that.createPartArrByAdd(command)
      _that.partListNew.push(partInfo[command])
      _that.$nextTick(() => {
        _that.partProcessList.forEach((processList, index) => {
          if (index == _that.partProcessList.length - 1) {
            processList.forEach(process => {
              if (process.isRequired == 0) {
                var name = 'partProcess' + (_that.partProcessList.length - 1)
                _that.$refs[name][0].toggleRowSelection(process, true)
              }
            })
          }
        })
      })
    },
    // 复制部件
    copyPartInfo(indexNo) {
      var _that = this
      _that.copeNumVisible = true
      _that.copeindex = indexNo
      _that.copeNum = ''
      // _that.copeFun();
    },
    copeFun() {
      var _that = this;
      var partItem = JSON.parse(JSON.stringify(_that.partListNew[_that.copeindex]))
      var processItem = JSON.parse(JSON.stringify(_that.partProcessList[_that.copeindex]))
      // console.log(partItem);
      partItem.paramValueList.forEach(item => {
        item.id = 0
      })
      // console.log(processItem);
      processItem.forEach(item => {
        item.id = 0
      })
      // partItem.processList.forEach(item =>{
      //   // console.log('processList',item);
      //   item.id = 0
      // })
      partItem.id = ''
      for (let i = 0; i < _that.copeNum; i++) {
        _that.partListNew.push(JSON.parse(JSON.stringify(partItem)))
        _that.partProcessList.push(JSON.parse(JSON.stringify(processItem)))
        _that.selectedProcessList.push([])
      }
      _that.copeNumVisible = false
      _that.$nextTick(() => {
        for (let i = 1; i <= _that.copeNum; i++) {
          _that.partProcessList.forEach((processList, index) => {
            if (index == _that.partProcessList.length - i) {
              processList.forEach(process => {
                _that.selectedProcessList[_that.copeindex].forEach((selected) => {
                  if (process.idProcess == selected.idProcess) {
                    var name = 'partProcess' + index
                    _that.$refs[name][0].toggleRowSelection(process, true)
                  }
                })
              })
            }
          })
        }

        // _that.partProcessList.forEach((processList, index) => {
        //   if (index == _that.partProcessList.length - 1) {
        //     processList.forEach(process => {
        //       if (process.isRequired == 0) {
        //         var name = 'partProcess' + (_that.partProcessList.length - 1)
        //         _that.$refs[name][0].toggleRowSelection(process,true)
        //       }
        //     })
        //   }
        // })
      })
    },

    // 删除部件
    removePartInfo(indexNo) {
      var _that = this
      _that.$confirm('删除部件', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        _that.bInRemoving = true

        _that.partListNew.splice(indexNo, 1)

        _that.selectedProcessList.splice(indexNo, 1)
        _that.partProcessList.splice(indexNo, 1)
        _that.$nextTick(() => {
          _that.partProcessList.forEach((processList, index) => {
            processList.forEach(process => {
              _that.selectedProcessList[index].forEach((selected) => {
                if (process.idProcess == selected.idProcess) {
                  var name = 'partProcess' + index
                  _that.$refs[name][0].toggleRowSelection(process, true)
                }
              })
            })
          })
          _that.bInRemoving = false
        })
      })
    },

    // 下拉框可输入
    selectBlur(e, index1, index2) {
      var _that = this
      _that.partList[index1].paramValueList[index2].paramLabel = e.target.value
    },
    selectBlur1(e, index1, index2) {
      var _that = this
      if (e.target != undefined) {
        _that.partListNew[index1].paramValueList[index2].paramDisplay = e.target.value
        _that.partListNew[index1].paramValueList[index2].paramValue = e.target.value
      }
    },
    parameterSelect(e, index1, index2) {
      const _that = this
      _that.partListNew[index1].paramValueList[index2].itemList.forEach(item => {
        if (item.itemValue == e) {
          _that.partListNew[index1].paramValueList[index2].paramDisplay = item.itemName
        }
      })
    },
    // 参数选择弹窗
    parameterChoose(index1, index2, type, name) {
      const _that = this
      _that.dialogTitle = name
      _that.parameterChooseVisible = true
      _that.timer = new Date().getTime()
      _that.parameterChooseType = type
      _that.partId = _that.partListNew[index1].idPart
      _that.parameterId = _that.partListNew[index1].paramValueList[index2].idParameter
      _that.parameterIndex1 = index1
      _that.parameterIndex2 = index2
      // console.log('index1', index1)
      // console.log('index2', index2)
      // console.log(_that.partListNew[index1].paramValueList[index2])
      // console.log(_that.partId)
      // console.log(_that.parameterId)
    },
    // 选择纸张档案
    choosePaper(row) {
      var _that = this
      _that.parameterChooseVisible = false
      _that.partListNew[_that.parameterIndex1].paramValueList[_that.parameterIndex2].paramDisplay = row.paperQuoteName
      _that.partListNew[_that.parameterIndex1].paramValueList[_that.parameterIndex2].paramValue = row.id
    },
    // 选择参数辅料档案
    chooseAccessoriesByParameter(row) {
      var _that = this
      _that.parameterChooseVisible = false
      // console.log(row)
      _that.partListNew[_that.parameterIndex1].paramValueList[_that.parameterIndex2].paramDisplay = row.materialName
      _that.partListNew[_that.parameterIndex1].paramValueList[_that.parameterIndex2].paramValue = row.id
    },
    // 工序辅料选择弹窗
    processChoose(index1, index2, row) {
      // console.log(row)
      const _that = this
      _that.dialogTitle = '选择辅料'
      _that.timer = new Date().getTime()
      _that.materialTypeIds = row.materialTypeIds
      _that.processChooseVisible = true

      _that.parameterIndex1 = index1
      _that.processIndex = index2
    },
    // 选择工序辅料档案
    chooseAccessories(row) {
      var _that = this
      _that.processChooseVisible = false
      _that.partProcessList[_that.parameterIndex1][_that.processIndex].materialName = row.materialName
      _that.partProcessList[_that.parameterIndex1][_that.processIndex].idMaterial = row.id
    },

    // 部件工序多选
    handleSelectionChange(val, index) {
      // console.log(val)
      // console.log(index)
      var _that = this
      this.partListNew[index].processList = val
      // if (_that.bInRemoving) {
      //   return
      // }
      this.selectedProcessList[index] = JSON.parse(JSON.stringify(val))
    },
    // 增加工序
    addProcess(index1) {
      // console.log(index1);
      var _that = this
      _that.processVisible = true
      _that.processListData.page = 1

      _that.processSearch.keyWord = ''

      _that.parameterIndex1 = index1
      _that.getProcessList()
    },

    // 工序搜索
    processSearchData() {
      this.processListData.page = 1
      this.getProcessList()
    },

    // 获取工序列表
    getProcessList() {
      var _that = this
      var params = _that.processSearch
      var page = {
        pageIndex: _that.processListData.page,
        pageSize: _that.processListData.pageSize
      }
      var data = {
        'params': JSON.stringify(params),
        'page': JSON.stringify(page)
      }
      getWorkProcessList(data).then(response => {
        // console.log(response)
        const data = response.data
        _that.processList = data
        _that.processListData.total = response.total
      }).catch(err => {
        _that.$message.error(err)
      })
    },

    // 选择此行工序
    addThis(row) {
      var _that = this
      // console.log(row)
      var data = {
        idWorkProcess: row.id
      }

      getWorkProcess(data).then(res => {
        // console.log(res);
        var processList = _that.partProcessList[_that.parameterIndex1]
        // console.log(processList)
        if (res.data.workProcessList.length > 0) {
          var list = res.data.workProcessList
          list.forEach(item => {
            var addState = processList.some(process => {
              if (process.idProcess == item.id) {
                return true
              }
            })
            _that.addworkProcessFun(item, addState)
          })
        }
        var result = processList.some(item => {
          if (item.idProcess == row.id) {
            return true
          }
        })

        _that.addworkProcessFun(row, result)

        _that.processVisible = false
      })
    },
    addworkProcessFun(item, state) {
      var _that = this
      var processItem = {
        'isRequired': 1,
        'idProcess': item.id,
        'processName': item.processName,
        'materialTypeIds': item.materialTypeIds,
        'processMemo': '',
        'obvRevId': 1,
        'processPrice': '', // 工序单价、
        'processQty': '',
        'processMoney': '',
        'processRule': '',
        'idMaterial': '',
        'materialName': ''
      }

      if (!state) {
        _that.partProcessList[_that.parameterIndex1].push(processItem)
        // 默认选中
        var name = 'partProcess' + _that.parameterIndex1
        _that.$refs[name][0].toggleRowSelection(processItem, true)
      } else {
        _that.$message.error('已有' + item.processName)
      }
    },
    // 解析地址
    parseAddressBtn() {
      const _that = this
      if (!_that.parseAddress) {
        _that.$message.warning('请粘贴地址')
        return
      }
      var data = {
        'address': _that.parseAddress
      }
      parseAddress(data).then(response => {
        // console.log(response)
        var data = response.data[0]
        var sendAddressItem = Object.assign({}, sendAddressInfo)
        sendAddressItem.linkMan = data.name
        if (data.mobile==null || data.mobile=="" || data.mobile==undefined) {
          sendAddressItem.linkPhone = data.phone
        }else {
          sendAddressItem.linkPhone = data.mobile
        }
        sendAddressItem.sendProvince = data.province
        sendAddressItem.sendCity = data.city
        sendAddressItem.sendDistrict = data.county
        sendAddressItem.sendAddress = data.details
        _that.sendAddressList.push(sendAddressItem)
        // console.log(_that.sendAddressList);
        var addressOption = []

        if (data.province) {
          addressOption.push(TextToCode[data.province].code)
          if (data.city) {
            addressOption.push(TextToCode[data.province][data.city].code)
            if (data.county) {
              addressOption.push(TextToCode[data.province][data.city][data.county].code)
            }
          }
        }
        _that.addressOption.push(addressOption);
        _that.getSendKind();

      }).catch(err => {
        _that.$message.error(err)
      })
    },

    // 计算时间
    calcSendDate() {
      var _that = this
      var execParams = {}
      if (_that.orderCategory == 1) {

        if (_that.sendAddressList.length <= 0) {
          _that.$message.error('请填写收货地址')
          return
        }
        // if (_that.orderCategory == 1) {
        if (_that.sendAddressList[0].sendKind == undefined || _that.sendAddressList[0].sendKind == null || _that.sendAddressList[0].sendKind == '') {
          _that.$message.error('请选择发货方式')
          return
        }
        if(!_that.form.deliverDate){
          var deliverDate = "";
        }else {
          var deliverDate = _that.form.deliverDate+" "+_that.form.deliverTime
        }
        execParams = {
          'sendKind': _that.sendAddressList[0].sendKind,
          'deliverDate': deliverDate
        }
      } else {

        var sendAddressList = _that.$refs.deliveryNotice.sendAddressList
        if (sendAddressList.length <= 0) {
          _that.$message.error('请填写收货地址')
          return
        }
        if (sendAddressList[0].sendKind == undefined || sendAddressList[0].sendKind == null || sendAddressList[0].sendKind == '') {
          _that.$message.error('请选择发货方式')
          return
        }
        if(!_that.form.deliverDate){
          var deliverDate = "";
        }else {
          var deliverDate = _that.form.deliverDate+" "+_that.form.deliverTime
        }
        execParams = {
          'sendKind': sendAddressList[0].sendKind,
          'deliverDate': deliverDate
        }
      }

      var data = {
        'params': execParams
      }
      calcOrderSendDate(data).then(response => {
        // console.log(response)
        const data = response.data
        if(data.itemData.deliverDate){
          _that.form.deliverDate = data.itemData.deliverDate.slice(0,10);
          _that.form.deliverTime = data.itemData.deliverDate.slice(11,19)
        }

      }).catch(err => {
        _that.$message.error(err)
      })
    },
    sendKindChange(val){
      // console.log(val);
      var _that = this
      var execParams = {}
      if(!_that.form.deliverDate){
        var deliverDate = "";
      }else {
        var deliverDate = _that.form.deliverDate+" "+_that.form.deliverTime
      }
      execParams = {
        'sendKind': val,
        'deliverDate': deliverDate
      }
      var data = {
        'params': execParams
      }
      calcOrderSendDate(data).then(response => {
        // console.log(response)
        const data = response.data
        if(data.itemData.deliverDate){
          _that.form.deliverDate = data.itemData.deliverDate.slice(0,10);
          _that.form.deliverTime = data.itemData.deliverDate.slice(11,19)
        }

      }).catch(err => {
        _that.$message.error(err)
      })
    },
    // 计算价格
    async calculatePrice(type, func) {
      // console.log('点击计算价格',type);
      /** *
       *type 1 点击计算价格按钮
       * 2 保存或修改时获取价格
       */
      const _that = this
      _that.$refs['form'].validate((valid) => {
        if (valid) {
          for (var i = 0; i < _that.partListNew.length; i++) {
            for (var j = 0; j < _that.partListNew[i].paramValueList.length; j++) {
              var param = _that.partListNew[i].paramValueList[j]
              if ((param.paramValue == '' || param.paramValue == null) && (param.fieldType != 6) && (param.fieldType != 7) && (param.fieldType != 3)) {
                _that.$message.error(param.parameterName + '为必填项')
                return
              }
              if (param.fieldType == 3) {
                var reg = new RegExp("^[0-9]*$");
                // console.log(param.fieldType,reg.test(param.paramValue));
                if(!reg.test(param.paramValue)){
                  _that.$message.error('请输入正确的' + param.parameterName)
                  return
                }
              }
              if (param.fieldType == 6) {
                var reg = /^(\d+([.]\d+)?)\*(\d+([.]\d+)?)$/;
                // console.log(param.fieldType,reg.test(param.paramValue));
                if(!reg.test(param.paramValue)){
                  _that.$message.error('请输入正确的' + param.parameterName)
                  return
                }
              }

              if (param.fieldType == 7) {
                var reg =  /^(\d+([.]\d+)?)\*(\d+([.]\d+)?)\*(\d+([.]\d+)?)$/;
                // console.log(param.fieldType,reg.test(param.paramValue));
                if(!reg.test(param.paramValue)){
                  _that.$message.error('请输入正确的' + param.parameterName)
                  return
                }
              }
            }
          }

          _that.form.sendAddressList = _that.sendAddressList
          _that.createParameter()
          var data = JSON.stringify(_that.form)
          // var res = await quotePrintOrder({order: data});
          //
          // console.log(res)
          quotePrintOrder(data).then(res => {
            // console.log(res)
            if (res.httpCode = 200) {
              if (!res.data.ErrorMsg) {
                // console.log(type);
                if (type == 1) {
                  _that.form.orderMoneyTotal = res.data.TotalMoney;
                  _that.form.orderMoneyPrint = res.data.pMoney;
                  _that.form.orderMoneyProcess = res.data.sMoney;
                  _that.PriceInfo = res.data.PriceInfo;
                } else {
                  _that.jsTotalMoney = res.data.TotalMoney
                  if (func) {
                    func()
                  }
                }
              } else {
                _that.$message.error(res.data.ErrorMsg)
              }
            }
          })
        }
      })
    },

    // 保存
    save(type) {
      var _that = this
      _that.form.sendAddressList = _that.sendAddressList
      var packrequireArr = []
      _that.packrequireList.forEach(item => {
        if (parseInt(item.packNum) && parseInt(item.countNum)) {
          var packrequire = item.packNum + '*' + item.countNum
          packrequireArr.push(packrequire)
        }
      })
      _that.form.packRequire = packrequireArr.join('+')
      // console.log(_that.form.packRequire);
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          if (_that.form.deliverDate === '' || _that.form.deliverDate == null) {
            _that.$message.error('交货时间不能为空')
            return
          }
          // if (_that.form.sendAddressList.length <= 0) {
          //   _that.$message.error('请填写收货地址')
          //   return
          // }
          var sendAddressList = _that.form.sendAddressList;
          for (let i = 0; i < sendAddressList.length; i++) {
            if (!sendAddressList[i].sendKind) {
              _that.$message.error('请选择发货方式')
              return
            }
            if (!sendAddressList[i].sendProvince) {
              _that.$message.error('请选择省市区')
              return
            }
          }
          // 付款方式
          var selectionArr = []
          for (let j = 0; j < _that.payType.length; j++) {
            if(_that.payType[j].guarantee.indexOf("+")!= -1 || _that.payType[j].guarantee.indexOf(":")!= -1){
              _that.$message.error('输入框中不能出现符号+和:')
              return
            }
            if (_that.payType[j].value > 0) {
              if (_that.payType[j].id == 2) {
                if (!_that.payType[j].guarantee) {
                  _that.$message.error('担保人不能为空')
                  return
                }
              }
              var selectionString = ''
              selectionString = _that.payType[j].id + ':' + _that.payType[j].name + ':' + _that.payType[j].value + ':' + _that.payType[j].guarantee
              selectionArr.push(selectionString)
            }
          }
          _that.form.payKind = selectionArr.join('+')

          // if (parseInt(_that.form.orderMoneyTotal) !== parseInt(_that.sums) + parseInt(_that.form.orderMoneyPre)) {
          //   _that.$message.error('付款方式总计金额和预收款之和不等于总金额')
          //   return
          // }

          if(_that.form.usePreStore==0){
            if (parseInt(_that.sums) < parseInt(_that.form.orderMoneyTotal)) {
              _that.$message.error('付款方式总计金额不能小于总金额')
              return
            }
          }
          if (_that.partListNew.length <= 0) {
            _that.$message.error('请添加部件')
            return
          }
          // console.log(_that.partListNew);
          for (var i = 0; i < _that.partListNew.length; i++) {
            for (var j = 0; j < _that.partListNew[i].paramValueList.length; j++) {
              var param = _that.partListNew[i].paramValueList[j]
              if ((param.paramValue == '' || param.paramValue == null) && (param.fieldType != 6) && (param.fieldType != 7) && (param.fieldType != 3)) {
                _that.$message.error(param.parameterName + '为必填项')
                return
              }
              if (param.fieldType == 3) {
                var reg = new RegExp("^[0-9]*$");
                // console.log(param.fieldType,reg.test(param.paramValue));
                if(!reg.test(param.paramValue)){
                  _that.$message.error('请输入正确的' + param.parameterName)
                  return
                }
              }
              if (param.fieldType == 6) {
                var reg = /^(\d+([.]\d+)?)\*(\d+([.]\d+)?)$/;
                // console.log(param.fieldType,reg.test(param.paramValue));
                if(!reg.test(param.paramValue)){
                  _that.$message.error('请输入正确的' + param.parameterName)
                  return
                }
              }

              if (param.fieldType == 7) {
                var reg =  /^(\d+([.]\d+)?)\*(\d+([.]\d+)?)\*(\d+([.]\d+)?)$/;
                // console.log(param.fieldType,reg.test(param.paramValue));
                if(!reg.test(param.paramValue)){
                  _that.$message.error('请输入正确的' + param.parameterName)
                  return
                }
              }
            }
          }
          if (_that.form.orderMoneyPre > 0 && type == 2) {
            _that.$message.error('订单有预收款不能直接提交')
            return
          }
          _that.calculatePrice(2, function () {
            if (_that.jsTotalMoney) {
              if (_that.jsTotalMoney > _that.form.orderMoneyTotal || _that.form.orderMoneyTotal > _that.jsTotalMoney * 1.2) {
                _that.$confirm(`计算金额为${_that.jsTotalMoney}元，请确认价格是否正确`, '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消'
                }).then(() => {
                  // 总金额判断
                  if (_that.form.orderMoneyTotal == 0) {
                    _that.$message.warning('订单金额不能为0')
                    return
                  } else {
                    // 添加
                    if (type == 1) {
                      _that.saveBtn()
                    } else {
                      _that.$message.warning('订单文件未上传')
                      _that.saveAndPush()
                    }
                  }
                }).catch(() => {
                  return
                })
              } else {
                // 总金额判断
                if (_that.form.orderMoneyTotal == 0) {
                  _that.$message.warning('订单金额不能为0')
                  return
                } else {
                  // 添加
                  if (type == 1) {
                    _that.saveBtn()
                  } else {
                    _that.$message.warning('订单文件未上传')
                    _that.saveAndPush()
                  }
                }
              }
            } else {
              // 总金额判断
              if (_that.form.orderMoneyTotal == 0) {
                // _that.$confirm('金额为0是否继续', '提示', {
                //   confirmButtonText: '确定',
                //   cancelButtonText: '取消'
                // }).then(() => {
                //   // 确定操作
                //   if (type == 1) {
                //     _that.saveBtn()
                //   } else {
                //     _that.$message.warning('订单文件未上传')
                //     _that.saveAndPush()
                //   }
                // }).catch(() => {
                //   return
                // })
                _that.$message.warning('订单金额不能为0')
                return
              } else {
                // 添加
                if (type == 1) {
                  _that.saveBtn();
                } else {
                  _that.$message.warning('订单文件未上传')
                  _that.saveAndPush();
                }
              }
            }
          })
        }
      })
    },
    createParameter() {
      var _that = this
      var partList = JSON.parse(JSON.stringify(_that.partListNew))
      partList.forEach((part, index) => {
        var paramValueList = []
        part.paramValueList.forEach(parameter => {
          var parameterItem = {}
          parameterItem['idParameter'] = parameter.idParameter
          parameterItem['idPartInfo'] = parameter.idPartInfo
          parameterItem['idProduct'] = parameter.idProduct
          parameterItem['paramValue'] = parameter.paramValue
          paramValueList.push(parameterItem)
        })
        partList[index].paramValueList = paramValueList
      })
      _that.form.partList = partList
    },
    saveBtn() {
      var _that = this
      _that.clickLoading = true
      _that.form.sendAddressList = _that.sendAddressList;
      _that.createParameter();
      if(_that.form.deliverDate){
        var deliverDate = "";
        deliverDate = _that.form.deliverDate.slice(0,10)+" "+_that.form.deliverTime;
        _that.form.deliverDate = deliverDate;
      }
      var data = JSON.stringify(_that.form)
      // var data = {
      //   'printOrder': JSON.stringify(_that.form)
      // }
      // console.log(_that.form);
      // return
      addPrintOrder(data, _that.formToken).then(response => {
        // console.log('addPrintOrder',response)
        if (response.httpCode == 200) {
          _that.clickLoading = false
          _that.$store.dispatch('tagsView/delView', _that.tempRoute).then(() => {
            _that.$router.push({path: '/order/tobeEditedOrder/0'})
          })
        } else if (response.httpCode != 409) {
          _that.getToken()
        }
      }).catch(err => {
        _that.clickLoading = false
        // console.log('addPrintOrdererr',err)
        // console.log(err.name);
        // console.log(err.message);
        if (err.name != 409) {
          _that.getToken()
        }
        // _that.$message.error(err)
      })
    },
    saveAndPush() {
      var _that = this
      _that.clickLoading = true
      _that.form.sendAddressList = _that.sendAddressList
      _that.createParameter()
      if(_that.form.deliverDate){
        var deliverDate = "";
        deliverDate = _that.form.deliverDate.slice(0,10)+" "+_that.form.deliverTime;
        _that.form.deliverDate = deliverDate;
      }
      var data = JSON.stringify(_that.form)
      // console.log(_that.form);
      // console.log(data)
      // return
      addAndCommitPrintOrder(data, _that.formToken).then(response => {
        // console.log(response)
        if (response.httpCode == 200) {
          _that.clickLoading = false
          _that.$store.dispatch('tagsView/delView', _that.tempRoute).then(() => {
            _that.$router.push({path: '/order/orderList'})
          })
        } else if (response.httpCode != 409) {
          _that.getToken()
        }
      }).catch(err => {
        _that.clickLoading = false
        // console.log(err)
        // _that.$message.error(err)
        if (err.name != 409) {
          _that.getToken()
        }
      })
    },

    // 修改保存
    editOrder(type) {
      var _that = this
      var packrequireArr = []

      var sendAddressList = _that.$refs.deliveryNotice.sendAddressList
      for (let i = 0; i < sendAddressList.length; i++) {
        var item = sendAddressList[i]
        if (item.edit == true) {
            _that.$message.warning('请先保存收货信息')
            return
        }
      }
      _that.packrequireList.forEach(item => {
        if (parseInt(item.packNum) && parseInt(item.countNum)) {
          var packrequire = item.packNum + '*' + item.countNum
          packrequireArr.push(packrequire)
        }
      })
      _that.form.packRequire = packrequireArr.join('+')
      // console.log(_that.form.packRequire);
      // return;
      this.$refs['form'].validate((valid) => {
        if (valid) {
          if (_that.form.deliverDate === '' || _that.form.deliverDate == null) {
            _that.$message.error('交货时间不能为空')
            return
          }
          // var sendAddressList = _that.form.sendAddressList
          // for (let i = 0; i < sendAddressList.length; i++) {
          //   if (!sendAddressList[i].sendKind) {
          //     _that.$message.error('请选择发货方式')
          //     return
          //   }
          // }
          // 付款方式
          var selectionArr = []
          for (let j = 0; j < _that.payType.length; j++) {
            if(_that.payType[j].guarantee.indexOf("+")!= -1 || _that.payType[j].guarantee.indexOf(":")!= -1){
              _that.$message.error('付款方式输入框中不能出现符号+和:')
              return
            }
            if (_that.payType[j].value > 0) {
              if (_that.payType[j].id == 2) {
                if (!_that.payType[j].guarantee) {
                  _that.$message.error('担保人不能为空')
                  return
                }
              }
              var selectionString = ''
              selectionString = _that.payType[j].id + ':' + _that.payType[j].name + ':' + _that.payType[j].value + ':' + _that.payType[j].guarantee
              selectionArr.push(selectionString)
            }
          }
          _that.form.payKind = selectionArr.join('+')
          // console.log(_that.form.orderMoneyPre);
          // return;
          // if (parseInt(_that.form.orderMoneyTotal) !== parseInt(_that.sums) + parseInt(_that.form.orderMoneyPre)) {
          //   _that.$message.error('付款方式总计金额和预收款之和不等于总金额')
          //   return
          // }
          if(_that.form.usePreStore==0){
            if (parseInt(_that.sums) < parseInt(_that.form.orderMoneyTotal)) {
              _that.$message.error('付款方式总计金额不能小于总金额')
              return
            }
          }

          if (_that.partListNew.length <= 0) {
            _that.$message.error('请添加部件')
            return
          }
          for (var i = 0; i < _that.partListNew.length; i++) {
            for (var j = 0; j < _that.partListNew[i].paramValueList.length; j++) {
              var param = _that.partListNew[i].paramValueList[j]
              if ((param.paramValue == '' || param.paramValue == null) && (param.fieldType != 6) && (param.fieldType != 7) && (param.fieldType != 3)) {
                _that.$message.error(param.parameterName + '为必填项')
                return
              }
              if (param.fieldType == 3) {
                var reg = new RegExp("^[0-9]*$");
                if(!reg.test(param.paramValue)){
                  _that.$message.error('请输入正确的' + param.parameterName)
                  return
                }
              }
              if (param.fieldType == 6) {
                var reg = /^(\d+([.]\d+)?)\*(\d+([.]\d+)?)$/;
                // console.log(param.fieldType,reg.test(param.paramValue));
                if(!reg.test(param.paramValue)){
                  _that.$message.error('请输入正确的' + param.parameterName)
                  return
                }
              }

              if (param.fieldType == 7) {
                var reg =  /^(\d+([.]\d+)?)\*(\d+([.]\d+)?)\*(\d+([.]\d+)?)$/;
                // console.log(param.fieldType,reg.test(param.paramValue));
                if(!reg.test(param.paramValue)){
                  _that.$message.error('请输入正确的' + param.parameterName)
                  return
                }
              }

            }
          }
          _that.calculatePrice(2, function () {
            // console.log('_that.jsTotalMoney', _that.jsTotalMoney)

            if (_that.jsTotalMoney) {
              if (_that.jsTotalMoney > _that.form.orderMoneyTotal || _that.form.orderMoneyTotal > _that.jsTotalMoney * 1.2) {
                // console.log('价格不对');
                _that.$confirm(`计算金额为${_that.jsTotalMoney}元，请确认价格是否正确 `, '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消'
                }).then(() => {
                  // 总金额判断
                  if (_that.form.orderMoneyTotal == 0) {
                    _that.$message.warning('订单金额不能为0')
                    return
                  } else {
                    if (type == 1) {
                      _that.editBtn()
                    } else {
                      _that.editAndPush()
                    }
                  }
                }).catch(() => {
                  return
                })
              } else {
                // 总金额判断
                if (_that.form.orderMoneyTotal == 0) {
                  _that.$message.warning('订单金额不能为0')
                  return
                } else {
                  if (type == 1) {
                    _that.editBtn()
                  } else {
                    _that.editAndPush()
                  }
                }
              }
            } else {
              // 总金额判断
              if (_that.form.orderMoneyTotal == 0) {
                _that.$message.warning('订单金额不能为0')
                return
              } else {
                if (type == 1) {
                  _that.editBtn()
                } else {
                  _that.editAndPush()
                }
              }
            }
          })
        }
      })
    },
    editBtn() {
      var _that = this
      _that.clickLoading = true
      _that.form.id = _that.idOrder
      _that.form.sendAddressList = _that.sendAddressList
      _that.form.partList = _that.partListNew
      // console.log(_that.form)
      if(_that.form.deliverDate){
        var deliverDate = "";
        deliverDate = _that.form.deliverDate.slice(0,10)+" "+_that.form.deliverTime;
        _that.form.deliverDate = deliverDate;
      }
      var data = JSON.stringify(_that.form)
      if(_that.editType == 1){
        updatePrintOrder(data).then(response => {
          // console.log(response)
          if (response.httpCode == 200) {
            _that.clickLoading = false
            _that.$store.dispatch('tagsView/delView', _that.tempRoute).then(() => {
              if (_that.pageFrom == '2') {
                _that.$router.push({path: '/order/TobeReviewed/1'})
              } else if (_that.pageFrom == '1'){
                _that.$router.push({path: '/order/tobeEditedOrder/0'})
              }else {
                _that.$router.push({path: '/order/tobeEditedOrder/0'})
              }
            })
          }
        }).catch(err => {
          _that.clickLoading = false
          // console.log(err)
          // _that.$message.error(err)
        })
      }else {
        reprintOrder(data, _that.formToken).then(response => {
          // console.log(response)
          if (response.httpCode == 200) {
            _that.clickLoading = false

            _that.$store.dispatch('tagsView/delView', _that.tempRoute).then(() => {
              if (_that.pageFrom == '2') {
                _that.$router.push({path: '/order/TobeReviewed/1'})
              } else if (_that.pageFrom == '1'){
                _that.$router.push({path: '/order/tobeEditedOrder/0'})
              } else {
                _that.$router.push({path: '/order/tobeEditedOrder/0'})
              }
            })
          }else if (response.httpCode != 409) {
            _that.getToken()
          }
        }).catch(err => {
          _that.clickLoading = false
          // console.log(err)
          // _that.$message.error(err)
          if (err.name != 409) {
            _that.getToken()
          }
        })
      }
    },
    editAndPush() {
      var _that = this
      _that.form.id = _that.idOrder
      _that.form.sendAddressList = _that.sendAddressList
      _that.form.partList = _that.partListNew

      if(_that.editType == 2){
        _that.form.needImageProcess = 0;
        if(_that.form.deliverDate){
          var deliverDate = "";
          deliverDate = _that.form.deliverDate.slice(0,10)+" "+_that.form.deliverTime;
          _that.form.deliverDate = deliverDate;
        }
        var data = JSON.stringify(_that.form)
        _that.editAndPushSure(data)
      } else {
        checkCompleteDispatchOrder({idOrder: _that.idOrder}).then(res => {
          // console.log(res)
          if (res.data.length == 0) {
            _that.form.needImageProcess = 0;
            if(_that.form.deliverDate){
              var deliverDate = "";
              deliverDate = _that.form.deliverDate.slice(0,10)+" "+_that.form.deliverTime;
              _that.form.deliverDate = deliverDate;
            }
            var data = JSON.stringify(_that.form)
            _that.editAndPushSure(data)
          } else {
            _that.commitVisible = true
            _that.commitInfo.infoList = res.data;
          }
        })
      }


      // var data = JSON.stringify(_that.form)

      // console.log(data)
      // return
    },
    commitBtn() {
      const _that = this
      _that.form.needImageProcess = _that.commitInfo.needImageProcess;
      var data = JSON.stringify(_that.form)
      _that.editAndPushSure(data)
    },
    editAndPushSure(data) {
      const _that = this
      if (!_that.hasFile) {
        _that.$message.warning('订单文件未上传')
      }
      _that.clickLoading = true
      // console.log(data)
      if(_that.editType == 1){
      editAndCommitPrintOrder(data).then(response => {
          // console.log(response)
          if (response.httpCode == 200) {
            _that.clickLoading = false
            _that.$store.dispatch('tagsView/delView', _that.tempRoute).then(() => {
              if (_that.pageFrom == '2') {
                _that.$router.push({path: '/order/TobeReviewed/1'})
              } else if (_that.pageFrom == '1'){
                _that.$router.push({path: '/order/tobeEditedOrder/0'})
              } else {
                _that.$router.push({path: '/order/tobeEditedOrder/0'})
              }
            })
          }
        }).catch(err => {
          _that.clickLoading = false
          // console.log(err)
          _that.$message.error(err)
        })
      }else {
        reprintCommitOrder(data, _that.formToken).then(response => {
          // console.log(response)
          if (response.httpCode == 200) {
            _that.clickLoading = false
            _that.$store.dispatch('tagsView/delView', _that.tempRoute).then(() => {
              if (_that.form.stateMemo == '待审核') {
                _that.$router.push({path: '/order/TobeReviewed/1'})
              } else {
                _that.$router.push({path: '/order/orderList'})
              }
            })
          }else if (response.httpCode != 409) {
            _that.getToken()
          }
        }).catch(err => {
          _that.clickLoading = false
          // console.log(err)
          _that.$message.error(err)
          if (err.name != 409) {
            _that.getToken()
          }
        })
      }
    },
    // 表格合计
    getSummaries(param) {
      const {columns, data} = param
      const sums = []
      columns.forEach((column, index) => {
        // 如果是第一列，则最后一行展示为“总计”两个字
        if (index === 0) {
          sums[index] = '总计'
          // 如果是最后一列，索引为列数-1，则显示计算总和
        } else if (index === 1) {
          const values = data.map(item => Number(item[column.property]))
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
          } else {
            sums[index] = 'N/A'
          }
          // 如果是除了第一列和最后一列的其他列，则显示为空
        } else {
          sums[index] = ''
        }
      })
      // console.log(sums)
      this.sums = sums[1]
      return sums
    },

    // handleFileChange(fileList) {
    //   var _that = this
    //   console.log('handleFileChange', fileList)
    //
    //   // setTimeout(() => {
    //   //   _that.tableRefresh()
    //   // }, 1000)
    // },

    // 全部折叠
    closeAll() {
      var partList = document.getElementsByClassName('partInfoList')[0].children
      for (let i = 0; i < partList.length; i++) {
        var bodyClass = partList[i].children[1].className
        if (bodyClass != 'hideContent') {
          partList[i].children[1].removeAttribute('class')
          partList[i].children[1].setAttribute('class', 'hideContent')
          partList[i].children[1].children[0].setAttribute('class', 'show')
          partList[i].children[0].children[0].children[1].className = 'box-header-icon el-icon-caret-bottom'
        }
      }
    },

    // 全部展开
    openAll() {
      var partList = document.getElementsByClassName('partInfoList')[0].children
      for (let i = 0; i < partList.length; i++) {
        var bodyClass = partList[i].children[1].className
        if (bodyClass == 'hideContent') {
          partList[i].children[1].removeAttribute('class')
          partList[i].children[1].setAttribute('class', 'el-card__body')
          partList[i].children[1].children[0].removeAttribute('class')
          partList[i].children[0].children[0].children[1].className = 'box-header-icon el-icon-caret-top'
        }
      }
    },

    // 展开收起
    unfold: function (e, data, type) {
      const dv = document.getElementById(data)

      var pv = dv.parentNode
      if (dv.className == 'show') {
        dv.removeAttribute('class')
        pv.className = 'el-card__body'
        if (type == 2) {
          e.target.className = 'box-header-icon el-icon-caret-top'
        } else {
          pv.parentNode.children[0].children[0].children[1].className = 'box-header-icon el-icon-caret-top'
        }
      } else {
        dv.setAttribute('class', 'show')
        pv.className = 'hideContent'
        if (type == 2) {
          e.target.className = 'box-header-icon el-icon-caret-bottom'
        } else {
          pv.parentNode.children[0].children[0].children[1].className = 'box-header-icon el-icon-caret-bottom'
        }
      }
    },

    handleCurrentChange(row, event, column) {
      // console.log(row, event, column, event.currentTarget)
    },
    handleEdit(index, row) {
      // console.log(index, row);
    }
  }
}
</script>
<style>

.el-card__header {
  padding: 5px 20px;
}

.el-form-item--mini.el-form-item, .el-form-item--small.el-form-item {
  margin-bottom: 10px;
}

.el-input__inner {
  padding: 0 10px;
}

.itemlabel .el-form-item__label {
  margin-top: 5px;
}
</style>
<style scoped>
.filter-container {
  margin-bottom: 10px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}

.show {
  display: none;
}

.hideContent {
  padding: 0;
}

.box-card {
  margin-bottom: 10px;
}

.box-header-title {
  line-height: 36px;
  font-size: 17px;
  color: #666;
}

.box-header-right {
  float: right;
  color: #20a0ff;
  line-height: 36px;
  cursor: pointer;
  margin-right: 10px;
}

.box-header-icon {
  float: right;
  color: #20a0ff;
  line-height: 36px;
  cursor: pointer;
}

.tb-edit .el-select, .tb-edit .el-checkbox {
  display: inline-block;
}

.tb-edit .el-input, .tb-edit .el-select, .tb-edit .el-cascader, .tb-edit .el-checkbox {
  display: none
}

.tb-edit .current-row .el-input, .tb-edit .current-row .el-checkbox, .tb-edit .current-row .el-select, .tb-edit .current-row .el-cascader {
  display: block
}

.tb-edit .current-row .el-input + span, .tb-edit .current-row .el-checkbox + span, .tb-edit .current-row .el-select + span, .tb-edit .current-row .el-cascader + span {
  display: none
}

.processDialog ::v-deep .el-dialog__body {
  padding: 0;
}

::v-deep .el-card__body {
  padding: 10px;
}
</style>
