index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. <template>
  2. <view class="content">
  3. <view class="title-box">
  4. <view class="title">
  5. <view class="title">价格采集</view>
  6. </view>
  7. </view>
  8. <view class="container-box">
  9. <view class="container">
  10. <view class="info-box">
  11. <!-- <view>
  12. <u-cell title="经度" :value="position.longitude"></u-cell>
  13. <u-cell title="纬度" :value="position.latitude"></u-cell>
  14. </view> -->
  15. <view>
  16. <u-cell title="站点名称" v-if="isSelfPriceMonitor" :value="monitor.name"></u-cell>
  17. <u-cell title="站点名称" v-if="!isSelfPriceMonitor" :value="monitor.name" :is-link="true" @click="show = true"></u-cell>
  18. <u-cell title="详细地址" :value="monitor.address"></u-cell>
  19. <u-cell title="价格采集人" :value="monitor.userName"></u-cell>
  20. <u-cell title="市州" :value="monitor.sysOrgName"></u-cell>
  21. <u-cell title="联系方式" :value="monitor.userPhone"></u-cell>
  22. <u-cell title="采集时间" :value="nowDate"></u-cell>
  23. </view>
  24. </view>
  25. <view class="price">
  26. <view class="title">价格信息</view>
  27. <view class="item-table">
  28. <view class="center title-1">粮食品类: 原粮</view>
  29. <u-row class="row">
  30. <u-col :span="4">
  31. <view class="center">品种</view>
  32. </u-col>
  33. <u-col :span="8">
  34. <view class="center">收购价</view>
  35. </u-col>
  36. </u-row>
  37. <u-row v-for="(item, index) in price1" :key="index" class="row">
  38. <u-col :span="4">
  39. <view class="center">{{item.name}}</view>
  40. </u-col>
  41. <u-col :span="8">
  42. <view class="center"><u-input v-model.number="item.price"></u-input></view>
  43. </u-col>
  44. </u-row>
  45. </view>
  46. <view class="item-table">
  47. <view class="center title-1">粮食品类: 储备粮</view>
  48. <u-row class="row">
  49. <u-col :span="4">
  50. <view class="center">品种</view>
  51. </u-col>
  52. <u-col :span="4">
  53. <view class="center">出库价</view>
  54. </u-col>
  55. <u-col :span="4">
  56. <view class="center">入库价</view>
  57. </u-col>
  58. </u-row>
  59. <u-row v-for="(item, index) in price2" :key="index" class="row">
  60. <u-col :span="4">
  61. <view class="center">{{item.name}}</view>
  62. </u-col>
  63. <u-col :span="4">
  64. <view class="center m-l-2"><u-input v-model.number="item.price1"></u-input></view>
  65. </u-col>
  66. <u-col :span="4">
  67. <view class="center m-l-2"><u-input v-model.number="item.price2"></u-input></view>
  68. </u-col>
  69. </u-row>
  70. </view>
  71. <view class="item-table">
  72. <view class="center">粮食品类: 成品粮</view>
  73. <u-row class="row">
  74. <u-col :span="4">
  75. <view class="center">品种</view>
  76. </u-col>
  77. <u-col :span="4">
  78. <view class="center">批发价</view>
  79. </u-col>
  80. <u-col :span="4">
  81. <view class="center">零售价</view>
  82. </u-col>
  83. </u-row>
  84. <u-row v-for="(item, index) in price3" :key="index" class="row">
  85. <u-col :span="4">
  86. <view class="center">{{item.name}}</view>
  87. </u-col>
  88. <u-col :span="4">
  89. <view class="center m-l-2"><u-input v-model.number="item.price1"></u-input></view>
  90. </u-col>
  91. <u-col :span="4">
  92. <view class="center m-l-2"><u-input v-model.number="item.price2"></u-input></view>
  93. </u-col>
  94. </u-row>
  95. </view>
  96. <view class="item-table">
  97. <view class="center">粮食品类: 杂粮</view>
  98. <u-row class="row">
  99. <u-col :span="4">
  100. <view class="center">品种</view>
  101. </u-col>
  102. <u-col :span="4">
  103. <view class="center">批发价</view>
  104. </u-col>
  105. <u-col :span="4">
  106. <view class="center">零售价</view>
  107. </u-col>
  108. </u-row>
  109. <u-row v-for="(item, index) in price4" :key="index" class="row">
  110. <u-col :span="4">
  111. <view class="center">{{item.name}}</view>
  112. </u-col>
  113. <u-col :span="4">
  114. <view class="center m-l-2"><u-input v-model.number="item.price1"></u-input></view>
  115. </u-col>
  116. <u-col :span="4">
  117. <view class="center m-l-2"><u-input v-model.number="item.price2"></u-input></view>
  118. </u-col>
  119. </u-row>
  120. </view>
  121. <view class="remark">
  122. <u--textarea v-model="remark" placeholder="备注:本周/日采集数据与上周/日采集数据作对比价格超出5%,需要填写备注"></u--textarea>
  123. </view>
  124. </view>
  125. <view class="btns">
  126. <u-button text="上传" type="primary" class="btn-upload" @click="upload"></u-button>
  127. </view>
  128. </view>
  129. </view>
  130. <u-action-sheet
  131. :actions="allMonitor"
  132. :closeOnClickOverlay="true"
  133. :closeOnClickAction="true"
  134. title="选择站点"
  135. :show="show"
  136. @select="chooseMonitor"
  137. @close="show = false">
  138. </u-action-sheet>
  139. </view>
  140. </template>
  141. <script>
  142. import { getMonitorInfoByPoint, getMonitorInfo, addCollect } from '@/api/collect'
  143. import { dateFormat } from '@/utils/dates'
  144. import { clone } from '@/utils/common'
  145. const DEFAULT_MONITOR = {
  146. name: '',
  147. address: '',
  148. userName: '',
  149. sysOrgName: '',
  150. userPhone: '',
  151. }
  152. const PURCHASE_PRICE = 1 // 收购价
  153. const INBOUND_PRICE = 2// 入库价
  154. const OUTBOUND_PRICE = 3 // 出库价
  155. const EX_FACTORY_PRICE = 4 // 出厂价
  156. const WHOLESALE_PRICE = 5 // 批发价
  157. const RETAIL_PRICE = 6 // 零售价
  158. export default {
  159. data() {
  160. return {
  161. showTips: false,
  162. loadingMsg: '',
  163. position: {
  164. longitude: null, // 经度
  165. latitude: null, // 纬度
  166. },
  167. price1: [
  168. {
  169. name: '小麦',
  170. firstLevel: 1,
  171. secondLevel: 11,
  172. threeLevel: 0,
  173. price: null,
  174. },
  175. {
  176. name: '青稞',
  177. firstLevel: 1,
  178. secondLevel: 12,
  179. threeLevel: 0,
  180. price: null,
  181. },
  182. {
  183. name: '油菜籽',
  184. firstLevel: 1,
  185. secondLevel: 13,
  186. threeLevel: 0,
  187. price: null,
  188. },
  189. ],
  190. price2: [
  191. {
  192. name: '省储小麦',
  193. firstLevel: 4,
  194. secondLevel: 41,
  195. threeLevel: 0,
  196. price1: null,
  197. price2: null,
  198. },
  199. {
  200. name: '省储青稞',
  201. firstLevel: 4,
  202. secondLevel: 42,
  203. threeLevel: 0,
  204. price1: null,
  205. price2: null,
  206. },
  207. {
  208. name: '省储菜籽油',
  209. firstLevel: 4,
  210. secondLevel: 43,
  211. threeLevel: 0,
  212. price1: null,
  213. price2: null,
  214. },
  215. ],
  216. price3: [
  217. {
  218. name: '一级菜籽油',
  219. firstLevel: 3,
  220. secondLevel: 31,
  221. threeLevel: 311,
  222. price1: null,
  223. price2: null,
  224. },
  225. {
  226. name: '三级菜籽油',
  227. firstLevel: 3,
  228. secondLevel: 31,
  229. threeLevel: 312,
  230. price1: null,
  231. price2: null,
  232. },
  233. {
  234. name: '小榨菜籽油',
  235. firstLevel: 3,
  236. secondLevel: 31,
  237. threeLevel: 313,
  238. price1: null,
  239. price2: null,
  240. },
  241. {
  242. name: '特一粉',
  243. firstLevel: 3,
  244. secondLevel: 32,
  245. threeLevel: 321,
  246. price1: null,
  247. price2: null,
  248. },
  249. {
  250. name: '牛肉面粉',
  251. firstLevel: 3,
  252. secondLevel: 32,
  253. threeLevel: 322,
  254. price1: null,
  255. price2: null,
  256. },
  257. {
  258. name: '一级长粒粳米',
  259. firstLevel: 3,
  260. secondLevel: 33,
  261. threeLevel: 331,
  262. price1: null,
  263. price2: null,
  264. },
  265. {
  266. name: '一级圆粒粳米',
  267. firstLevel: 3,
  268. secondLevel: 33,
  269. threeLevel: 332,
  270. price1: null,
  271. price2: null,
  272. },
  273. ],
  274. price4: [
  275. {
  276. name: '黄豆',
  277. firstLevel: 2,
  278. secondLevel: 21,
  279. threeLevel: 0,
  280. price1: null,
  281. price2: null,
  282. },
  283. {
  284. name: '玉米面',
  285. firstLevel: 2,
  286. secondLevel: 22,
  287. threeLevel: 0,
  288. price1: null,
  289. price2: null,
  290. },
  291. {
  292. name: '小米',
  293. firstLevel: 2,
  294. secondLevel: 23,
  295. threeLevel: 0,
  296. price1: null,
  297. price2: null,
  298. },
  299. ],
  300. monitor: DEFAULT_MONITOR,
  301. allMonitor: [],
  302. userId: null,
  303. nowDate: null,
  304. isSelfPriceMonitor: false,
  305. show: false,
  306. remark: null,
  307. }
  308. },
  309. mounted() {
  310. uni.showModal({
  311. content: '上报需要获取当前设备定位信息,是否允许?',
  312. confirmText: '允许',
  313. cancelText: '不允许',
  314. success: (ret) => {
  315. if(ret.confirm)
  316. this.getPosition()
  317. else
  318. uni.redirectTo({
  319. url: '/pages/collectionList/index'
  320. })
  321. },
  322. fail: () => {
  323. uni.redirectTo({
  324. url: '/pages/collectionList/index'
  325. })
  326. }
  327. })
  328. },
  329. methods: {
  330. doGetPosition() {
  331. return new Promise((resolve, reject) => {
  332. uni.getLocation({
  333. altitude: true,
  334. isHighAccuracy: true,
  335. success: (ret) => {
  336. resolve(ret)
  337. },
  338. fail: (err) => {
  339. reject(err)
  340. }
  341. })
  342. })
  343. // for debug
  344. // return Promise.resolve({
  345. // longitude: 40.7124,
  346. // latitude: -74.006,
  347. // })
  348. },
  349. getPosition() {
  350. this.loadingMsg = '正在获取定位'
  351. uni.showLoading({
  352. title: this.loadingMsg,
  353. mask: true
  354. })
  355. this.doGetPosition()
  356. .then(ret => {
  357. this.position.latitude = ret.latitude
  358. this.position.longitude = ret.longitude
  359. }).then(_ => {
  360. // 请求所有站点数据
  361. return getMonitorInfo().then(resp => {
  362. console.log('所有站点', resp);
  363. const all = resp.data
  364. this.allMonitor = all.map(d => {
  365. const ret = {
  366. ... d,
  367. disabled: d.locationSwitch == 1
  368. }
  369. if(ret.disabled) {
  370. ret.subname = '该站点必须实地采集'
  371. }
  372. return ret
  373. })
  374. })
  375. }).then(_ => {
  376. if(this.allMonitor.length <= 0) {
  377. return Promise.reject('你没有可用的检测点')
  378. }else {
  379. this.userId = this.allMonitor[0].userId
  380. return Promise.resolve()
  381. }
  382. }).then(_ => {
  383. // 请求检测点
  384. return getMonitorInfoByPoint({
  385. userId: this.userId,
  386. point: `POINT(${this.position.latitude} ${this.position.longitude})`
  387. // point: `POINT(1 ${this.position.latitude})`
  388. }).then(resp => {
  389. console.log('最近站点', resp);
  390. if(resp.data.status === 'error') {
  391. uni.showToast({
  392. icon: 'error',
  393. title: resp.data.message
  394. })
  395. this.monitor = DEFAULT_MONITOR
  396. this.isSelfPriceMonitor = false
  397. return
  398. }else {
  399. const data = this.allMonitor.find(d => d.id === resp.data.id)
  400. if(data) {
  401. this.monitor = data
  402. this.isSelfPriceMonitor = true
  403. }else {
  404. uni.showToast({
  405. icon: 'error',
  406. title: '最近站点数据异常'
  407. })
  408. this.monitor = DEFAULT_MONITOR
  409. this.isSelfPriceMonitor = false
  410. return
  411. }
  412. }
  413. })
  414. }).then(_ => {
  415. this.nowDate = dateFormat(new Date())
  416. }).catch(err => {
  417. console.log(err);
  418. uni.showToast({
  419. title: err
  420. })
  421. })
  422. },
  423. chooseMonitor(m) {
  424. this.monitor = m
  425. },
  426. calPrice(rawData, dataList, priceType1, priceType2) {
  427. const temp1 = clone(rawData)
  428. const temp2 = clone(rawData)
  429. delete temp1.name
  430. delete temp2.name
  431. temp1.priceType = priceType1
  432. temp2.priceType = priceType2
  433. temp1.price = rawData.price1
  434. temp2.price = rawData.price2
  435. delete temp1.price1
  436. delete temp1.price2
  437. delete temp2.price1
  438. delete temp2.price2
  439. dataList.push(temp1)
  440. dataList.push(temp2)
  441. },
  442. upload() {
  443. if(this.monitor === DEFAULT_MONITOR) {
  444. uni.showToast({
  445. title: '请选择监测点',
  446. icon: "error"
  447. })
  448. return
  449. }
  450. const dataList = []
  451. this.price1.forEach(d => {
  452. const temp = clone(d)
  453. delete temp.name
  454. temp.priceType = PURCHASE_PRICE
  455. dataList.push(temp)
  456. })
  457. this.price2.forEach(d => {
  458. this.calPrice(d, dataList, OUTBOUND_PRICE, INBOUND_PRICE)
  459. })
  460. this.price3.forEach(d => {
  461. this.calPrice(d, dataList, WHOLESALE_PRICE, RETAIL_PRICE)
  462. })
  463. this.price4.forEach(d => {
  464. this.calPrice(d, dataList, WHOLESALE_PRICE, RETAIL_PRICE)
  465. })
  466. const data = {
  467. type: 0, // 移动端
  468. priceMonitorId: this.monitor.id,
  469. userCollectId: this.monitor.userId,
  470. userId: this.monitor.userId,
  471. isSelfPriceMonitor: this.isSelfPriceMonitor ? 1 : 0, // 是否实地采集, 0 否 1 是
  472. userCollectName: this.monitor.userName,
  473. userCollectPhone: this.monitor.userPhone,
  474. userCollectDate: this.nowDate,
  475. remark: this.remark,
  476. categoryAddParamList: dataList,
  477. point: `${this.position.longitude},${this.position.latitude}`
  478. }
  479. console.log(data);
  480. addCollect(data).then(resp => {
  481. console.log('保存上报', resp);
  482. if(resp.code == 200) {
  483. uni.showToast({
  484. title: '保存成功',
  485. icon: 'success',
  486. mask: true,
  487. duration: 1_500,
  488. })
  489. setTimeout(() => {
  490. uni.redirectTo({
  491. url: '/pages/collectionList/index'
  492. })
  493. }, 1_500)
  494. }else {
  495. uni.showToast({
  496. title: resp.msg,
  497. icon: 'error',
  498. })
  499. }
  500. })
  501. },
  502. getPositionErrMessage(errCode) {
  503. console.log('定位失败', errCode);
  504. let message;
  505. switch (errCode) {
  506. case '1505004':
  507. message = '获取定位失败,请开启定位权限';
  508. break;
  509. case '1505005':
  510. message = '获取定位失败,请开启高经度定位权限';
  511. break;
  512. case '1505021':
  513. message = '获取定位失败,请重试';
  514. break;
  515. case '1505022':
  516. message = '获取定位失败,设备不支持当前类型定位';
  517. break;
  518. case '1505023':
  519. message = '获取定位失败,设备不支持逆地理编码';
  520. break;
  521. case '1505024':
  522. message = '获取定位失败,请开启设备的定位功能';
  523. break;
  524. case '1505025':
  525. message = '获取定位失败,逆地理编码捕获失败';
  526. break;
  527. case '1505026':
  528. message = '获取定位失败,捕获定位失败';
  529. break;
  530. default:
  531. message = '获取定位失败'
  532. }
  533. return message
  534. }
  535. }
  536. }
  537. </script>
  538. <style lang="scss" scoped>
  539. .container{
  540. background-color: #fff;
  541. border-radius: 24rpx;
  542. .info-box{
  543. padding: 0 30rpx;
  544. }
  545. }
  546. .price {
  547. // margin: 5px;
  548. // padding-bottom: 70px;
  549. .title {
  550. position: relative;
  551. margin: 10px;
  552. display: inline-flex;
  553. justify-content: center;
  554. align-items: flex-end;
  555. font-weight: bold;
  556. z-index: 1;
  557. &::after{
  558. content: "";
  559. position: absolute;
  560. width: 80%;
  561. height: 20rpx;
  562. background: url(@/static/bg-item-title.png) top center no-repeat;
  563. background-size: 100% 100%;
  564. z-index: -1;
  565. }
  566. }
  567. .title-1 {
  568. position: relative;
  569. margin: 10px 0;
  570. padding: 20rpx 0;
  571. padding-left: 30rpx;
  572. display: flex;
  573. align-items: center;
  574. background-color: #f4f4f4;
  575. font-weight: bold;
  576. z-index: 1;
  577. &::after{
  578. content: "";
  579. position: absolute;
  580. left: 0;
  581. margin-right: 20rpx;
  582. width: 12rpx;
  583. height: 30rpx;
  584. background: linear-gradient(0deg,#48d9f4 0%,#29a1ff 100%);
  585. border-radius: 24rpx;
  586. z-index: -1;
  587. }
  588. }
  589. .row {
  590. margin-top: 5px;
  591. }
  592. .center {
  593. text-align: center;
  594. }
  595. .m-l-2 {
  596. margin-left: 2px;
  597. }
  598. .remark{
  599. margin: 20rpx;
  600. }
  601. }
  602. .btns {
  603. margin-bottom: 20px;
  604. width: 100%;
  605. height: 50px;
  606. .btn-upload {
  607. width: 80%;
  608. margin-bottom: 10px;
  609. }
  610. }
  611. ::v-deep{
  612. .u-cell__body{
  613. padding: 20rpx 0!important;
  614. }
  615. }
  616. </style>