<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" @submit.native.prevent :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item prop="washCode">
        <el-input v-model="queryParams.washCode" placeholder="请输入衣服条码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label-width="120px" prop="storeId" v-if="userInfoVO.userType !== '02'">
        <el-select v-model="queryParams.storeId" filterable placeholder="请选择门店" clearable>
          <template>
            <el-option v-for="store in storeList" :key="store.id" :label="store.name" :value="store.id">
            </el-option>
          </template>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-date-picker v-model="createTimeRange" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-"
          start-placeholder="收衣日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item prop="clothItemName">
        <el-input v-model="queryParams.clothItemName" placeholder="请输入衣服名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item prop="appUserPhoneNumber">
        <el-input v-model="queryParams.appUserPhoneNumber" placeholder="请输入客户电话" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-tabs type="card" @tab-click="handleClick">
      <el-tab-pane>
        <span slot="label">全部（{{ reception_info.allCount }}）</span>
      </el-tab-pane>
      <el-tab-pane>
        <span slot="label">清洗中（{{ reception_info.washingCount }}）</span>
      </el-tab-pane>
      <el-tab-pane>
        <span slot="label">上挂（{{ reception_info.hangerCount }}）</span>
      </el-tab-pane>
      <el-tab-pane>
        <span slot="label" style="color: #f56c6c">超时（{{ reception_info.timeoutCount }}）</span>
      </el-tab-pane>
      <el-tab-pane>
        <span slot="label">未取（{{ reception_info.notTakeCount }}）</span>
      </el-tab-pane>
    </el-tabs>

    <Page uri="/mapi/order/clothItem/list" :request-params="queryParams" ref="pagination">
      <el-table-column label="订单编号" align="center" prop="orderNo" min-width="150" fixed="left" />
      <el-table-column label="衣物条码" align="center" prop="washCode" width="200" />
      <el-table-column label="衣服名称" align="center" prop="clothItemName" width="150" />
      <el-table-column label="衣物照片" align="center" width="120">
        <template slot-scope="scope">
          <div class="cloth-photos" v-if="scope.row.pics">
            <el-image v-for="(pic, index) in scope.row.pics.split(',')" :key="index" :src="pic" :preview-src-list="scope.row.pics.split(',')"
              fit="cover" class="cloth-photo" @click="handlePreview(scope.row.pics.split(','))">
              <div slot="error" class="image-slot">
                <i class="el-icon-picture-outline"></i>
              </div>
            </el-image>
          </div>
          <span v-else>暂无照片</span>
        </template>
      </el-table-column>
      <el-table-column label="是否重洗" align="center" prop="repeatCount" width="120">
        <template slot-scope="scope">
          <span v-if="scope.row.repeatCount && scope.row.repeatCount > 0" style="color: red"> 重洗 {{ scope.row.repeatCount }} 次 </span>
          <span v-else> 否 </span>
        </template>
      </el-table-column>
      <el-table-column label="客户信息" align="center" prop="appUserName" width="150">
        <template slot-scope="scope">
          <span>{{ scope.row.appUserName ? scope.row.appUserName : '--' }} </span>
          <br />
          <span>{{ scope.row.appUserPhoneNumber ? scope.row.appUserPhoneNumber : '' }}</span>
        </template>
      </el-table-column>

      <el-table-column label="颜色" align="center" width="100">
        <template slot-scope="scope">
          <template v-for="(item, index) in scope.row.orderClothColors">
            {{ index == 0 ? item.clothColorName : ',' + item.clothColorName }}
          </template>
        </template>
      </el-table-column>
      <el-table-column label="收衣时间" align="center" prop="createTime" min-width="130" />
      <el-table-column label="状态" align="center" prop="flowStatus" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_cloth_flow_status" :value="scope.row.flowStatus" />
        </template>
      </el-table-column>
      <el-table-column label="挂衣号" align="center" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.clothHanger">
            {{ scope.row.clothHanger.name + '#' + scope.row.clothHangerCode }}
          </span>
          <span v-else> -- </span>
        </template>
      </el-table-column>
      <el-table-column label="超时" align="center" prop="timeoutDayNum" width="100">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.timeoutDayNum" type="danger">{{ scope.row.timeoutDayNum }}天</el-tag>
          <span v-else>未超时</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" min-width="100">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-view" @click="handleUpdate(scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </Page>

    <!-- 添加或修改洗衣订单衣服明细对话框 -->
    <el-dialog :title="title" :visible.sync="open" size="50%" append-to-body>
      <el-row :gutter="15" style="margin-bottom: 80px; margin-left: 20px; width: calc(100% - 20px)">
        <el-col :span="24">
          <el-descriptions class="margin-top" :column="2" border>
            <el-descriptions-item>
              <template slot="label"> 衣物条码 </template>
              {{ form.washCode }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label"> 洗衣单号 </template>
              {{ form.orderNo }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label"> 衣服名称 </template>
              {{ form.clothItemName }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label"> 颜色 </template>
              <el-tag size="small" v-for="(item, index) in form.orderClothColors" :key="index"
                style="margin-right: 10px; margin-bottom: 2.5px; margin-top: 2.5px">{{ item.clothColorName }}</el-tag>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label"> 瑕疵 </template>
              <el-tag size="small" v-for="(item, index) in form.orderClothFlaws" :key="index"
                style="margin-right: 10px; margin-bottom: 2.5px; margin-top: 2.5px">{{ item.clothFlawName }}</el-tag>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label"> 特殊处理 </template>
              <el-tag size="small" v-for="(item, index) in form.orderClothCrafts" :key="index"
                style="margin-right: 10px; margin-bottom: 2.5px; margin-top: 2.5px">{{ item.clothCraftName + '（￥' + item.price + '）' }}</el-tag>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label"> 附件 </template>
              <el-tag size="small" v-for="(item, index) in form.orderClothAdjuncts" :key="index"
                style="margin-right: 10px; margin-bottom: 2.5px; margin-top: 2.5px">{{ item.adjunctName + '*' + item.num }}</el-tag>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label"> 挂衣号 </template>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label"> 预计取衣 </template>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label"> 衣服状态 </template>
              <dict-tag :options="dict.type.order_cloth_flow_status" :value="form.flowStatus" />
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label"> 照片 </template>
              <template v-if="form.pics">
                <el-image v-for="(item, index) in form.pics.split(',')" :key="index"
                  style="width: 100px; height: 100px; margin-right: 10px; margin-top: 2.5px; margin-bottom: 2.5px" :src="item"
                  :preview-src-list="form.pics.split(',')"> </el-image>
              </template>
            </el-descriptions-item>
          </el-descriptions>
        </el-col>
        <el-col :span="24" style="margin-top: 10px">
          <el-table :data="flowRecords">
            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.order_cloth_flow_action" :value="scope.row.flowStatus" />
              </template>
            </el-table-column>
            <el-table-column label="时间" align="center" prop="createTime" />
            <el-table-column label="操作人" align="center" prop="operateName" />
            <el-table-column label="单位" align="center" prop="operateOrgName" />
          </el-table>
        </el-col>
      </el-row>

      <div slot="footer" class="dialog-footer">
        <!--        <el-button type="primary" @click="submitForm" style="margin-left: 5%">提交</el-button>-->
        <el-button @click="cancel" style="margin-left: 5%">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getreceptionClothing, ListClothingInfo } from '@/api/statistics/reception'
import { getClothItem } from '@/api/order/clothItem'
import { listOrderClothFlowRecordByOrderClothId } from '../../api/order/clothItemFlowRecord'
import { allOrg } from '@/api/system/store'
export default {
  name: 'queryReception',
  dicts: ['sys_yes_no', 'order_cloth_flow_status', 'order_cloth_flow_action'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 洗衣订单衣服明细表格数据
      clothItemList: [],
      // 查询参数
      queryParams: {
        storeId: null,
        clothItemName: null,
        washCode: null,
        clothHangerId: null,
        beginCreateTime: null,
        endCreateTime: null
      },
      createTimeRange: [],
      reception_info: {},
      flowStatus: null,
      timeoutStatus: null,
      userInfoVO: null,
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      flowRecords: [],
      storeList: [],
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.userInfoVO = this.getUserInfo()
    this.getStoreList()
    this.getreception()
    this.getList()
  },
  methods: {
    /** 获取门店下拉数据 */
    getStoreList() {
      allOrg({
        sourceType: '02'
      }).then((response) => {
        this.storeList = response.data
      })
    },
    /** 查询洗衣订单衣服明细列表 */
    getList() {
      this.loading = true
      if (null != this.createTimeRange && '' != this.createTimeRange) {
        this.queryParams['beginCreateTime'] = this.createTimeRange[0]
        this.queryParams['endCreateTime'] = this.createTimeRange[1]
      } else {
        delete this.queryParams.beginCreateTime
        delete this.queryParams.endCreateTime
      }

      this.queryParams.flowStatus = this.flowStatus
      this.queryParams.timeoutStatus = this.timeoutStatus

      this.$nextTick(() => {
        this.$refs.pagination.handleSearch(true)
      })
    },
    getreception() {
      getreceptionClothing(this.queryParams).then((response) => {
        this.reception_info = response.data
      })
    },
    handleClick(tab, event) {
      switch (tab.index) {
        case '0':
          this.flowStatus = ''
          this.timeoutStatus = ''
          break
        case '1':
          this.flowStatus = 0
          this.timeoutStatus = ''
          break
        case '2':
          this.flowStatus = 1
          this.timeoutStatus = ''
          break
        case '3':
          this.timeoutStatus = 0
          this.flowStatus = ''
          break
        default:
          this.flowStatus = 4
          this.timeoutStatus = ''
      }

      this.handleQuery()
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.createTimeRange = []
      this.handleQuery()
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderId: null,
        clothItemId: null,
        clothItemName: null,
        clothSpeedId: null,
        clothSpeedName: null,
        clothMultiple: null,
        clothWashDayNum: null,
        price: null,
        clothNum: null,
        clothWashModeId: null,
        clothWashModeName: null,
        pics: null,
        washCode: null,
        clothHangerId: null,
        isHedging: null,
        hedgingPrice: null,
        createById: null,
        createBy: null,
        createTime: null,
        updateById: null,
        updateBy: null,
        updateTime: null,
        remark: null
      }
      this.resetForm('form')
    },
    handleUpdate(row) {
      this.reset()
      this.flowRecords = []
      const id = row.id || this.ids
      getClothItem(id).then((response) => {
        this.form = response.data
        this.open = true
        this.title = '衣物详情'
        listOrderClothFlowRecordByOrderClothId({ orderClothId: id }).then((res) => {
          this.flowRecords = res.data
        })
      })
    }
  }
}
</script>
