customField.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. this.setData({
  39. list: this.data.customField
  40. });
  41. //判断是否有未填写的
  42. let data = this.data.customField.some(i => {
  43. return i.customNameVal === null && i.isShow == 1
  44. });
  45. //没有未填写过&展示的
  46. if (!data) {
  47. this.triggerEvent('isFillFields', this.data.customField);
  48. return;
  49. }
  50. //判断是否有可编辑的
  51. let result = this.data.customField.some(j => {
  52. return j.customNameVal === null && j.isShow == 1 && j.isEditable == 1
  53. })
  54. this.triggerEvent('isFillFields', !result?this.data.customField:false)
  55. },
  56. // 下拉
  57. getSelect(e) {
  58. let index = e.target.dataset.index
  59. let customNameVal = `list[${index}].customNameVal`
  60. this.setData({
  61. [customNameVal]: this.data.list[index].configurationOption[e.detail.value].name
  62. })
  63. this.triggerEvent('isFillFields', this.setList())
  64. },
  65. // 文本&时间&日期
  66. getValue(e) {
  67. let customNameVal = `list[${e.target.dataset.index}].customNameVal`
  68. this.setData({
  69. [customNameVal]: e.detail.value,
  70. })
  71. this.triggerEvent('isFillFields', this.setList())
  72. },
  73. // 获取省市区(街道)列表
  74. getAddress(e) {
  75. let index = e.currentTarget.dataset.index
  76. let list = this.data.list
  77. list[index].customNameVal = e.detail
  78. this.setData({
  79. list
  80. })
  81. this.triggerEvent('isFillFields', this.setList())
  82. },
  83. //上传图片
  84. doUploadAvatar(event) {
  85. let that = this
  86. let list = this.data.list
  87. let index = event.target.dataset.index
  88. wx.chooseMedia({
  89. mediaType: ['image'],
  90. sizeType: ['original'],
  91. sourceType: ['album', 'camera'],
  92. success(res) {
  93. var image = {
  94. url: res.tempFiles[0].tempFilePath
  95. }
  96. wx.showLoading({
  97. title: '上传中~',
  98. })
  99. upload_image(image).then((img) => {
  100. wx.hideLoading()
  101. list[index].customNameVal = img.url
  102. that.setData({
  103. list
  104. })
  105. that.triggerEvent('isFillFields', that.setList())
  106. }).catch(() => {
  107. wx.hideLoading()
  108. })
  109. }
  110. })
  111. },
  112. //删除照片
  113. DelImg(e) {
  114. let that = this
  115. let index = e.currentTarget.dataset.index
  116. let list = this.data.list
  117. wx.showModal({
  118. title: '提示',
  119. content: '确定删除?',
  120. cancelText: '取消',
  121. confirmText: '确定',
  122. success: res => {
  123. if (res.confirm) {
  124. list[index].customNameVal = null
  125. that.setData({
  126. list
  127. })
  128. that.triggerEvent('isFillFields', this.setList())
  129. }
  130. }
  131. })
  132. },
  133. // 预览图片
  134. previewImg(event) {
  135. let currentUrl = event.currentTarget.dataset.src;
  136. wx.previewImage({
  137. current: currentUrl,
  138. urls: [currentUrl]
  139. })
  140. },
  141. // 判断是否填写
  142. setList() {
  143. let canSubmit = true;
  144. let list = this.data.list
  145. for (let index = 0; index < list.length; index++) {
  146. if ((list[index].customNameVal == null || list[index].customNameVal == '') && list[index].isShow === 1 && list[index].isEditable == 1) {
  147. canSubmit = false;
  148. break;
  149. }
  150. }
  151. if (canSubmit) {
  152. return list
  153. } else {
  154. return canSubmit
  155. }
  156. },
  157. },
  158. lifetimes: {
  159. attached: function () {
  160. this.getList();
  161. }
  162. },
  163. })