'use strict';

/*
 * @Author: codingfly
 * @Description:
 * @Date: 2021-10-12 11:39:33
 * @LastEditTime: 2022-02-23 13:10:22
 * @FilePath: \remaxui\src\icon\other\ali\ali.js
 */
Component({
  props: {
    // zhengque | fenge | barcode | bianji | tag | shouye | caidan | cart | cartadd | zanting | bofang | zhibozhong | shoucang1 | zan1 | zuji | shijian | zhuanlan | zhizhen | time | bukanjian | kanjian | jiankang | rili | zhibo | chuangzuo | yisheng | weixin | eye | zan | shoucang | shuaxin | tongzhi | home | hot | yiyuan | keshi | mobile | left | filter | jia | album | biaoqing | voice | xiangji | xingxing | tip | jianshao | zengjia | right | home-solid | monitor | notice | new | add | clear | clear2 | yes | search | searchlist | down | dingdan | loading2 | loading
    name: null,
    // string | string[]
    color: '',
    size: 18,
  },
  data: {
    colors: '',
    quot: '"',
    svgSize: 18,
    isStr: true,
  },
  didMount: function didMount() {
    var size = this.props.size;
    var color = this.props.color;
    this.setData({
      colors: this.fixColor(color),
      isStr: typeof color === 'string',
    });

    if (size !== this.data.svgSize) {
      this.setData({
        svgSize: size,
      });
    }
  },
  didUpdate: function didUpdate(prevProps) {
    var size = this.props.size;
    var color = this.props.color;

    if (color !== prevProps.color) {
      this.setData({
        colors: this.fixColor(color),
        isStr: typeof color === 'string',
      });
    }

    if (size !== prevProps.size) {
      this.setData({
        svgSize: size,
      });
    }
  },
  methods: {
    fixColor: function fixColor() {
      var color = this.props.color;
      var hex2rgb = this.hex2rgb;

      if (typeof color === 'string') {
        return color.indexOf('#') === 0 ? hex2rgb(color) : color;
      }

      return color.map(function(item) {
        return item.indexOf('#') === 0 ? hex2rgb(item) : item;
      });
    },
    hex2rgb: function hex2rgb(hex) {
      var rgb = [];
      hex = hex.substr(1);

      if (hex.length === 3) {
        hex = hex.replace(/(.)/g, '$1$1');
      }

      hex.replace(/../g, function(color) {
        rgb.push(parseInt(color, 0x10));
        return color;
      });
      return 'rgb(' + rgb.join(',') + ')';
    },
  },
});
