index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // components/input/index.js
  2. const upload_image = require("../../utils/upload/upload_image")
  3. Component({
  4. /**
  5. * 组件的属性列表
  6. */
  7. properties: {
  8. value: '',
  9. // 标题
  10. title: {
  11. type: String,
  12. value: ''
  13. },
  14. // 注释
  15. placeholder: {
  16. type: String,
  17. value: '请输入'
  18. },
  19. // 类型
  20. type: {
  21. type: String,
  22. value: 'text'
  23. },
  24. // input类型
  25. inputType: {
  26. type: String,
  27. value: 'text'
  28. },
  29. // 是否必填
  30. isRequired: {
  31. type: Boolean,
  32. value: false
  33. },
  34. // 是否禁用
  35. disabled: {
  36. type: Boolean,
  37. value: false
  38. },
  39. maxLength: {
  40. type: Number,
  41. value: 200
  42. },
  43. // 遍历数组
  44. listErgodic: {
  45. type: Array,
  46. value: function () {
  47. return []
  48. }
  49. },
  50. // key
  51. key1: {
  52. type: String,
  53. value: ''
  54. },
  55. // name
  56. name1: {
  57. type: String,
  58. value: ''
  59. },
  60. // 计数器最大值
  61. stepperMax: {
  62. type: Number,
  63. value: 10000000,
  64. },
  65. // 日期-开始
  66. startDate: {
  67. type: String,
  68. value: ''
  69. },
  70. // 日期-结束
  71. endDate: {
  72. type: String,
  73. value: ''
  74. },
  75. // 时间-开始
  76. startTime: {
  77. type: String,
  78. value: '',
  79. },
  80. // 时间-结束
  81. endTime: {
  82. type: String,
  83. value: '',
  84. },
  85. },
  86. /**
  87. * 组件的初始数据
  88. */
  89. data: {
  90. },
  91. lifetimes: {
  92. attached: function () {},
  93. detached: function () {
  94. // 在组件实例被从页面节点树移除时执行
  95. },
  96. },
  97. /**
  98. * 组件的方法列表
  99. */
  100. methods: {
  101. getValue(e) {
  102. // console.log(e.detail);
  103. let val = ''
  104. switch (e.currentTarget.dataset.type) {
  105. case '1':
  106. val = e.detail
  107. this.setData({
  108. value: e.detail
  109. })
  110. break;
  111. default:
  112. val = e.detail.value
  113. this.setData({
  114. value: e.detail.value
  115. })
  116. break;
  117. }
  118. this.triggerEvent('change', val)
  119. },
  120. //选择照片
  121. ChooseImage(e) {
  122. let that = this
  123. wx.chooseMedia({
  124. count: 1,
  125. mediaType: ['image'],
  126. sourceType: ['album', 'camera'],
  127. success(res) {
  128. var image = {
  129. url: res.tempFiles[0]
  130. }
  131. wx.showLoading({
  132. title: '上传中~',
  133. })
  134. console.log(image);
  135. upload_image(image).then((img) => {
  136. wx.hideLoading()
  137. that.triggerEvent('change', img.url)
  138. }).catch(() => {
  139. wx.hideLoading()
  140. })
  141. }
  142. })
  143. },
  144. // 删除照片
  145. clearImg(e) {
  146. this.triggerEvent('clearImg', true)
  147. },
  148. }
  149. })