inventoryCost.vue 7.9 KB

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