index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // pages/wallet/index.js
  2. var AV = require('../../utils/av-weapp-min.js');
  3. var server = require('../../libs/config.js');
  4. var upload = require('../../utils/upload.js');
  5. var app = getApp()
  6. Page({
  7. data: {
  8. // 故障车周围环境图路径数组
  9. picUrls: [],
  10. // 故障车编号和备注
  11. inputValue: {
  12. num: '',
  13. desc: ""
  14. },
  15. // 故障类型数组
  16. checkboxValue: [],
  17. // 选取图片提示
  18. actionText: "拍照/相册",
  19. // 提交按钮的背景色,未勾选类型时无颜色
  20. btnBgc: "#00AA55",
  21. // 复选框的value,此处预定义,然后循环渲染到页面
  22. itemsValue: [
  23. {
  24. checked: false,
  25. value: "私锁私用",
  26. color: "#b9dd08"
  27. },
  28. {
  29. checked: false,
  30. value: "车牌缺损",
  31. color: "#b9dd08"
  32. },
  33. {
  34. checked: false,
  35. value: "轮胎坏了",
  36. color: "#b9dd08"
  37. },
  38. {
  39. checked: false,
  40. value: "车锁坏了",
  41. color: "#b9dd08"
  42. },
  43. {
  44. checked: false,
  45. value: "违规乱停",
  46. color: "#b9dd08"
  47. },
  48. {
  49. checked: false,
  50. value: "密码不对",
  51. color: "#b9dd08"
  52. },
  53. {
  54. checked: false,
  55. value: "刹车坏了",
  56. color: "#b9dd08"
  57. },
  58. {
  59. checked: false,
  60. value: "其他故障",
  61. color: "#b9dd08"
  62. }
  63. ]
  64. },
  65. // 页面加载
  66. onLoad: function (options) {
  67. wx.setNavigationBarTitle({
  68. title: '上传图片'
  69. })
  70. },
  71. // 勾选故障类型,获取类型值存入checkboxValue
  72. checkboxChange: function (e) {
  73. let _values = e.detail.value;
  74. if (_values.length == 0) {
  75. this.setData({
  76. btnBgc: ""
  77. })
  78. } else {
  79. this.setData({
  80. checkboxValue: _values,
  81. btnBgc: "#b9dd08"
  82. })
  83. }
  84. },
  85. // 输入单车编号,存入inputValue
  86. numberChange: function (e) {
  87. this.setData({
  88. inputValue: {
  89. num: e.detail.value,
  90. desc: this.data.inputValue.desc
  91. }
  92. })
  93. },
  94. // 输入备注,存入inputValue
  95. descChange: function (e) {
  96. this.setData({
  97. inputValue: {
  98. num: this.data.inputValue.num,
  99. desc: e.detail.value
  100. }
  101. })
  102. },
  103. // 提交到服务器
  104. formSubmit: function (e) {
  105. if (this.data.picUrls.length > 0) {
  106. console.log(this.data.picUrls)
  107. upload.uploadimg({
  108. url: server.Server.url + '/api/upload/batch/image',//这里是你图片上传的接口
  109. path: this.data.picUrls,//这里是选取的图片的地址数组,
  110. info: this.data.inputValue,
  111. userid: app.globalData.nwUserid
  112.     });
  113. wx.showLoading({
  114. title: '上传中',
  115. })
  116. } else {
  117. wx.showModal({
  118. title: "请至少上传一张图片",
  119. // content: '请填反馈信息',
  120. confirmText: "好的",
  121. cancelText: "不上传了",
  122. success: (res) => {
  123. if (res.confirm) {
  124. // 继续填
  125. } else {
  126. console.log("back")
  127. wx.navigateBack({
  128. delta: 1 // 回退前 delta(默认为1) 页面
  129. })
  130. }
  131. }
  132. })
  133. }
  134. },
  135. // 选择故障车周围环境图 拍照或选择相册
  136. bindCamera: function () {
  137. wx.chooseImage({
  138. count: 4,
  139. sizeType: ['original', 'compressed'],
  140. sourceType: ['album', 'camera'],
  141. success: (res) => {
  142. let tfps = res.tempFilePaths;
  143. let _picUrls = this.data.picUrls;
  144. for (let item of tfps) {
  145. _picUrls.push(item);
  146. this.setData({
  147. picUrls: _picUrls,
  148. actionText: "+"
  149. });
  150. };
  151. var tempFilePath = res.tempFilePaths[0];
  152. }
  153. })
  154. },
  155. // 删除选择的故障车周围环境图
  156. delPic: function (e) {
  157. let index = e.target.dataset.index;
  158. let _picUrls = this.data.picUrls;
  159. _picUrls.splice(index, 1);
  160. this.setData({
  161. picUrls: _picUrls
  162. })
  163. }
  164. })