<!--
 * @Descripttion: 
 * @version: 
 * @Author: 王三华
 * @Date: 2023-10-18 09:55:36
-->
<!--
 * @Descripttion: 
 * @version: 
 * @Author: 王三华
 * @Date: 2023-10-17 14:09:39
-->
<template>
  <view class="content">
    <template v-if="methodsIndex!=2">
      <view class="kuang">{{'订单编号'}}: {{ order }}</view>
      <view class="kuang"
            v-for="(item,index) in backCodeList.orderCancelDetailVOList"
            :key="index">
        <view class="flex_i">
          <view>{{ '产品名称' }}</view>
          <view>{{ item.productName }}</view>
        </view>
        <view class="flex_i">
          <view>{{ '产品数量' }}</view>
          <view>{{ item.number }}</view>
        </view>
        <view class="flex_i">
          <view>订单价格(￥)</view>
          <view>{{ item.orderAmount |toThousandthAndKeepDecimal}}</view>
        </view>
        <view class="flex_i">
          <view>{{ '产品业绩' }}({{ isLocalSymbol() }})</view>
          <view>{{ item.achievement |toThousandthAndKeepDecimal}}</view>
        </view>
        <view class="flex_i">
          <view>{{ '产品业绩' }}(BV)</view>
          <view>{{ item.assAchievement |toThousandthAndKeepDecimal}}</view>
        </view>
      </view>
      <view class="kuang">
        <view>
          <view style="margin-bottom: 10rpx;">{{'扣款币种'}}: {{ backCodeList.accountKeyVal }}</view>
          <view>扣款金额(￥): {{ backCodeList.cost|toThousandthAndKeepDecimal }}</view>
        </view>
      </view>
      <view class="kuang">
        <u--textarea v-model="returnRemark"
                     placeholder="请输入备注"></u--textarea>
      </view>
    </template>
    <template v-else>
      <view class="kuang"
            v-for="(item,index) in backCodeList.memberList"
            :key="index">
        <view class="flex_i">
          <view>{{ '会员编号' }}</view>
          <view>{{ item.memberCode }}</view>
        </view>
        <view class="flex_i">
          <view>{{ '会员姓名' }}</view>
          <view>{{ item.memberName }}</view>
        </view>
        <view class="flex_i">
          <view>{{ '扣款币种' }}</view>
          <view>{{ item.accountKeyVal}}</view>
        </view>
        <view class="flex_i">
          <view>扣款金额(￥)</view>
          <view>{{ item.cost |toThousandthAndKeepDecimal}}</view>
        </view>
      </view>
    </template>
    <view class="zhan"></view>
    <view class="table_a">
      <view class="table_f">
        <u-button size="small"
                  @click="toBack"
                  :text="'取消'"></u-button>
        <u-button size="small"
                  @click="saveBackkOrder(1)"
                  color="rgba(0, 155, 88, 1)"
                  v-hasButtons="['ordercancelMq']"
                  :text="'免签'"></u-button>
        <u-button size="small"
                  @click="saveBackkOrder(2)"
                  color="rgba(243, 169, 0, 1)"
                  v-hasButtons="['ordercancelMf']"
                  :text="'免付'"></u-button>
        <u-button size="small"
                  @click="saveBackkOrder(3)"
                  color="rgba(228, 27, 27, 1)"
                  v-hasButtons="['ordercancelQm']"
                  :text="'全免'"></u-button>
        <u-button size="small"
                  @click="saveBackkOrder(0)"
                  color="rgba(72, 178, 253, 1)"
                  v-hasButtons="['ordercancelQr']"
                  :text="'确认'"></u-button>
      </view>
    </view>
  </view>
</template>

<script>
import * as api from '@/api/information'
import { isLocals, isLocalSymbol } from '@/util/numberToCurrency'
export default {
  data() {
    return {
      changeIndex: 0,
      methodsIndex: 0,
      order: '',
      backCodeList: '',
      returnRemark: '',
    }
  },
  onLoad(options) {
    this.order = options.order
    this.methodsIndex = options.index
    let str
    if (this.methodsIndex == 3) {
      str = '撤销订单'
    } else if (this.methodsIndex == 1) {
      str = '单次撤单'
    }else{
      str = '合并撤单'
    }
    uni.setNavigationBarTitle({
      title: str,
    })
    this.backOrder()
  },
  methods: {
    isLocalSymbol,
    backOrder() {
      api
        .toCancelOrder({ cancelType: this.methodsIndex, orderCode: this.order })
        .then((res) => {
          if (res.code == 200) {
            if (this.methodsIndex == 2) {
              this.backCodeList = res.data
              this.backCodeList.memberList.forEach((item) => {
                item.orderCode = res.data.orderCode
                item.productName = res.data.productName
                item.accountKeyVal = res.data.accountKeyVal
                item.cost = res.data.cost
              })
              this.backCodeList.cancelType = this.methodsIndex
            } else {
              res.data.orderCancelDetailVOList.forEach((item) => {
                item.orderCode = res.data.orderCode
                item.accountKeyVal = res.data.accountKeyVal
                item.cost = res.data.cost
              })
              this.backCodeList = res.data
              this.backCodeList.cancelType = this.methodsIndex
            }
          }
        })
    },
    toBack() {
      uni.navigateBack({ delta: 1 })
    },
    // 撤销订单确认
    saveBackkOrder(index) {
      api
        .validateBind({
          orderCode: this.backCodeList.orderCode,
        })
        .then((res) => {
          if (res.code == 200) {
            if (index == 1 || index == 3) {
              api
                .freeCancelOrder({
                  cancelType: this.backCodeList.cancelType,
                  cancelRoad: index,
                  orderCode: this.backCodeList.orderCode,
                  signType: 1,
                  remark: this.returnRemark,
                })
                .then((response) => {
                  if (response.code == 200) {
                    uni.showToast({
                      title: res.msg,
                      icon: 'none',
                      duration: 1500,
                    })
                    setTimeout(() => {
                      uni.navigateBack({ delta: 1 })
                    }, 1500)
                  }
                })
            } else {
              uni.navigateTo({
                url:
                  '/pages/information/cancleOrder/onlineSign?data=' +
                  JSON.stringify([this.backCodeList]) +
                  '&index=234' +
                  '&cancelRoad=' +
                  index,
              })
            }
          } else {
            uni.showModal({
              title: res.msg,
              success: function (res) {
                if (res.confirm) {
                  if (index == 1 || index == 3) {
                    api
                      .freeCancelOrder({
                        cancelType: this.backCodeList.cancelType,
                        cancelRoad: index,
                        orderCode: this.backCodeList.orderCode,
                        signType: 1,
                        remark: this.returnRemark,
                      })
                      .then((response) => {
                        if (response.code == 200) {
                          uni.showToast({
                            title: res.msg,
                            icon: 'none',
                            duration: 1500,
                          })
                          setTimeout(() => {
                            uni.navigateBack({ delta: 1 })
                          }, 1500)
                        }
                      })
                  } else {
                    uni.navigateTo({
                      url:
                        '/pages/information/cancleOrder/onlineSign?data=' +
                        JSON.stringify([this.backCodeList]) +
                        '&index=234' +
                        '&cancelRoad=' +
                        index,
                    })
                  }
                }
              },
            })
          }
        })
    },
  },
}
</script>

<style lang="scss" scoped>
.content {
  background: #f9f9f9;
  // padding: 20rpx;
  min-height: 94vh;
  padding: 20rpx 0;
}
.kuang {
  margin: 20rpx;
  background: #fff;
  border-radius: 10px 10px 10px 10px;
  padding: 30rpx;
  font-size: 13px;
  font-family: PingFang SC-Regular, PingFang SC;
  font-weight: 400;
  color: #333333;
  display: flex;
  flex-wrap: wrap;
}
.flex_i {
  width: 50%;
  font-size: 12px;
  font-family: PingFang HK-Medium, PingFang HK;
  font-weight: 500;
  color: #999999;
  :nth-child(1) {
    margin-bottom: 10rpx;
  }
  :nth-child(2) {
    font-size: 13px;
    font-family: PingFang HK-Medium, PingFang HK;
    font-weight: 500;
    color: #333333;
    margin-bottom: 20rpx;
  }
}
.zhan {
  height: 100px;
}
.table_a {
  position: fixed;
  width: 100%;
  bottom: 0;
  background: #fff;
  padding: 20rpx 0 40px 0;
}
.table_f {
  display: flex;

  uni-button {
    margin: 20rpx 10rpx;
  }
}
</style>