review.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. import { post } 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: 'https://store.test-api.ijolijoli.com/api/upload',
  151. header: {
  152. token: wx.getStorageSync('token') || '',
  153. },
  154. filePath,
  155. name: 'file',
  156. formData: {
  157. 'type': 'check'
  158. },
  159. success(res) {
  160. console.log(res)
  161. if(res.statusCode == 200 && res.data) {
  162. let data = JSON.parse(res.data);
  163. if(data.code == 200 && data.data) {
  164. resolve(data)
  165. } else {
  166. wx.showToast({
  167. title: '上传失败',
  168. icon: 'none'
  169. })
  170. }
  171. } else {
  172. wx.showToast({
  173. title: '上传失败',
  174. icon: 'none'
  175. })
  176. }
  177. },
  178. fail(err) {
  179. wx.showToast({
  180. title: '上传失败',
  181. icon: 'none'
  182. })
  183. }
  184. })
  185. })
  186. },
  187. /**
  188. * 删除列表项
  189. */
  190. onDeleteItem(e) {
  191. let imgs = this.data.imgs;
  192. if(this.data.is_list) {
  193. imgs = this.data.check.feedback.media_list
  194. }
  195. imgs.splice(e.currentTarget.dataset.index, 1);
  196. this.setData({ imgs })
  197. console.log(imgs)
  198. },
  199. /**
  200. * /api/check/update
  201. * 添加/修改检查信息
  202. */
  203. onCheckUpdate() {
  204. let { orderId,value,imgs,check,check_id } = this.data;
  205. let option_ids = [], option_values= [];
  206. check.option_list.forEach((item,index) => {
  207. item.children.forEach((newItem,index) => {
  208. option_ids.push(newItem.id)
  209. if(newItem.status) {
  210. option_values.push(1)
  211. } else {
  212. option_values.push(2)
  213. }
  214. })
  215. })
  216. post('api/check/update',{
  217. check_id,
  218. type: check.type,
  219. option_ids: option_ids.toString(),
  220. option_values: option_values.toString(),
  221. content: value,
  222. media_list: JSON.stringify(imgs)
  223. },(res) => {
  224. wx.showToast({
  225. title: res.msg,
  226. icon: 'none'
  227. })
  228. setTimeout(() => {
  229. let pages=getCurrentPages()
  230. let prePage = pages[pages.length-1]
  231. prePage.onShow()
  232. this.setData({
  233. is_list: true
  234. })
  235. }, 1500);
  236. console.log(res)
  237. })
  238. },
  239. /** 预览图片和视频 */
  240. previewMedia(e) {
  241. let arr = this.data.imgs
  242. if(this.data.is_list) {
  243. arr = this.data.check.feedback.media_list
  244. }
  245. let current = e.currentTarget.dataset.index
  246. wx.previewMedia({
  247. sources: arr,
  248. current
  249. })
  250. },
  251. /** 切换编辑 */
  252. onChangeEdit() {
  253. this.setData({
  254. is_list: false
  255. })
  256. }
  257. }
  258. })