inventoryCost.vue 6.7 KB

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