/*
 *@description:系统参数
 *@author: hudw
 *@date: 2022-07-15 14:43:54
*/
<template>
  <div class="pages">
    <p-card class="full-card-panel full-body-flex" :loading="loading">
      <a-space slot="extra">
        <p-button type="primary" @click="submit" style="width: 100px" htmlType="submit">保存</p-button>
      </a-space>
      <formDetails ref="formDetails" :record="sysConfig" :mainId="mainId" :options="options" @submit="submit"> </formDetails>
    </p-card>
  </div>
</template>
<script>
import formDetails from './model/formDetails/index.formDetails.vue'; /**表单 */
import { mainSaveData, queryAppointment } from './api';
import { initDictionary } from '@/blocks/utils';

export default {
  components: { formDetails },
  props: {
    updateScrollbar: {
      type:Function
    }
  },
  data() {
    return {
      sysConfig: null,
      loading: false,
      options: {},
      selectedRowKeys: [],
      mainId: '',
      currentMainData: null,
      detailsState: 0 /**0=不显示,1=查看,2=新建,3=修改,4=复制 */,
    };
  },

  mounted() {
    this.loading = true;
    let _this = this;
    // -- 装车扫描方式  SCANLOADING_METHED
    // -- 待理货列表显示方式  ARRAGE_GOODS_SHOW
    // -- 待装卸列表显示方式 LOADING_SHOW
    // -- 待预约列表显示方式 APPOINTMENT_SHOW
    // -- 待提货列表显示方式  PICKUP_SHOW
    // -- 待送达列表显示方式  DELIVERY_SHOW
    // -- 待提货处理方式  PICKUP_HANDLE_TYPE
    // -- 待送达处理方式  DELIVERY_HANDLE_TYPE
    // -- 司机开启接单拒绝 DRIVER_OPEN_RECEIVE_REJECT
    // -- 关联外围系统  RELATION_THIRD_SYSTEM
    // -- 事件反馈方式 EVENT_FEEDBACK_MODE

    initDictionary([
      { objectcode: 'SCAN_DISPATCH_METHOD'},
      { objectcode: 'SIGNIN_NOTEQUAL_DELIVERY_HANDLETYPE' },
      { objectcode: 'ARRIVE_NOTEQUAL_DELIVERY_HANDLETYPE' },
      { objectcode: 'DISPATCH_SELFPICK_HANDLE_TYPE' },
      { objectcode: 'SIGNCONFIG_TYPE' },
      { objectcode: 'LOCATE_INTERVAL' },
      { objectcode: 'ARRAGE_GOODS_SHOW' },
      { objectcode: 'SCANLOADING_METHED' },
      { objectcode: 'LOADING_SHOW' },
      { objectcode: 'APPOINTMENT_SHOW' },
      { objectcode: 'DRIVER_APPOINTMENT_SHOW' },
      { objectcode: 'DRIVER_PICKUP_SHOW' },
      { objectcode: 'DRIVER_DELIVERY_SHOW' },
      { objectcode: 'DELIVERY_SHOW' },
      { objectcode: 'PICKUP_SHOW' },
      { objectcode: 'DRIVER_SHOW_TYPE' },
      { objectcode: 'DRIVER_QR_SHOW_TYPE' },
      { objectcode: 'SHIPBILL_ID_CREATE_RULE' },
      { objectcode: 'LOADING_BILL_CREATE_RULE' },
      { objectcode: 'PICKUP_HANDLE_TYPE' },
      { objectcode: 'DELIVERY_HANDLE_TYPE' },
      { objectcode: 'DRIVER_OPEN_RECEIVE_REJECT' },
      { objectcode: 'RELATION_THIRD_SYSTEM' },
      { objectcode: 'EVENT_FEEDBACK_MODE' },
      { objectcode: 'ENABLE_STATUS' },
      { objectcode: 'BUSINESS_CONDITION_TYPE' },
      { objectcode: 'GOODS_TRANSFINITE_ENABLED' },
      { objectcode: 'GOODS_TRANSFINITE_WIDTH' },
      { objectcode: 'GOODS_TRANSFINITE_LENGTH' },
      { objectcode: 'GOODS_TRANSFINITE_HEIGHT' },
      { objectcode: 'GOODS_TRANSFINITE_WEIGHT' },
      { objectcode: 'WHETHER' },
    ]).then((res) => {
      for (let key in res) {
        res[key].forEach((item) => {
          if (!isNaN(item.value)) {
            item.value = item.value;
          }
        });
        if (key === 'EVENT_FEEDBACK_MODE') {
          res[key].forEach((item) => {
            item.disabled = false;
          });
        }
      }
      _this.options = res;

      queryAppointment(_this).finally(() => {
        _this.loading = false;
        _this.$nextTick(() => {
          _this.updateScrollbar?.();
        });
      });
    });
  },
  computed: {},
  methods: {
    submit(event) {
      event && event.preventDefault();
      let form = this.$refs.formDetails.form();
      form.validateFieldsAndScroll((error, obj) => {
        if (!error) {
          let value = [];
          let c = {
            DISPATCH_SELFPICK_HANDLE_TYPE: '待调度、待自提处理方式',
            ARRIVE_NOTEQUAL_DELIVERY_HANDLETYPE: '送达数量不等于配送数量处理方式',
            SIGNIN_NOTEQUAL_DELIVERY_HANDLETYPE: '签收数量不等于配送数量处理方式',
            GPS_SAVE_DAYS: '车辆轨迹保存',
            LOCATE_INTERVAL: '车辆定位间隔',
            SCANLOADING_METHED: '装车扫描方式',
            ARRAGE_GOODS_SHOW: '待理货列表显示方式',
            LOADING_SHOW: '待装卸列表显示方式',
            APPOINTMENT_SHOW: '待预约列表显示方式',
            PICKUP_SHOW: '待提货列表显示方式',
            DELIVERY_SHOW: '待送达列表显示方式',
            DRIVER_APPOINTMENT_SHOW: '司机待预约列表显示方式',
            DRIVER_PICKUP_SHOW: '司机待提货列表显示方式',
            DRIVER_DELIVERY_SHOW: '司机待送达列表显示方式',
            DRIVER_QR_SHOW_TYPE: '司机端二维码显示方式',
            DRIVER_SHOW_TYPE: '司机端列表显示方式',
            SHIPBILL_ID_CREATE_RULE: '拆分,中转子单运单号生成方式',
            LOADING_BILL_CREATE_RULE: '多个发货地址调度单生成方式',
            PICKUP_HANDLE_TYPE: '待提货处理方式',
            DELIVERY_HANDLE_TYPE: '待送达处理方式',
            DRIVER_OPEN_RECEIVE_REJECT: '司机开启接单拒绝',
            RELATION_THIRD_SYSTEM: '关联外围系统',
            EVENT_FEEDBACK_MODE: '事件反馈方式',
            DRIVER_VOICE_BROADCAST_SWITCH: '是否开启司机语音播报',
            VOICE_BROADCAST_INTERVAL: '语音播报间隔',
            DRIVER_VOICE_BROADCAST_SHIP_TEMPLATE: '司机启运语音播报配置',
            DRIVER_VOICE_BROADCAST_DELIVERY_TEMPLATE: '司机送达语音播报配置',
            GOODS_TRANSFINITE_ENABLED: '是否启用商品超限',
            GOODS_TRANSFINITE_WIDTH: '商品超限宽度',
            GOODS_TRANSFINITE_LENGTH: '商品超限长度',
            GOODS_TRANSFINITE_HEIGHT: '商品超限高度',
            GOODS_TRANSFINITE_WEIGHT: '商品超限重量',
            INTF_SHIPBILL_AUTO_CRT_GOODS: '接口订单自动生成商品及商品大类',
            INTF_SHIPBILL_AUTO_CRT_CONSIGNEE: '接口订单自动生成收货方',
            CONTAINER_WITH_VEHICLE: '容器随车标识',
            PICK_UP_CHECK_DETAIL_SWITCH: '启运登记开启检查清单',
            SCAN_DISPATCH_METHOD: '扫描派车方式',
            MAX_INTELLIGENT_DISPATCH_SHIP_BILL_NUM:'智能调度选择运单数上限'
          };
          for (let key in obj) {
            if (['RELATION_THIRD_SYSTEM', 'EVENT_FEEDBACK_MODE'].includes(key)) {
              value.push({
                name: c[key],
                code: key,
                value: obj[key]?.join(',') ?? '',
              });
            } else {
              value.push({
                name: c[key],
                code: key,
                value: obj[key] || 0,
              });
            }
          }
          return mainSaveData(this, value);
        }
      });
    },
  },
};
</script>
