<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" >
	  <el-form-item :label="$t('table.customerName1')" prop="username" label-width="100px">
        <el-input
          v-model="queryParams.name"
          :placeholder="$t('placeholder.name')"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="$t('table.username2')" prop="username" label-width="180px">
        <el-input
          v-model="queryParams.username"
          :placeholder="$t('placeholder.username1')"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{$t('btn.search')}}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{$t('btn.Reset')}}</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-table v-loading="loading" :data="customerManageList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" /> -->
	  <el-table-column :label="$t('table.SerialNumber')" width="50px" align="center">
		<template slot-scope="scope">
			{{ scope.$index + (queryParams.pageNum - 1) * queryParams.pageSize + 1 }}
		</template>
	  </el-table-column>
      <el-table-column :label="$t('table.customerName1')" align="center" prop="name" />
      <el-table-column :label="$t('table.username2')" align="center" prop="username" />
      <el-table-column :label="$t('table.integral')" align="center" prop="integral" :formatter="formatNumberType" />
      <el-table-column :label="$t('table.operation')" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['customerManage:customerManage:orderList']"
          >{{$t('table.orderRecord')}}</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-circle-check"
            @click="handleUpdate2(scope.row)"
            v-hasPermi="['customerIntegralRecord:customerIntegralRecord:list']"
          >{{$t('table.integralRecord')}}</el-button>
		  <el-button
            size="mini"
            type="text"
            icon="el-icon-key"
            @click="handleUpdate3(scope.row)"
            v-hasPermi="['customerManage:customerManage:resetPassword']"
          >{{$t('table.resetPassword')}}</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改客户信息管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-row class="mb8" :gutter="10" style="">
      <el-descriptions class="margin-top" :column="4" border>

        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            {{$t('table.customerName1')}}
          </template>
          {{form.name}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-mobile-phone"></i>
            {{$t('table.phone')}}
          </template>
          {{form.username}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-location-outline"></i>
            {{$t('dialog.payTotal1')}}
          </template>
          {{form.payTotal }}
        </el-descriptions-item>
        <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-tickets"></i>
          {{$t('dialog.payTotal2')}}
        </template>
          {{ form.integral }}
        </el-descriptions-item>

      </el-descriptions>
      </el-row>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px" style="display: flex;flex-wrap:wrap;">
        <el-divider content-position="center">{{$t('dialog.customerManageTitel3')}}</el-divider>
        <el-row class="mb8" :gutter="10" style="">
          <el-table style="width:1150px" v-loading="loading" :data="form.orderList">
            <el-table-column :label="$t('table.SerialNumber')" width="50px" align="center">
              <template slot-scope="scope">
                {{ scope.$index + (queryParams.pageNum - 1) * queryParams.pageSize + 1 }}
              </template>
            </el-table-column>
            <el-table-column :label="$t('table.orderyNo')" align="center" prop="orderyNo" />
            <el-table-column :label="$t('table.commodityType')" align="center" prop="typeName" />
            <el-table-column :label="$t('table.commodityName')" align="center" prop="commodityName" />
            <el-table-column :label="$t('table.departurePlace')" align="center" prop="departurePlace" />
            <el-table-column :label="$t('dialog.departureDate')" align="center" prop="departureDate" />
            <el-table-column :label="$t('dialog.adultNum')" align="center" prop="adultNum" />
            <el-table-column :label="$t('dialog.childNum')" align="center" prop="childNum" />
            <el-table-column :label="$t('dialog.isCoupon')" align="center" prop="isCoupon" >
              <template slot-scope="scope">
                <span v-if="scope.row.isCoupon=='0'">{{$t('dialog.no')}}</span>
                <span v-if="scope.row.isCoupon=='1'">{{$t('dialog.yes')}}</span>
              </template>
            </el-table-column>
            <el-table-column :label="$t('dialog.couponDeduction')" align="center" prop="couponDeduction" />
            <el-table-column :label="$t('dialog.orderMoney4')" align="center" prop="orderMoney" :formatter="formatNumberType" />
          </el-table>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="submitForm">确 定</el-button> -->
        <el-button @click="cancel">{{$t('btn.cancel')}}</el-button>
      </div>
    </el-dialog>
	<el-dialog :title="title" :visible.sync="open2" width="1200px" append-to-body>
    <el-row :gutter="20">
      <el-col :span="6"><div class="grid-content bg-purple"></div></el-col>
      <el-col :span="6"><div class="grid-content bg-purple"></div></el-col>
      <el-col :span="6"><div class="grid-content bg-purple"></div></el-col>
      <el-col :span="6"><div class="grid-content bg-purple"></div></el-col>
    </el-row>
      

      <el-descriptions class="margin-top" :column="3" border>

        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user"></i>
            {{$t('table.customerName1')}}
          </template>
          {{form.name}}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-mobile-phone"></i>
            {{$t('table.phone')}}
          </template>
          {{form.username}}
        </el-descriptions-item>
        <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-tickets"></i>
          {{$t('dialog.supIntegral')}}
        </template>
          {{ form.integral }}
        </el-descriptions-item>

      </el-descriptions>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px" style="display: flex;flex-wrap:wrap;">
      <el-divider content-position="center">{{$t('table.integralRecord')}}</el-divider>
		<!-- <el-divider content-position="center">订单记录</el-divider> -->
		<el-tabs v-model="activeName" type="card">
			<el-tab-pane :label="$t('dialog.customerManageTitel4')" name="1">
				<el-table style="width:1150px" v-loading="loading" :data="list1">
					<el-table-column :label="$t('table.SerialNumber')" width="50px" align="center">
						<template slot-scope="scope">
							{{ scope.$index + 1 }}
						</template>
					</el-table-column>
					<el-table-column :label="$t('dialog.orderMoney4')" align="center" prop="integralNum" :formatter="formatStringNumberType" />
					<el-table-column :label="$t('dialog.updateTime')" align="center" prop="createTime" />
					<el-table-column :label="$t('dialog.orderMoney3')" align="center" prop="integralNum" :formatter="formatStringNumberType" />
					<el-table-column :label="$t('dialog.supIntegral')" align="center" prop="supIntegral" :formatter="formatStringNumberType" />
				</el-table>
			</el-tab-pane>
			<el-tab-pane :label="$t('dialog.customerManageTitel5')" name="2">
				<el-table style="width:1150px" v-loading="loading" :data="list2">
					<el-table-column :label="$t('table.SerialNumber')" width="50px" align="center">
						<template slot-scope="scope">
							{{ scope.$index+ 1 }}
						</template>
					</el-table-column>
					<el-table-column :label="$t('table.customerName1')" align="center" prop="turnInName" />
					<el-table-column :label="$t('table.phone')" align="center" prop="turnInPhone" />
					<el-table-column :label="$t('dialog.createTime3')" align="center" prop="createTime" />
					<el-table-column :label="$t('dialog.integralNum1')" align="center" prop="integralNum" :formatter="formatStringNumberType" />
				</el-table>
			</el-tab-pane>
			<el-tab-pane :label="$t('dialog.customerManageTitel6')" name="3">
				<el-table style="width:1150px" v-loading="loading" :data="list3">
					<el-table-column :label="$t('table.SerialNumber')" width="50px" align="center">
						<template slot-scope="scope">
							{{ scope.$index  + 1 }}
						</template>
					</el-table-column>
					<el-table-column :label="$t('table.customerName1')" align="center" prop="turnInName" />
					<el-table-column :label="$t('table.phone')" align="center" prop="turnInPhone" />
					<el-table-column :label="$t('dialog.createTime4')" align="center" prop="createTime" />
					<el-table-column :label="$t('dialog.integralNum2')" align="center" prop="integralNum" :formatter="formatStringNumberType" />
				</el-table>
			</el-tab-pane>
		</el-tabs>
		<el-row class="mb8" :gutter="10" style="">
			
		</el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="submitForm">确 定</el-button> -->
        <el-button @click="open2=false">{{$t('btn.cancel')}}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCustomerManage, getCustomerManage, delCustomerManage, addCustomerManage, updateCustomerManage,getOrderList,getIntegralList,resetPassword } from "@/api/customerManage/customerManage";
//import {utilsMixin} from "@/utils/mixins/index";

export default {
  name: "CustomerManage",
 // mixins: [utilsMixin],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 客户信息管理表格数据
      customerManageList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
	  open2: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        username: null,
        // password: null,
        // integral: null,
        // deptId: null,
      },
      // 表单参数
      form: {
	  },
	  list1:[],
	  list2:[],
	  list3:[],
      // 表单校验
      rules: {
      },
	  activeName:'1'
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询客户信息管理列表 */
    getList() {
      this.loading = true;
      listCustomerManage(this.queryParams).then(response => {
        this.customerManageList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        username: null,
        password: null,
        integral: null,
        delFlag: null,
        deptId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
    //   this.resetForm("queryForm");
	  this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        name: null,
        username: null
      }
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加客户信息管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      this.title = this.$t('dialog.customerManageTitel1')
      this.form.name = row.name
      this.form.username = row.username
      this.form.integral = row.integral?row.integral.toLocaleString():0
      getOrderList({customerId:id}).then((res) => {
      if(res.code==200){
        this.open = true;
        console.log(res)
        this.form.orderList = res.data.orderList;
        this.form.payTotal = res.data.payTotal?'¥'+res.data.payTotal.toLocaleString():0
      }
      })
    },
	handleUpdate2(row) {
      this.reset();
	  this.list1 = [];
	  this.list2 = [];
	  this.list3 = [];
      const id = row.id || this.ids
	  this.title = this.$t('dialog.customerManageTitel2')
	  this.form.name = row.name
	  this.form.username = row.username
	  this.form.integral = row.integral?row.integral.toLocaleString():0
	  this.open2 = true;
	  getIntegralList({customerId:id,integralType:'1'}).then((res) => {
	  	if(res.code==200){
        console.log(res)
	  		this.list1 = res.rows;
	  	}
	  })
	  getIntegralList({customerId:id,integralType:'3'}).then((res) => {
	  	if(res.code==200){
	  		this.list2 = res.rows;
	  	}
	  })
	  getIntegralList({customerId:id,integralType:'2'}).then((res) => {
	  	if(res.code==200){
	  		this.list3 = res.rows;
	  	}
	  })
    },
	handleUpdate3(row){
		const id = row.id || this.ids
		resetPassword({id:id}).then((res) => {
			if(res.code==200){
				this.$modal.msgSuccess(this.$t('message.success4'));
			}
		})
	},
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCustomerManage(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCustomerManage(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除客户信息管理编号为"' + ids + '"的数据项？').then(function() {
        return delCustomerManage(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('customerManage/customerManage/export', {
        ...this.queryParams
      }, `customerManage_${new Date().getTime()}.xlsx`)
    },
    formatNumberType: function (row,column,cellValue,index) {
      if (cellValue)
        return cellValue.toLocaleString()
      return 0
    },
    formatStringNumberType: function (row,column,cellValue,index) {
      if ( (cellValue) && Number(cellValue) )
        return Number(cellValue).toLocaleString()
      return 0
    }
  }
};
</script>
