index.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. // pages/wx_airport/rlxf_userMsg/index.js
  2. const util = require('../../../utils/util/util')
  3. const {
  4. selectContextByCardId,
  5. userInfoInsert
  6. } = require('../../../utils/api/api')
  7. const upload_image = require("../../../utils/upload/upload_image");
  8. const app = getApp()
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. list: [],
  15. orgId: null,
  16. org: null,
  17. },
  18. // 获取自定义列表
  19. getList() {
  20. wx.showLoading({
  21. title: '加载中...'
  22. })
  23. selectContextByCardId(this.data.orgId, wx.getStorageSync('userInfo').userId)
  24. .then((suc) => {
  25. let data = suc.data.some(i => {
  26. return i.customNameVal === null && i.isShow == 1 && i.isEditable === 1
  27. })
  28. if (data) {
  29. this.setData({
  30. list: suc.data,
  31. })
  32. } else {
  33. this.submit()
  34. }
  35. })
  36. .finally(() => {
  37. wx.hideLoading()
  38. })
  39. },
  40. // 下拉
  41. getSelect(e) {
  42. let index = e.target.dataset.index
  43. let customNameVal = `list[${index}].customNameVal`
  44. this.setData({
  45. [customNameVal]: this.data.list[index].configurationOption[e.detail.value].name
  46. })
  47. },
  48. // 文本&时间&日期
  49. getValue(e) {
  50. let customNameVal = `list[${e.target.dataset.index}].customNameVal`
  51. this.setData({
  52. [customNameVal]: e.detail.value,
  53. })
  54. },
  55. // 获取省市区(街道)列表
  56. getAddress(e) {
  57. let index = e.currentTarget.dataset.index
  58. let list = this.data.list
  59. list[index].customNameVal = e.detail
  60. this.setData({
  61. list
  62. })
  63. },
  64. //上传图片
  65. doUploadAvatar(event) {
  66. let that = this
  67. let list = this.data.list
  68. let index = event.target.dataset.index
  69. wx.chooseMedia({
  70. count: 1,
  71. mediaType: ['image'],
  72. sizeType: ['original'],
  73. sourceType: ['album', 'camera'],
  74. success(res) {
  75. var image = {
  76. url: res.tempFiles[0].tempFilePath
  77. }
  78. wx.showLoading({
  79. title: '上传中~',
  80. })
  81. upload_image(image).then((img) => {
  82. wx.hideLoading()
  83. list[index].customNameVal = img.url
  84. that.setData({
  85. list
  86. })
  87. }).catch(() => {
  88. wx.hideLoading()
  89. })
  90. }
  91. })
  92. },
  93. //删除照片
  94. DelImg(e) {
  95. let that = this
  96. let index = e.currentTarget.dataset.index
  97. let list = this.data.list
  98. wx.showModal({
  99. title: '提示',
  100. content: '确定删除?',
  101. cancelText: '取消',
  102. confirmText: '确定',
  103. success: res => {
  104. if (res.confirm) {
  105. list[index].customNameVal = null
  106. that.setData({
  107. list
  108. })
  109. }
  110. }
  111. })
  112. },
  113. // 预览图片
  114. previewImg(event) {
  115. // 拿到图片的地址url
  116. let currentUrl = event.currentTarget.dataset.src;
  117. // 微信预览图片的方法
  118. wx.previewImage({
  119. current: currentUrl, // 图片的地址url
  120. urls: [currentUrl] // 预览的地址url
  121. })
  122. },
  123. // 提交
  124. submit() {
  125. if (!this.setList()) {
  126. wx.showToast({
  127. title: '请将内容填写完整~',
  128. icon: 'none'
  129. })
  130. return
  131. }
  132. let that = this;
  133. let userInfo = wx.getStorageSync('userInfo')
  134. let data = {
  135. contents: this.data.list,
  136. userId: userInfo.userId,
  137. adminId: parseInt(this.data.orgId),
  138. type: app.data.type,
  139. action: 1, //1-自定义字段更新 2-下发
  140. }
  141. userInfoInsert(data).then((suc) => {
  142. if (suc.code === 200 && suc.data.status) {
  143. userInfo.org = that.data.org;
  144. userInfo.orgId = that.data.orgId;
  145. wx.setStorageSync('userInfo', userInfo);
  146. wx.reLaunch({
  147. url: '/pages/wx_airport/rlxf_pass/rlxf_pass?orgId=' + that.data.orgId + '&org=' + that.data.org + '&showModal=' + this.data.showModal
  148. })
  149. } else {
  150. setTimeout(()=>{
  151. wx.showToast({
  152. title: suc.msg,
  153. icon: 'none'
  154. })
  155. },0)
  156. wx.navigateBack(1)
  157. }
  158. }).catch(err => {
  159. console.log(err)
  160. })
  161. },
  162. // 判断是否填写
  163. setList() {
  164. let canSubmit = true;
  165. let list = this.data.list
  166. list.forEach((item, index) => {
  167. if (item.customNameVal == null && item.isShow === 1) {
  168. return canSubmit = false
  169. }
  170. })
  171. return canSubmit;
  172. },
  173. /**
  174. * 生命周期函数--监听页面加载
  175. */
  176. onLoad: function ({
  177. org = '',
  178. orgId = null,
  179. showModal = false
  180. }) {
  181. this.setData({
  182. org,
  183. orgId,
  184. showModal,
  185. })
  186. this.getList()
  187. },
  188. /**
  189. * 生命周期函数--监听页面初次渲染完成
  190. */
  191. onReady: function () {
  192. },
  193. /**
  194. * 生命周期函数--监听页面显示
  195. */
  196. onShow: function () {
  197. },
  198. /**
  199. * 生命周期函数--监听页面隐藏
  200. */
  201. onHide: function () {
  202. },
  203. /**
  204. * 生命周期函数--监听页面卸载
  205. */
  206. onUnload: function () {
  207. },
  208. /**
  209. * 页面相关事件处理函数--监听用户下拉动作
  210. */
  211. onPullDownRefresh: function () {
  212. },
  213. /**
  214. * 页面上拉触底事件的处理函数
  215. */
  216. onReachBottom: function () {
  217. },
  218. /**
  219. * 用户点击右上角分享
  220. */
  221. onShareAppMessage: function () {
  222. },
  223. })