<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="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="订单状态">
              <j-dict-select-tag placeholder="请选择订单状态" v-model="queryParam.state" dictCode="order_state"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户标识">
              <j-search-select-tag placeholder="请选择用户标识" v-model="queryParam.userId" dict="han_hai_member,nick_name,id"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="关联技师">
                <j-search-select-tag placeholder="请选择关联技师" v-model="queryParam.technicianId" dict="msg_technician,title,id"/>
              </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.payType" dictCode="order_pay"/>
              </a-form-item>
            </a-col>
          </template>
          <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>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </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,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </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="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <msg-order-modal ref="modalForm" @ok="modalFormOk"></msg-order-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import MsgOrderModal from './modules/MsgOrderModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'

  export default {
    name: 'MsgOrderList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      MsgOrderModal
    },
    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: 'createTime'
          },
          {
            title:'头像',
            align:"center",
            dataIndex: 'image',
            scopedSlots: {customRender: 'imgSlot'}
          },
          {
            title:'姓名',
            align:"center",
            dataIndex: 'name'
          },
          {
            title:'电话',
            align:"center",
            dataIndex: 'phone'
          },
          {
            title:'支付时间',
            align:"center",
            dataIndex: 'payTime'
          },
          {
            title:'下单地址',
            align:"center",
            dataIndex: 'address'
          },
          {
            title:'地址标识',
            align:"center",
            dataIndex: 'addressId_dictText'
          },
          {
            title:'总计时间',
            align:"center",
            dataIndex: 'useTime'
          },
          {
            title:'技师名称',
            align:"center",
            dataIndex: 'terName'
          },
          {
            title:'订单状态',
            align:"center",
            dataIndex: 'state_dictText'
          },
          {
            title:'订单价格',
            align:"center",
            dataIndex: 'money'
          },
          {
            title:'用户标识',
            align:"center",
            dataIndex: 'userId_dictText'
          },
          {
            title:'关联技师',
            align:"center",
            dataIndex: 'technicianId_dictText'
          },
          {
            title:'项目标识',
            align:"center",
            dataIndex: 'projectId_dictText'
          },
          {
            title:'项目名称',
            align:"center",
            dataIndex: 'projectName'
          },
          {
            title:'支付方式',
            align:"center",
            dataIndex: 'payType_dictText'
          },
          {
            title:'订单备注',
            align:"center",
            dataIndex: 'remark'
          },
          {
            title:'优惠券标识',
            align:"center",
            dataIndex: 'couponId_dictText'
          },
          {
            title:'技师状态',
            align:"center",
            dataIndex: 'tenState_dictText'
          },
          {
            title:'技师是否接单',
            align:"center",
            dataIndex: 'tenOk',
            customRender: (text) => (text ? filterMultiDictText(this.dictOptions['tenOk'], text) : ''),
          },
          {
            title:'接单时间',
            align:"center",
            dataIndex: 'confirmTime'
          },
          {
            title:'出发时间',
            align:"center",
            dataIndex: 'startTime'
          },
          {
            title:'到达时间',
            align:"center",
            dataIndex: 'arriveTime'
          },
          {
            title:'到达照片',
            align:"center",
            dataIndex: 'arrivalPicture',
            scopedSlots: {customRender: 'imgSlot'}
          },
          {
            title:'服务时间',
            align:"center",
            dataIndex: 'startServiceTime'
          },
          {
            title:'结束服务时间',
            align:"center",
            dataIndex: 'endErviceTime'
          },
          {
            title:'结束服务照片',
            align:"center",
            dataIndex: 'endPicture',
            scopedSlots: {customRender: 'imgSlot'}
          },
          {
            title:'车费',
            align:"center",
            dataIndex: 'temp'
          },
          {
            title:'服务下单时间',
            align:"center",
            dataIndex: 'serviceTime'
          },
          {
            title:'用户评价',
            align:"center",
            dataIndex: 'evaluated'
          },
          {
            title:'技师评价',
            align:"center",
            dataIndex: 'jsEvaluated'
          },
          {
            title:'服务日期',
            align:"center",
            dataIndex: 'serviceDate',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'分销商所得(一级)',
            align:"center",
            dataIndex: 'shopMoney'
          },
          {
            title:'技师所得（项目）',
            align:"center",
            dataIndex: 'tenMoney'
          },
          {
            title:'一级所得',
            align:"center",
            dataIndex: 'tenPrice'
          },
          {
            title:'二级所得',
            align:"center",
            dataIndex: 'tenMinPrice'
          },
          {
            title:'评价所得',
            align:"center",
            dataIndex: 'pinPrice'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/msgOrder/msgOrder/list",
          delete: "/msgOrder/msgOrder/delete",
          deleteBatch: "/msgOrder/msgOrder/deleteBatch",
          exportXlsUrl: "/msgOrder/msgOrder/exportXls",
          importExcelUrl: "msgOrder/msgOrder/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.$set(this.dictOptions, 'tenOk', [{text:'是',value:'Y'},{text:'否',value:'N'}])
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'datetime',value:'createTime',text:'创建日期'})
        fieldList.push({type:'string',value:'image',text:'头像',dictCode:''})
        fieldList.push({type:'string',value:'name',text:'姓名',dictCode:''})
        fieldList.push({type:'string',value:'phone',text:'电话',dictCode:''})
        fieldList.push({type:'datetime',value:'payTime',text:'支付时间'})
        fieldList.push({type:'string',value:'address',text:'下单地址',dictCode:''})
        fieldList.push({type:'sel_search',value:'addressId',text:'地址标识',dictTable:"msg_address", dictText:'address_detail', dictCode:'id'})
        fieldList.push({type:'int',value:'useTime',text:'总计时间',dictCode:''})
        fieldList.push({type:'string',value:'terName',text:'技师名称',dictCode:''})
        fieldList.push({type:'int',value:'state',text:'订单状态',dictCode:'order_state'})
        fieldList.push({type:'BigDecimal',value:'money',text:'订单价格',dictCode:''})
        fieldList.push({type:'sel_search',value:'userId',text:'用户标识',dictTable:"han_hai_member", dictText:'nick_name', dictCode:'id'})
        fieldList.push({type:'sel_search',value:'technicianId',text:'关联技师',dictTable:"msg_technician", dictText:'title', dictCode:'id'})
        fieldList.push({type:'sel_search',value:'projectId',text:'项目标识',dictTable:"msg_shop", dictText:'title', dictCode:'id'})
        fieldList.push({type:'string',value:'projectName',text:'项目名称',dictCode:''})
        fieldList.push({type:'int',value:'payType',text:'支付方式',dictCode:'order_pay'})
        fieldList.push({type:'string',value:'remark',text:'订单备注',dictCode:''})
        fieldList.push({type:'sel_search',value:'couponId',text:'优惠券标识',dictTable:"msg_coupon", dictText:'money', dictCode:'id'})
        fieldList.push({type:'int',value:'tenState',text:'技师状态',dictCode:'ten_state'})
        fieldList.push({type:'switch',value:'tenOk',text:'技师是否接单'})
        fieldList.push({type:'datetime',value:'confirmTime',text:'接单时间'})
        fieldList.push({type:'datetime',value:'startTime',text:'出发时间'})
        fieldList.push({type:'datetime',value:'arriveTime',text:'到达时间'})
        fieldList.push({type:'string',value:'arrivalPicture',text:'到达照片',dictCode:''})
        fieldList.push({type:'datetime',value:'startServiceTime',text:'服务时间'})
        fieldList.push({type:'datetime',value:'endErviceTime',text:'结束服务时间'})
        fieldList.push({type:'string',value:'endPicture',text:'结束服务照片',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'temp',text:'车费',dictCode:''})
        fieldList.push({type:'datetime',value:'serviceTime',text:'服务下单时间'})
        fieldList.push({type:'int',value:'evaluated',text:'用户评价',dictCode:''})
        fieldList.push({type:'int',value:'jsEvaluated',text:'技师评价',dictCode:''})
        fieldList.push({type:'date',value:'serviceDate',text:'服务日期'})
        fieldList.push({type:'BigDecimal',value:'shopMoney',text:'分销商所得(一级)',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'tenMoney',text:'技师所得（项目）',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'tenPrice',text:'一级所得',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'tenMinPrice',text:'二级所得',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'pinPrice',text:'评价所得',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>