inventoryCost.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <template>
  2. <view class="content">
  3. <view @click='goposition(item)' class="cost-list" v-for="(item,index) in costList">
  4. <view style="display: flex;justify-content: space-between;">
  5. <view class="title">{{item.warehouseName}}</view>
  6. <!-- <view class="button" @click="toDetail(item.warehouseName)">详细记录</view> -->
  7. </view>
  8. <view class="goods-table">
  9. <view class="goods-table-title">
  10. <view class="font">货名</view>
  11. <view class="font">储量(吨)</view>
  12. <view class="font">平均成本</view>
  13. </view>
  14. <view class="goods-table-content" v-for="(item1,index1) in item.goodList">
  15. <view class="font" :class="item.goodList.length>1&&index1==item.goodList.length-1?'active':''">
  16. {{item1.goodsName}}
  17. </view>
  18. <view class="font" :class="item.goodList.length>1&&index1==item.goodList.length-1?'active':''">
  19. {{item1.storage}}
  20. </view>
  21. <view class="font">{{item1.cost}}</view>
  22. </view>
  23. </view>
  24. </view>
  25. <u-modal class="record" v-model="isShowDetailBtn" :title-style="{fontSize: '18px',fontWeight:'500'}"
  26. :content-style="{fontSize: '14px',fontWeight:'400'}" confirm-color='#22C572' confirm-text='确定' title='导出记录'
  27. :showCancelButton='false' @confirm="alertBtn" @cancel="cancelClick">
  28. <view>
  29. <u-radio-group v-model="value">
  30. <u-radio active-color="#22C572" @change="radioChange" v-for="(item, index) in list" :key="index"
  31. :name="item.name" :disabled="item.disabled">
  32. {{item.name}}
  33. </u-radio>
  34. </u-radio-group>
  35. <view class="modal-row">
  36. <view class="">查询日期</view>
  37. <view class="" @click="selectDate">
  38. {{parameter.endDate?parameter.startDate+' - '+parameter.endDate:'请选择查询日期'}}
  39. </view>
  40. </view>
  41. <view @click='show1=true' class="modal-row">
  42. <view class="">仓库名称</view>
  43. <view>{{parameter.warehouseName}}</view>
  44. </view>
  45. <u-picker mode="selector" v-model="show1" @confirm='warehouseConfirm' range-key='warehouseName' :default-selector="[0]" :range="warehouseList"></u-picker>
  46. </view>
  47. </u-modal>
  48. <u-calendar v-model="show" :mode="mode" @change="change" range-color='#22C572' btn-type='success'
  49. range-bg-color='rgba(25, 190, 107, 0.13)' active-bg-color='#22C572'></u-calendar>
  50. <u-modal v-model="isShowAlert" :title-style="{fontSize: '18px',fontWeight:'500'}"
  51. :content-style="{fontSize: '14px',fontWeight:'400'}" confirm-color='#22C572' confirm-text='确定' title='提示'
  52. :showCancelButton='false' :content="content" @confirm="alertBtn" @cancel="cancelClick"></u-modal>
  53. </view>
  54. </template>
  55. <script>
  56. import helper from '@/common/helper.js';
  57. import {
  58. mapState
  59. } from 'vuex';
  60. export default {
  61. data() {
  62. return {
  63. isShowAlert: false,
  64. show1:false,
  65. content: '当前登录身份已失效,请重新登录!',
  66. warehouseList:[],
  67. parameter: {
  68. startDate: "",
  69. endDate: '',
  70. warehouseName: '',
  71. warehouseId: ''
  72. },
  73. show: false,
  74. mode: 'range',
  75. list: [{
  76. name: '入库记录',
  77. disabled: false
  78. },
  79. {
  80. name: '出库记录',
  81. disabled: false
  82. }
  83. ],
  84. // u-radio-group的v-model绑定的值如果设置为某个radio的name,就会被默认选中
  85. value: '入库记录',
  86. costList: [],
  87. isShowDetailBtn: false,
  88. searchMonth: '2022-10-10'
  89. }
  90. },
  91. onLoad: function(option) {
  92. console.log(option)
  93. this.searchMonth = option.searchMonth
  94. this.init()
  95. },
  96. onNavigationBarButtonTap() {
  97. this.parameter.warehouseName = this.costList[0].warehouseName
  98. this.parameter.startDate = helper.getNowNumFormatDate(-1)
  99. console.log(this.parameter.startDate)
  100. this.parameter.endDate = helper.getNowFormatDate()
  101. uni.showLoading({
  102. title: '正在加载'
  103. })
  104. this.$api.doRequest('get', '/warehouseBaseInfo/selectWarehouseSelfApp', {
  105. compId: uni.getStorageSync('pcUserInfo').compId,
  106. }).then(res => {
  107. this.warehouseList=res.data.data
  108. this.isShowDetailBtn = true
  109. })
  110. },
  111. computed: {
  112. ...mapState(['hasLogin', 'userInfo']),
  113. },
  114. methods: {
  115. warehouseConfirm(e){
  116. console.log(e)
  117. this.parameter.warehouseName = this.warehouseList[e[0]].warehouseName
  118. },
  119. alertBtn() {
  120. uni.navigateTo({
  121. url: '/pages/public/login'
  122. })
  123. },
  124. goposition(item) {
  125. uni.navigateTo({
  126. url: '/pages/user/contractLook/position?warehouse=' + item.warehouseName + '&warehouseId=' +
  127. item.warehouseId
  128. })
  129. },
  130. cancelClick() {
  131. this.isShowAlert = false
  132. },
  133. selectDate() {
  134. this.show = true
  135. },
  136. change(e) {
  137. this.parameter.startDate = e.startDate
  138. this.parameter.endDate = e.endDate
  139. },
  140. radioChange(e) {
  141. console.log(e);
  142. },
  143. alertBtn() {
  144. let _url = ''
  145. if (this.value == '入库记录') {
  146. _url = '/warehouseBaseInfo/exportphone'
  147. } else {
  148. _url = "/warehouseBaseInfo/exportPhoneOut"
  149. }
  150. uni.showLoading({
  151. title: '正在加载'
  152. })
  153. this.$api.doRequest('post', _url, {
  154. startDate: this.parameter.startDate+' 00:00:00',
  155. endDate: this.parameter.endDate+' 00:00:00',
  156. warehouseName: this.parameter.warehouseName
  157. }).then(res => {
  158. uni.hideLoading()
  159. console.log('-----------')
  160. console.log(res.data.data)
  161. uni.downloadFile({
  162. url: res.data.data,
  163. success: function(res) {
  164. var filePath = res.tempFilePath;
  165. uni.openDocument({
  166. filePath: filePath,
  167. showMenu: true,
  168. success: function(res) {
  169. console.log('打开文档成功');
  170. }
  171. });
  172. }
  173. });
  174. })
  175. },
  176. cancelClick() {
  177. this.isShowDetailBtn = false
  178. },
  179. toDetail(warehouseName) {
  180. // this.parameter.warehouseName = warehouseName
  181. },
  182. init() {
  183. if (!this.hasLogin) {
  184. this.isShowAlert = true;
  185. } else {
  186. uni.showLoading({
  187. title: '正在加载'
  188. })
  189. this.$api.doRequest('get', '/costManagementInfo/selectCostManagementInfo', {
  190. compId: uni.getStorageSync('pcUserInfo').compId,
  191. warehouseType: 1,
  192. searchMoth: this.searchMonth
  193. }).then(res => {
  194. uni.hideLoading()
  195. if (res.data.data) {
  196. const results = this.makeGroupData(res.data.data, function(item) {
  197. return [item.warehouseName];
  198. });
  199. console.log('this.costList')
  200. console.log(this.costList)
  201. let _data = []
  202. for (let i = 0; i < results.length; i++) {
  203. let _obj = {}
  204. _obj.warehouseName = results[i][0].warehouseName
  205. _obj.warehouseId = results[i][0].warehouseId
  206. // 大于两条添加合计行
  207. if (results[i].length > 1) {
  208. let _price = 0
  209. for (let k = 0; k < results[i].length; k++) {
  210. _price += results[i][k].storage
  211. }
  212. _price = _price.toFixed(2)
  213. results[i].push({
  214. 'goodsName': '合计',
  215. 'storage': _price
  216. })
  217. }
  218. _obj.goodList = results[i]
  219. _data.push(_obj)
  220. }
  221. console.log(_data)
  222. this.costList = _data
  223. }
  224. })
  225. }
  226. },
  227. makeGroupData(array, fn) {
  228. const groups = {};
  229. array.forEach(function(item) {
  230. const group = JSON.stringify(fn(item));
  231. groups[group] = groups[group] || [];
  232. groups[group].push(item);
  233. });
  234. return Object.keys(groups).map(function(group) {
  235. console.log(groups, groups[group])
  236. return groups[group];
  237. })
  238. }
  239. }
  240. }
  241. </script>
  242. <style scoped lang="scss">
  243. .active {
  244. font-size: 32rpx;
  245. font-weight: 700;
  246. }
  247. .modal-row {
  248. display: flex;
  249. justify-content: space-between;
  250. padding: 10rpx 60rpx;
  251. margin-top: 20rpx;
  252. margin-bottom: 20rpx;
  253. }
  254. .u-radio-group {
  255. width: 100%;
  256. display: flex;
  257. justify-content: space-between;
  258. }
  259. .u-radio {
  260. width: 50% !important;
  261. display: flex;
  262. justify-content: center;
  263. }
  264. .record {
  265. background: red;
  266. display: flex;
  267. justify-content: center;
  268. }
  269. .button {
  270. font-size: 24rpx;
  271. padding: 4rpx 20rpx;
  272. border-radius: 15px;
  273. background: #22C572;
  274. color: white;
  275. // margin: 0 10px;
  276. }
  277. .cost-list {
  278. margin: 20rpx;
  279. background: white;
  280. border-radius: 20rpx;
  281. padding: 20rpx;
  282. .title {
  283. font-size: 32rpx;
  284. font-weight: 500;
  285. color: #333333;
  286. }
  287. .goods-table {
  288. margin-top: 22rpx;
  289. }
  290. .goods-table-title {
  291. display: flex;
  292. border-bottom: 1px solid #EEEEEE;
  293. padding-bottom: 16rpx;
  294. // margin-bottom: ;
  295. .font {
  296. font-size: 27rpx;
  297. font-weight: 400;
  298. color: #B2B3BB;
  299. }
  300. .font:nth-of-type(1) {
  301. width: 40%;
  302. }
  303. .font:nth-of-type(2) {
  304. width: 30%;
  305. }
  306. .font:nth-of-type(3) {
  307. width: 30%;
  308. text-align: right;
  309. }
  310. }
  311. .goods-table-content {
  312. display: flex;
  313. margin: 22rpx 0;
  314. font-size: 28rpx;
  315. font-weight: 400;
  316. color: #333333;
  317. .font:nth-of-type(1) {
  318. width: 40%;
  319. }
  320. .font:nth-of-type(2) {
  321. width: 30%;
  322. }
  323. .font:nth-of-type(3) {
  324. width: 30%;
  325. text-align: right;
  326. }
  327. }
  328. }
  329. </style>