inventoryCost.vue 7.9 KB

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