// pages/infor/details.js
const app = getApp()
var sever = require("../../api.js").sever;
console.log(sever)
Page({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    showinfofalse:true,
    showinfotrue:false,
    showinfo:false,
    pic_url: '',
    showpic:false,
    expected_time:'',
    msg:'',
    order_num: 0,
    order_status: '',
    order_created_time: '',
    gType: '',
    gCategory: '',
    gColor: '',
    gDescription: '',
    uName: '',
    uMobile: '',
    uAddress: '',
    theimgs: [],
    steps: [{
        // 此步骤是否当前完成状态
        current: false,
        // 此步骤是否已经完成
        done: true,
        // 此步骤显示文案
        text: '10.01',
        // 此步骤描述语
        desc: '步骤一'
      },
      {
        done: true,
        current: false,
        desc: '步骤二',
        text: '10.02'

      },
      {
        done: true,
        current: true,
        text: '10.03',
        desc: '步骤三'
      }
    ],
    pingjia: 0,
    status: 0,
  },
  si:function(){
    var that = this
    if(that.data.showinfo == true){
      that.setData({
        showinfo:false,
        showinfofalse: true,
        showinfotrue: false,
      })
    }else{
      that.setData({
        showinfo: true,
        showinfofalse: false,
        showinfotrue: true,
      })
    }
  },
  onLoad: function() {
    var that = this
    console.log('detailpage')

    app.request({
      url: sever+'getorderdetail',
      method: 'get',
      data: {
        store_id: wx.getStorageSync('user').store_id,
        order_id: wx.getStorageSync('detail_order_id')
      },
      success: function(res) {
        console.log(res.data)
        var order = res.data.data.order
        var picArr = []
        picArr = [...order.picture]
        console.log(picArr)
        //picArr.push(order.picture.split(','))
        var stateArr = ["待审核", "待生产", "生产中", "待发货", "运输中", "待评价", "已评价", "已取消"]
        // that.setData({
        //   msg:res.data.message
        // })
        that.setData({
          status:order.status,
          pic_url:order.qrcode,
          msg:order.remark,
          expected_time: order.expected_time,
          order_num: order.sno,
          order_status: stateArr[order.status],
          order_created_time: order.created_at,
          gCategory: order.category,
          gType: order.type,
          gColor: order.color,
          gDescription: order.question,
          uName: order.customer_name,
          uMobile: order.customer_phone,
          uAddress: order.customer_address,
          theimgs: [...picArr]
        })
        var progress = res.data.data.progress
        var pArr = []
        for (var i = 0; i < progress.length;i++){
          var pObj = {}
          pObj.done= true
          pObj.current=false
          pObj.text=progress[i].created_at
          pObj.desc=progress[i].description
          pArr.push(pObj)
        }
        if (that.data.status!=0) pArr[pArr.length - 1].current = true
        that.setData({
          steps:[...pArr]
        })
      }
    })
  },
  /**
   * 组件的方法列表
   */
  //methods: {
  assess: function() {
    wx.navigateTo({
      url: '../infor/assess',
      success: function() {},
      fail: function() {},
      complete: function() {}
    })
  },
  backhome: function () {
    wx.reLaunch({
      url: '/page/homePage/homePage',
    })
  },
  quxiao: function() {
    app.request({
      url: sever+'updatestatus',
      method: 'post',
      data: {
        store_id: wx.getStorageSync('user').store_id,
        order_id: wx.getStorageSync('detail_order_id'),
        status: 7,
      },
      success: function (res) {
        console.log(res.data)
        if(res.data.data.ok == true){
          wx.showToast({
            title: '取消成功',
            icon:'success',
            duration:1000,
            success: function () {
              wx.reLaunch({
                url: 'infor',
              })
            }
          })
        }else{
          wx.showToast({
            title: '取消失败',
            icon: 'none',
            duration: 1000
          })
        }
      },
      fail:()=>{
        wx.showToast({
          title: '取消失败',
          icon: 'none',
          duration: 1000
        })
      }
    })
  },
  shouhuo: function() {
    app.request({
      url: sever+'updatestatus',
      method: 'post',
      data: {
        store_id: wx.getStorageSync('user').store_id,
        order_id: wx.getStorageSync('detail_order_id'),
        status: 5,
      },
      success: function (res) {
        console.log(res.data)
        if (res.data.data.ok == true) {
          wx.showToast({
            title: '收货成功',
            icon: 'success',
            duration: 1000,
            success: function () {
              wx.reLaunch({
                url: 'infor',
              })
            }
          })
        } else {
          wx.showToast({
            title: '收货失败',
            icon: 'none',
            duration: 1000
          })
        }
      },
      fail:()=>{
        wx.showToast({
          title: '收货失败',
          icon: 'none',
          duration: 1000
        })
      }
    })
  },
  fanhui: function() {
    wx.navigateBack({
      delta: 1
    })
  },
  preImg:function(event){
    var src = event.currentTarget.dataset.src;//获取data-src
    var imgList = event.currentTarget.dataset.list;//获取data-list
    //图片预览
    wx.previewImage({
      current: src, // 当前显示图片的http链接
      urls: imgList // 需要预览的图片http链接列表
    })
  },
  showPic: function (event) {
    // var that = this
    // that.setData({
    //   showpic: true
    // })
    var src = event.currentTarget.dataset.src;//获取data-src
    var imgList = [src];//获取data-list
    //图片预览
    wx.previewImage({
      current: src, // 当前显示图片的http链接
      urls: imgList // 需要预览的图片http链接列表
    })
  },
  hidepic: function () {
    var that = this
    that.setData({
      showpic: false
    })
  },
  upFormID: function (e) {
    console.log('....')
    app.request({
      url: sever+'saveformid',
      method: 'post',
      data: {
        store_id: wx.getStorageSync('user').store_id,
        openid: wx.getStorageSync('user').wechat_open_id,
        formid: e.detail.formId
      },
      success: (res) => {
        console.log(res.data.data.msg)
      }
    })
  }
  //}
})