<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="是否子单">
              <j-dict-select-tag type="radio" placeholder="请选择是否子单" v-model="queryParam.ischild" dictCode="ischild"/>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="订单类型">
              <j-dict-select-tag type="radio" placeholder="请选择订单类型" v-model="queryParam.ordersType" dictCode="orders_type"/>
            </a-form-item>
          </a-col>
<!--          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="发票客户类型">
              <j-dict-select-tag type="radio" placeholder="请选择发票客户类型" v-model="queryParam.invoiceCustomerType" dictCode="invoice_customer_type"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="发票类型">
              <j-dict-select-tag type="radio" placeholder="请选择发票类型" v-model="queryParam.invoiceType" dictCode="invoice_type"/>
            </a-form-item>
          </a-col>-->
          <a-col :xl="4" :lg="5" :md="6" :sm="22">
            <a-form-item label="订单编号">
              <a-input placeholder="请输入订单编号" v-model="queryParam.ordersNum"></a-input>
            </a-form-item>
          </a-col>
<!--            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="支付方式">
                <j-dict-select-tag placeholder="请选择支付方式" v-model="queryParam.paymentMethod" dictCode="payment_method"/>
              </a-form-item>
            </a-col>-->
            <a-col :xl="3" :lg="5" :md="4" :sm="12">
              <a-form-item label="支付状态">
                <j-dict-select-tag placeholder="请选择支付状态" v-model="queryParam.paymentStatus" dictCode="payment_status"/>
              </a-form-item>
            </a-col>
<!--            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="账号/卡号">
                <a-input placeholder="请输入账号/卡号" v-model="queryParam.accountNo"></a-input>
              </a-form-item>
            </a-col>-->
            <a-col :xl="4" :lg="5" :md="6" :sm="22">
              <a-form-item label="城市">
                <j-area-linkage type="cascader" v-model="queryParam.cityId" placeholder="请选择省市区"/>
              </a-form-item>
            </a-col>
<!--            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="公户账号">
                <a-input placeholder="请输入公户账号" v-model="queryParam.accountNumber"></a-input>
              </a-form-item>
            </a-col>-->
<!--            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="物流企业">
                <j-select-depart placeholder="请选择物流企业" v-model="queryParam.logisticsEnterprisesId"/>
              </a-form-item>
            </a-col>-->
            <a-col :xl="3" :lg="5" :md="4" :sm="12">
              <a-form-item label="交付状态">
                <j-dict-select-tag placeholder="请选择交付状态" v-model="queryParam.deliveryStatus" dictCode="delivery_status"/>
              </a-form-item>
            </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
<!--      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
      <a-button type="primary" icon="download" @click="handleExportXls('订单基本信息管理')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="pcaSlot" slot-scope="text">
          <div>{{ getPcaText(text) }}</div>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="chaidan(record)">拆单</a>
          <a-divider type="vertical" />
          <a @click="shengchan(record)">生产</a>
          <a-divider type="vertical" />
<!--          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />-->
          <a @click="handleDetail(record)">详情</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定撤销订单吗?" @confirm="() => handleDelete(record.id)">
                  <a>撤销订单</a>
          </a-popconfirm>
        </span>

      </a-table>
    </div>

    <zy-orders-modal ref="modalForm" @ok="modalFormOk"></zy-orders-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ZyOrdersModal from './modules/ZyOrdersModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import Area from '@/components/_util/Area'
  import { httpAction, getAction } from '@/api/manage'

  export default {
    name: 'ZyOrdersList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      ZyOrdersModal
    },
    data () {
      return {
        description: '订单基本信息管理管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'是否子单',
            align:"center",
            dataIndex: 'ischild_dictText'
          },
          {
            title:'原订单',
            align:"center",
            dataIndex: 'orderId_dictText'
          },
          {
            title:'下单时间',
            align:"center",
            dataIndex: 'orderTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'订单编号',
            align:"center",
            dataIndex: 'ordersNum'
          },
          {
            title:'总金额(元)',
            align:"center",
            dataIndex: 'money'
          },
          {
            title:'运费',
            align:"center",
            dataIndex: 'freight'
          },
          {
            title:'促销',
            align:"center",
            dataIndex: 'promotionPrice'
          },
          {
            title:'实付款',
            align:"center",
            dataIndex: 'actualPayment'
          },
          {
            title:'交货期(天)',
            align:"center",
            dataIndex: 'deliveryTime'
          },
          {
            title:'订单类型',
            align:"center",
            dataIndex: 'ordersType_dictText'
          },
          {
            title:'顾客',
            align:"center",
            dataIndex: 'userId_dictText'
          },
          {
            title:'商品条目数量',
            align:"center",
            dataIndex: 'goodsQuantity'
          },
/*          {
            title:'支付方式',
            align:"center",
            dataIndex: 'paymentMethod_dictText'
          },*/
          {
            title:'支付状态',
            align:"center",
            dataIndex: 'paymentStatus_dictText'
          },
/*          {
            title:'账号/卡号',
            align:"center",
            dataIndex: 'accountNo'
          },
          {
            title:'开户银行',
            align:"center",
            dataIndex: 'bankDeposit'
          },*/
          {
            title:'支付时间',
            align:"center",
            dataIndex: 'paymentTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'城市',
            align:"center",
            dataIndex: 'cityId',
            scopedSlots: {customRender: 'pcaSlot'}
          },
/*          {
            title:'地址',
            align:"center",
            dataIndex: 'address'
          },
          {
            title:'邮编',
            align:"center",
            dataIndex: 'zipCode'
          },*/
          {
            title:'收货人',
            align:"center",
            dataIndex: 'receiver_dictText'
          },
          {
            title:'联系电话',
            align:"center",
            dataIndex: 'mobile'
          },
/*          {
            title:'发票客户类型',
            align:"center",
            dataIndex: 'invoiceCustomerType_dictText'
          },
          {
            title:'发票类型',
            align:"center",
            dataIndex: 'invoiceType_dictText'
          },
          {
            title:'纳税人识别号',
            align:"center",
            dataIndex: 'taxIdentificationNumber'
          },
          {
            title:'开票地址',
            align:"center",
            dataIndex: 'addressBilling'
          },*/
          {
            title:'电话',
            align:"center",
            dataIndex: 'telephone'
          },
/*          {
            title:'公户开户行',
            align:"center",
            dataIndex: 'bankPublic'
          },
          {
            title:'公户账号',
            align:"center",
            dataIndex: 'accountNumber'
          },*/
          {
            title:'销售门店',
            align:"center",
            dataIndex: 'salesEnterpriseId_dictText'
          },
          {
            title:'销售员',
            align:"center",
            dataIndex: 'salespersonId_dictText'
          },
/*          {
            title:'物流企业',
            align:"center",
            dataIndex: 'logisticsEnterprisesId_dictText'
          },*/
          {
            title:'交付状态',
            align:"center",
            dataIndex: 'deliveryStatus_dictText'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/zyorders/zyOrders/list",
          delete: "/zyorders/zyOrders/delete",
          deleteBatch: "/zyorders/zyOrders/deleteBatch",
          exportXlsUrl: "/zyorders/zyOrders/exportXls",
          importExcelUrl: "zyorders/zyOrders/importExcel",
          chaidan:"/zyorders/zyOrders/chaidan",
          shengchan:"zyorders/zyOrders/shengchan",

        },
        dictOptions:{},
        pcaData:'',
        superFieldList:[],
      }
    },
    created() {
      this.pcaData = new Area()
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      chaidan(record){
        if(record.ischild===0){
          getAction(this.url.chaidan,{id:record.id}).then((res) => {
            if (res.success) {
              this.$message.success("拆单成功！");
              this.loadData();
            }else{
              this.$message.error(res.message);
            }
          })
        }else{
          this.$message.warning("该订单为子单，不可进行拆单！");
        }
      },
      shengchan(record){
        console.log(record)
        if(record.goodsQuantity===1&&record.deliveryStatus===1){
          getAction(this.url.shengchan,{id:record.id}).then((res) => {
            if (res.success) {
              this.$message.success("生产成功！");
              this.loadData();
            }else{
              this.$message.error(res.message);
            }
          })
        }else{
          this.$message.warning("该订单不可生产！");
        }

      },
      getPcaText(code){
        return this.pcaData.getText(code);
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'int',value:'ischild',text:'是否子单',dictCode:'ischild'})
        fieldList.push({type:'string',value:'orderId',text:'原订单',dictCode:'zy_orders,orders_num,id'})
        fieldList.push({type:'date',value:'orderTime',text:'下单时间'})
        fieldList.push({type:'string',value:'ordersNum',text:'订单编号',dictCode:''})
        fieldList.push({type:'double',value:'money',text:'总金额',dictCode:''})
        fieldList.push({type:'double',value:'freight',text:'运费',dictCode:''})
        fieldList.push({type:'double',value:'promotionPrice',text:'促销',dictCode:''})
        fieldList.push({type:'double',value:'actualPayment',text:'实付款',dictCode:''})
        fieldList.push({type:'int',value:'deliveryTime',text:'交货期',dictCode:''})
        fieldList.push({type:'int',value:'ordersType',text:'订单类型',dictCode:'orders_type'})
        fieldList.push({type:'sel_user',value:'userId',text:'顾客'})
        fieldList.push({type:'int',value:'goodsQuantity',text:'商品条目数量',dictCode:''})
        fieldList.push({type:'int',value:'paymentMethod',text:'支付方式',dictCode:'payment_method'})
        fieldList.push({type:'int',value:'paymentStatus',text:'支付状态',dictCode:'payment_status'})
        fieldList.push({type:'string',value:'accountNo',text:'账号/卡号',dictCode:''})
        fieldList.push({type:'string',value:'bankDeposit',text:'开户银行',dictCode:''})
        fieldList.push({type:'date',value:'paymentTime',text:'支付时间'})
        fieldList.push({type:'pca',value:'cityId',text:'城市'})
        fieldList.push({type:'string',value:'address',text:'地址',dictCode:''})
        fieldList.push({type:'string',value:'zipCode',text:'邮编',dictCode:''})
        fieldList.push({type:'sel_user',value:'receiver',text:'收货人'})
        fieldList.push({type:'string',value:'mobile',text:'联系电话',dictCode:''})
        fieldList.push({type:'int',value:'invoiceCustomerType',text:'发票客户类型',dictCode:'invoice_customer_type'})
        fieldList.push({type:'int',value:'invoiceType',text:'发票类型',dictCode:'invoice_type'})
        fieldList.push({type:'string',value:'taxIdentificationNumber',text:'纳税人识别号',dictCode:''})
        fieldList.push({type:'string',value:'addressBilling',text:'开票地址',dictCode:''})
        fieldList.push({type:'string',value:'telephone',text:'电话',dictCode:''})
        fieldList.push({type:'string',value:'bankPublic',text:'公户开户行',dictCode:''})
        fieldList.push({type:'string',value:'accountNumber',text:'公户账号',dictCode:''})
        fieldList.push({type:'sel_depart',value:'salesEnterpriseId',text:'销售门店'})
        fieldList.push({type:'sel_user',value:'salespersonId',text:'销售员'})
        fieldList.push({type:'sel_depart',value:'logisticsEnterprisesId',text:'物流企业'})
        fieldList.push({type:'int',value:'deliveryStatus',text:'交付状态',dictCode:'delivery_status'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>