inspect.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. preCheck: {
  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].thumbTempFilePath).then((data) => {
  123. if(imgs.length > 0 && imgs[0].type == 'video') {
  124. that.setData({
  125. ['imgs[' + 0 + '].thumb']: data.data.url
  126. })
  127. } else {
  128. imgs.unshift({
  129. type: 'video',
  130. thumb: data.data.url,
  131. url: ''
  132. })
  133. that.setData({ imgs })
  134. }
  135. // that.setData({ imgs })
  136. wx.hideLoading()
  137. });
  138. that.upload(tempFiles[0].tempFilePath).then((data) => {
  139. if(imgs.length > 0 && imgs[0].type == 'video') {
  140. that.setData({
  141. ['imgs[' + 0 + '].url']: data.data.url
  142. })
  143. } else {
  144. imgs.unshift({
  145. type: 'video',
  146. thumb: '',
  147. url: data.data.url
  148. })
  149. that.setData({ imgs })
  150. }
  151. // imgs.unshift({
  152. // type: 'video',
  153. // thumb: tempFiles[0].thumbTempFilePath,
  154. // url: data.data.url
  155. // })
  156. // that.setData({ imgs })
  157. wx.hideLoading()
  158. });
  159. }
  160. })
  161. },
  162. /** 上传视频/图片 */
  163. upload(filePath) {
  164. let that = this;
  165. // 上传类型/业务类型:avatar头像,order订单反馈,check检查表反馈
  166. return new Promise((resolve,reject) => {
  167. let { imgs } = this.data;
  168. wx.uploadFile({
  169. url: 'https://store.test-api.ijolijoli.com/api/upload',
  170. header: {
  171. token: wx.getStorageSync('token') || '',
  172. },
  173. filePath,
  174. name: 'file',
  175. formData: {
  176. 'type': 'check'
  177. },
  178. success(res) {
  179. console.log(res)
  180. if(res.statusCode == 200 && res.data) {
  181. let data = JSON.parse(res.data);
  182. if(data.code == 200 && data.data) {
  183. resolve(data)
  184. } else {
  185. wx.showToast({
  186. title: '上传失败',
  187. icon: 'none'
  188. })
  189. }
  190. } else {
  191. wx.showToast({
  192. title: '上传失败',
  193. icon: 'none'
  194. })
  195. }
  196. },
  197. fail(err) {
  198. wx.showToast({
  199. title: '上传失败',
  200. icon: 'none'
  201. })
  202. }
  203. })
  204. })
  205. },
  206. /**
  207. * 删除列表项
  208. */
  209. onDeleteItem(e) {
  210. let imgs = this.data.imgs;
  211. if(this.data.is_list) {
  212. imgs = this.data.check.feedback.media_list
  213. }
  214. imgs.splice(e.currentTarget.dataset.index, 1);
  215. this.setData({ imgs })
  216. console.log(imgs)
  217. },
  218. /**
  219. * /api/check/update
  220. * 添加/修改检查信息
  221. */
  222. onCheckUpdate() {
  223. let { orderId,value,imgs,check,check_id } = this.data;
  224. let option_ids = [], option_values= [];
  225. check.option_list.forEach((item,index) => {
  226. item.children.forEach((newItem,index) => {
  227. option_ids.push(newItem.id)
  228. if(newItem.status) {
  229. option_values.push(1)
  230. } else {
  231. option_values.push(2)
  232. }
  233. })
  234. })
  235. post('api/check/update',{
  236. check_id,
  237. type: check.type,
  238. option_ids: option_ids.toString(),
  239. option_values: option_values.toString(),
  240. content: value,
  241. media_list: JSON.stringify(imgs)
  242. },(res) => {
  243. wx.showToast({
  244. title: res.msg,
  245. icon: 'none'
  246. })
  247. setTimeout(() => {
  248. let pages=getCurrentPages()
  249. let prePage = pages[pages.length-1]
  250. prePage.onShow()
  251. this.setData({
  252. is_list: true
  253. })
  254. }, 1500);
  255. console.log(res)
  256. })
  257. },
  258. /** 预览图片和视频 */
  259. previewMedia(e) {
  260. let arr = this.data.imgs
  261. if(this.data.is_list) {
  262. arr = this.data.check.feedback.media_list
  263. }
  264. let current = e.currentTarget.dataset.index
  265. wx.previewMedia({
  266. sources: arr,
  267. current
  268. })
  269. },
  270. /** 切换编辑 */
  271. onChangeEdit() {
  272. this.setData({
  273. is_list: false
  274. })
  275. }
  276. }
  277. })