inventoryCost.vue 8.6 KB

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