list.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065
  1. <template>
  2. <view class="container">
  3. <view class="header">
  4. <view class="segmented-control-item" :class="{ 'active': activeTab === 0 }" @click="switchTab(0)">上传
  5. <view class="underline" v-show="activeTab === 0"></view>
  6. </view>
  7. <view class="segmented-control-item" :class="{ 'active': activeTab === 1 }" @click="switchTab(1)">已上传
  8. <view class="underline" v-show="activeTab === 1"></view>
  9. </view>
  10. </view>
  11. <!-- <view class="absolute-element"> -->
  12. <swiper class="scroll-view swiper" :current="activeTab" duration="0" @change="handleSwiperChange">
  13. <swiper-item>
  14. <scroll-view scroll-y="true" :style="{'height': clientHeight + 'px'}">
  15. <!-- <scroll-view scroll-y="true" style="height: 100%;" > -->
  16. <view class="content" v-show="activeTab === 0">
  17. <view class="list" v-for="(item, index) in list" :key="index">
  18. <view class="list-item">
  19. <view style="padding-top: 5px;">
  20. <checkbox-group @change="toggleSelect(index)">
  21. <checkbox
  22. style="transform: scale(0.6,0.6);activeBackgroundColor: #253a6f;iconColor: #253a6f;"
  23. v-model="selected[index]" :checked="selected[index]" :key="item.id" />
  24. </checkbox-group>
  25. </view>
  26. <view>
  27. <view class="item" @click="goDetailPage(item.uid)">
  28. <image class="icon" src="/static/meeting.png" />
  29. <text class="text">{{ item.exhibitionName }}</text>
  30. </view>
  31. <view class="item" @click="goDetailPage(item.uid)">
  32. <image class="icon" src="/static/customer.png" />
  33. <text class="text">{{ item.customerName }}</text>
  34. </view>
  35. <view class="item" @click="goDetailPage(item.uid)">
  36. <image class="icon" src="/static/receiver.png" />
  37. <text class="text">{{ item.receiver }}</text>
  38. </view>
  39. <view class="item1" style=""
  40. :style="{ 'flex-wrap': item.fileSavePath.length <= 2 ? 'nowrap' : 'wrap' }">
  41. <u--image class="image-item" v-for="(element, i) in item.fileSavePath" :key="i"
  42. :src="element" width="80px" height="80px"
  43. @click="previewImage(item,i)"></u--image>
  44. </view>
  45. <view class="item">
  46. <text class="text">备注信息:{{ item.exhibitionNote }}</text>
  47. </view>
  48. <!-- <view class="item">
  49. <button style="width:100%;background-color: #253a6f;color: white;height: 40px;font-size: 14px;line-height: 40px;
  50. text-align: center;margin-top: 50px;" @click="upload(index)">上传</button>
  51. </view> -->
  52. </view>
  53. </view>
  54. <button style="background-color: #253a6f;color: white;height: 40px;font-size: 14px;line-height: 40px;
  55. text-align: center;margin-top: 50px;margin-bottom: 10px;width: 90%;" :disabled="uploadingStatus[index]"
  56. @click="upload(index)"><span v-if="uploadingStatus[index]">上传中...</span>
  57. <span v-else>上传</span></button>
  58. </view>
  59. </view>
  60. </scroll-view>
  61. </swiper-item>
  62. <swiper-item>
  63. <!-- <scroll-view scroll-y="true" style="height: 100%;"> -->
  64. <scroll-view scroll-y="true" :style="{'height': clientHeight + 'px'}">
  65. <view class="content" v-show="activeTab === 1">
  66. <view class="list" v-for="(item, index) in uploadedList" :key="index">
  67. <view class="list-item">
  68. <view style="padding-top: 5px;">
  69. <checkbox-group @change="toggleSelect1(index)">
  70. <checkbox
  71. style="transform: scale(0.6,0.6);activeBackgroundColor: #253a6f;iconColor: #253a6f;"
  72. v-model="selected1[index]" :checked="selected1[index]" :key="item.id" />
  73. </checkbox-group>
  74. </view>
  75. <view>
  76. <view class="item" @click="goDetailPage(item.uid)">
  77. <image class="icon" src="/static/meeting.png" />
  78. <text class="text">{{ item.exhibitionName }}</text>
  79. </view>
  80. <view class="item" @click="goDetailPage(item.uid)">
  81. <image class="icon" src="/static/customer.png" />
  82. <text class="text">{{ item.customerName }}</text>
  83. </view>
  84. <view class="item" @click="goDetailPage(item.uid)">
  85. <image class="icon" src="/static/receiver.png" />
  86. <text class="text">{{ item.receiver }}</text>
  87. </view>
  88. <view class="item1"
  89. :style="{ 'flex-wrap': item.fileSavePath.length <= 2 ? 'nowrap' : 'wrap' }">
  90. <u--image class="image-item" v-for="(element, i) in item.fileSavePath" :key="i"
  91. :src="element" width="80px" height="80px"
  92. @click="previewImage(item,i)"></u--image>
  93. </view>
  94. <view class="item">
  95. <text class="text">备注信息:{{ item.exhibitionNote }}</text>
  96. </view>
  97. </view>
  98. </view>
  99. </view>
  100. </view>
  101. </scroll-view>
  102. </swiper-item>
  103. </swiper>
  104. <!-- 底部操作栏 -->
  105. <view class="bottom-bar" v-show="activeTab === 0">
  106. <view style="display: flex; width: 90%;margin: 0 auto;align-items: center;">
  107. <checkbox-group style="margin-left: 10px;" @change="toggleSelectAll">
  108. <view style="width: 300rpx;">
  109. <checkbox :value="selectAll" :checked="selectAll"
  110. style="transform: scale(0.5,0.5);activeBackgroundColor: #253a6f;iconColor: #253a6f;" />
  111. 全选 已选{{selectedCount}}项
  112. </view>
  113. </checkbox-group>
  114. <!-- <view style="margin-left:90px;align-items: center;border: solid 1px red;"> -->
  115. <view style="margin-right: 10px;margin-left:5px;">
  116. <button type="default"
  117. style="color:#ffffff;backgroundColor:#27DBBB; border-radius: 50px;width:150rpx; height:65rpx;font-size: unset;display: flex;justify-content: center; align-items:center"
  118. @click="changeListData"><span>删除</span></button>
  119. </view>
  120. <view>
  121. <button
  122. style="color:#ffffff;backgroundColor:#253a6f; border-radius: 50px;width:150rpx; height:65rpx;font-size: unset;display: flex;justify-content: center; align-items:center"
  123. @click="uploadSelect" :disabled="isSubmitting"><span v-if="isSubmitting">...</span>
  124. <span v-else>上传</span></button>
  125. </view>
  126. <!-- </view> -->
  127. </view>
  128. </view>
  129. <view class="bottom-bar" v-show="activeTab === 1">
  130. <view style="display: flex; width: 90%;margin: 0 auto;align-items: center;">
  131. <checkbox-group style="margin-left: 10px;" @change="toggleSelectAll1">
  132. <view style="width: 300rpx;">
  133. <checkbox :value="selectAll1" :checked="selectAll1"
  134. style="transform: scale(0.5,0.5);activeBackgroundColor: #253a6f;iconColor: #253a6f;" />
  135. 全选 已选{{selectedCount1}}项
  136. </view>
  137. </checkbox-group>
  138. <!-- <view style="display: flex;margin-left:70px;align-items: center;"> -->
  139. <view style="margin-right: 10px;">
  140. <button type="default"
  141. style="color:#ffffff;backgroundColor:#27DBBB; border-radius: 50px;width:150rpx; height:65rpx;font-size: unset;visibility: hidden;">删除</button>
  142. </view>
  143. <view>
  144. <button
  145. style="color:#ffffff;backgroundColor:#27DBBB; border-radius: 50px;width:150rpx; height:65rpx;font-size: unset;display: flex;justify-content: center; align-items:center"
  146. @click="deleteSelectedUploaded">删除</button>
  147. </view>
  148. <!-- </view> -->
  149. </view>
  150. </view>
  151. </view>
  152. </template>
  153. <script>
  154. import {
  155. getToken,
  156. setToken
  157. } from '@/utils/auth'
  158. import {
  159. openSqlite,
  160. executeSql,
  161. closedb,
  162. getTable,
  163. isTable,
  164. getAllField,
  165. insertAll,
  166. addSql,
  167. getPageList,
  168. selectList,
  169. deleteSql,
  170. updateSql,
  171. selectSql,
  172. batchUpdate
  173. } from "@/utils/database";
  174. export default {
  175. data() {
  176. return {
  177. tableName: "public",
  178. options: {
  179. current: 1, // 分页默认为第1页
  180. size: 10,
  181. },
  182. list: [],
  183. uploadedList: [],
  184. activeTab: 0, // 当前选中的页面索引
  185. selected: [], // 保存每个数据项是否被选中的状态
  186. selectAll: false, // 全选状态
  187. selected1: [], // 保存每个数据项是否被选中的状态
  188. selectAll1: false, // 全选状态
  189. selectedCount: 0,
  190. selectedCount1: 0,
  191. clientHeight: '',
  192. isSubmitting: false, // 控制提交按钮状态
  193. uploadingStatus: [], // 用于存储上传状态的对象
  194. // a:1,
  195. // b:1
  196. };
  197. },
  198. watch: {
  199. selected: {
  200. handler() {
  201. this.selectedCount = this.selected.filter(value => value === true).length;
  202. },
  203. deep: true,
  204. },
  205. selected1: {
  206. handler() {
  207. this.selectedCount1 = this.selected1.filter(value => value === true).length;
  208. },
  209. deep: true,
  210. },
  211. },
  212. onShow() {
  213. this.getToBeUploadedData()
  214. this.getUploadedData()
  215. this.selected = new Array(this.list.length).fill(false)
  216. this.selected1 = new Array(this.uploadedList.length).fill(false)
  217. plus.key.hideSoftKeybord();
  218. const res = uni.getSystemInfo({
  219. success: (res => {
  220. console.log(res.windowHeight)
  221. // console.log(getApp().globalData.navHeight)
  222. this.clientHeight = res.windowHeight - 120;
  223. })
  224. });
  225. console.log('res', this.clientHeight)
  226. },
  227. // onLoad() {
  228. // this.getToBeUploadedData()
  229. // this.getUploadedData()
  230. // },
  231. mounted() {
  232. this.selected = new Array(this.list.length).fill(false)
  233. this.selected1 = new Array(this.uploadedList.length).fill(false)
  234. plus.key.hideSoftKeybord();
  235. },
  236. methods: {
  237. handleSwiperChange(event) {
  238. console.log(event.detail.current)
  239. this.activeTab = event.detail.current;
  240. if (event.detail.current == 1) {
  241. console.log(event.detail.current)
  242. setTimeout(() => {
  243. console.log('隐藏')
  244. plus.key.hideSoftKeybord();
  245. // uni.hideKeyboard()
  246. }, 700)
  247. }
  248. },
  249. toggleSelectAll(e) {
  250. console.log(e.detail)
  251. console.log(this.selectAll = !this.selectAll)
  252. this.selectAll = e.detail.value[0] == false ? true : false
  253. // console.log(this.selectAll)
  254. this.selected = this.list.map(() => this.selectAll);
  255. // console.log(this.selected)
  256. },
  257. toggleSelect(index) {
  258. console.log(index)
  259. this.selected[index] = !this.selected[index];
  260. this.selectAll = this.selected.every(item => item);
  261. console.log(this.selectAll)
  262. this.selectedCount = this.selected.filter(value => value === true).length;
  263. },
  264. toggleSelectAll1(e) {
  265. console.log(e.detail)
  266. console.log(this.selectAll1 = !this.selectAll1)
  267. this.selectAll1 = e.detail.value[0] == false ? true : false
  268. // console.log(this.selectAll1)
  269. this.selected1 = this.uploadedList.map(() => this.selectAll1);
  270. // console.log(this.selected)
  271. },
  272. toggleSelect1(index) {
  273. console.log(index)
  274. this.selected1[index] = !this.selected1[index];
  275. this.selectAll1 = this.selected1.every(item => item);
  276. console.log(this.selectAll1)
  277. this.selectedCount1 = this.selected1.filter(value => value === true).length;
  278. },
  279. deleteSelectedUploaded() {
  280. const listToDelete1 = this.uploadedList.filter((item, index) => this.selected1[index]).map(item => {
  281. return {
  282. id: item.id,
  283. deleted: 1
  284. };
  285. });
  286. // console.log(idsToDelete1)
  287. if (this.isEmptyObject(listToDelete1)) {
  288. uni.showToast({
  289. title: "请选择删除条目",
  290. icon: "none"
  291. });
  292. return
  293. }
  294. console.log(listToDelete1)
  295. console.log('selected', this.selected1)
  296. let self = this
  297. uni.showModal({
  298. // title: '提示',
  299. content: '确认删除选中的条目?',
  300. success: async function(res) {
  301. if (res.confirm) {
  302. console.log('用户点击确定')
  303. try {
  304. // const self = this
  305. await batchUpdate(self.tableName, listToDelete1, "id")
  306. // 过滤掉arr1中对应arr2中值为true的索引的元素
  307. self.uploadedList = self.uploadedList.filter((item, index) => !self.selected1[
  308. index])
  309. self.selectAll1 = false
  310. console.log(self.uploadedList)
  311. uni.showToast({
  312. title: "删除成功",
  313. icon: "none",
  314. success: function() {}
  315. });
  316. } catch (e) {
  317. console.error("批量修改数据,报错", e)
  318. }
  319. } else if (res.cancel) {
  320. console.log('用户点击取消')
  321. }
  322. }
  323. })
  324. // 调用接口删除数据项
  325. // console.log('需要删除的数据项ID:', idsToDelete);
  326. // // 删除选中的数据项后,重新获取数据列表
  327. // this.getList();
  328. },
  329. async getToBeUploadedData() {
  330. let where = {
  331. "deleted": 0,
  332. "uploaded": 0
  333. }
  334. this.list = await this.getData(where)
  335. console.log(this.list)
  336. this.selected = new Array(this.list.length).fill(false)
  337. // this.list = this.getData(where)
  338. },
  339. async getUploadedData() {
  340. let where = {
  341. "deleted": 0,
  342. "uploaded": 1
  343. }
  344. this.uploadedList = await this.getData(where)
  345. console.log(this.uploadedList)
  346. this.selected1 = new Array(this.uploadedList.length).fill(false)
  347. plus.key.hideSoftKeybord();
  348. // this.list = this.getData(where)
  349. },
  350. // 获取数据
  351. async getData(where) {
  352. try {
  353. // let where = {
  354. // "deleted": 0,
  355. // "uploaded": 0
  356. // }
  357. let res = await selectList(this.tableName, where, "createTime desc")
  358. console.log("加载数据", res)
  359. const result = res.map(({
  360. fileSavePath,
  361. ...rest
  362. }) => ({
  363. fileSavePath: fileSavePath ? fileSavePath.split(',') : [],
  364. ...rest
  365. }));
  366. // 清空原先的数据
  367. // this.list = [];
  368. // console.log(result);
  369. // this.list = result
  370. return result
  371. } catch (e) {
  372. uni.showToast({
  373. title: "报错,请查看控制台",
  374. icon: "none"
  375. });
  376. console.error("报错", e)
  377. }
  378. },
  379. isEmptyObject(obj) {
  380. return Object.keys(obj).length === 0;
  381. },
  382. // 批量修改数据
  383. async changeListData() {
  384. const listToDelete = this.list.filter((item, index) => this.selected[index]).map(item => {
  385. return {
  386. id: item.id,
  387. deleted: 1
  388. };
  389. });
  390. if (this.isEmptyObject(listToDelete)) {
  391. uni.showToast({
  392. title: "请选择删除条目",
  393. icon: "none"
  394. });
  395. return
  396. }
  397. console.log(listToDelete)
  398. console.log('selected', this.selected)
  399. let self = this
  400. uni.showModal({
  401. // title: '提示',
  402. content: '确认删除选中的条目?',
  403. success: async function(res) {
  404. if (res.confirm) {
  405. console.log('用户点击确定')
  406. try {
  407. // const self = this
  408. await batchUpdate(self.tableName, listToDelete, "id")
  409. // 过滤掉arr1中对应arr2中值为true的索引的元素
  410. self.list = self.list.filter((item, index) => !self.selected[index])
  411. self.selectAll = false
  412. console.log(self.list)
  413. uni.showToast({
  414. title: "修改成功",
  415. icon: "none",
  416. success: function() {}
  417. });
  418. } catch (e) {
  419. console.error("批量修改数据,报错", e)
  420. }
  421. } else if (res.cancel) {
  422. console.log('用户点击取消')
  423. }
  424. }
  425. })
  426. },
  427. //图片预览
  428. previewImage(item, i) {
  429. uni.previewImage({
  430. current: i,
  431. urls: item.fileSavePath
  432. });
  433. },
  434. switchTab(index) {
  435. this.activeTab = index; // 切换页面
  436. },
  437. goDetailPage(uid) {
  438. console.log(uid)
  439. uni.navigateTo({
  440. url: '/pages/collections/sample-collection-detail?uid=' + uid
  441. });
  442. },
  443. uploadSelect() {
  444. // this.a++
  445. // console.log("aaaaaaaa",this.a)
  446. console.log(getToken())
  447. if (!getToken()) {
  448. uni.showToast({
  449. title: "请先登录",
  450. icon: "none"
  451. });
  452. uni.reLaunch({
  453. url: '/pages/login/index'
  454. })
  455. return
  456. }
  457. if (this.isSubmitting) return; // 如果正在提交中,则直接返回
  458. const trueIndexes = this.selected.reduce((acc, val, index) => {
  459. if (val === true) {
  460. acc.push(index);
  461. }
  462. return acc;
  463. }, []);
  464. console.log(trueIndexes)
  465. // const listToDelete = this.list.filter((item, index) => this.selected[index]).map(item => item.id);
  466. // console.log(listToDelete)
  467. // return
  468. if (this.isEmptyObject(trueIndexes)) {
  469. uni.showToast({
  470. title: "请选择上传条目",
  471. icon: "none"
  472. });
  473. return
  474. }
  475. let self = this
  476. uni.showModal({
  477. // title: '提示',
  478. content: '确认上传选中的条目?',
  479. success: function(res) {
  480. if (res.confirm) {
  481. self.isSubmitting = true; // 设置提交中状态
  482. console.log('用户点击确定')
  483. // try {
  484. const uploadPromises = trueIndexes.map((item) => self.uploadData(item));
  485. console.log(uploadPromises)
  486. Promise.all(uploadPromises)
  487. .then(async (result) => {
  488. console.log(result)
  489. for (const obj of result) {
  490. if (obj.code == 200) {
  491. console.log(obj.data.uid);
  492. try {
  493. await updateSql('public', {
  494. uploaded: 1,
  495. }, {
  496. uid: obj.data.uid
  497. })
  498. // const self = this
  499. console.log("上传成功")
  500. const filteredData = self.list.filter(item => item
  501. .uid !== obj.data.uid);
  502. console.log(filteredData);
  503. self.list = filteredData
  504. self.getUploadedData()
  505. // console.log(self.list)
  506. // arr.splice(2, 1);
  507. // self.list = self.list.filter((item, index) => !self.selected[index])
  508. uni.showToast({
  509. title: "上传成功",
  510. icon: "none",
  511. });
  512. } catch (e) {
  513. uni.showToast({
  514. title: "修改报错,请联系开发人员",
  515. icon: "none"
  516. });
  517. console.error("修改报错", e)
  518. }
  519. //修改状态
  520. } else {
  521. console.log("上传失败")
  522. console.log("上传失败")
  523. if (obj.msg == "token 无效" || obj.msg == "未能读取到有效 token") {
  524. uni.showModal({
  525. content: "请重新登录",
  526. showCancel: false
  527. });
  528. uni.reLaunch({
  529. url: '/pages/login/index'
  530. })
  531. }
  532. if (obj.status === 500) {
  533. uni.showModal({
  534. content: "上传失败:" + obj.error,
  535. showCancel: false
  536. });
  537. }
  538. }
  539. }
  540. self.selected = new Array(self.list.length).fill(false)
  541. self.selectAll = false
  542. await self.getUploadedData()
  543. self.isSubmitting = false; // 恢复按钮可用状态
  544. // 所有文件上传完成
  545. console.log('所有文件上传完成');
  546. }, (errorMessage) => {
  547. self.isSubmitting = false; // 恢复按钮可用状态
  548. console.error("操作失败:" + errorMessage.errMsg);
  549. uni.showModal({
  550. content: "请检查网络",
  551. showCancel: false
  552. });
  553. })
  554. .catch((error) => {
  555. console.error('文件上传出错:', error);
  556. self.isSubmitting = false; // 恢复按钮可用状态
  557. });
  558. // }
  559. // for (let i = 0; i < trueIndexes.length; i++) {
  560. // self.uploadData(trueIndexes[i])
  561. // }
  562. // self.selected = new Array(self.list.length).fill(false)
  563. // self.selectAll = false
  564. // await self.getUploadedData()
  565. // } catch (e) {
  566. // console.error("批量修改数据,报错", e)
  567. // }
  568. } else if (res.cancel) {
  569. console.log('用户点击取消')
  570. }
  571. }
  572. })
  573. // console.log(listToDelete)
  574. // console.log('selected', this.selected)
  575. // for (let i = 0; i < trueIndexes.length; i++) {
  576. // this.upload(trueIndexes[i])
  577. // }
  578. },
  579. upload(index) {
  580. if (!getToken()) {
  581. uni.showToast({
  582. title: "请先登录",
  583. icon: "none"
  584. });
  585. uni.reLaunch({
  586. url: '/pages/login/index'
  587. })
  588. return
  589. }
  590. if (this.uploadingStatus[index]) return; // 如果正在上传中,则直接返回
  591. console.log(this.uploadingStatus[index])
  592. let self = this
  593. // this.b++
  594. // console.log("bbbbbb",this.b)
  595. uni.showModal({
  596. // title: '提示',
  597. content: '确认上传选中的条目?',
  598. success: function(res) {
  599. if (res.confirm) {
  600. self.uploadingStatus[index] = true; // 设置上传中状态
  601. self.$forceUpdate();
  602. console.log('用户点击确定')
  603. // try {
  604. // self.uploadData(index)
  605. // self.selected = new Array(self.list.length).fill(false)
  606. // self.selectAll = false
  607. // // self.switchTab(1)
  608. // } catch (e) {
  609. // console.error("上传,报错", e)
  610. // }
  611. self.uploadData(index)
  612. .then(async (result) => {
  613. self.uploadingStatus[index] = false; // 恢复按钮可用状态
  614. console.log(result)
  615. console.log(result)
  616. // return
  617. if (result.code == 200) {
  618. console.log(result.data.uid);
  619. try {
  620. await updateSql('public', {
  621. uploaded: 1,
  622. }, {
  623. uid: result.data.uid
  624. })
  625. // const self = this
  626. console.log("上传成功")
  627. const filteredData = self.list.filter(item => item
  628. .uid !== result.data.uid);
  629. console.log(filteredData);
  630. self.list = filteredData
  631. self.getUploadedData()
  632. // console.log(self.list)
  633. // arr.splice(2, 1);
  634. // self.list = self.list.filter((item, index) => !self.selected[index])
  635. uni.showToast({
  636. title: "上传成功",
  637. icon: "none",
  638. });
  639. } catch (e) {
  640. uni.showToast({
  641. title: "修改报错,请联系开发人员",
  642. icon: "none"
  643. });
  644. console.error("修改报错", e)
  645. }
  646. //修改状态
  647. } else {
  648. console.log("上传失败")
  649. if (result.msg == "token 无效" || result.msg ==
  650. "未能读取到有效 token") {
  651. uni.showModal({
  652. content: "请重新登录",
  653. showCancel: false
  654. });
  655. uni.reLaunch({
  656. url: '/pages/login/index'
  657. })
  658. }
  659. if (result.status === 500) {
  660. uni.showModal({
  661. content: "上传失败:" + result.error,
  662. showCancel: false
  663. });
  664. }
  665. }
  666. }, (errorMessage) => {
  667. self.uploadingStatus[index] = false; // 恢复按钮可用状态
  668. self.$forceUpdate();
  669. console.log('aaaaaaaa',self.uploadingStatus[index])
  670. console.error("操作失败:" + errorMessage.errMsg);
  671. uni.showModal({
  672. content: "请检查网络",
  673. showCancel: false
  674. });
  675. })
  676. .catch((error) => {
  677. self.uploadingStatus[index] = false; // 恢复按钮可用状态
  678. self.$forceUpdate();
  679. console.error('文件上传出错:', error);
  680. });
  681. } else if (res.cancel) {
  682. console.log('用户点击取消')
  683. self.uploadingStatus[index] = false; // 恢复按钮可用状态
  684. self.$forceUpdate();
  685. }
  686. }
  687. })
  688. },
  689. async uploadData(index) {
  690. console.log(this.list[index])
  691. let fileSavePath = this.list[index].fileSavePath;
  692. console.log(fileSavePath)
  693. // console.log(fileSavePath.length === 0)
  694. let result = []
  695. if (fileSavePath.length === 0) {
  696. result = []
  697. } else {
  698. result = fileSavePath.map(function(path, index) {
  699. return {
  700. name: "public" + index,
  701. uri: path
  702. };
  703. });
  704. }
  705. console.log('result', result);
  706. let detailList = await this.getDetailListByUid(this.list[index].uid)
  707. console.log('detailList', detailList)
  708. if (detailList.length === 0) {
  709. console.log('数组为空');
  710. var files = result;
  711. } else {
  712. var result2 = detailList.map(function(item) {
  713. if (item.fileSavePath) {
  714. var fileSavePath = item.fileSavePath;
  715. var fileSavePathArray = fileSavePath.split(',');
  716. return fileSavePathArray.map(function(path, index) {
  717. return {
  718. name: "detail-" + item.id + "-" + index,
  719. uri: path
  720. };
  721. });
  722. } else {
  723. return []
  724. }
  725. });
  726. console.log('result2', result2)
  727. var result3 = result2.reduce(function(acc, cur) {
  728. return acc.concat(cur);
  729. }, []);
  730. console.log('result3', result3)
  731. var files = result.concat(result3);
  732. console.log('数组不为空');
  733. }
  734. if (files.length === 0) {
  735. files = [{
  736. "uri": 'a'
  737. }]
  738. }
  739. const {
  740. uid,
  741. exhibitionName,
  742. customerName,
  743. receiver,
  744. exhibitionNote
  745. } = this.list[index];
  746. const mainObj = {
  747. uid,
  748. exhibitionName,
  749. customerName,
  750. receiver,
  751. exhibitionNote
  752. };
  753. const detailArr = detailList.map(obj => {
  754. return {
  755. id: obj.id,
  756. publicId: obj.publicId,
  757. barCode: obj.barCode,
  758. bpQuantity: obj.bpQuantity,
  759. gyQuantity: obj.gyQuantity,
  760. myQuantity: obj.myQuantity,
  761. note: obj.note,
  762. };
  763. });
  764. const mainStr = JSON.stringify(mainObj);
  765. const detailStr = JSON.stringify(detailArr);
  766. console.log('mainStr', mainStr)
  767. console.log('detailStr', detailStr)
  768. console.log('files', files)
  769. let self = this
  770. return new Promise((resolve, reject) => {
  771. uni.uploadFile({
  772. url: 'https://xyxt.lttc.cn/samplescan/api/input', //仅为示例,非真实的接口地址
  773. // url: 'http://10.20.70.228:8028/samplescan/api/input', //仅为示例,非真实的接口地址
  774. files: files,
  775. header: {
  776. 'Content-Type': 'multipart/form-data',
  777. 'Authorization': getToken()
  778. },
  779. formData: {
  780. 'main': mainStr,
  781. 'detail': detailStr
  782. },
  783. success: (res) => {
  784. // JSON.parse(uploadFileRes.data)
  785. resolve(JSON.parse(res.data));
  786. // success: async (uploadFileRes) => {
  787. // console.log(uploadFileRes.data);
  788. // const obj = JSON.parse(uploadFileRes.data);
  789. // console.log(obj.code);
  790. // if (obj.code == 200) {
  791. // console.log(obj.data.uid);
  792. // try {
  793. // await updateSql('public', {
  794. // uploaded: 1,
  795. // }, {
  796. // uid: obj.data.uid
  797. // })
  798. // console.log("上传成功")
  799. // const filteredData = self.list.filter(item => item.uid !== obj.data.uid);
  800. // console.log(filteredData);
  801. // self.list = filteredData
  802. // self.getUploadedData()
  803. // uni.showToast({
  804. // title: "上传成功",
  805. // icon: "none",
  806. // });
  807. // } catch (e) {
  808. // uni.showToast({
  809. // title: "修改报错,请联系开发人员",
  810. // icon: "none"
  811. // });
  812. // console.error("修改报错", e)
  813. // }
  814. // //修改状态
  815. // } else {
  816. // console.log("上传失败")
  817. // if(obj.msg == "token 无效"){
  818. // uni.reLaunch({
  819. // url: '/pages/login/index'
  820. // })
  821. // }
  822. // uni.showModal({
  823. // content: "请重新登录",
  824. // showCancel: false
  825. // });
  826. // }
  827. },
  828. fail: (err) => {
  829. reject(err);
  830. console.log(err);
  831. // uni.showModal({
  832. // content: "请检查网络",
  833. // showCancel: false
  834. // });
  835. }
  836. });
  837. });
  838. // })
  839. },
  840. async getDetailListByUid(uid) {
  841. try {
  842. let where = {
  843. "publicId": uid,
  844. 'deleted': 0
  845. }
  846. // let res = await selectList(this.tableName, where)
  847. let res = await selectList('detail', where)
  848. console.log("加载数据", res)
  849. return res
  850. // this.total = res.data.data.total
  851. } catch (e) {
  852. uni.showToast({
  853. title: "报错,请查看控制台",
  854. icon: "none"
  855. });
  856. console.error("报错", e)
  857. }
  858. },
  859. },
  860. };
  861. </script>
  862. <style>
  863. button::after {
  864. border: 0; // 或者 border: none;
  865. }
  866. .container {
  867. position: relative;
  868. width: 100%;
  869. height: 100vh;
  870. overflow: hidden;
  871. background-color: #EDEDED
  872. /* 隐藏溢出内容,禁止滚动 */
  873. }
  874. .header {
  875. position: fixed;
  876. background-color: #253a6f;
  877. height: 170rpx;
  878. width: 100%;
  879. z-index: 1;
  880. display: flex;
  881. }
  882. .scroll-view {
  883. position: absolute;
  884. left: 50%;
  885. top: 60%;
  886. transform: translate(-50%, -50%);
  887. width: 90%;
  888. height: 100%;
  889. overflow: auto;
  890. /* 设置滚动 */
  891. background-color: white;
  892. border-radius: 5px;
  893. /* border: 1px solid red; */
  894. /* padding: 0 10px; */
  895. z-index: 998;
  896. }
  897. .content {
  898. width: 100%;
  899. margin-bottom: 150px;
  900. border-radius: 5px;
  901. background-color: #EDEDED;
  902. overflow-y: auto;
  903. z-index: 999;
  904. /* border: 1px solid blue; */
  905. /* 此处设置滚动区域的内容样式 */
  906. }
  907. .segmented-control-item {
  908. flex: 1;
  909. text-align: center;
  910. padding: 10px;
  911. color: white;
  912. }
  913. .underline {
  914. bottom: 0;
  915. left: 0;
  916. width: 20%;
  917. height: 1px;
  918. background-color: white;
  919. /* 设置下划线的颜色 */
  920. display: none;
  921. margin: 0 auto;
  922. }
  923. .segmented-control-item.active .underline {
  924. display: block;
  925. }
  926. .icon {
  927. width: 40rpx;
  928. height: 40rpx;
  929. margin-right: 20rpx;
  930. }
  931. .list {
  932. margin-bottom: 10px;
  933. border-radius: 5px;
  934. background-color: white;
  935. }
  936. .list-item {
  937. display: flex;
  938. margin-top: 2px;
  939. background-color: white;
  940. }
  941. .item {
  942. display: flex;
  943. align-items: center;
  944. padding-top: 10px;
  945. }
  946. .item1 {
  947. display: flex;
  948. /* flex-wrap: wrap; */
  949. justify-content: flex-start;
  950. }
  951. .upload-btn {
  952. justify-content: center;
  953. align-items: center;
  954. }
  955. .image-item {
  956. /* flex: 1; */
  957. /* width: 30%; */
  958. margin: 5px;
  959. border: solid 1px #dadbde;
  960. }
  961. .bottom-bar {
  962. position: fixed;
  963. /* 将底部操作栏固定在页面底部 */
  964. left: 0;
  965. bottom: 0;
  966. width: 100%;
  967. height: 80rpx;
  968. /* text-align: center; */
  969. background-color: white;
  970. /* color: #fff; */
  971. font-size: 32rpx;
  972. line-height: 80rpx;
  973. z-index: 999;
  974. }
  975. .text {
  976. color: #949494;
  977. margin-top: 3px;
  978. }
  979. uni-checkbox .uni-checkbox-input {
  980. border-radius: 80rpx !important;
  981. border: 2px solid #ccc;
  982. }
  983. /deep/ uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked:before {
  984. font: normal normal normal 14px/1 uni;
  985. content: "EA08";
  986. font-size: 0;
  987. /* 重点使用这一步取消的默认样式 */
  988. position: absolute;
  989. top: 50%;
  990. left: 50%;
  991. transform: translate(-50%, -48%) scale(1);
  992. -webkit-transform: translate(-50%, -48%) scale(1);
  993. }
  994. /deep/ .uni-checkbox-input-checked::before {
  995. width: 19px;
  996. height: 19px;
  997. background: #253a6f;
  998. border-radius: 50%;
  999. /* background: url(../../static/img/seal.png) no-repeat center; */
  1000. }
  1001. </style>