<template>
    <div>
        <Toptitle :title="type==1?'新增':type==2?'编辑':'详情'">
            <Button @click="$router.go(-1)" style="margin-right:10px">取消</Button>
            <Button type='error' style="margin-right:10px" @click="handleDel">强制删除</Button>
            <Button @click="handleTakeApart" style="margin-right:10px" type='primary' v-show="type==2">批量拆单</Button>
            <Upload
        ref="upload"
          name="your_file"
          :show-upload-list="false"
          :headers="headers"
          :on-error="uploadError"
          :on-success="uploadSuccess"
          :action="$store.state.ip + '/api/split_import_news'"
          :data='{list:JSON.stringify(selectData)}'
         v-show="false"
        >
        </Upload>
        <Button @click="handleExport" type="primary" v-if="type==3" style="margin-right:10px">批量下生产</Button>
            <Button type="primary" @click="handleSubmit('formValidate')" v-if="type!=3">保存</Button>
        </Toptitle>
        <Form ref="formValidate" :model="formData" :rules="ruleValidate" class="form_content" :label-width='120'>
                <FormItem label='项目编号：' prop='order_no'>
                    <Input clearable v-model="formData.order_no" class="form_item" placeholder="请输入项目编码" disabled/>
                </FormItem>
                <FormItem label='项目名称：' prop='residential_name'>
                    <Input v-model="formData.residential_name" clearable class="form_item" placeholder="请输入项目名称" :disabled='type==3'/>
                </FormItem>
                <FormItem label="项目简称：" prop='abbreviation'>
                    <Input v-model="formData.abbreviation" clearable class="form_item" placeholder="请输入项目简称" :disabled='type==3'/>
                </FormItem>
                <FormItem label="客户：" prop='custom_id'>
                    <Select v-model="formData.custom_id" clearable class="form_item" :disabled='type==3'>
                        <Option v-for="item in customList" :key="item.id" :value="item.id" :label="item.nickname" :disabled='type==3'/>
                    </Select>
                </FormItem>
                <FormItem label="紧急程度：" prop='warning_state'>
                    <Select v-model="formData.warning_state" clearable filterable class="form_item" :disabled='type==3'>
                        <Option v-for="item in warningList" :key="item.id" :value="item.id" :label='item.title'></Option>
                    </Select>
                </FormItem>
                <FormItem label='项目定金：'>
                    <Input clearable class="form_item" placeholder="请输入项目定金" v-model="formData.front_money" :disabled='type==3'/>
                </FormItem>
                 <FormItem label='详细地址：'>
                    <Input clearable class="form_item" placeholder="请输入详细地址" v-model="formData.address" :disabled='type==3'/>
                </FormItem>
                 <FormItem label='手机号：'>
                    <Input clearable class="form_item" placeholder="请输入手机号" v-model="formData.mobile" :disabled='type==3'/>
                </FormItem>
                <FormItem label='开始日期：'>
                    <DatePicker type='date' v-model="formData.start_time" placeholder='年/月/日' class="form_item" :disabled='type==3'></DatePicker>
                </FormItem>
                 <FormItem label='交付日期：'>
                    <DatePicker type='date' v-model="formData.predict_time" placeholder='年/月/日' class="form_item" :disabled='type==3'></DatePicker>
                </FormItem>
                <FormItem label='业务员：'>
                    <Select filterable clearable v-model="formData.salesman" class="form_item" :disabled='type==3'>
                     <Option v-for="item in users" :key="item.id" :value="item.id" :label="item.nickname"></Option>
                    </Select>
                </FormItem>
                 <FormItem label='备注：'>
                    <Input type="textarea" class="form_item" placeholder="请输入" v-model="formData.remark" :disabled='type==3'/>
                </FormItem>
        </Form>
        <Card style="max-height:67%;overflow:auto">
            <Form :label-width='110' class="form_content">
                 <FormItem label='区域：'>
                    <Select filterable clearable class="form_item" v-model="searchData.area">
                        <Option v-for="(item,index) in TableAreaList" :key="index" :value="item" :label="item"/>
                    </Select>
                </FormItem>
                         <FormItem label='楼栋：'>
                    <Select filterable clearable class="form_item" v-model="searchData.house">
                        <Option v-for="(item,index) in TableHouseList" :key="index" :value="item" :label="item"/>
                    </Select>
                </FormItem>
                         <FormItem label='单元：'>
                    <Select filterable clearable class="form_item" v-model="searchData.unit">
                        <Option v-for="(item,index) in TableUnitList" :key="index" :value="item" :label="item"/>
                    </Select>
                </FormItem>
                         <FormItem label='楼层：'>
                    <Select filterable clearable class="form_item" v-model="searchData.layer">
                        <Option v-for="(item,index) in TableLayerList" :key="index" :value="item" :label="item"/>
                    </Select>
                </FormItem>
                         <FormItem label='房号：'>
                    <Select filterable clearable class="form_item" v-model="searchData.number">
                        <Option v-for="(item,index) in TableNumberList" :key="index" :value="item" :label="item"/>
                    </Select>
                </FormItem>
                <FormItem label='产品分类：'>
                    <Select filterable clearable class="form_item" v-model="searchData.product_type">
                        <Option v-for="(item,index) in productTypeList" :key="index" :value="item" :label="item"/>
                    </Select>
                </FormItem>
                 <FormItem label='图号：'>
                    <Select filterable clearable class="form_item" v-model="searchData.url_number">
                        <Option v-for="(item,index) in productTitleList" :key="index" :value="item" :label="item"/>
                    </Select>
                </FormItem>
                 <FormItem label='产品名称：'>
                    <Select filterable clearable class="form_item" v-model="searchData.title">
                        <Option v-for="(item,index) in urlNumberList" :key="index" :value="item" :label="item"/>
                    </Select>
                </FormItem>
                 <FormItem label='左右式：'>
                    <Select filterable clearable class="form_item" v-model="searchData.fashion">
                         <Option :value="0" label='无'/>
                        <Option :value="1" label="左"/>
                         <Option :value="2" label='右'/>
                    </Select>
                </FormItem>
                 <FormItem label='拆单状态：' v-if="type==2">
                    <Select filterable clearable class="form_item" v-model="searchData.explode_status">
                        <Option :value="0" label='未拆单'/>
                        <Option :value="1" label="已拆单"/>
                    </Select>
                </FormItem>
                <FormItem label='下生产状态：' v-if="type==3">
                    <Select filterable clearable class="form_item" v-model="searchData.status">
                        <Option :value="0" label="未下生产"/>
                        <Option :value="1" label="已下生产"/>
                    </Select>
                </FormItem>
                 <FormItem :label-width='50'>
                    <Button type="primary" @click="handleSearch">搜索</Button>
                </FormItem>
            </Form>
            <!-- <div class="over_table">
                <Button type="primary" style="float:left" @click="handleSet(null,6)">新增</Button>
                <Upload
              style="display:inline-block;float:right"
          name="your_file"
          :show-upload-list="false"
          :headers="headers"
          :on-error="uploadError"
          :on-success="uploadSuccess"
          :action="$store.state.ip + '/api/deep_import_news'"
          :data='{order_no:recordOrderNO?recordOrderNO:formData.order_no}'
        >
          <Button type="primary">导入</Button
          >
        </Upload>
            </div> -->
            <!-- <Table :data='tableData' :columns='tableColumns' border style="clear:both" max-height='400'>
                <template slot="set" slot-scope="{row}">
                    <a style="margin-right:10px" @click="handleSet(row,1)">拆单</a>
                    <a style="margin-right:10px" @click="handleSet(row,2)">复制</a>
                    <a style="margin-right:10px" @click="handleSet(row,3)">详情</a>
                    <a @click="handleSet(row,4)">删除</a>
                </template>
            </Table> -->
             <vxe-table
          border
          align='center'
          ref="xTable"
          max-height='65%'
          show-overflow
          :data="tableData"
          :column-config="{resizable: true}"
          :edit-config="{trigger: 'click', mode: 'row'}"
          @checkbox-change='handleSelectTable'
          @checkbox-all='handleSelectAll'
          >
          <vxe-column type="checkbox" width="80" title="选择"></vxe-column>
           <vxe-column field="order_number" width="120" title="订单编号"></vxe-column>
           <vxe-column field="area" width="60" title="区域"></vxe-column>
          <vxe-column field="house" width="60" title="楼栋"></vxe-column>
          <vxe-column field="unit" width="60" title="单元"></vxe-column>
          <vxe-column field="layer" width="60" title="楼层"></vxe-column>
          <vxe-column field="number" width="60" title="房号"></vxe-column>
            <vxe-column field="product_type" title="产品分类" :edit-render="{enabled:type==3?false:true}" min-width="100">
              <template #edit="{ row }">
                <vxe-select v-model="row.product_type" type="text" :filterable='true' clearable transfer>
                    <vxe-option v-for="(item,index) in productTypeList" :key="index" :value="item" :label="item"></vxe-option>
                </vxe-select>
              </template>
            </vxe-column>
            <vxe-column field="title" title="产品名称" :edit-render="{enabled:type==3?false:true}" min-width="100">
                <template #default="{row}">
                      <span>{{row.title}}</span>
                </template>
              <template #edit="{ row }">
                <vxe-input v-model="row.title" type="text" :clearable='true'></vxe-input>
              </template>
            </vxe-column>
            <vxe-column field="url_number" title="图号" :edit-render="{enabled:type==3?false:true}" min-width="80">
              <!-- <template #default="{ row }">
               <span>{{row.sex}}</span>
              </template> -->
              <template #edit="{ row }">
               <vxe-input v-model="row.url_number" type="text"></vxe-input>
              </template>
            </vxe-column>
            <!-- <vxe-column field="measure" title="型号" :edit-render="{enabled:type==3?false:true}" min-width="80">
              <template #edit="{ row }">
                <vxe-input v-model="row.measure" type="text" placeholder="请输入型号"></vxe-input>
              </template>
            </vxe-column> -->
            <vxe-column field="num" title="数量" min-width="80">
              <template #default="{ row }">
             <a @click="clickNum(row)">{{row.num}}</a>
            </template>
            </vxe-column>
              <!-- <vxe-column field="long" title="长" :edit-render="{enabled:type==3?false:true}" min-width="80">
              <template #edit="{ row }">
              <vxe-input v-model="row.long" type="text" placeholder="请输入长" transfer></vxe-input>
            </template>
            </vxe-column> -->
              <!-- <vxe-column field="width" title="宽" :edit-render="{enabled:type==3?false:true}" min-width="80">
              <template #edit="{ row }">
              <vxe-input v-model="row.width" type="text" placeholder="请输入宽" transfer></vxe-input>
            </template>
            </vxe-column> -->
              <!-- <vxe-column field="high" title="高" :edit-render="{enabled:type==3?false:true}" min-width="80">
              <template #edit="{ row }">
              <vxe-input v-model="row.high" type="text" placeholder="请输入高" transfer></vxe-input>
            </template>
            </vxe-column> -->
              <!-- <vxe-column field="url" title="图纸" min-width="80">
              <template #default="{ row }">
                <img
                  @click="looks(row.url)"
                  :src="$store.state.ip + row.url"
                  alt=""
                  style="width:40px;height:auto"
                />
            </template>
            </vxe-column> -->
              <!-- <vxe-column field="fashion" title="左右式" min-width="80">
            <template #default='{row}'>
                <span>{{row.fashion==1?'左':row.fashion==2?'右':''}}</span>
            </template> -->
              <!-- <template #edit="{ row }">
             <vxe-select v-model="row.date12" type="text" :filterable='true' clearable>

             </vxe-select>
            </template> -->
            <!-- </vxe-column> -->
              <!-- <vxe-column field="remark" title="备注" :edit-render="{enabled:type==3?false:true}" min-width="80">
              <template #edit="{ row }">
              <vxe-input v-model="row.remark" type="text" placeholder="请输入备注" transfer>

              </vxe-input>
            </template>
            </vxe-column> -->
          <vxe-column field="explode_status" title="拆单状态" min-width="80">
           <template #default="{ row }">
               <span>{{row.explode_status==0?'未拆单':'已拆单'}}</span>
              </template>
          </vxe-column>
           <vxe-column field="status" title="生产状态" v-if="type==3" min-width="80">
           <template #default="{ row }">
               <span>{{row.status==0?'未下生产':'已下生产'}}</span>
              </template>
          </vxe-column>
           <vxe-column title="操作" min-width="150">
            <template #default="{ row }">
                 <!-- <a style="margin-right:10px" @click="handleSet(row,1)" v-show="type==2&&row.status==0&&row.split_state==1">拆单</a> -->
                    <!-- <a style="margin-right:10px" @click="handleSet(row,2)" v-show="type!=3">复制</a> -->
                    <a style="margin-right:10px" @click="handleSet(row,3)">详情</a>
                    <!-- <a @click="handleSet(row,4,$rowIndex)" v-show="type!=3">删除</a> -->
                    <a @click="handleSet(row,5)" v-show="type==3&&row.explode_status==1&&row.status==0">下生产</a>
              </template>
          </vxe-column>
        </vxe-table>
            <div class="footer">
                 <Page
          :page-size-opts="[10, 20, 30, 40, 100]"
          @on-page-size-change="changeSize"
          @on-change="changePage"
          :current="pageIndex"
          show-total
          :total="total"
          show-sizer
          transfer
          :page-size="pageSize"
        />
            </div>
        </Card>
        <Modal title="下生产" width='400' :closable='false' :mask-closable='false' v-model="show_product">
             <div style="text-align:center">
                <div><label>生产人员：</label><Select v-model="modalProductData.process_man" filterable clearable style="width:200px;margin-bottom:15px">
                    <Option v-for="item in users" :key="item.id" :value="item.id" :label="item.nickname"></Option>
                    </Select></div>
                <div><label>选择时间：</label><DatePicker type='daterange' v-model="modalProductData.time" style="width:200px" placeholder='年/月/日'></DatePicker></div>
             </div>
             <div slot="footer">
                <Button @click="show_product=false">取消</Button>
                <Button type="primary" @click="handleSureProduct">确认</Button>
             </div>
        </Modal>
        <Modal width='1000' footer-hide :mask-closable='false' v-model="show_num">
            <Form  :label-width='100' style="display:flex;flex-wrap:wrap">
                <FormItem label='区域编码：'>
                    <Select v-model="modalNumData.code" filterable clearable style="width:200px">
                        <Option v-for="(item,index) in codeList" :key="index" :value="item" :label="item"/>
                    </Select>
                </FormItem>
                <FormItem label='区域名称：'>
                    <Select v-model="modalNumData.title" filterable clearable style="width:200px">
                         <Option v-for="(item,index) in titleList" :key="index" :value="item" :label="item"/>
                    </Select>
                </FormItem>
                <FormItem label='户型：'>
                    <Select v-model="modalNumData.house_type" filterable clearable style="width:200px">
                         <Option v-for="(item,index) in houseTypeList" :key="index" :value="item" :label="item"/>
                    </Select>
                </FormItem>
                <FormItem label='楼栋：'>
                    <Select v-model="modalNumData.house" filterable clearable style="width:200px">
                         <Option v-for="(item,index) in houseList" :key="index" :value="item" :label="item"/>
                    </Select>
                </FormItem>
                <FormItem label='单元：'>
                    <Select v-model="modalNumData.unit" filterable clearable style="width:200px">
                         <Option v-for="(item,index) in unitList" :key="index" :value="item" :label="item"/>
                    </Select>
                </FormItem>
                <FormItem label='楼层：'>
                    <Select v-model="modalNumData.layer" filterable clearable style="width:200px">
                         <Option v-for="(item,index) in layerList" :key="index" :value="item" :label="item"/>
                    </Select>
                </FormItem>
                <FormItem label='房间号：'>
                    <Select v-model="modalNumData.number" filterable clearable style="width:200px">
                         <Option v-for="(item,index) in numberList" :key="index" :value="item" :label="item"/>
                    </Select>
                </FormItem>
                <FormItem :label-width='40'>
                    <Button type="primary" @click="handleNumSearch">搜索</Button>
                </FormItem>
            </Form>
            <Table :data='numTableData' :columns='numTableColumns' border max-height='550'>
            </Table>
             <div class="footer">
                 <Page
          :page-size-opts="[10, 20, 30, 40, 100]"
          @on-page-size-change="numChangeSize"
          @on-change="numChangePage"
          :current="numPageIndex"
          show-total
          :total="numTotal"
          show-sizer
          :page-size="numPageSize"
          transfer
        />
            </div>
        </Modal>
        <Modal title="强制删除" width='30' :closable='false' :mask-closable='false' v-model="show_del">
            <div>
                <label>用户名：</label><Input clearable v-model="delData.user_name"/>
            </div>
            <div>
                <label>密码：</label><Input clearable v-model="delData.password" type="password"/>
            </div>
            <div slot="footer" style="text-align:center">
                <Button style="margin-right:10px" @click="show_del=false">取消</Button>
                <Button type="primary" @click="handleDelSure">确认</Button>
            </div>
        </Modal>
    </div>
</template>
<script>
export default {
    data(){
        return{
            delData:{
                 user_name:'',
                 password:''
            },
            show_del:false,
            selectData:[],
            TableHouseList:[],
            TableUnitList:[],
            TableLayerList:[],
            TableAreaList:[],
            TableNumberList:[],
            codeList:[],
            titleList:[],
            houseList:[],
            houseTypeList:[],
            unitList:[],
            layerList:[],
            numberList:[],
            modalNumData:{
                code:'',
                title:'',
                house:'',
                house_type:'',
                unit:'',
                layer:'',
                number:''
            },
            numUrlNumber:'',
            numProxyData:{},
            numTableData:[],
            numTableColumns:[
                {title:'序号',type:'index',align:'center',minWidth:100},
                {title:'区域编码',key:'code',align:'center',minWidth:100},
                {title:'区域名称',key:'title',align:'center',minWidth:100},
                {title:'户型',key:'house_type',align:'center',minWidth:100},
                {title:'楼栋',key:'house',align:'center',minWidth:100},
                {title:'单元',key:'unit',align:'center',minWidth:100},
                {title:'楼层',key:'layer',align:'center',minWidth:100},
                {title:'房号',key:'number',align:'center',minWidth:100}
            ],
            numPageIndex:1,
            numPageSize:10,
            numTotal:0,
            show_num:false,
            exportProduct:[],
            modalProductData:{
                time:[],
                process_man:'',
            },
            show_product:false,
            proxyData:{},
            productTypeList:[],
            urlNumberList:[],
            productTitleList:[],
            searchData:{
                layer:'',
                unit:'',
                number:'',
                area:'',
                house:'',
                product_type:'',
                url_number:'',
                title:'',
                fashion:'',
                explode_status:'',
                status:''
            },
               headers: { Authorization: localStorage.getItem("token") },
            pageSize:10,
            pageIndex:1,
            total:0,
            tableData:[],
            users:[],
            warningList:[],
            customList:[],
           type:'',
           formData:{
              order_no:'',
              residential_name:'',
              abbreviation:'',
              warning_state:'',
              custom_id:null,

            //   project_title:'',
            //   abbreviation:'',
            //   client_id:'',
            //   warning_state:'',
            //   front_money:'',
            //   address:'',
            //   mobile:'',
            //   remark:'',
            //   start_time:'',
            //   end_time:'',
            //   user_id:''
           },
           ruleValidate:{
           order_no: [
                        { required: true, message: '项目编号不能为空！', trigger: 'blur' }
                    ],
            residential_name:[
                {required:true,message:'项目名称不能为空',trigger:'blur'}
            ],
            abbreviation:[
                {required:true,message:'项目简称不能为空',trigger:'blur'}
            ],
            custom_id:[
                {required:true,message:'客户名称不能为空',trigger:'change',type:'number'}
            ],
             warning_state: [
                        { required: true, message: '紧急程度不能为空', trigger:'blur',type:'number'}
                    ],
           }
        }
    },
    created(){
            this.type = this.$route.query.type;
            // 获取紧急程度
    this.axios.get("/api/warning_list").then((res) => {
      this.warningList = res.data.data;
    });
    //获取客户列表
    this.axios.get("/api/custom_list").then((res) => {
      this.customList = res.data.data;
    });
    //获取人员列表
     this.axios.get('/api/user').then(res=>{
            this.users = res.data.data
        })
    },
    mounted(){
           this.initData();
    },
    methods:{
        handleDelSure(){
           if(!this.delData.password||!this.delData.user_name){
            return this.$Message.warning('请输入完整信息！')
           }
           let url_number=[];
           this.selectData.forEach(v=>{
            if(url_number.indexOf(v.url_number)==-1){
                url_number.push(v.url_number);
            }
           })
           this.axios.post('/api/split_del',{...this.delData,order_no:this.$route.query.order_no,url_number}).then(res=>{
            if(res.code==200){
                this.$Message.success(res.msg);
                this.show_del = false;
                this.initData(this.proxyData);
            }
           })
        },
        handleDel(){
              if(this.selectData.length==0){
            return this.$Message.warning('请选择要强制删除的数据！');
           }
               this.delData={
                 user_name:'',
                 password:''
            };
              this.show_del=true;
        },
        handleExport(){
           if(this.selectData.length==0){
            return this.$Message.warning('请选择要下生产的数据！');
           }
           if(!this.selectData.every(v=>(v.explode_status==1&&v.status==0))){
            return this.$Message.warning('数据中有不能下生产的数据！');
           }
           this.show_product = true;
           let data = [];
           this.selectData.forEach(v=>{
            data.push({
                url_number:[v.url_number],
                          cut_order_product_ids:v.cut_order_product_ids,
                          measure:[v.measure],
                          house_id:[v.house_id],
                          order_no:v.order_no
            })
           })
                    this.exportProduct=data;
        },
           uploadSuccess(res) {
      if (res.code == 200) {
          this.$Message.success(res.msg);
          this.initData(this.proxyData);
      } else {
        this.$Message.warning(res.msg || "上传失败");
      }
    },
          uploadError(err) {
      this.$Message.error(err.msg || "上传失败");
    },
        handleSelectAll(e){
            let data = [];
             e.records.forEach(v=>{
                 data.push({
                    id:v.id,
                    order_no:v.order_no,
                    product_name:v.title,
                    url_number:v.url_number,
                    cut_order_product_ids:v.cut_order_product_id,
                          measure:v.measure,
                          house_id:v.house_id,
                          explode_status:v.explode_status,
                          status:v.status,
                 })
             })
           this.selectData = data;
        },
        // { checked, row, rowIndex, $rowIndex, column, columnIndex, $columnIndex, $event }
        handleSelectTable(e){
             console.log(e.records);
             let data = [];
             e.records.forEach(v=>{
                 data.push({
                    id:v.id,
                    order_no:v.order_no,
                    product_name:v.title,
                    url_number:v.url_number,
                    cut_order_product_ids:v.cut_order_product_id,
                          measure:v.measure,
                          house_id:v.house_id,
                           explode_status:v.explode_status,
                          status:v.status,
                 })
             })
             this.selectData = data;
             
        },
        handleTakeApart(){
              if(this.selectData.length==0){
                return this.$Message.warning('请选择需要拆单的数据！');
              }
              if(!this.selectData.every(v=>(v.url_number==this.selectData[0].url_number))){
                return this.$Message.warning('批量拆单只能选择一个图号！')
              }
              if(!this.selectData.every(v=>(v.status==0))){
                return this.$Message.warning('选择的数据中有不能拆单的数据！')
              }
              document.getElementsByClassName('ivu-upload-input')[0].click();
        },
        handleNumSearch(){
              let obj = JSON.parse(JSON.stringify(this.modalNumData));
              this.numProxyData = obj;
              this.numInitData(obj);
        },
        numChangeSize(e){
           this.numPageSize = e;
           this.numPageIndex = 1;
           this.numInitData(this.numProxyData);
        },
        numChangePage(e){
            this.numPageIndex = e;
            this.numInitData(this.numProxyData);
        },
        numInitData(row){
          this.axios.post('/api/split_num_detail',{order_no:this.$route.query.order_no,url_number:this.numUrlNumber,...row,page_index:this.numPageIndex,page_size:this.numPageSize}).then(res=>{
                      this.numTableData = res.data.data;
                      this.numTotal = res.data.total;
                      this.codeList = res.data.code;
                      this.houseList =res.data.house;
                      this.houseTypeList = res.data.house_type;
                      this.layerList = res.data.layer;
                      this.numberList =res.data.number;
                      this.titleList = res.data.title;
                      this.unitList = res.data.unit;
          })
        },
        clickNum(row){
               
               this.numUrlNumber = row.url_number;
               this.numInitData();
               this.$nextTick(()=>{
                 this.show_num = true;
               })
              
        },
        handleSureProduct(){
             if(this.modalProductData.time.length!=2||!this.modalProductData.process_man){
                return this.$Message.warning('请填写完整数据！')
             }
             let process_start_time = Date.parse(this.modalProductData.time[0]).toString().slice(0,10);
             let process_end_time = Date.parse(this.modalProductData.time[1]).toString().slice(0,10); 
             let data = [];
             this.exportProduct.forEach(ele => {
                 data.push({...ele,process_man:this.modalProductData.process_man,process_start_time,process_end_time})
             });
             this.axios.post('/api/split_pull_product',{list:data}).then(res=>{
                if(res.code==200){
                    this.$Message.success(res.msg);
                    this.show_product=false;
                    this.initData(this.proxyData);
                }
             })
        },
        handleSearch(){
               let obj = JSON.parse(JSON.stringify(this.searchData));
               this.proxyData = obj;
               this.initData(obj);
        },
          looks(img) {
      const array = [{ img_url: img }];
      this.$previewImg({
        list: array,
        baseUrl: this.$store.state.ip,
        baseImgField: "img_url",
        baseTitleField: "",
      });
    },
        initData(row){
   this.axios.get('/api/split_detail',{params:{order_no:this.$route.query.order_no,oa_id:this.$route.query.oa_id,page_size:this.pageSize,page_index:this.pageIndex,...row}}).then(res=>{
            this.tableData = res.data.detail.data;
            this.total = res.data.detail.total;
            this.productTypeList = res.data.product_type;
            this.productTitleList = res.data.product_title;
            this.urlNumberList = res.data.url_number;
            this.TableHouseList = res.data.house;
            this.TableUnitList= res.data.unit;
            this.TableAreaList = res.data.area;
            this.TableNumberList = res.data.number;
            this.TableLayerList = res.data.layer;
            this.tableData.forEach((v,index)=>{
                v.index = index+1
            })
           this.formData = JSON.parse(JSON.stringify(res.data));
           delete this.formData.detail;
           if(!this.customList.find(v=>(v.id==this.formData.custom_id))){
            this.formData.custom_id=null;
           }
           
           this.formData.start_time = this.func.replaceDateNoHMS(this.formData.start_time);
           this.formData.predict_time = this.func.replaceDateNoHMS(this.formData.predict_time);
   })
        },
    //       uploadSuccess(res) {
    //   if (res.code == 200) {
    //        this.axios.post('/api/deep_detail',{order_no:this.recordOrderNO?this.recordOrderNO:this.formData.order_no}).then(res=>{
    //              this.tableData = res.data.data;
    //              this.total = res.data.total;
    //        })
    //   } else {
    //     this.$Message.warning(res.msg || "上传失败");
    //   }
    // },
    //       uploadError(err) {
    //   this.$Message.error(err.msg || "上传失败");
    // },

        changeSize(e){
         this.pageSize = e;
         this.pageIndex =1;
         this.initData(this.proxyData);
                 },
        changePage(e){
           this.pageIndex = e;
           this.initData(this.proxyData);
        },
        handleSet(row,type,index){//1拆单2复制3详情4删除5下计划6新增
              switch(type){
                case 3:
                case 1:
                    this.$router.push({path:'/cms/BidSystem/ProductDeOrder/newSplitOrder',query:{order_no:this.$route.query.order_no,...row,type}})
                    break;
                case 2:
            //         delete row._X_ROW_KEY; //删个下标，不然下表就很奇怪
            //          let xTable = this.$refs.xTable
            //   const record = {
            //     checked: false,
            //     ...row
            //   }
            //   xTable.insertAt(record, row).then(({ row }) => {
            //     xTable.setActiveRow(row)
            //   })
            let obj = JSON.parse(JSON.stringify(row));
            this.tableData.splice(index,0,obj);
            this.tableData.forEach((v,idx)=>{
                v.index = idx+1;
            })
                    break;
                // case 3:
                //     this.$router.push('/cms/BidSystem/ProductDeOrder/newConfirm')
                //     break;
                case 4:
                    // this.$refs.xTable.remove(this.$refs.xTable.getData(index))
                    this.tableData.splice(index,1);
                    this.tableData.forEach((val,idx)=>{
                        val.index = idx+1;
                    })
                    break;
                case 5:
                    this.show_product = true;
                    this.exportProduct=[{
                        url_number:[row.url_number],
                          cut_order_product_ids:row.cut_order_product_id,
                          measure:[row.measure],
                          house_id:[row.house_id],
                          order_no:row.order_no
                    }]
                    break;
                case 6:
                   let data = {};
                   this.tableData.unshift(data);
                    this.tableData.forEach((val,idx)=>{
                        val.index = idx+1;
                    })
                    break;
              }
        },
         handleSubmit (name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                     this.handleSave();
                    } else {
                        this.$Message.warning('请填写必填信息！');
                    }
                })
            },
              handleSave(){
                this.axios.post('/api/split_order_save',{order_no:this.$route.query.order_no,...this.formData}).then(res=>{
                    if(res.code==200){
                        this.$Message.success(res.msg);
                        this.initData(this.proxyData)
                    }
                })
              }
    }
}
</script>
<style lang="scss" scoped>
.form_content{
    display: flex;
    flex-wrap: wrap;
    margin-top: 10px;
    .form_item{
        width:230px
    }
}
.over_table{
margin-bottom: 10px;
}
.over_table::after{
    content:'';
    clear:both;
    display: block;
}
.footer{
    margin-top: 10px;
    text-align: center;
}
</style>