feedbackinfo.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. import constant from '../../utils/constant';
  4. const app = getApp();
  5. Page({
  6. data: {
  7. Feedback:constant.arrFeedback,
  8. ImageArr:[],
  9. ImagePath: app.globalData.uploadImageUrl,
  10. },
  11. onLoad: function (options) {
  12. var that = this;
  13. var feedbackType=0;
  14. if (options.type){
  15. that.data.Feedback[0].CSS="";
  16. that.data.Feedback[options.type].CSS="Selected";
  17. }
  18. that.setData({
  19. Containnerheight: main.getWindowHeight(),
  20. IsShow:app.globalData.userInfo.IsShow,
  21. Feedback:that.data.Feedback,
  22. });
  23. },
  24. bindKeyInput:function(e){
  25. var that=this;
  26. that.setData({
  27. InputValue:e.detail.value,
  28. });
  29. },
  30. bindKeyInput2:function(e){
  31. var that=this;
  32. that.setData({
  33. InputValue2:e.detail.value,
  34. });
  35. },
  36. saveFeedback:function(){
  37. var that=this;
  38. if (!that.data.InputValue){
  39. wx.showToast({
  40. title: '请填写内容',
  41. });
  42. }
  43. else if (that.data.InputValue.length<5){
  44. wx.showToast({
  45. title: '请多写点内容',
  46. });
  47. }
  48. else{
  49. wx.showLoading({
  50. title: '保存中',
  51. mask: true,
  52. });
  53. that.uploadImageAll(that.data.ImageArr,function (success,arrResult) {
  54. if (success) {
  55. wx.hideLoading();
  56. var param={};
  57. param.UserID=app.globalData.userInfo.UserID;
  58. param.Content=that.data.InputValue;
  59. param.ContactTa=that.data.InputValue2;
  60. param.FeedbackType=[];
  61. for(var i=0;i<that.data.Feedback.length;i++){
  62. if (that.data.Feedback[i].CSS=="Selected")
  63. param.FeedbackType.push(that.data.Feedback[i].Name);
  64. }
  65. param.FeedbackType=param.FeedbackType.join(",");
  66. if (arrResult.length>0)
  67. param.ImageUrl1=arrResult[0].Target;
  68. if (arrResult.length>1)
  69. param.ImageUrl2=arrResult[1].Target;
  70. if (arrResult.length>2)
  71. param.ImageUrl3=arrResult[2].Target;
  72. if (arrResult.length>3)
  73. param.ImageUrl4=arrResult[3].Target;
  74. main.postData('MPSFeedback', param, function (data) {
  75. wx.showModal({
  76. title: '提醒',
  77. content: '您的反馈已经收到,我们会尽快处理。感谢您的支持!',
  78. showCancel: false,
  79. complete: (res) => {
  80. if (res.confirm) {
  81. wx.navigateBack({
  82. delta: 1
  83. });
  84. }
  85. }
  86. });
  87. });
  88. } else {
  89. wx.showToast({
  90. title: '图片上传失败',
  91. image: "../images/universalpic_exclamation_white_120x120.png",
  92. mask: true,
  93. });
  94. }
  95. });
  96. }
  97. },
  98. //选择图片上传
  99. uploadImageField: function () {
  100. //console.log("uploadImageStart");
  101. var that = this;
  102. //若是安卓机
  103. if (app.globalData.IsAndroid) {
  104. selectImage(that);
  105. } else {
  106. wx.showActionSheet({
  107. itemList: ['拍照', '从手机相册选择'],
  108. success(res) {
  109. if (res.tapIndex == 0) {
  110. wx.chooseImage({
  111. count: 1,
  112. sizeType: ['compressed'],
  113. sourceType: ['camera'],
  114. success(res2) {
  115. wx.showLoading({
  116. title: '请稍候',
  117. mask: true,
  118. });
  119. setTimeout(function () {
  120. wx.hideLoading();
  121. selectImage(that);
  122. }, 2000);
  123. },
  124. });
  125. } else if (res.tapIndex == 1) {
  126. selectImage(that);
  127. }
  128. },
  129. fail(res) {
  130. console.log(res.errMsg)
  131. }
  132. });
  133. }
  134. function selectImage(that) {
  135. var sizeType = ['album'];
  136. //若是安卓机
  137. if (app.globalData.IsAndroid)
  138. sizeType = ['album', 'camera'];
  139. wx.chooseImage({
  140. count: 1,
  141. sizeType: ['compressed'],
  142. sourceType: sizeType,
  143. success(res) {
  144. // tempFilePath可以作为img标签的src属性显示图片
  145. var tempFilePaths = res.tempFilePaths;
  146. //console.log(tempFilePaths[0]);
  147. //that.data.FieldContent = that.data.FieldContent + "[图 url='" + tempFilePaths[0] + "']" + tempFilePaths[0] + "[/图]";
  148. that.data.ImageArr.push(tempFilePaths[0]);
  149. that.setData({
  150. ImageArr:that.data.ImageArr,
  151. });
  152. },
  153. fail: function () {
  154. }
  155. });
  156. }
  157. },
  158. uploadFileToServer: function (file, callback) {
  159. var url = common.Encrypt("MiaoguoUploadFile2");
  160. wx.showLoading({
  161. title: '上传中',
  162. mask: true,
  163. });
  164. url=app.globalData.serverUrl + url;
  165. wx.uploadFile({
  166. url: url,
  167. filePath: file,
  168. name: 'file',
  169. success(res) {
  170. var err = JSON.parse(res.data);
  171. if (err.errcode == 10000) {
  172. wx.hideLoading();
  173. callback(err.result);
  174. } else {
  175. wx.hideLoading();
  176. wx.showModal({
  177. title: '上传文件失败1',
  178. showCancel: false,
  179. content: JSON.stringify(err.errMsg),
  180. });
  181. }
  182. },
  183. fail: function (err) {
  184. wx.hideLoading();
  185. wx.showModal({
  186. title: '上传文件失败2',
  187. showCancel: false,
  188. content: JSON.stringify(err)+" url:"+url,
  189. });
  190. }
  191. });
  192. },
  193. uploadImageAll: function (arr, callback) {
  194. var that = this;
  195. var b = false;
  196. var arrResult = [];
  197. for (var i = 0; i < arr.length; i++) {
  198. var source = arr[i];
  199. that.uploadFileToServer(source, function (data) {
  200. if (data) {
  201. var result = data;
  202. result.Target = app.globalData.uploadImageUrl + result.Target;
  203. arrResult.push(result);
  204. }
  205. });
  206. }
  207. //检查是否上传成功
  208. setTimeout(function () {
  209. if (arrResult.length==arr.length)
  210. callback(true, arrResult);
  211. }, 2000);
  212. },
  213. goto: function (e) {
  214. main.goto(e);
  215. },
  216. onSelect:function(event){
  217. var that=this;
  218. main.onSelect(that,event,function(obj,e,result){
  219. if (e.currentTarget.dataset.object=="Feedback"){
  220. }
  221. });
  222. },
  223. onShareTimeline: function () {
  224. return this.onShareAppMessage();
  225. },
  226. onShareAppMessage: function () {
  227. return {
  228. title: app.globalData.ShareTitle,
  229. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  230. imageUrl: app.globalData.ShareImage,
  231. }
  232. },
  233. })