123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- import zIndex from '../behaviors/zIndex';
- import hover from '../behaviors/hover';
- Component({
- behaviors: [zIndex,hover],
- externalClasses: ['l-class-title', 'l-class-item', 'l-class-cancel','l-title-class','l-item-class','l-cancel-class'],
- properties: {
- locked: Boolean,
- showCancel: Boolean,
- show: Boolean,
- itemList: Array,
- cancelText: {
- type: String,
- value: '取消'
- },
- title: String,
- zIndex:{
- type:Number,
- value: 777
- },
- openApi: {
- type: Boolean,
- value: true,
- }
- },
- data: {
- success: '',
- fail: '',
- isIphoneX: false
- },
- attached() {
- if (this.data.openApi) {
- this.initActionSheet();
- }
- this.initUIAdapter();
- },
- pageLifetimes: {
- show() {
- if (this.data.openApi) {
- this.initActionSheet();
- }
- },
- },
- methods: {
- /**
- * 区分UI尺寸
- */
- initUIAdapter() {
- wx.getSystemInfo({
- success: (res) => {
- this.setData({
- isIphoneX: res.model == 'iPhone X' ? true : false,
- });
- }
- });
- },
- initActionSheet() {
- wx.lin = wx.lin || {};
- wx.lin.showActionSheet = (options={}) => {
- const {
- itemList = [],
- success = null,
- fail = null,
- title = '',
- locked = false,
- cancelText = '取消',
- showCancel = false,
- } = options;
- this.setData({
- itemList: itemList.slice(0, 10),
- success,
- fail,
- title,
- locked,
- cancelText,
- showCancel,
- show: true,
- });
- return this;
- };
- },
- handleClickItem(e) {
- const {
- success
- } = this.data;
- success && success({ ...e.currentTarget.dataset });
- this.triggerEvent('linitemtap', { ...e.currentTarget.dataset },{ bubbles: true, composed: true });
- this._hideActionSheet();
- },
- _showActionSheet() {
- this.setData({
- show: true
- });
- },
- _hideActionSheet() {
- this.setData({
- show: false
- });
- },
- handleClickCancel() {
- const {
- fail
- } = this.data;
- fail && fail({
- errMsg: 'showactionsheet:fail cancel'
- });
- this.triggerEvent('lincancel', {
- errMsg: 'showactionsheet:fail cancel'
- },{ bubbles: true, composed: true });
- this._hideActionSheet();
- },
- handleClickPopUp() {
- if (!this.data.locked) {
- this.handleClickCancel();
- }
- },
- }
- });
|