<template>
    <div class="main-content12">
        <div class="pageheader">
            <span class="pagetitle">{{info.type_desc}}-收款设置</span>
        </div>

        <div class="flex-common payment-area">
            <PromptText text="按住左侧图标，上下拖动可进行排序，平台卡券只能放到最后。" :type="1" class="mb32"/>
            <PaymentMethod :paymentList="payList" @confirm="confirmPayment"/>
        </div>

        <div class="save-button" v-if="payList && payList.length>0">
            <GuipButton type="primary" :btnstyle="saveBtnStyleObj" @click="saveConfirm">保存</GuipButton>
        </div>
    </div>
</template>
<script>

import PaymentMethod from "@/components/paymentMethod.vue";
import PromptText from "@/components/PromptText.vue";
import GuipButton from "@/components/GuipButton.vue";

export default {
  name: 'paymentSet',
  props: {
      serviceInfo: {
          type: Object,
          required: true
      }
  },
  components: {
      GuipButton,
      PromptText,
      PaymentMethod
  },
  data(){
    return {
        token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NTAwNTM3MjQsIm5iZiI6MTc1MDA1MzcyNCwiZXhwIjoxNzUyNjQ1NzI0LCJ1c2VyIjoic3VidXNlciIsImxvZ2luX3R5cGUiOjAsImFpZCI6IjEifQ.xyIqBLelB-k6jCifgRevBJTyg_Qrm6m1e4OcHhOpepU',
        info:[],
        payList:[],
        //添加按钮样式
        saveBtnStyleObj: {
            width: '144px',
            height: '46px',
            borderRadius: '4px',
            background: '#006AFF',
        },
    }
  },
  mounted() {
      this.info = this.serviceInfo
      this.payList = this.serviceInfo.paylist
  },
  methods:{
      confirmPayment(payList){
          this.payList = payList
      },
      saveConfirm() {
          let obj = {}
          obj.uid = this.serviceInfo.uid
          obj.type = this.serviceInfo.type
          obj.info = ""

          this.payList.forEach((row) => {
              if(row.status === 1) {
                  let value = row.pay_type
                  if(row.id) value += ',' + row.id

                  obj.info = obj.info + ';' + value;
              }
          });
          obj.info = obj.info.substr(1, obj.info.length-1);

          const that = this
          this.$http('POST', '/agentnew/ajax_payment_switch', obj,{
              headers:{
                  'Auth': this.token
              }
          }).then(response => {
              if(response.status){
                  that.$message.success('保存成功');
                  that.payList = response.data.paylist
                  that.$emit('saveEvent', that.payList)
                  return true;
              }
              that.$message.success(response.info);
          }).catch(error => {
              console.error(error, 'error')
          })
      },
  }
}
</script>
<style lang="scss">

</style>