inventoryCost.vue 8.7 KB

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