index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <template>
  2. <view>
  3. <u-modal :show="showModal" ref="uModal" :title="editOrAdd === 'edit' ? '编辑' : '新增'" :asyncClose="false" showCancelButton @cancel="closeDialog" cancelColor="#909399" :confirmText="'确定'" confirmColor="#2979ff" @confirm="confirm" @close="closeDialog" :closeOnClickOverlay="false">
  4. <view class="modal_wrap">
  5. <text @click="handleBrandClick" class="item" :class="info.dictLabel ? 'brand' : 'brand placeholder'">{{ info.dictLabel || '品牌' }}</text>
  6. <text class="divider">|</text>
  7. <u--input placeholder="型号" class="item" border="none" v-model="info.model" clearable @blur="handleModelBlur"></u--input>
  8. <text class="divider">|</text>
  9. <u--input class="code-input item" placeholder="编码" border="none" v-model="info.code" clearable></u--input>
  10. </view>
  11. <view class="img_wrap">
  12. <imgs-row-scroll v-if="info.imgsUrl.length > 0" :isShowDeleteIcon="true" @deleteImgInfo="getDeleteImgInfo" imgMode="aspectFill" :totalWidth="400" :images="info.imgsUrl" :previewEnabled="true" :imageWidth="150" :imageHeight="150"></imgs-row-scroll>
  13. <u-upload
  14. @afterRead="afterRead"
  15. name="3"
  16. multiple
  17. :maxCount="10"
  18. ></u-upload>
  19. </view>
  20. <u--input v-if="editOrAdd === 'edit'" class="price" placeholder="价格" border="bottom" v-model="info.price" clearable></u--input>
  21. <view class="charts_box" v-show="chartShow">
  22. <qiun-data-charts type="line" :chartData="chartData" canvasId="trendChart" :opts="opts" :ontouch="true"
  23. width="700rpx" height="200rpx" backgroundColor="#ffffff" />
  24. </view>
  25. </u-modal>
  26. <brandList ref="brandListRef" @selectedBrand="handleSelectedBrand"></brandList>
  27. </view>
  28. </template>
  29. <script>
  30. import imgsRowScroll from '@/components/imgs-row-scroll/index.vue'
  31. import brandList from '@/components/brand-list/index.vue'
  32. export default {
  33. name: 'AddInquiryDialog',
  34. components: {
  35. imgsRowScroll,
  36. brandList
  37. },
  38. props: {
  39. clueId: {
  40. type: String,
  41. default: ''
  42. },
  43. show: {
  44. type: Boolean,
  45. default: false
  46. },
  47. editOrAdd: {
  48. type: String,
  49. default: ''// edit 编辑(有价格), editForm 编辑询价单(无价格), add 新增询价单, receptFormAdd 新增接收询价单
  50. },
  51. editInfo: {
  52. type: Object,
  53. default: () => {}
  54. },
  55. type: {
  56. type: Number,
  57. default: 1
  58. },
  59. },
  60. emits: ['submitSuccess'],
  61. data() {
  62. return {
  63. showModal: false,
  64. info: {
  65. model:'',
  66. code:'',
  67. id:'',
  68. price:'',
  69. dictLabel:'',
  70. dictValue:'',
  71. imgsUrl:[]
  72. },
  73. rules: {
  74. brand: [
  75. { required: true, message: '请输入品牌', trigger: 'blur' }
  76. ]
  77. },
  78. chartData:{},
  79. opts: {
  80. color: ["#f9ae3d"],
  81. padding: [10, 10, 0, 0],
  82. dataLabel: false,
  83. dataPointShape: false,
  84. enableScroll: true,
  85. legend: {
  86. show: false
  87. },
  88. xAxis: {
  89. disableGrid: true,
  90. scrollShow: true,
  91. itemCount: 7
  92. },
  93. yAxis: {
  94. gridType: "dash",
  95. dashLength: 7,
  96. axisLabel:{
  97. show: false
  98. }
  99. },
  100. extra: {
  101. line: {
  102. type: "curve",
  103. width: 3,
  104. activeType: "hollow",
  105. linearType: "custom",
  106. onShadow: true,
  107. animation: "horizontal"
  108. }
  109. }
  110. },
  111. chartShow: false
  112. }
  113. },
  114. watch: {
  115. show: {
  116. handler(newVal) {
  117. this.showModal = newVal;
  118. },
  119. immediate: true
  120. }
  121. },
  122. methods: {
  123. // 编辑回显
  124. initData() {
  125. this.$nextTick(()=>{
  126. this.info = JSON.parse(JSON.stringify(this.editInfo))
  127. this.showModal = true;
  128. if(this.info.model && this.info.dictValue){
  129. this.getChartData()
  130. }
  131. })
  132. },
  133. // 获取删除图片信息
  134. getDeleteImgInfo(info) {
  135. this.info.imgsUrl = info.newImages
  136. },
  137. handleBrandClick() {
  138. this.$refs.brandListRef.showBrandList();
  139. },
  140. handleSelectedBrand(info) {
  141. this.info.dictLabel = info.dictLabel
  142. this.info.dictValue = info.dictValue
  143. },
  144. // 上传图片
  145. afterRead(info) {
  146. info.file.forEach(item=>{
  147. uni.$u.api.uploadFile(item.url).then((res) => {
  148. this.info.imgsUrl.push(res.data.url);
  149. uni.$u.toast("文件上传成功");
  150. }).catch(() => {
  151. uni.$u.toast("上传文件失败");
  152. })
  153. })
  154. },
  155. // 确认添加
  156. confirm() {
  157. if (!this.info.dictLabel || !this.info.dictValue) {
  158. uni.showToast({
  159. title: '请选择品牌',
  160. icon: 'none'
  161. })
  162. return
  163. }
  164. if (!this.info.model) {
  165. uni.showToast({
  166. title: '请输入型号',
  167. icon: 'none'
  168. })
  169. return
  170. }
  171. if (!this.info.code) {
  172. uni.showToast({
  173. title: '请输入编码',
  174. icon: 'none'
  175. })
  176. return
  177. }
  178. if(this.info.imgsUrl.length == 0){
  179. uni.showToast({
  180. title: '请上传图片',
  181. icon: 'none'
  182. })
  183. return
  184. }
  185. if(this.editOrAdd === 'edit' && !this.info.price){
  186. uni.showToast({
  187. title: '请输入价格',
  188. icon: 'none'
  189. })
  190. return
  191. }
  192. const data = {
  193. clueId: this.clueId,
  194. dictValue: this.info.dictValue,
  195. dictLabel: this.info.dictLabel,
  196. model: this.info.model,
  197. code: this.info.code,
  198. id: (this.editOrAdd === 'edit' || this.editOrAdd === 'editForm') ? this.info.id : '',
  199. price: this.editOrAdd === 'edit' ? this.info.price : '',
  200. imgsUrl:this.info.imgsUrl,
  201. status: this.editOrAdd === 'edit' ? '2' : '1',
  202. type: this.type
  203. }
  204. uni.$u.api.addInquiry(data).then(res => {
  205. if (res.code == 200) {
  206. uni.showToast({
  207. title: '添加成功',
  208. icon: 'success'
  209. })
  210. this.closeDialog()
  211. this.$emit('submitSuccess')
  212. }
  213. })
  214. },
  215. showDialog() {
  216. if (this.editOrAdd === 'edit' || this.editOrAdd === 'editForm' || this.editOrAdd === 'receptFormAdd') {
  217. this.initData();
  218. }else if(this.editOrAdd === 'add'){
  219. this.clearForm()
  220. this.showModal = true;
  221. }
  222. },
  223. clearForm() {
  224. this.info = {
  225. dictLabel:'',
  226. dictValue:'',
  227. model:'',
  228. code:'',
  229. id:'',
  230. price:'',
  231. imgsUrl:[]
  232. }
  233. },
  234. closeDialog() {
  235. this.showModal = false;
  236. this.chartShow = false
  237. this.chartData = {}
  238. },
  239. handleModelBlur() {
  240. if (this.info.model !== ''){
  241. this.getChartData()
  242. }
  243. },
  244. getChartData() {
  245. uni.$u.api.inquiryChart({
  246. dictValue: this.info.dictValue,
  247. model: this.info.model,
  248. }).then(res => {
  249. if (res.code == 200) {
  250. let data = {
  251. categories: res.data.map(item=>item.recycleTime),
  252. series: [
  253. {
  254. name: this.info.model+'价格趋势',
  255. data: res.data.map(item=>item.costPrice),
  256. setShadow: [
  257. 3,
  258. 8,
  259. 15,
  260. "#f9ae3d"
  261. ],
  262. }
  263. ]
  264. }
  265. this.chartData = JSON.parse(JSON.stringify(data))
  266. this.chartShow = true
  267. }
  268. })
  269. },
  270. }
  271. };
  272. </script>
  273. <style lang="scss" scoped>
  274. @import './index.scss'
  275. </style>