review.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. import { post,api_url } from "../../../../utils/http";
  2. // pages/recordSheet/components/inspect/inspect.js
  3. Component({
  4. /**
  5. * 组件的属性列表
  6. */
  7. options: {
  8. addGlobalClass: true
  9. },
  10. properties: {
  11. manager: {
  12. type: Object,
  13. value: null,
  14. observer(newVal,oldVal) {
  15. if(newVal) {
  16. console.log(newVal)
  17. console.log(newVal.option_list)
  18. newVal.option_list.forEach((item,index)=> {
  19. item.children.forEach((newItem) => {
  20. console.log(newItem)
  21. newItem.status = true
  22. })
  23. })
  24. this.setData({
  25. check: newVal
  26. })
  27. console.log(this.data.check)
  28. }
  29. console.log(newVal,oldVal)
  30. // this.setData({
  31. // check
  32. // })
  33. }
  34. },
  35. check_id: {
  36. type: String,
  37. value: null,
  38. }
  39. },
  40. /**
  41. * 组件的初始数据
  42. */
  43. data: {
  44. is_list: true,
  45. list: ['','','',''],
  46. more: true,
  47. maxlength: 500,
  48. number: 0,
  49. value: "",
  50. imgs: [],
  51. check: {}
  52. },
  53. /**
  54. * 组件的方法列表
  55. */
  56. methods: {
  57. onOpenList() {
  58. this.setData({
  59. more: false
  60. })
  61. },
  62. /**
  63. * 切换结果
  64. */
  65. onChangeStatus(e) {
  66. let { idx,index,status } = e.currentTarget.dataset;
  67. this.setData({
  68. ['check.option_list[' + idx + '].children['+index+'].status']: status == 'true' ? true : false
  69. })
  70. },
  71. /** 监听文本域 */
  72. bindTextAreaInput(e) {
  73. this.setData({
  74. number: e.detail.cursor,
  75. value: e.detail.value
  76. })
  77. },
  78. /** 选择图片 */
  79. chooseImage() {
  80. let that = this;
  81. let imgs = this.data.imgs;
  82. let count = 9 - this.data.imgs.length
  83. wx.chooseImage({
  84. count,
  85. sizeType: ['original', 'compressed'],
  86. sourceType: ['album', 'camera'],
  87. success (res) {
  88. wx.showLoading({
  89. title: '正在上传图片',
  90. mask: true
  91. });
  92. const tempFiles = res.tempFiles
  93. tempFiles.forEach((item) => {
  94. that.upload(item.path).then((data) => {
  95. imgs.push({
  96. type: 'image',
  97. url: data.data.url,
  98. })
  99. that.setData({ imgs })
  100. wx.hideLoading()
  101. });
  102. })
  103. }
  104. })
  105. },
  106. /** 选择视频 */
  107. chooseVideo(){
  108. let that = this;
  109. let imgs = this.data.imgs;
  110. wx.chooseMedia({
  111. count: 1,
  112. mediaType: ['video'],
  113. sourceType: ['album', 'camera'],
  114. maxDuration: 30,
  115. camera: 'back',
  116. success(res) {
  117. wx.showLoading({
  118. title: '正在上传视频',
  119. mask: true
  120. });
  121. const tempFiles = res.tempFiles
  122. that.upload(tempFiles[0].tempFilePath).then((data) => {
  123. imgs.unshift({
  124. type: 'video',
  125. thumb: tempFiles[0].thumbTempFilePath,
  126. url: data.data.url
  127. })
  128. that.setData({ imgs })
  129. wx.hideLoading()
  130. });
  131. return;
  132. tempFiles.forEach((item) => {
  133. imgs.unshift({
  134. type: 'video',
  135. thumb: item.thumbTempFilePath,
  136. url: item.tempFilePath
  137. })
  138. })
  139. that.setData({ imgs })
  140. }
  141. })
  142. },
  143. /** 上传视频/图片 */
  144. upload(filePath) {
  145. let that = this;
  146. // 上传类型/业务类型:avatar头像,order订单反馈,check检查表反馈
  147. return new Promise((resolve,reject) => {
  148. let { imgs } = this.data;
  149. wx.uploadFile({
  150. url: `${api_url}api/upload`,
  151. // url: 'https://store.test-api.ijolijoli.com/api/upload',
  152. header: {
  153. token: wx.getStorageSync('token') || '',
  154. },
  155. filePath,
  156. name: 'file',
  157. formData: {
  158. 'type': 'check'
  159. },
  160. success(res) {
  161. console.log(res)
  162. if(res.statusCode == 200 && res.data) {
  163. let data = JSON.parse(res.data);
  164. if(data.code == 200 && data.data) {
  165. resolve(data)
  166. } else {
  167. wx.showToast({
  168. title: '上传失败',
  169. icon: 'none'
  170. })
  171. }
  172. } else {
  173. wx.showToast({
  174. title: '上传失败',
  175. icon: 'none'
  176. })
  177. }
  178. },
  179. fail(err) {
  180. wx.showToast({
  181. title: '上传失败',
  182. icon: 'none'
  183. })
  184. }
  185. })
  186. })
  187. },
  188. /**
  189. * 删除列表项
  190. */
  191. onDeleteItem(e) {
  192. let imgs = this.data.imgs;
  193. if(this.data.is_list) {
  194. imgs = this.data.check.feedback.media_list
  195. }
  196. imgs.splice(e.currentTarget.dataset.index, 1);
  197. this.setData({ imgs })
  198. console.log(imgs)
  199. },
  200. /**
  201. * /api/check/update
  202. * 添加/修改检查信息
  203. */
  204. onCheckUpdate() {
  205. let { orderId,value,imgs,check,check_id } = this.data;
  206. let option_ids = [], option_values= [];
  207. check.option_list.forEach((item,index) => {
  208. item.children.forEach((newItem,index) => {
  209. option_ids.push(newItem.id)
  210. if(newItem.status) {
  211. option_values.push(1)
  212. } else {
  213. option_values.push(2)
  214. }
  215. })
  216. })
  217. post('api/check/update',{
  218. check_id,
  219. type: check.type,
  220. option_ids: option_ids.toString(),
  221. option_values: option_values.toString(),
  222. content: value,
  223. media_list: JSON.stringify(imgs)
  224. },(res) => {
  225. wx.showToast({
  226. title: res.msg,
  227. icon: 'none'
  228. })
  229. setTimeout(() => {
  230. let pages=getCurrentPages()
  231. let prePage = pages[pages.length-1]
  232. prePage.onShow()
  233. this.setData({
  234. is_list: true
  235. })
  236. }, 1500);
  237. console.log(res)
  238. })
  239. },
  240. /** 预览图片和视频 */
  241. previewMedia(e) {
  242. let arr = this.data.imgs
  243. if(this.data.is_list) {
  244. arr = this.data.check.feedback.media_list
  245. }
  246. let current = e.currentTarget.dataset.index
  247. wx.previewMedia({
  248. sources: arr,
  249. current
  250. })
  251. },
  252. /** 切换编辑 */
  253. onChangeEdit() {
  254. this.setData({
  255. is_list: false
  256. })
  257. }
  258. }
  259. })