> For the complete documentation index, see [llms.txt](https://calundar.gitbook.io/lunar-calendar-picker/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://calundar.gitbook.io/lunar-calendar-picker/master.md).

# 小程序-农历日期选择器

原生的日期选择只可以选择公元历日期，在一些场景下我们可能需要使用到传统农历，这个插件可以帮助您很好的选择农历日期，同时自带的方法可以做到公历转农历日期。如果有个性化的需求的话可以联系开发者（微信 raymondSATA）

## 当前版本

当前最新版本是 `1.0.0`

appid是 `wx6ac335896f1078f1`

## 申请小程序插件的使用

请在知晓程序的插件商店申请使用

## 在小程序中使用本插件

在 `app.json` 中声明插件

{% code title="app.json" %}

```javascript
{
    "plugins": {
        "lunarDatePicker": {
            "version": "1.0.0",
            "provider": "wx6ac335896f1078f1"
        }
    }
}
```

{% endcode %}

在需要引入的页面的json配置中加入

{% code title="index.json" %}

```javascript
{ 
    "usingComponents": { 
        "lunarDatePicker": "plugin://lunarDatePicker/lunarDatePicker" 
    }
}
```

{% endcode %}

在相应的页面的js文件中加入

```javascript
var plugin = requirePlugin("lunarDatePicker")
Page({
  data: {
    date: "1998-06-18",
    ldate: plugin.date2Lunar("1998-06-18")
  },
  onLoad: function () {    
  },
  test: function (e) {
    console.log(e.detail)
    this.setData({
      date: e.detail.date,
      ldate: e.detail.lunarDate
    })
  }
})
```

在相应页面的wxml文件中加入

{% code title="index.wxml" %}

```markup
<lunarDatePicker value="{{date}}" bindpickerchange="test"> 
    当前选择：{{ldate}}
</lunarDatePicker>
```

{% endcode %}

编译页面，预览效果

## 插件方法

`date2Lunar`公历日期转化为农历日期，输出的格式为 `1998年五月廿四`

```javascript
plugin.date2Lunar("1998-06-18") 
```

## 组件方法

`bindpickerchange` 在点击确认的时候触发的方法，返回的`event.detail`：

```javascript
{
    date: "1998-06-18", 
    lunarDate: "1998年五月廿四"
}
```
