feedbackinfo.js 6.6 KB

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