<template>
<!--  个人中心-->
  <div class="gerenzhongxin">
    <Header></Header>
    <div class="bg"></div>
    <div class="info jz d-flex">
      <img src="../assets/photo.png">
      <p class="f_36 c_1B" v-if="this.userInfo().username==null">请登录</p>
      <p class="f_36 c_1B" v-if="this.userInfo().username!=null">welcome, {{this.userInfo().username}}</p>
      <a>量体数据</a>
    </div>
    <div class="jz">
      <a-menu class="menu" v-model="current" mode="horizontal" @click="menuChange">
        <a-menu-item key="mail"> 我的账户 </a-menu-item>
        <a-menu-item key="collect"> 我的收藏 </a-menu-item>
        <a-menu-item key="addr"> 地址管理 </a-menu-item>
        <a-sub-menu key="invoice">
          <span slot="title" class="submenu-title-wrapper">发票管理<a-icon type="down" /></span>

            <a-menu-item key="invoice1">
              Option 1
            </a-menu-item>
            <a-menu-item key="invoice2">
              Option 2
            </a-menu-item>
            <a-menu-item key="invoice3">
              Option 3
            </a-menu-item>
            <a-menu-item key="invoice4">
              Option 4
            </a-menu-item>
        </a-sub-menu>
        <a-sub-menu>
          <span slot="title" class="submenu-title-wrapper">全部订单<a-icon type="down" /></span>
          <a-menu-item key="allorders">
            全部订单
          </a-menu-item>
            <a-menu-item key="daizhifu">
              待支付
            </a-menu-item>
            <a-menu-item key="daishouhuo">
              待收货
            </a-menu-item>
            <a-menu-item key="yiwancheng">
              已完成
            </a-menu-item>
            <a-menu-item key="tuihuan">
              退换服务
            </a-menu-item>
        </a-sub-menu>

      </a-menu>
      <div class="mall" v-if="current[0] == 'mail'">
        <div style="width: 1002px;margin: 0 auto">
          <a-form-model
            ref="ruleForm"
            :model="form"
            :rules="rules"
            :label-col="labelCol"
            :wrapper-col="wrapperCol"
          >
            <a-form-model-item label="性别" prop="region">
              <a-select v-model="form.region" placeholder="请选择性别">
                <a-select-option value="shanghai">
                  女士
                </a-select-option>
                <a-select-option value="beijing">
                  先生
                </a-select-option>
              </a-select>
            </a-form-model-item>
            <a-form-model-item label="姓名" prop="desc">
              <a-input placeholder="请输入姓名" v-model="form.desc"  />
            </a-form-model-item>
            <a-form-model-item label="地区" prop="desc">
              <a-input placeholder="请选择地区" v-model="form.desc"  />
            </a-form-model-item>

            <a-form-model-item label="电话" prop="desc">
              <a-input placeholder="请输入电话" v-model="form.desc"  />
            </a-form-model-item>

            <a-form-model-item label="出生日期" required prop="date1">
              <a-date-picker
                v-model="form.date1"
                show-time
                type="date"
                placeholder="请选择出生日期"
                style="width: 100%;"
              />
            </a-form-model-item>
            <a-form-model-item label="电子邮箱" prop="desc">
              <a-input placeholder="请输入电子邮箱" v-model="form.desc"  />
            </a-form-model-item>
            <a-form-model-item label="1" prop="type">
              <a-checkbox value="1" name="type">
                我已阅读并同意黄淮服装定制商城的销售条款和个人信息处理规则
              </a-checkbox>
              <a-checkbox value="2" name="type">
                我同意按照《个人信息处理规则》告知的内容跨境提供本人的个人信息
              </a-checkbox>
            </a-form-model-item>
          </a-form-model>
          <div class="d-flex btnDiv">
            <div type="primary" style="width: 100%;margin-bottom: 10px" class="dialogButton primary   f_12">修改信息</div>
          </div>
          <a @click="show" class="xgmm"> 更改密码?</a>
          <a-modal v-model="visible1" title="更改密码" @ok="handleOk" @cancel="handleCancel">
            <a-form-model
              ref="ruleForm1"
              :model="form1"
              :rules="rules"
            >
              <a-form-model-item label="当前密码" prop="desc">
                <a-input placeholder="请输入当前密码" v-model="form.desc"  />
              </a-form-model-item>
              <a-form-model-item label="新密码" prop="desc">
                <a-input placeholder="请输入新密码" v-model="form.desc"  />
              </a-form-model-item>
            </a-form-model>
          </a-modal>
        </div>
      </div>
      <div class="orderList" >
        <div class="item" v-for="(item,index) in allOrders" :key="index">
          <div class="top d-flex">
            <span>订单编号：{{item.orderNum}}</span>
            <span>
              <a class="delete">删除</a>
              <a class="pay" v-if="!item.pay">未支付</a>
              <a class="pay" v-if="item.pay">已支付</a>
            </span>
          </div>
          <div class="bottom d-flex">
            <div class="l">
              <img :src="item.url">
            </div>
            <div class="r">
              <p class="name f_18 c_333">{{item.name}}</p>
              <p class="kuanshi f_16 c_666 d-flex">
                <span>款式：{{item.type}}<span class="line">|</span>尺码：{{item.size}}<span class="line">|</span>数量：{{item.num}}件</span>
                <span  class="f_20 c_333">¥ {{item.price}}</span>
              </p>
              <p><span class="c_666 f_16">主辅料：{{item.material}}</span><span class="c_333 f_14"></span></p>
              <p class="heji d-flex">
                <span class="f_20 c_1B">总计：¥ {{item.total}}</span>
                <span class="f_16 c_333 ">
                  <a class="btn ljzf" v-if="!item.pay" @click="ljzf(item)">立即支付</a>
                  <a class="btn ljzf" v-if="!item.receipt && item.pay">确认收货</a>
                  <a  class="btn ckxq" @click="openDetail(item)">查看详情</a>
                </span>
              </p>
            </div>
          </div>
        </div>
      </div>
    </div>
    <Footer></Footer>
  </div>
</template>
<script>
  import Header from "../components/Header/HeaderView";
  import Footer from "../components/Footer/FooterView"
  import {mapGetters} from 'vuex'
  import { getFileAccessHttpUrl} from "@/api/manage"
  import { httpAction, getAction } from '@/api/manage'
  export default {
    name: "gerenzhongxin",
    components: { Header,Footer },
    data() {0
      return {
      model:{
        username1: ""
      },

        current: ['allorders'],//目前打开的菜单
        key:'',//当前选择的订单状态（待支付、待收货等）
        allOrders2:[],
        allOrders1:[
          {
            id:1,
            orderNum:'CN172839729',
            pay:false,//是否支付
            receipt:false,//是否收货
            url:require("../assets/cloth001.png"),
            name:'商品名商品名商品名商品名商品',
            type:'衬衫',
            size:'XXL',
            num:1,
            price:2456,
            material:'主料1，辅料2，辅料3，辅料4，辅料5，辅料6',
            total:5912
          },
          {
            id:2,
            orderNum:'CN172839730',
            pay:true,
            receipt:true,//是否收货
            url:require("../assets/cloth002.png"),
            name:'商品名商品名商品名商品名商品',
            type:'衬衫',
            size:'XXL',
            num:2,
            price:2456,
            material:'主料1，辅料2，辅料3，辅料4，辅料5，辅料6',
            total:5912
          },
          {
            id:3,
            orderNum:'CN172839731',
            pay:true,
            receipt:false,//是否收货
            url:require("../assets/cloth002.png"),
            name:'商品名商品名商品名商品名商品',
            type:'衬衫',
            size:'XXL',
            num:3,
            price:2456,
            material:'主料1，辅料2，辅料3，辅料4，辅料5，辅料6',
            total:5912
          }
        ],//所有订单，包括未支付、未收获等
        allOrders:[],//目前展示的订单


        url: {
          list: "/starehouse/starehouse/list",
          getusername: "/sys/user/getusername",
          findgoods: "/sys/user/findgoods"

        },
        labelCol: { span: 3 },
        wrapperCol: { span: 21 },
        other: '',
        form: {
          name: '',
          region: undefined,
          date1: undefined,
          delivery: false,
          type: [],
          resource: '',
          desc: '',
        },
        form1: {
          name: '',
          region: undefined,
          date1: undefined,
          delivery: false,
          type: [],
          resource: '',
          desc: '',
        },
        rules: {
          name: [
            { required: true, message: 'Please input Activity name', trigger: 'blur' },
            { min: 3, max: 5, message: 'Length should be 3 to 5', trigger: 'blur' },
          ],
          region: [{ required: true, message: 'Please select Activity zone', trigger: 'change' }],
          date1: [{ required: true, message: 'Please pick a date', trigger: 'change' }],
          type: [
            {
              type: 'array',
              required: true,
              message: 'Please select at least one activity type',
              trigger: 'change',
            },
          ],
          resource: [
            { required: true, message: 'Please select activity resource', trigger: 'change' },
          ],
          desc: [{ required: true, message: 'Please input activity form', trigger: 'blur' }],
        },
        visible1: false,

      };
    },

    created() {
      this.getusername();
      this.getallgoods();

    },
    mounted() {
      if(this.current[0] == 'allorders'){
        /*this.allOrders = this.allOrders1*/
        this.allOrders = this.allOrders2
      }
    },
    methods: {
      handleCancel(e) {
        this.visible1 = false;
      },
      show() {
        this.visible1 = true;
      },
      handleOk(e) {
        console.log(e);
        this.visible1 = false;
      },
      onSubmit() {
        this.$refs.ruleForm.validate(valid => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm() {
        this.$refs.ruleForm.resetFields();
      },
      getallgoods(){
        getAction(this.url.findgoods).then((res) => {
          if(res.success) {
            this.allOrders2 = res.result;
            this.visible = true;
          } else {
          }
        });
      },
      getusername(){
        getAction(this.url.getusername).then((res) => {
          if(res.success) {
            this.model.username1 = res.result;
            console.log(res.message)
            this.visible = true;
          } else {
          }
        });
      },
      ...mapGetters(["nickname", "avatar", "userInfo", "addRouters", "username", "permissionList"]),
      //获取用户头像
      getAvatar(){
        return getFileAccessHttpUrl(this.avatar())
      },
      callback(key) {
        console.log(key);
      },
      openDetail(item) {
        console.log('item')
        console.log(item)
        if(item.pay == false){
          this.key = 'daizhifu'
        }else if(item.pay == true && item.receipt == false){
          this.key = 'daishouhuo'
        }else if(item.receipt == true){
          this.key = 'yiwancheng'
        }
        this.$router.push({
          path: "/shopping/order",
          query: {
            id: item.id,
            orderNum: item.orderNum,
            pay: item.pay,
            receipt: item.receipt,
            key:this.key,
            },
        });
      },
      ljzf(item){
        this.$router.push({
          path: "/shopping/pay",
          query: {
            id: item.id,
          },
        });
      },
      menuChange(key){
        this.current.shift()
        this.current.push(key.key)
        if(key.key == 'allorders'){
         /* this.allOrders = this.allOrders1*/
          this.allOrders = this.allOrders2
        }
        else if(key.key == 'daizhifu'){
         /* this.allOrders = this.allOrders1.filter(item=>item.pay == false)*/
          this.allOrders = this.allOrders2.filter(item=>item.pay == false)
        }
        else if(key.key == 'daishouhuo'){
          /*this.allOrders = this.allOrders1.filter(item=>item.receipt == false && item.pay == true)*/
          this.allOrders = this.allOrders2.filter(item=>item.receipt == false && item.pay == true)
        }
        else if(key.key == 'yiwancheng'){
          /*this.allOrders = this.allOrders1.filter(item=>item.receipt == true)*/
          this.allOrders = this.allOrders2.filter(item=>item.receipt == true)
        }else{
          this.allOrders=[]
        }
      }
    },
  };
</script>
<style lang="less" scoped>
  @import '../assets/common.css';
  .btnDiv{
    justify-content: space-around;
    .dialogButton {
      width: 240px;
      height: 40px;
      text-align: center;
      line-height: 40px;
      transition: all 0.2s;
    }
    .primary {
      background: #1b1b1b;
      border: 2px solid #1b1b1b;
      color: #e5dfd9;
      &:hover {
        opacity: 0.8;
      }
    }
  }
  .bg{
    width: 100%;
    height: 250px;
    background-image: url("../assets/bg05.png");
  }
  .info{
    flex-direction: column;
    align-items: center;
    margin-top: -75px;
    img{
      width: 150px;
      height: 150px;
      margin-bottom: 30px;
    }
    p{
      margin-bottom: 15px;
    }
    a{
      color: #666;
      font-size: 16px;
      margin-bottom: 60px;
    }
  }
  .menu{width: 1114px;margin:0 auto}
  /deep/ .ant-menu{
    display: flex;
    justify-content: space-between;
  }
  .orderList{
    /*margin-top: 60px;*/
    width: 1114px;margin:0 auto;
    padding: 20px;
    .item{
      border-bottom: 1px solid #DADADA;
      padding-top: 30px;
      .top{
        justify-content: space-between;
        color: #333;
        .delete{
          text-decoration: underline;
          color: #1B1B1B;
          margin-right: 20px;
        }
        .pay{
          color: #E53E41;
        }
      }
      .bottom{
        justify-content: space-between;
        .l{
          img{
            width: 230px;
            height: 230px;
          }
        }
        .r{
          min-width: 800px;
          padding-top: 30px;
          .name{
            font-weight: 500;
          }
          .kuanshi{
            justify-content: space-between;
          }
          .line{
            margin-left: 30px;
            margin-right: 30px;
          }
          .heji{
            justify-content: space-between;
            .btn{
              display: inline-block;
              width: 145px;
              height: 40px;
              line-height: 40px;
              text-align: center;
            }
            .ljzf{
              background: #333333;
              color: #fff;
              margin-right: 20px;
              border: 1px solid #333333;

              &:hover{
                background: rgba(0,0,0,0.7);
                /*color: #333;*/
              }
            }
            .ckxq{
              color: #333;
              border: 1px solid #333333;
              &:hover{
                background: #333;
                color: #fff;
              }
            }
          }
        }
      }
    }
  }
  .mall{
    padding: 50px 100px;
    .ant-checkbox-wrapper + .ant-checkbox-wrapper{
      margin-left: 0;
    }
    .xgmm{
      color: #1b1b1b;
      transition: all 0.32s;
      &:hover{
        opacity: 0.8;
      }
    }
  }
</style>

