verify.js 6.9 KB

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