/*******************************************************************************
 * Copyright(c) 2024 dongke All rights reserved. / Confidential
 * 类的信息：
 *		1.程序名称：
 *		2.功能描述：表单（收款、付款单等）
 * 编辑履历：
 *		作者				日期					版本				修改内容
 *		周兴		  	2024-2-20    1.00		   	  新建
 *******************************************************************************/
const common = require('@/utils/common');
const Constants = require('@/utils/Constants');
const config = require('@/config/config.js')
const chooseLocation = requirePlugin('chooseLocation');
const util = require('@/utils/util.js')
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    // 日期取值列
    dateCol: {
      type: String
    },
    // 日期列名
    dateLabel: {
      type: String
    },
    // 对象取值列
    objCol: {
      type: String
    },
    // 对象列名
    objLabel: {
      type: String
    },
    // 对象类型(客户customer；供应商supplier)
    objType: {
      type: String
    },
    // 对象标题
    objTitle: {
      type: String,
      value: 'cusName'
    },
    // 对象副标题
    objSubTitle: {
      type: String,
      value: 'cusPhone'
    },
    // 金额数组
    amountArr: {
      type: Array
    },
    // 金额标题
    amountTitle: {
      type: String,
      value: '应收金额'
    },
    // 金额列
    amountCol: {
      type: String,
      value: 'receivableResidue'
    },
    // 对象Id列
    objIdCol: {
      type: String,
      value: 'cusId'
    },
    // 区域
    cardList: {
      type: Array,
      value: []
    },
    // 内容
    contentObj: {
      type: Object,
    },
    // 合计相关
    totalObj: {
      type: Object,
    },
    // 组件类型
    type: {
      type: String,
    },
    // 明细按钮
    itemBtn: {
      type: String,
      value: '添加明细'
    },
    // 路由名称
    routeObjName: {
      type: String
    },
    // 是否只读
    readonly: {
      type: Boolean,
    },
    // 删除时是否进行校验
    delValidFlag: {
      type: Boolean,
    },
    // 结果集
    value: {
      type: String,
      observer: function (newVal) {
        if (newVal) {
          let form = JSON.parse(newVal) || {};
          // 默认加一条明细
          if (this.data.contentObj['items'] &&
            (!form[this.data.itemName]
              || form[this.data.itemName].length == 0)) {
            form[this.data.itemName] = []
            let item = {}
            let contentObject = this.data.contentObj;
            contentObject['items'].forEach(it => {
              item[it.code] = null;
            })
            form[this.data.itemName].push(item);
          }
          this.setData({
            form: form
          })
        }
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    maxSize: Constants.uploadFileConfig.maxSize,
    // 是否显示pop
    show: false,
    showDate: false,
    date: new Date().toDateStr(),
    $t: app.globalData.lang,
    routeUrl: app.globalData['routeUrl'],
    item: null,
    index: null,
    card: null,
    // 下拉类型
    dropType: null,
    dropCode: null,
    dropName: null,
    chooseText: null,
    itemName: 'itemList',
    deleteName: 'deleteList',
    itemsContent: [{ code: 'collectType', name: 'collectName', type: 'drop', required: true, dropType: 'collect' }, { code: 'collectAmount', type: 'number', title: '收款金额', required: true }],
    form: {}
  },
  lifetimes: {
    attached: function () {
      // 给日期加默认值
      let form = this.data.form;
      let time = new Date().getTime();
      form[this.data.dateCol + '_time'] = time;
      form[this.data.dateCol] = util.toDateStr(time);
      this.setData({
        value: JSON.stringify(form),
        form: form,
      })
      // 设置选择对象标题
      let text = this.setChooseText();
      this.setData({
        chooseText: text
      })
    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  pageLifetimes: {
    /**
     * @desc :  生命周期函数--监听页面显示
     * @author : 周兴
     * @date : 2024/2/19 12:16
     */
    show: function () {
      const location = chooseLocation.getLocation();
      // console.log('loc', location);
      let form = this.data.form
      if (location) {
        form['address'] = location;
        // 如果有校验信息就清除掉
        let card = this.data.card;
        let index = this.data.index;
        let contentObj = this.data.contentObj;
        if (card && contentObj[card][index]?.errMsg) {
          contentObj[card][index].errMsg = undefined;
          this.setData({
            contentObj: contentObj
          })
        }
      }
      this.setData({
        value: JSON.stringify(form),
        form: form
      })
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    /**
    * @desc : 选单
    * @author : 周兴
    * @date : 2024/2/22 18:16
    */
    choose(e) {
      let item = e.currentTarget.dataset;
      let cardIndex = e.currentTarget.dataset.index
      let cardList = this.data.cardList
      // 跳转链接
      if (cardList && cardList[cardIndex] && cardList[cardIndex].urlKey) {
        let route = this.data.routeUrl[this.data.routeObjName][cardList[cardIndex].urlKey]
        let url = route.url
        if (url) {
          let that = this
          wx.navigateTo({
            url: url,
            events: {
              // 回调后
              bindData: function (data) {
                // //处理明细 给明细赋值  例如选仓库回调赋值
                // let form = that.data.form
                // form[item.item.code] = data.data.id
                // form[item.item.name] = data.data.name
                // that.setData({
                //   form: form
                // })
                that.triggerEvent("chooseData", { code: cardList[cardIndex].name, data: data, index: item.index })
                // // 如果需要联动控制选商品按钮
                // if (item.item.controlChooseFlag) {
                //   that.setData({
                //     chooseVisible: false
                //   })
                // }
                // if (form[this.data.itemName][index][key + '_errMsg'] && e.detail) {
                //   form[this.data.itemName][index][key + '_errMsg'] = undefined;
                // }
              }
            },
            success: function (res) {
              // 通过eventChannel向被打开页面传送数据
              let item = {}
              let form = that.data.form
              item[that.data.objIdCol] = form[that.data.objIdCol]
              if (form && form[that.data.itemName]) {
                item.data = util.filterArrayEmpty(form[that.data.itemName])
              }
              // 退收款用的参数 
              console.log("choose", cardList[cardIndex]);
              if (cardList[cardIndex].urlParam) {
                item[cardList[cardIndex].urlParam] = cardList[cardIndex].urlParamValue
              }
              res.eventChannel.emit('params', { item: item, route: route })
            }
          })
        }
      }
    },
    /**
    * @desc : 点击收起/展开按钮
    * @author : 周兴
    * @date : 2024/2/22 18:16
    */
    clickTag(e) {
      let cardIndex = e.currentTarget.dataset.index
      let cardList = this.data.cardList
      if (cardList[cardIndex]) {
        cardList[cardIndex].show = (cardList[cardIndex].show
          || cardList[cardIndex].show == undefined) ? false : true
      }
      this.setData({
        cardList: cardList
      })
    },
    /**
     * @desc : 删除明细
     * @author : 周兴
     * @date : 2024/2/22 18:16
     */
    onCloseDel(e) {
      let deleteFlag = true;
      let item = e.currentTarget.dataset.item
      // 判断删除前是否需要判断
      if (this.data.delValidFlag) {
        // 行不允许删除
        if (item.deleteFlag == false) {
          deleteFlag = false;
        }
      }
      // 不允许删除给出提示信息
      if (!deleteFlag) {
        util.showToast(item.message ? item.message : '不满足删除条件');
      } else {
        const { instance } = e.detail;
        let index = e.currentTarget.dataset.index
        // 删除明细
        this.delItem(index);
        instance.close();
      }
    },
    /**
     * @desc : 删除商品明细
     * @author : 周兴
     * @date : 2024/2/22 18:16
     */
    delItem(index) {
      let form = this.data.form
      let goodsList = form[this.data.itemName] || []
      let deleteList = form[this.data.deleteName] || []
      // 把删除的数据记录下来
      if (goodsList[index]) {
        deleteList.push(goodsList[index])
      }
      goodsList.splice(index, 1)
      form[this.data.itemName] = goodsList
      form[this.data.deleteName] = deleteList
      this.setData({
        form: form,
        value: JSON.stringify(form)
      })

      // 外露setGoods方法
      this.triggerEvent("delItem", { data: goodsList })
    },
    /**
     * @desc   : 打开选择对象的页面
     * @author : 周兴
     * @date   : 2024/1/26 11:46
     */
    openObjPop() {
      // 只读
      if (this.data.readonly) {
        return;
      }
      // 退收款单用，不能选择对象，对象从列表中传入新建退收款单
      let cardList = this.data.cardList
      if (cardList[1] != null && cardList[1].urlParam) {
        return
      }
      let _this = this
      // 选择客户
      if (this.data.objType == Constants.objType.customer) {
        wx.navigateTo({
          url: '/package-base-select/pages/select-customers/select-customers',
          events: {
            // 回调后
            bindData: function (data) {
              console.log('rr', data);
              let form = _this.data.form
              let objIdCol = _this.data.objIdCol;
              // 赋值对象Id
              if (objIdCol && data[objIdCol]) {
                form[objIdCol] = data[objIdCol]
              }
              console.log('ddd', form);
              form.objInfo = data;
              _this.setData({
                form: form,
                value: JSON.stringify(form)
              })
              _this.triggerEvent("chooseObjTypeData", { data: form, })
            }
          },
          success: function (res) {
            // 通过eventChannel向被打开页面传送数据
            res.eventChannel.emit('params', { data: 'test' })
          }
        })
        // 选择供应商
      } else if (this.data.objType == Constants.objType.supplier) {
        wx.navigateTo({
          // url: '/package-base-select/pages/select-suppliers/select-suppliers',
          url: '/package-base-select/pages/select-data/select-data',
          events: {
            // 回调后
            bindData: function (data) {
              let dataitem = data.data.item
              let form = _this.data.form
              let objIdCol = _this.data.objIdCol;
              // 赋值对象Id
              if (objIdCol && dataitem[objIdCol]) {
                form[objIdCol] = dataitem[objIdCol]
              }
              form.objInfo = dataitem;
              _this.setData({
                form: form,
                value: JSON.stringify(form)
              })
              _this.triggerEvent("chooseObjTypeData", { data: form, })
            }
          },
          success: function (res) {
            // 通过eventChannel向被打开页面传送数据
            let item = {}
            console.log('re', _this.data.routeObjName, _this.data.routeUrl);
            let route = _this.data.routeUrl[_this.data.routeObjName];
            res.eventChannel.emit('params', { item: item, route: route['chooseSupplier'] })
          }
        })
      }
    },
    /**
     * @desc   : 获取显示选择对象的文字
     * @author : 周兴
     * @date   : 2024/1/26 11:46
     */
    setChooseText() {
      let text = this.$t('chose') + this.$t(this.data.objType);
      return text;
    },
    /**
     * @desc   : 打开日期pop
     * @author : 周兴
     * @date   : 2024/1/26 11:46
     */
    openDatePop(e) {

      // 只读
      if (this.data.readonly) {
        return;
      }
      this.setData({
        showDate: true
      })
      let item = e.currentTarget.dataset;
      if (item) {
        this.setData({
          index: item.index,
          key: item.key,
          card: item.card
        })
      }
    },
    /**
     * @desc   : 关闭日期pop
     * @author : 周兴
     * @date   : 2024/1/26 11:46
     */
    cancelDatePop() {
      this.setData({
        showDate: false
      })
    },
    /**
     * @desc   : 选择日期
     * @author : 周兴
     * @date   : 2024/1/26 11:46
     */
    chooseDate(e) {
      let form = this.data.form;
      if (this.data.dateCol) {
        form[this.data.dateCol + '_time'] = e.detail;
        form[this.data.dateCol] = util.toDateStr(e.detail);
      } else {
        let code = this.data.key;
        form[code + '_time'] = e.detail
        form[code] = util.toDateStr(e.detail);
      }
      let index = this.data.index;
      let card = this.data.card;
      let contentObj = this.data.contentObj;
      if (card && contentObj[card][index]?.errMsg && e.detail) {
        contentObj[card][index].errMsg = undefined;
      }
      this.setData({
        value: JSON.stringify(form),
        form: form,
        contentObj: contentObj,
        showDate: false
      })
    },
    /**
     * @desc   : 添加明细
     * @author : 周兴
     * @date   : 2024/1/26 11:46
     */
    addItem() {
      let form = this.data.form
      let items = form[this.data.itemName]
      let contentObj = this.data.contentObj
      // 默认加一条明细
      if (contentObj['items']) {
        let item = {}
        contentObj['items'].forEach(it => {
          item[it.code] = null;
        })
        items.push(item);
      }
      this.setData({
        form: form
      })
    },
    /**
     * @desc   : 打开下拉
     * @author : 周兴
     * @date   : 2024/1/26 11:46
     */
    open(e) {
      // 只读 
      if (this.data.readonly) {
        return;
      }
      let item = e.currentTarget.dataset;
      let that = this
      if (item.item.type == 'drop') {
        this.setData({
          show: true,
          dropCode: item.key,
          dropName: item.name,
          dropType: item.type,
          index: item.index,
          card: item.card
        })
      } else if (item.item.type == 'mutidrop') {
        this.setData({
          mutishow: true,
          dropCode: item.key,
          dropName: item.name,
          dropType: item.type,
          index: item.index,
          card: item.card
        })
      } else if (item.item.type == 'choose') {
        // 跳转链接
        if (item.item.urlKey) {
          this.setData({
            index: item.index,
            card: item.card
          })
          let route = this.data.routeUrl[this.data.routeObjName][item.item.urlKey]
          let url = route.url
          if (url) {
            wx.navigateTo({
              url: url,
              events: {
                // 回调后
                bindData: function (data) {
                  //处理明细 给明细赋值  例如选仓库回调赋值
                  let form = that.data.form
                  if (item.card == 'items') {
                    form[that.data.itemName][item.index][item.item.code] = data.data.id
                    form[that.data.itemName][item.index][item.item.name] = data.data.name
                    form[that.data.itemName][item.index][item.item.code + '_data'] = data.data.list
                  } else {
                    form[item.item.code] = data.data.id
                    form[item.item.name] = data.data.name
                    // 如果有校验信息就清除掉
                    let card = that.data.card;
                    let index = that.data.index;
                    let contentObj = that.data.contentObj;
                    if (card && contentObj[card][index]?.errMsg) {
                      contentObj[card][index].errMsg = undefined;
                      that.setData({
                        contentObj: contentObj
                      })
                    }
                  }
                  that.setData({
                    form: form
                  })
                  console.log('form', form)
                  that.triggerEvent("chooseData", { code: item.key, data: data, index: item.index })
                  // 如果需要联动控制选商品按钮
                  if (item.item.controlChooseFlag) {
                    that.setData({
                      chooseVisible: false
                    })
                  }
                }
              },
              success: function (res) {
                let data = { item: item.item, route: route }
                let form = that.data.form;
                if (form && form[item.item.code + '_data']) {
                  form[that.data.itemName][item.index].data = form[that.data.itemName][item.index][item.item.code + '_data']
                  delete form[that.data.itemName][item.index][item.item.code + '_data']
                  that.setData({
                    form: form
                  })
                }
                // 通过eventChannel向被打开页面传送数据
                res.eventChannel.emit('params', data)
              }
            })
          }
        }
      }
    },
    /**
     * @desc   : 非空校验
     * @author : 周兴
     * @date   : 2024/2/20 11:46
     */
    validData() {
      let flag = true;
      let cardList = this.data.cardList;
      if (!cardList || cardList.length == 0) {
        return flag;
      }
      let form = this.data.form;
      let contentObj = this.data.contentObj;
      cardList.forEach(card => {
        if (contentObj[card.name]) {
          // 明细
          if (card.name == 'items') {
            contentObj[card.name].forEach(item => {
              let title = this.$t(item.title ? item.title : item.code)
              // 如果必须输入，就要进行判断
              if (item.required && form[this.data.itemName] && form[this.data.itemName].length > 0) {
                form[this.data.itemName].forEach(t => {
                  console.log('tt', t, item.code);
                  if (!t[item.code]) {
                    t[item.code + '_errMsg'] = title + '不为空'
                    flag = false;
                  }
                })
              }
            })
          } else {
            contentObj[card.name].forEach(item => {
              let title = this.$t(item.title ? item.title : item.code)
              // 如果必须输入，就要进行判断
              if (item.required && form[item.code]==undefined) {
                item.errMsg = title + '不为空'
                flag = false;
              }
            })
          }
        }
      })
      this.setData({
        contentObj: contentObj,
        form: form
      })
      return flag;
    },
    /**
     * @desc   : 选择数据
     * @author : 周兴
     * @date   : 2024/1/26 11:46
     */
    chooseData(e) {
      let contentObj = this.data.contentObj;
      let form = this.data.form
      form[this.data.dropCode] = e.detail.value;
      form[this.data.dropName] = e.detail.text;
      let card = this.data.card;
      // 选择后清空校验提示信息
      if (card && contentObj[card][this.data.index]?.errMsg && e.detail) {
        contentObj[card][this.data.index].errMsg = undefined;
      }
      this.setData({
        value: JSON.stringify(form),
        form: form,
        contentObj: contentObj
      })
      // 如果处理id，name还需要赋值其他，需要在页面事件中自行处理
      this.triggerEvent("chooseData", { code: this.data.dropCode, item: e.detail.item })
    },
    /**
     * @desc : 上传附件超出大小
     * @author : 周兴
     * @date : 2024/3/27 16:16
     */
    overSize(e) {
      util.showToast('文件超出' + Constants.uploadFileConfig.maxSizeMB);
    },
    /**
     * @desc : 上传附件
     * @author : 周兴
     * @date : 2024/3/27 16:16
     */
    afterRead(e) {
      // this.setData({
      //     uploadFileFlag:true
      // })
      // 只读    
      const _this = this;
      const {
        file
      } = e.detail;
      // 配置存放的文件夹 公司code - 表名 - 年月 -- 日
      let folder = app.globalData.company.cpCode + '/' + this.data.table + '/' + new Date().toYearMonth2() + '/' + new Date().toDay()
      let url = config.upload_url;
      url = url.replace('mdm-server', 'mdm-server' + '-' + app.globalData.company.svcCode.replace('_', '-'))
      file.forEach(res => {
        // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
        wx.uploadFile({
          url: url,
          filePath: res.path,
          name: 'file',
          formData: {
            'folder': folder
          },
          header: {
            'Authorization': 'Bearer ' + app.globalData.token
          },
          success(res) {
            let data = JSON.parse(res.data)
            if (data.code === 200) {
              _this.setData({
                uploadFileFlag: false
              })
              let form = _this.data.form
              let annexPaths = form['annexPaths'] || []
              data.data.url = config.image_url + data.data.path
              annexPaths.push(data.data)
              form.annexPaths = annexPaths;
              _this.setData({
                form: form,
                value: JSON.stringify(form)
              })
              console.log('ff', _this.data.form);
            }
          },
        })
      })
    },
    /**
     * @desc   : 修改输入框的值
     * @author : 周兴
     * @date   : 2024/2/2 11:46
     */
    changeItemField(e) {
      let ds = e.currentTarget.dataset
      let key = ds.key
      let item = ds.item
      let index = ds.index
      let form = this.data.form
      form[this.data.itemName][index][key] = e.detail
      // 输入值后清空校验提示信息
      if (form[this.data.itemName][index][key + '_errMsg'] && e.detail) {
        form[this.data.itemName][index][key + '_errMsg'] = undefined;
      }
      this.setData({
        value: JSON.stringify(form),
        form: form,
      })
    },
    /**
     * @desc   : 修改输入框的值
     * @author : 周兴
     * @date   : 2024/2/2 11:46
     */
    changeField(e) {
      let ds = e.currentTarget.dataset
      let key = ds.key
      let item = ds.item
      let form = this.data.form
      form[key] = e.detail
      let contentObj = this.data.contentObj;
      // 输入值后清空校验提示信息
      if (item.errMsg && e.detail) {
        contentObj[ds.card][ds.index].errMsg = undefined;
      }
      this.setData({
        value: JSON.stringify(form),
        form: form,
        contentObj: contentObj
      })
    },
    /**
     * @desc   : 修改数值输入框的值
     * @author : 周兴
     * @date   : 2024/2/2 11:46
     */
    changeItemNumberField(e) {
      let ds = e.currentTarget.dataset
      let key = ds.key
      let item = ds.item
      let index = ds.index
      let form = this.data.form
      form[this.data.itemName][index][key] = e.detail.value
      // 输入值后清空校验提示信息
      if (form[this.data.itemName][index][key + '_errMsg'] && e.detail) {
        form[this.data.itemName][index][key + '_errMsg'] = undefined;
      }
      this.setData({
        value: JSON.stringify(form),
        form: form,
      })
      this.triggerEvent("changeItemNumberField", {})
    },
    /**
     * @desc   : 修改数值输入框的值
     * @author : 周兴
     * @date   : 2024/2/2 11:46
     */
    changeNumberField(e) {
      let ds = e.currentTarget.dataset
      let key = ds.key
      let item = ds.item
      let form = this.data.form
      form[key] = e.detail.value
      let contentObj = this.data.contentObj;
      // 输入值后清空校验提示信息
      if (item.errMsg && e.detail) {
        contentObj[ds.card][ds.index].errMsg = undefined;
      }
      this.setData({
        value: JSON.stringify(form),
        form: form,
        contentObj: contentObj
      })
      console.log("changeNumber组件", form);
      this.triggerEvent("changeNumber", { code: key, data: e.detail.value })
    },
    /**
     * @desc   : 修改电话的值
     * @author : 周兴
     * @date   : 2024/2/2 11:46
     */
    changePhone(e) {
      // 只读
      if (this.data.readonly) {
        return;
      }
      let ds = e.currentTarget.dataset;
      let key = ds.key;
      let index = ds.index;
      let card = ds.card;
      let form = this.data.form
      form[key] = e.detail.detail
      let contentObj = this.data.contentObj;
      if (card && contentObj[card][index]?.errMsg && e.detail.detail) {
        contentObj[card][index].errMsg = undefined;
      }
      this.setData({
        value: JSON.stringify(form),
        form: form,
        contentObj: contentObj
      })
    },
    /**
     * @desc   : 给电话赋值错误信息
     * @author : 周兴
     * @date   : 2024/2/20 11:46
     */
    changePhoneblur(e) {
      // 只读
      if (this.data.readonly) {
        return;
      }
      let ds = e.currentTarget.dataset
      let errMsg = e.detail.errMsg;
      let card = ds.card;
      let index = ds.index;
      let contentObj = this.data.contentObj;
      if (errMsg && card && contentObj[card][index]) {
        contentObj[card][index].errMsg = errMsg;
        this.setData({
          errMsg: errMsg
        })
      }
    },
    /**
     * @desc : 小程序地图调用
     * @author : 周兴
     * @date : 2024/2/18 18:16
     */
    onClickWxchartAddress(e) {
      // 只读
      if (this.data.readonly) {
        return;
      }
      // 跳转新建地图实例
      common.onClickWxchartAddress();
      let item = e.currentTarget.dataset;
      this.setData({
        index: item.index,
        card: item.card
      })
    },
    /**
     * @desc   : 改变选择框内容
     * @author : 周兴
     * @date   : 2024/1/26 11:46
     */
    onItemChange(e) {
      let key = e.currentTarget.dataset.key
      let checkFlag = e.currentTarget.dataset.value
      let index = e.currentTarget.dataset.index
      let form = this.data.form
      form[this.data.itemName][index][key] = !checkFlag
      this.setData({
        value: JSON.stringify(form),
        form: form
      })
    },
    /**
 * @desc   : 改变选择框内容
 * @author : 周兴
 * @date   : 2024/1/26 11:46
 */
    onChange(e) {
      console.log("onChange", e);
      // 只读
      if (this.data.readonly) {
        return;
      }
      let key = e.currentTarget.dataset.key
      let checkFlag = e.currentTarget.dataset.value
      let form = this.data.form       
      form[key] = !checkFlag
      this.setData({
        value: JSON.stringify(form),
        form: form
      })
      this.triggerEvent("onCheckChange", { data: form, })
    },
    /**
     * @desc   : 清空输入框的值
     * @author : 周兴
     * @date   : 2024/2/2 11:46
     */
    clearItemField(e) {
      let ds = e.currentTarget.dataset
      let index = ds.index
      let key = ds.key
      let form = this.data.form
      form[this.data.itemName][index][key] = undefined
      this.setData({
        value: JSON.stringify(form),
        form: form
      })
      // 如果要清除其他值，需要调用
      this.triggerEvent("clear", { code: ds.key })
    },
    /**
     * @desc   : 清空输入框的值
     * @author : 周兴
     * @date   : 2024/2/2 11:46
     */
    clearField(e) {
      let ds = e.currentTarget.dataset
      let key = ds.key
      let form = this.data.form
      form[key] = undefined
      this.setData({
        value: JSON.stringify(form),
        form: form
      })
      // 如果要清除其他值，需要调用
      this.triggerEvent("clear", { code: ds.key })
    },
    /**
     * @desc   : 清空选单的值
     * @author : 周兴
     * @date   : 2024/2/2 11:46
     */
    clearChoose(e) {
      let ds = e.currentTarget.dataset
      let key = ds.key
      let name = ds.name
      let form = this.data.form
      let card = ds.card
      // 明细
      if (card == 'items') {
        form[this.data.itemName][key] = undefined
        form[this.data.itemName][name] = undefined
      } else {
        form[key] = undefined
        form[name] = undefined
      }

      this.setData({
        value: JSON.stringify(form),
        form: form
      })
      // 如果要清除其他值，需要调用
      this.triggerEvent("clear", { code: ds.key })
    },
    /**
     * @desc   : 清空地址的值
     * @author : 周兴
     * @date   : 2024/2/2 11:46
     */
    clearAddress(e) {
      let form = this.data.form
      form['address'] = undefined
      this.setData({
        value: JSON.stringify(form),
        form: form
      })
      // 如果要清除其他值，需要调用
      this.triggerEvent("clear", { code: ds.key })
    },
    /**
     * @desc   : 清空日期的值
     * @author : 周兴
     * @date   : 2024/2/2 11:46
     */
    clearDate(e) {
      let ds = e.currentTarget.dataset
      let key = ds.key
      let form = this.data.form
      form[key] = undefined
      form[key + '_time'] = undefined
      this.setData({
        value: JSON.stringify(form),
        form: form
      })
    },
    /**
     * @desc : 设置明细列展示内容
     * @author : 周兴
     * @date : 2024/1/19
     */
    setItemsContent() {
      moreItemsType
    },
    /**
     * @desc : 获取语言的方法
     * @author : 周兴
     * @date : 2024/1/19
     */
    $t(name) {
      if (this.data.$t[name]) {
        return this.data.$t[name];
      } else {
        return name;
      }
    },
  },
})
