customField.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // components/customField.js
  2. const upload_image = require("../../utils/upload/upload_image");
  3. Component({
  4. /**
  5. * 组件的属性列表
  6. */
  7. properties: {
  8. pageType: {
  9. type: ''
  10. },
  11. customField: {
  12. type: ''
  13. }
  14. },
  15. /**
  16. * 组件的初始数据
  17. */
  18. data: {
  19. list: [],
  20. orgId: null,
  21. org: null,
  22. },
  23. observers: {
  24. customField() {
  25. this.getList()
  26. }
  27. },
  28. /**
  29. * 组件的方法列表
  30. */
  31. methods: {
  32. // 获取自定义列表
  33. getList() {
  34. if (!this.data.customField) {
  35. return;
  36. }
  37. //判断是否有未填写的
  38. let data = this.data.customField.some(i => {
  39. return i.customNameVal === null && i.isShow == 1 && i.isEditable === 1
  40. })
  41. if (data) {
  42. this.setData({
  43. list: this.data.customField
  44. })
  45. this.triggerEvent('isFillFields', false)
  46. } else {
  47. this.triggerEvent('isFillFields', true)
  48. }
  49. },
  50. // 下拉
  51. getSelect(e) {
  52. let index = e.target.dataset.index
  53. let customNameVal = `list[${index}].customNameVal`
  54. this.setData({
  55. [customNameVal]: this.data.list[index].configurationOption[e.detail.value].name
  56. })
  57. this.triggerEvent('isFillFields', this.setList())
  58. },
  59. // 文本&时间&日期
  60. getValue(e) {
  61. let customNameVal = `list[${e.target.dataset.index}].customNameVal`
  62. this.setData({
  63. [customNameVal]: e.detail.value,
  64. })
  65. this.triggerEvent('isFillFields', this.setList())
  66. },
  67. // 获取省市区(街道)列表
  68. getAddress(e) {
  69. let index = e.currentTarget.dataset.index
  70. let list = this.data.list
  71. list[index].customNameVal = e.detail
  72. this.setData({
  73. list
  74. })
  75. this.triggerEvent('isFillFields', this.setList())
  76. },
  77. //上传图片
  78. doUploadAvatar(event) {
  79. let that = this
  80. let list = this.data.list
  81. let index = event.target.dataset.index
  82. wx.chooseMedia({
  83. mediaType: ['image'],
  84. sizeType: ['original'],
  85. sourceType: ['album', 'camera'],
  86. success(res) {
  87. var image = {
  88. url: res.tempFiles[0].tempFilePath
  89. }
  90. wx.showLoading({
  91. title: '上传中~',
  92. })
  93. upload_image(image).then((img) => {
  94. wx.hideLoading()
  95. list[index].customNameVal = img.url
  96. that.setData({
  97. list
  98. })
  99. that.triggerEvent('isFillFields', that.setList())
  100. }).catch(() => {
  101. wx.hideLoading()
  102. })
  103. }
  104. })
  105. },
  106. //删除照片
  107. DelImg(e) {
  108. let that = this
  109. let index = e.currentTarget.dataset.index
  110. let list = this.data.list
  111. wx.showModal({
  112. title: '提示',
  113. content: '确定删除?',
  114. cancelText: '取消',
  115. confirmText: '确定',
  116. success: res => {
  117. if (res.confirm) {
  118. list[index].customNameVal = null
  119. that.setData({
  120. list
  121. })
  122. that.triggerEvent('isFillFields', this.setList())
  123. }
  124. }
  125. })
  126. },
  127. // 预览图片
  128. previewImg(event) {
  129. let currentUrl = event.currentTarget.dataset.src;
  130. wx.previewImage({
  131. current: currentUrl,
  132. urls: [currentUrl]
  133. })
  134. },
  135. // 判断是否填写
  136. setList() {
  137. let canSubmit = true;
  138. let list = this.data.list
  139. for (let index = 0; index < list.length; index++) {
  140. if ((list[index].customNameVal == null || list[index].customNameVal == '') && list[index].isShow === 1) {
  141. canSubmit = false;
  142. break;
  143. }
  144. }
  145. if (canSubmit) {
  146. return list
  147. } else {
  148. return canSubmit
  149. }
  150. },
  151. },
  152. lifetimes: {
  153. attached: function () {
  154. this.getList();
  155. }
  156. },
  157. })