customField.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. const _my = require("../../__antmove/api/index.js")(my);
  2. const wx = _my;
  3. // components/customField.js
  4. const {
  5. selectContextByCardId,
  6. InsertContentByCardId
  7. } = require("../../utils/api/customField");
  8. const upload_image = require("../../utils/upload/upload_image");
  9. Component({
  10. options: {
  11. observers: true
  12. },
  13. /**
  14. * 组件的属性列表
  15. */
  16. properties: {
  17. orgId: {
  18. type: Number
  19. }
  20. },
  21. /**
  22. * 组件的初始数据
  23. */
  24. data: {
  25. list: [],
  26. orgId: null,
  27. org: null
  28. },
  29. observers: {
  30. orgId(e) {
  31. if (e) {
  32. this.getList();
  33. }
  34. }
  35. },
  36. /**
  37. * 组件的方法列表
  38. */
  39. methods: {
  40. // 获取自定义列表
  41. getList() {
  42. wx.showLoading({
  43. title: "加载中..."
  44. });
  45. selectContextByCardId(this.data.orgId, wx.getStorageSync("userInfo").userId).then(suc => {
  46. let data = suc.data.some(i => {
  47. return i.customNameVal === null && i.isShow == 1 && i.isEditable === 1;
  48. });
  49. if (data) {
  50. this.setData({
  51. list: suc.data
  52. });
  53. this.triggerEvent("isFillFields", false);
  54. } else {
  55. this.triggerEvent("isFillFields", true);
  56. }
  57. }).finally(() => {
  58. wx.hideLoading();
  59. });
  60. },
  61. // 下拉
  62. getSelect(e) {
  63. let index = e.target.dataset.index;
  64. let customNameVal = `list[${index}].customNameVal`;
  65. this.setData({
  66. [customNameVal]: this.data.list[index].configurationOption[e.detail.value].name
  67. });
  68. this.triggerEvent("isFillFields", this.setList());
  69. },
  70. // 文本&时间&日期
  71. getValue(e) {
  72. let customNameVal = `list[${e.target.dataset.index}].customNameVal`;
  73. this.setData({
  74. [customNameVal]: e.detail.value
  75. });
  76. this.triggerEvent("isFillFields", this.setList());
  77. },
  78. // 获取省市区(街道)列表
  79. getAddress(e) {
  80. let index = e.currentTarget.dataset.index;
  81. let list = this.data.list;
  82. list[index].customNameVal = e.detail;
  83. this.setData({
  84. list
  85. });
  86. this.triggerEvent("isFillFields", this.setList());
  87. },
  88. //上传图片
  89. doUploadAvatar(event) {
  90. let that = this;
  91. let list = this.data.list;
  92. let index = event.target.dataset.index;
  93. wx.chooseMedia({
  94. mediaType: ["image"],
  95. sizeType: ["original"],
  96. sourceType: ["album", "camera"],
  97. success(res) {
  98. var image = {
  99. url: res.tempFiles[0].tempFilePath
  100. };
  101. wx.showLoading({
  102. title: "上传中~"
  103. });
  104. upload_image(image).then(img => {
  105. wx.hideLoading();
  106. list[index].customNameVal = img.url;
  107. that.setData({
  108. list
  109. });
  110. that.triggerEvent("isFillFields", that.setList());
  111. }).catch(() => {
  112. wx.hideLoading();
  113. });
  114. }
  115. });
  116. },
  117. //删除照片
  118. DelImg(e) {
  119. let that = this;
  120. let index = e.currentTarget.dataset.index;
  121. let list = this.data.list;
  122. wx.showModal({
  123. title: "提示",
  124. content: "确定删除?",
  125. cancelText: "取消",
  126. confirmText: "确定",
  127. success: res => {
  128. if (res.confirm) {
  129. list[index].customNameVal = null;
  130. that.setData({
  131. list
  132. });
  133. that.triggerEvent("isFillFields", this.setList());
  134. }
  135. }
  136. });
  137. },
  138. // 预览图片
  139. previewImg(event) {
  140. // 拿到图片的地址url
  141. let currentUrl = event.currentTarget.dataset.src;
  142. // 微信预览图片的方法
  143. wx.previewImage({
  144. current: currentUrl,
  145. // 图片的地址url
  146. urls: [currentUrl] // 预览的地址url
  147. });
  148. },
  149. // 提交
  150. // submit() {
  151. // if (!this.setList()) {
  152. // wx.showToast({
  153. // title: '请将内容填写完整~',
  154. // icon: 'none'
  155. // })
  156. // return
  157. // }
  158. // let that = this;
  159. // let data = {
  160. // list: this.data.list,
  161. // id: wx.getStorageSync('userInfo').userId,
  162. // adminId: parseInt(this.data.orgId)
  163. // }
  164. // InsertContentByCardId(data).then((suc) => {
  165. // if (suc.code === 200) {
  166. // wx.showModal({
  167. // content: '提交成功!',
  168. // showCancel: false,
  169. // success() {
  170. // let url = `/pages/wx_airport/${(that.data.org !== null&&that.data.org !== '')?'rlxf_logs/rlxf_logs?org=' + that.data.org:'rlxf_pass/rlxf_pass?orgId=' + that.data.orgId}`
  171. // wx.reLaunch({
  172. // url
  173. // })
  174. // }
  175. // })
  176. // } else {
  177. // wx.showToast({
  178. // title: suc.msg,
  179. // })
  180. // }
  181. // })
  182. // },
  183. // 判断是否填写
  184. setList() {
  185. let canSubmit = true;
  186. let list = this.data.list;
  187. list.forEach((item, index) => {
  188. if ((item.customNameVal == null || item.customNameVal == "") && item.isShow === 1) {
  189. return canSubmit = false;
  190. }
  191. });
  192. if (canSubmit) return list;else return canSubmit;
  193. },
  194. antmoveAction: function () {
  195. //执行时动态赋值,请勿删除
  196. }
  197. }
  198. });