feedback.js 6.5 KB

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