<template>
  <div>
    <el-form ref="form" :model="form" :rules="rules" label-position="top" label-width="120px">

      <el-divider content-position="left">基础信息</el-divider>
      <el-row>
        <el-col :span="12">
          <el-form-item label="店铺名称" prop="storeName">
            <el-input v-model="form.storeName" placeholder="请输入店铺名称" disabled/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="电话" prop="phone">
            <el-input v-model="form.phone" placeholder="请输入店铺电话" disabled/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="企业全称" prop="fullName">
        <el-input v-model="form.fullName" placeholder="请输入企业全称" disabled/>
      </el-form-item>
      <el-row>
        <el-col :span="12">
          <el-form-item label="店铺LOGO" prop="logoUrl">
            <el-upload
              v-model="form.logoUrl"
              :action="uploadUrl"
              :before-upload="beforeAvatarUpload"
              :on-success="handleAvatarSuccess"
              :show-file-list="false"
              class="avatar-uploader"
            >
              <img v-if="form.logoUrl" :src="form.logoUrl" class="avatar" width="200px">
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
        </el-col>
        <el-col :span="12">
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="店铺介绍" prop="descs">
            <el-input v-model="form.descs" placeholder="请输入店铺介绍" type="textarea" disabled/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="所属城市" prop="cityIds">
            <el-cascader
              ref="citySelect"
              v-model="form.cityIds"
              :options="citys"
              @change="handleCityChange"
              disabled
            >
            </el-cascader>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="地址" prop="address">
            <el-input v-model="form.address" placeholder="请输入地址" disabled/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="法人姓名" prop="legalPersonName">
            <el-input v-model="form.legalPersonName" placeholder="请输入法人姓名" disabled/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="统一社会信用代码" prop="unifiedSocialCreditCode">
            <el-input v-model="form.unifiedSocialCreditCode" placeholder="请输入统一社会信用代码" disabled/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="营业范围" prop="businessScope">
        <el-input v-model="form.businessScope" placeholder="请输入营业范围" type="textarea" disabled/>
      </el-form-item>

      <!-- 证书上传相关字段 -->
      <el-divider content-position="left">资质证书信息</el-divider>
      <el-row>
        <el-col :span="12">
          <el-form-item label="营业执照上传" prop="businessLicense">
            <el-upload
              :action="uploadUrl"
              :before-upload="beforeAvatarUpload"
              :on-success="(response, file) => handleFileSuccess(response, file, 'businessLicense')"
              :show-file-list="false"
              class="avatar-uploader"
            >
              <img v-if="form.businessLicense" :src="form.businessLicense" class="avatar" width="100px">
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="营业执照是否长期有效" prop="isBusinessLicensePermanent">
              <el-switch
                @change="switchChange()"
                v-model="switchValue"
                active-color="#13ce66"
                inactive-color="#ff4949">
              </el-switch>
             </el-form-item>
          <el-form-item label="营业执照失效日期" prop="businessLicenseExpire"  v-if="!switchValue">
            <el-date-picker
              v-model="form.businessLicenseExpire"
              end-placeholder="结束日期"
              range-separator="至"
              start-placeholder="开始日期"
              type="daterange"
              value-format="yyyy-MM-dd"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <div v-if="medicalMallConfig.isMedicalMall">
        <el-row>
          <el-col :span="12">
            <el-form-item label="药品经营许可证上传" prop="drugLicense">
              <el-upload
                :action="uploadUrl"
                :before-upload="beforeAvatarUpload"
                :on-success="(response, file) => handleFileSuccess(response, file, 'drugLicense')"
                :show-file-list="false"
                class="avatar-uploader"
              >
                <img v-if="form.drugLicense" :src="form.drugLicense" class="avatar" width="100px">
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="药品经营许可证有效期" prop="drugLicenseExpiry">
              <el-date-picker
                v-model="form.drugLicenseExpiry"
                end-placeholder="结束日期"
                range-separator="至"
                start-placeholder="开始日期"
                type="daterange"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="1类器械生产备案上传" prop="medicalDevice1">
              <el-upload
                :action="uploadUrl"
                :before-upload="beforeAvatarUpload"
                :on-success="(response, file) => handleFileSuccess(response, file, 'medicalDevice1')"
                :show-file-list="false"
                class="avatar-uploader"
              >
                <img v-if="form.medicalDevice1" :src="form.medicalDevice1" class="avatar" width="100px">
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="1类生产备案有效期" prop="medicalDevice1Expiry">
              <el-date-picker
                v-model="form.medicalDevice1Expiry"
                end-placeholder="结束日期"
                range-separator="至"
                start-placeholder="开始日期"
                type="daterange"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="2类医疗器械备案证书上传" prop="medicalDevice2">
              <el-upload
                :action="uploadUrl"
                :before-upload="beforeAvatarUpload"
                :on-success="(response, file) => handleFileSuccess(response, file, 'medicalDevice2')"
                :show-file-list="false"
                class="avatar-uploader"
              >
                <img v-if="form.medicalDevice2" :src="form.medicalDevice2" class="avatar" width="100px">
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="2类医疗器械备案有效期" prop="medicalDevice2Expiry">
              <el-date-picker
                v-model="form.medicalDevice2Expiry"
                end-placeholder="结束日期"
                range-separator="至"
                start-placeholder="开始日期"
                type="daterange"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="3类器械经营许可证上传" prop="medicalDevice3">
              <el-upload
                :action="uploadUrl"
                :before-upload="beforeAvatarUpload"
                :on-success="(response, file) => handleFileSuccess(response, file, 'medicalDevice3')"
                :show-file-list="false"
                class="avatar-uploader"
              >
                <img v-if="form.medicalDevice3" :src="form.medicalDevice3" class="avatar" width="100px">
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="3类器械经营许可证有效期" prop="medicalDevice3Expiry">
              <el-date-picker
                v-model="form.medicalDevice3Expiry"
                end-placeholder="结束日期"
                range-separator="至"
                start-placeholder="开始日期"
                type="daterange"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="食品经营许可证上传" prop="foodLicense">
              <el-upload
                :action="uploadUrl"
                :before-upload="beforeAvatarUpload"
                :on-success="(response, file) => handleFileSuccess(response, file, 'foodLicense')"
                :show-file-list="false"
                class="avatar-uploader"
              >
                <img v-if="form.foodLicense" :src="form.foodLicense" class="avatar" width="100px">
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="食品经营许可证有效期" prop="foodLicenseExpiry">
              <el-date-picker
                v-model="form.foodLicenseExpiry"
                end-placeholder="结束日期"
                range-separator="至"
                start-placeholder="开始日期"
                type="daterange"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="医疗机构执业许可证上传" prop="medicalLicense">
              <el-upload
                :action="uploadUrl"
                :before-upload="beforeAvatarUpload"
                :on-success="(response, file) => handleFileSuccess(response, file, 'medicalLicense')"
                :show-file-list="false"
                class="avatar-uploader"
              >
                <img v-if="form.medicalLicense" :src="form.medicalLicense" class="avatar" width="100px">
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="医疗机构执业许可证有效期" prop="medicalLicenseExpiry">
              <el-date-picker
                v-model="form.medicalLicenseExpiry"
                end-placeholder="结束日期"
                range-separator="至"
                start-placeholder="开始日期"
                type="daterange"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
      <el-divider content-position="left">店铺配置信息</el-divider>
      <el-form-item label="退货地址" prop="refundAddress">
        <el-input v-model="form.refundAddress" placeholder="请输入退货地址" disabled/>
      </el-form-item>
      <el-row>
        <el-col :span="12">
          <el-form-item label="退货电话" prop="refundPhone">
            <el-input v-model="form.refundPhone" placeholder="请输入退货电话" disabled/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="退货收货人" prop="refundConsignee">
            <el-input v-model="form.refundConsignee" placeholder="请输入退货收货人" disabled/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="寄件人电话" prop="sendPhone">
        <el-input v-model="form.sendPhone" placeholder="请输入寄件人电话" disabled/>
      </el-form-item>
      <el-row>
        <el-col :span="12">
          <el-form-item label="商品总数" prop="productCount">
            <el-input-number v-model="form.productCount"  :min="0" label="描述文字" disabled></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="销量" prop="salesCount">
            <el-input-number v-model="form.salesCount"  :min="0" label="描述文字" disabled></el-input-number>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="累计金额" prop="totalMoney">
            <el-input-number v-model="form.totalMoney" :precision="2" :step="0.1" disabled></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="12">
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="状态">
            <el-radio-group v-model="form.status" disabled>
              <el-radio
                v-for="dict in statusOptions"
                :key="dict.dictValue"
                :label="parseInt(dict.dictValue)"
              >{{dict.dictLabel}}</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="分佣方式" prop="brokerageType">
            <el-radio v-model="form.brokerageType" label="1" disabled>每盒</el-radio>
            <el-radio v-model="form.brokerageType" label="2" disabled>总价</el-radio>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="配送方式" prop="shippingType">
        <el-checkbox-group v-model="form.shippingType" size="medium" disabled>
          <el-checkbox v-for="(item, index) in shippingTypeOptions" :key="index" :label="item.value"
                       :disabled="item.disabled">{{item.label}}</el-checkbox>
        </el-checkbox-group>
      </el-form-item>

      <el-divider content-position="left">登录信息</el-divider>
      <el-form-item label="登录帐号" prop="account" v-if="title != '修改店铺管理'">
        <el-input v-model="form.account" placeholder="请输入登录帐号" disabled/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">保 存</el-button>
      <el-button @click="close">关 闭</el-button>
    </div>
  </div>
</template>

<script>
import { addStore, updateStore, editData } from '@/api/store/store'
import { getConfigByKey } from '@/api/system/config'
import { getCitys } from '@/api/store/city'
import { getStoreInfo } from '@/api/hisStore/store'

export default {
  data() {

    return {
      
      switchValue:false,
      title:'',
      statusOptions: [],
      citys: [],
      medicalMallConfig: {},
      shippingTypeOptions: [{
        "label": "配送",
        "value": "1"
      }, {
        "label": "自提",
        "value": "2"
      }, {
        "label": "配送自提",
        "value": "3"
      }],
      // 表单参数
      form: {},
      uploadUrl: process.env.VUE_APP_BASE_API + '/common/uploadOSS',
      baseUrl: process.env.VUE_APP_BASE_API,
      // 表单校验
      rules: {
        storeName: [
          { required: true, message: '店铺名称不能为空', trigger: 'blur' }
        ],
        fullName: [
          { required: true, message: '店铺名称不能为空', trigger: 'blur' }
        ],
        businessLicenseExpire: [
          { required: true, message: '营业执照失效日期不能为空', trigger: 'blur' }
        ],
        businessLicense: [
          { required: true, message: '营业执照不能为空', trigger: 'blur' }
        ],
        drugLicense: [
          { required: true, message: '药品经营许可证不能为空', trigger: 'blur' }
        ],
        drugLicenseExpiry: [
          { required: true, message: '药品经营许可证有效期不能为空', trigger: 'blur' }
        ],
        medicalLicense: [
          { required: true, message: '医疗机构执业许可证不能为空', trigger: 'blur' }
        ],
        medicalLicenseExpiry: [
          { required: true, message: '医疗机构执业许可证有效期不能为空', trigger: 'blur' }
        ],
        medicalDevice2: [
          { required: true, message: '2类医疗器械备案证不能为空', trigger: 'blur' }
        ],
        medicalDevice2Expiry: [
          { required: true, message: '2类医疗器械备案证有效期不能为空', trigger: 'blur' }
        ],
        logoUrl: [
          { required: true, message: '店铺LOGO不能为空', trigger: 'blur' }
        ],
        cityIds: [
          { required: true, message: '所属城市不能为空', trigger: 'blur' }
        ],
        address: [
          { required: true, message: '地址不能为空', trigger: 'blur' }
        ],
        licenseImages: [
          { required: true, message: '资质证书不能为空', trigger: 'blur' }
        ],
        shippingType: [
          { required: true, message: '配送方式不能为空', trigger: 'blur' }
        ],
        account: [
          { required: true, message: '登录账号不能为空', trigger: 'blur' }
        ],
        brokerageType: [
          { required: true, message: '分佣方式不能为空', trigger: 'blur' }
        ],
        refundPhone: [
          { required: true, message: '退货电话不能为空', trigger: 'blur' }
        ],
        refundAddress: [
          { required: true, message: '退货地址不能为空', trigger: 'blur' }
        ],
        refundConsignee: [
          { required: true, message: '退货收货人不能为空', trigger: 'blur' }
        ],
        sendPhone: [
          { required: true, message: '寄件人电话不能为空', trigger: 'blur' }
        ],
        phone: [
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: '请输入正确的手机号码',
            trigger: 'blur',
            required: true
          }
        ],
        // 新增字段校验规则
        enterpriseShortName: [
          { required: true, message: '企业简称不能为空', trigger: 'blur' }
        ],
        enterpriseFullName: [
          { required: true, message: '企业全称不能为空', trigger: 'blur' }
        ],
        contactPhone: [
          { required: true, message: '电话号码不能为空', trigger: 'blur' }
        ],
        enterpriseAddress: [
          { required: true, message: '企业地址不能为空', trigger: 'blur' }
        ],
        legalPersonName: [
          { required: true, message: '法人姓名不能为空', trigger: 'blur' }
        ],
        unifiedSocialCreditCode: [
          { required: true, message: '统一社会信用代码不能为空', trigger: 'blur' }
        ],
        businessScope: [
          { required: true, message: '营业范围不能为空', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '新密码不能为空', trigger: 'blur' },
          { min: 6, max: 20, message: '长度在 6 到 20 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getCitys()
    this.handleUpdate()
    getConfigByKey('medicalMall.func.switch').then(response => {
      if (response.data && response.data.configValue) {
        this.medicalMallConfig = JSON.parse(response.data.configValue)
      }
    })
    this.getDicts("sys_company_status").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {

    handleAvatarSuccess(res, file) {
      if (res.code == 200) {
        this.form.logoUrl = res.url
        self.$forceUpdate()
      } else {
        this.msgError(res.msg)
      }
    },
    beforeAvatarUpload(file) {
      const isLt1M = file.size / 1024 / 1024 < 1
      if (!isLt1M) {
        this.$message.error('上传图片大小不能超过 1MB!')
      }
      return isLt1M
    },

    submit() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          editData(this.user).then(response => {
            this.msgSuccess('修改成功')
          })
        }
      })
    },
    close() {
      this.$store.dispatch('tagsView/delView', this.$route)
      this.$router.push({ path: '/index' })
    },
    // 通用文件上传成功处理函数
    handleFileSuccess(response, file, field) {
      if (response.code === 200) {
        this.$set(this.form, field, response.url)
        this.$forceUpdate()
      } else {
        this.msgError(response.msg)
      }
    },
    // 表单重置
    reset() {
      
      this.switchValue = false;
      this.form = {
        storeId: null,
        cityIds: null,
        storeName: null,
        descs: null,
        logoUrl: null,
        address: null,
        lng: null,
        lat: null,
        phone: null,
        licenseImages: null,
        productCount: null,
        status: 0,
        createTime: null,
        updateTime: null,
        salesCount: null,
        balance: null,
        totalMoney: null,
        isAudit: 0,
        account: null,
        password: null,
        shippingType: ['1'],
        brokerageType: '1',
        brokerageRate: 0,
        fullName: null,
        // 重置新增字段
        enterpriseShortName: null,        // 企业简称
        enterpriseFullName: null,         // 企业全称
        contactPhone: null,               // 联系电话
        enterpriseAddress: null,          // 企业地址
        legalPersonName: null,            // 法人姓名
        unifiedSocialCreditCode: null,    // 统一社会信用代码
        businessScope: null,              // 营业范围
        // 重置证书相关字段
        businessLicense: null,                    // 营业执照文件
        businessLicenseExpire: null,              // 营业执照失效日期
        drugLicense: null,             // 药品经营许可证有效期
        drugLicenseExpiry: null,               // 药品经营许可证文件
        // 医疗器械相关证书
        medicalDevice1: null,          // 一类医疗器械备案证书
        medicalDevice1Expiry: null,        // 二类医疗器械备案有效期
        medicalDevice2: null,          // 二类器械生产备案文件
        medicalDevice2Expiry: null,        // 一类生产备案有效期
        medicalDevice3: null,         // 三类器械经营许可证文件
        medicalDevice3Expiry: null,       // 三类器械经营许可证有效期
        // 其他许可证相关字段
        foodLicense: null,               // 食品经营许可证文件
        foodLicenseExpiry: null,             // 食品经营许可证有效期
        medicalLicense: null,  // 医疗机构执业许可证文件
        medicalLicenseExpiry: null // 医疗机构执业许可证有效期
      }
      this.resetForm('form')
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          // 处理表单数据
          const formData = Object.assign({}, this.form)

          // 处理城市ID
          if (formData.cityIds) {
            formData.cityIds = formData.cityIds.toString()
          }

          // 处理配送方式
          if (formData.shippingType) {
            formData.shippingType = formData.shippingType.toString()
          }

          // 处理日期范围字段
          if (formData.drugLicenseExpiry && formData.drugLicenseExpiry.length === 2) {
            formData.drugLicenseExpiryStart = formData.drugLicenseExpiry[0]
            formData.drugLicenseExpiryEnd = formData.drugLicenseExpiry[1]
          }

          if (formData.medicalDevice2Expiry && formData.medicalDevice2Expiry.length === 2) {
            formData.medicalDevice2ExpiryStart = formData.medicalDevice2Expiry[0]
            formData.medicalDevice2ExpiryEnd = formData.medicalDevice2Expiry[1]
          }

          if (formData.medicalDevice1Expiry && formData.medicalDevice1Expiry.length === 2) {
            formData.medicalDevice1ExpiryStart = formData.medicalDevice1Expiry[0]
            formData.medicalDevice1ExpiryEnd = formData.medicalDevice1Expiry[1]
          }

          if (formData.medicalDevice3Expiry && formData.medicalDevice3Expiry.length === 2) {
            formData.medicalDevice3ExpiryStart = formData.medicalDevice3Expiry[0]
            formData.medicalDevice3ExpiryEnd = formData.medicalDevice3Expiry[1]
          }

          if (formData.foodLicenseExpiry && formData.foodLicenseExpiry.length === 2) {
            formData.foodLicenseExpiryStart = formData.foodLicenseExpiry[0]
            formData.foodLicenseExpiryEnd = formData.foodLicenseExpiry[1]
          }

          if (formData.medicalLicenseExpiry && formData.medicalLicenseExpiry.length === 2) {
            formData.medicalLicenseExpiryStart = formData.medicalLicenseExpiry[0]
            formData.medicalLicenseExpiryEnd = formData.medicalLicenseExpiry[1]
          }
          if (formData.businessLicenseExpire && formData.businessLicenseExpire.length === 2) {
            formData.businessLicenseExpireStart = formData.businessLicenseExpire[0]
            formData.businessLicenseExpireEnd = formData.businessLicenseExpire[1]
          }
                   if(!!this.switchValue){
              formData.isBusinessLicensePermanent = 1;
          }else{
              formData.isBusinessLicensePermanent = 0;
          }

          if (formData.storeId != null) {
            updateStore(formData).then(response => {
              this.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addStore(formData).then(response => {
              this.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    handleCityChange(value) {
      var nodes = this.$refs.citySelect.getCheckedNodes()
      this.form.address = nodes[0].pathLabels[0] + nodes[0].pathLabels[1] + nodes[0].pathLabels[2]
      this.form.cityIds = value.toString()
    },
    getCitys() {
      getCitys().then(res => {
        this.loading = false
        this.citys = res.data
      })
    },
    /** 修改按钮操作 */
    handleUpdate() {
      this.reset()
      getStoreInfo().then(response => {
        this.form = response.data
        this.open = true
        this.title = '修改店铺'
        if(this.form.isBusinessLicensePermanent == 1){
          this.switchValue = true;
        }
        let str = this.form.shippingType
        this.form.shippingType = str.split(',')
        this.form.cityIds = ((this.form.cityIds).split(',')).map(Number)

        const dateFields = [
          'drugLicenseExpiry',
          'medicalDevice1Expiry',
          'medicalDevice2Expiry',
          'medicalDevice3Expiry',
          'foodLicenseExpiry',
          'medicalLicenseExpiry',
          'businessLicenseExpire'
        ]
        dateFields.forEach(field => {
          const startField = field + 'Start'
          const endField = field + 'End'
          if (this.form[startField] && this.form[endField]) {
            this.$set(this.form, field, [this.form[startField], this.form[endField]])
          }
        })
      })
    }
  }
}
</script>
