inventoryCost.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. },
  72. show: false,
  73. mode: 'range',
  74. list: [{
  75. name: '入库记录',
  76. disabled: false
  77. },
  78. {
  79. name: '出库记录',
  80. disabled: false
  81. }
  82. ],
  83. // u-radio-group的v-model绑定的值如果设置为某个radio的name,就会被默认选中
  84. value: '入库记录',
  85. costList: [],
  86. isShowDetailBtn: false,
  87. searchMonth: '2022-10-10'
  88. }
  89. },
  90. onLoad: function(option) {
  91. console.log(option)
  92. this.searchMonth = option.searchMonth
  93. this.init()
  94. },
  95. onNavigationBarButtonTap() {
  96. this.parameter.warehouseName = this.costList[0].warehouseName
  97. this.parameter.startDate = helper.getNowFormatDate()
  98. this.parameter.endDate = helper.getNowFormatDate()
  99. this.$api.doRequest('get', '/warehouseBaseInfo/selectWarehouseSelf', {
  100. compId: uni.getStorageSync('pcUserInfo').compId,
  101. }).then(res => {
  102. this.warehouseList=res.data.data
  103. this.isShowDetailBtn = true
  104. })
  105. },
  106. computed: {
  107. ...mapState(['hasLogin', 'userInfo']),
  108. },
  109. methods: {
  110. warehouseConfirm(e){
  111. console.log(e)
  112. this.parameter.warehouseName = this.warehouseList[e[0]].warehouseName
  113. },
  114. alertBtn() {
  115. uni.navigateTo({
  116. url: '/pages/public/login'
  117. })
  118. },
  119. goposition(item) {
  120. uni.navigateTo({
  121. url: '/pages/user/contractLook/position?warehouse=' + item.warehouseName + '&warehouseType=' +
  122. item.warehouseType
  123. })
  124. },
  125. cancelClick() {
  126. this.isShowAlert = false
  127. },
  128. selectDate() {
  129. this.show = true
  130. },
  131. change(e) {
  132. this.parameter.startDate = e.startDate
  133. this.parameter.endDate = e.endDate
  134. },
  135. radioChange(e) {
  136. console.log(e);
  137. },
  138. alertBtn() {
  139. let _url = ''
  140. if (this.value == '入库记录') {
  141. _url = '/warehouseBaseInfo/exportphone'
  142. } else {
  143. _url = "/warehouseBaseInfo/exportPhoneOut"
  144. }
  145. uni.showLoading({
  146. title: '正在加载'
  147. })
  148. this.$api.doRequest('post', _url, {
  149. startDate: this.parameter.startDate+' 00:00:00',
  150. endDate: this.parameter.endDate+' 00:00:00',
  151. warehouseName: this.parameter.warehouseName
  152. }).then(res => {
  153. uni.hideLoading()
  154. console.log('-----------')
  155. console.log(res.data.data)
  156. uni.downloadFile({
  157. url: res.data.data,
  158. success: function(res) {
  159. var filePath = res.tempFilePath;
  160. uni.openDocument({
  161. filePath: filePath,
  162. showMenu: true,
  163. success: function(res) {
  164. console.log('打开文档成功');
  165. }
  166. });
  167. }
  168. });
  169. })
  170. },
  171. cancelClick() {
  172. this.isShowDetailBtn = false
  173. },
  174. toDetail(warehouseName) {
  175. // this.parameter.warehouseName = warehouseName
  176. },
  177. init() {
  178. if (!this.hasLogin) {
  179. this.isShowAlert = true;
  180. } else {
  181. uni.showLoading({
  182. title: '正在加载'
  183. })
  184. this.$api.doRequest('get', '/costManagementInfo/selectCostManagementInfo', {
  185. compId: uni.getStorageSync('pcUserInfo').compId,
  186. warehouseType: 1,
  187. searchMoth: this.searchMonth
  188. }).then(res => {
  189. uni.hideLoading()
  190. if (res.data.data) {
  191. const results = this.makeGroupData(res.data.data, function(item) {
  192. return [item.warehouseName];
  193. });
  194. console.log('this.costList')
  195. console.log(this.costList)
  196. let _data = []
  197. for (let i = 0; i < results.length; i++) {
  198. let _obj = {}
  199. _obj.warehouseName = results[i][0].warehouseName
  200. // 大于两条添加合计行
  201. if (results[i].length > 1) {
  202. let _price = 0
  203. for (let k = 0; k < results[i].length; k++) {
  204. _price += results[i][k].storage
  205. }
  206. _price = _price.toFixed(2)
  207. results[i].push({
  208. 'goodsName': '合计',
  209. 'storage': _price
  210. })
  211. }
  212. _obj.goodList = results[i]
  213. _data.push(_obj)
  214. }
  215. console.log(_data)
  216. this.costList = _data
  217. }
  218. })
  219. }
  220. },
  221. makeGroupData(array, fn) {
  222. const groups = {};
  223. array.forEach(function(item) {
  224. const group = JSON.stringify(fn(item));
  225. groups[group] = groups[group] || [];
  226. groups[group].push(item);
  227. });
  228. return Object.keys(groups).map(function(group) {
  229. console.log(groups, groups[group])
  230. return groups[group];
  231. })
  232. }
  233. }
  234. }
  235. </script>
  236. <style scoped lang="scss">
  237. .active {
  238. font-size: 32rpx;
  239. font-weight: 700;
  240. }
  241. .modal-row {
  242. display: flex;
  243. justify-content: space-between;
  244. padding: 10rpx 60rpx;
  245. margin-top: 20rpx;
  246. margin-bottom: 20rpx;
  247. }
  248. .u-radio-group {
  249. width: 100%;
  250. display: flex;
  251. justify-content: space-between;
  252. }
  253. .u-radio {
  254. width: 50% !important;
  255. display: flex;
  256. justify-content: center;
  257. }
  258. .record {
  259. background: red;
  260. display: flex;
  261. justify-content: center;
  262. }
  263. .button {
  264. font-size: 24rpx;
  265. padding: 4rpx 20rpx;
  266. border-radius: 15px;
  267. background: #22C572;
  268. color: white;
  269. // margin: 0 10px;
  270. }
  271. .cost-list {
  272. margin: 20rpx;
  273. background: white;
  274. border-radius: 20rpx;
  275. padding: 20rpx;
  276. .title {
  277. font-size: 32rpx;
  278. font-weight: 500;
  279. color: #333333;
  280. }
  281. .goods-table {
  282. margin-top: 22rpx;
  283. }
  284. .goods-table-title {
  285. display: flex;
  286. border-bottom: 1px solid #EEEEEE;
  287. padding-bottom: 16rpx;
  288. // margin-bottom: ;
  289. .font {
  290. font-size: 27rpx;
  291. font-weight: 400;
  292. color: #B2B3BB;
  293. }
  294. .font:nth-of-type(1) {
  295. width: 40%;
  296. }
  297. .font:nth-of-type(2) {
  298. width: 30%;
  299. }
  300. .font:nth-of-type(3) {
  301. width: 30%;
  302. text-align: right;
  303. }
  304. }
  305. .goods-table-content {
  306. display: flex;
  307. margin: 22rpx 0;
  308. font-size: 28rpx;
  309. font-weight: 400;
  310. color: #333333;
  311. .font:nth-of-type(1) {
  312. width: 40%;
  313. }
  314. .font:nth-of-type(2) {
  315. width: 30%;
  316. }
  317. .font:nth-of-type(3) {
  318. width: 30%;
  319. text-align: right;
  320. }
  321. }
  322. }
  323. </style>